3 /* A few tests for the maxmin library */
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
14 #include "xbt/sysdep.h"
15 #include "surf/maxmin.h"
18 #include "xbt/module.h"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
21 #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var));
25 /* ==l1== L2 ==L3== */
34 void test1(method_t method);
35 void test1(method_t method)
37 lmm_system_t Sys = NULL ;
38 lmm_constraint_t L1 = NULL;
39 lmm_constraint_t L2 = NULL;
40 lmm_constraint_t L3 = NULL;
42 lmm_variable_t R_1_2_3 = NULL;
43 lmm_variable_t R_1 = NULL;
44 lmm_variable_t R_2 = NULL;
45 lmm_variable_t R_3 = NULL;
47 Sys = lmm_system_new();
48 L1 = lmm_constraint_new(Sys, (void *) "L1", 1.0);
49 L2 = lmm_constraint_new(Sys, (void *) "L2", 10.0);
50 L3 = lmm_constraint_new(Sys, (void *) "L3", 1.0);
52 R_1_2_3 = lmm_variable_new(Sys, (void *) "R 1->2->3", 1.0 , -1.0 , 3);
53 R_1 = lmm_variable_new(Sys, (void *) "R 1", 1.0 , -1.0 , 1);
54 R_2 = lmm_variable_new(Sys, (void *) "R 2", 1.0 , -1.0 , 1);
55 R_3 = lmm_variable_new(Sys, (void *) "R 3", 1.0 , -1.0 , 1);
57 lmm_expand(Sys, L1, R_1_2_3, 1.0);
58 lmm_expand(Sys, L2, R_1_2_3, 1.0);
59 lmm_expand(Sys, L3, R_1_2_3, 1.0);
61 lmm_expand(Sys, L1, R_1, 1.0);
63 lmm_expand(Sys, L2, R_2, 1.0);
65 lmm_expand(Sys, L3, R_3, 1.0);
80 xbt_assert0(0,"Invalid method");
88 /* lmm_update_variable_weight(Sys,R_1_2_3,.5); */
91 /* PRINT_VAR(R_1_2_3); */
99 void test2(method_t method);
100 void test2(method_t method)
102 lmm_system_t Sys = NULL ;
103 lmm_constraint_t CPU1 = NULL;
104 lmm_constraint_t CPU2 = NULL;
106 lmm_variable_t T1 = NULL;
107 lmm_variable_t T2 = NULL;
109 Sys = lmm_system_new();
110 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
111 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
113 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
114 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
116 lmm_expand(Sys, CPU1, T1, 1.0);
117 lmm_expand(Sys, CPU2, T2, 1.0);
130 xbt_assert0(0,"Invalid method");
137 lmm_system_free(Sys);
140 void test3(method_t method);
141 void test3(method_t method)
143 int flows=11; //flows and conexions are synonnims ?
144 int links=10; //topology info
146 //just to be carefull
151 A = (double **)calloc(links+5, sizeof(double));
153 for(i=0 ; i< links+5; i++){
154 A[i] = (double *)calloc(flows+5, sizeof(double));
156 for(j=0 ; j< flows+5; j++){
159 if(i >= links || j >= flows){
165 //matrix that store the constraints/topollogy
167 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
168 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
169 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
170 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
171 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
172 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
173 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
174 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
175 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
176 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
178 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
179 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
180 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
181 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
182 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
234 //array to add the the constraints of fictiv variables
235 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
239 lmm_system_t Sys = NULL ;
240 lmm_constraint_t *tmp_cnst = NULL;
241 lmm_variable_t *tmp_var = NULL;
245 Sys = lmm_system_new();
249 * Creates the constraints
251 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
253 sprintf(tmp_name, "C_%03d", i);
254 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name, B[i]);
259 * Creates the variables
261 tmp_var = calloc(16, sizeof(lmm_variable_t));
263 sprintf(tmp_name, "X_%03d", j);
264 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name, 1.0, -1.0 , 15);
268 * Link constraints and variables
273 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
279 PRINT_VAR(tmp_var[j]);
289 xbt_assert0(0,"Invalid method");
292 PRINT_VAR(tmp_var[j]);
297 lmm_system_free(Sys);
304 int main(int argc, char **argv)
306 xbt_init(&argc,argv);
308 DEBUG0("***** Test 1 (Max-Min) ***** \n");
311 DEBUG0("***** Test 1 (SDP) ***** \n");
314 DEBUG0("***** Test 2 (Max-Min) ***** \n");
317 DEBUG0("***** Test 2 (SDP) ***** \n");
320 DEBUG0("***** Test 3 (Max-Min) ***** \n");
323 DEBUG0("***** Test 3 (SDP) ***** \n");