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"
21 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
23 #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var));
27 /* ==l1== L2 ==L3== */
37 void test1(method_t method);
38 void test1(method_t method)
40 lmm_system_t Sys = NULL ;
41 lmm_constraint_t L1 = NULL;
42 lmm_constraint_t L2 = NULL;
43 lmm_constraint_t L3 = NULL;
45 lmm_variable_t R_1_2_3 = NULL;
46 lmm_variable_t R_1 = NULL;
47 lmm_variable_t R_2 = NULL;
48 lmm_variable_t R_3 = NULL;
50 Sys = lmm_system_new();
51 L1 = lmm_constraint_new(Sys, (void *) "L1", 1.0);
52 L2 = lmm_constraint_new(Sys, (void *) "L2", 10.0);
53 L3 = lmm_constraint_new(Sys, (void *) "L3", 1.0);
55 R_1_2_3 = lmm_variable_new(Sys, (void *) "R 1->2->3", 1.0 , -1.0 , 3);
56 R_1 = lmm_variable_new(Sys, (void *) "R 1", 1.0 , -1.0 , 1);
57 R_2 = lmm_variable_new(Sys, (void *) "R 2", 1.0 , -1.0 , 1);
58 R_3 = lmm_variable_new(Sys, (void *) "R 3", 1.0 , -1.0 , 1);
60 lmm_expand(Sys, L1, R_1_2_3, 1.0);
61 lmm_expand(Sys, L2, R_1_2_3, 1.0);
62 lmm_expand(Sys, L3, R_1_2_3, 1.0);
64 lmm_expand(Sys, L1, R_1, 1.0);
66 lmm_expand(Sys, L2, R_2, 1.0);
68 lmm_expand(Sys, L3, R_3, 1.0);
82 else if(method==LAGRANGE)
85 xbt_assert0(0,"Invalid method");
93 /* lmm_update_variable_weight(Sys,R_1_2_3,.5); */
96 /* PRINT_VAR(R_1_2_3); */
101 lmm_system_free(Sys);
104 void test2(method_t method);
105 void test2(method_t method)
107 lmm_system_t Sys = NULL ;
108 lmm_constraint_t CPU1 = NULL;
109 lmm_constraint_t CPU2 = NULL;
111 lmm_variable_t T1 = NULL;
112 lmm_variable_t T2 = NULL;
114 Sys = lmm_system_new();
115 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
116 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
118 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
119 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
121 lmm_expand(Sys, CPU1, T1, 1.0);
122 lmm_expand(Sys, CPU2, T2, 1.0);
134 else if(method==LAGRANGE)
137 xbt_assert0(0,"Invalid method");
144 lmm_system_free(Sys);
147 void test3(method_t method);
148 void test3(method_t method)
150 int flows=11; //flows and conexions are synonnims ?
151 int links=10; //topology info
153 //just to be carefull
159 lmm_system_t Sys = NULL ;
160 lmm_constraint_t *tmp_cnst = NULL;
161 lmm_variable_t *tmp_var = NULL;
165 /*array to add the the constraints of fictiv variables */
166 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
169 A = (double **)calloc(links+5, sizeof(double));
171 for(i=0 ; i< links+5; i++){
172 A[i] = (double *)calloc(flows+5, sizeof(double));
174 for(j=0 ; j< flows+5; j++){
177 if(i >= links || j >= flows){
183 /*matrix that store the constraints/topollogy*/
185 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
186 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
187 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
188 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
189 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
190 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
191 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
192 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
193 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
194 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
196 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
197 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
198 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
199 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
200 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
253 Sys = lmm_system_new();
257 * Creates the constraints
259 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
261 sprintf(tmp_name, "C_%03d", i);
262 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name, B[i]);
267 * Creates the variables
269 tmp_var = calloc(16, sizeof(lmm_variable_t));
271 sprintf(tmp_name, "X_%03d", j);
272 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name, 1.0, -1.0 , 15);
276 * Link constraints and variables
281 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
287 PRINT_VAR(tmp_var[j]);
296 else if(method==LAGRANGE)
299 xbt_assert0(0,"Invalid method");
302 PRINT_VAR(tmp_var[j]);
307 lmm_system_free(Sys);
314 int main(int argc, char **argv)
316 xbt_init(&argc,argv);
318 DEBUG0("***** Test 1 (Max-Min) ***** \n");
321 DEBUG0("***** Test 1 (SDP) ***** \n");
324 DEBUG0("***** Test 1 (Lagrange) ***** \n");
328 DEBUG0("***** Test 2 (Max-Min) ***** \n");
331 DEBUG0("***** Test 2 (SDP) ***** \n");
334 DEBUG0("***** Test 3 (Max-Min) ***** \n");
337 DEBUG0("***** Test 3 (SDP) ***** \n");