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"
16 #include "surf/maxmin_private.h"
19 #include "xbt/module.h"
22 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
24 #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var));
28 /* ==l1== L2 ==L3== */
38 void test1(method_t method);
39 void test1(method_t method)
41 lmm_system_t Sys = NULL ;
42 lmm_constraint_t L1 = NULL;
43 lmm_constraint_t L2 = NULL;
44 lmm_constraint_t L3 = NULL;
46 lmm_variable_t R_1_2_3 = NULL;
47 lmm_variable_t R_1 = NULL;
48 lmm_variable_t R_2 = NULL;
49 lmm_variable_t R_3 = NULL;
51 Sys = lmm_system_new();
52 L1 = lmm_constraint_new(Sys, (void *) "L1", 1.0);
53 L2 = lmm_constraint_new(Sys, (void *) "L2", 10.0);
54 L3 = lmm_constraint_new(Sys, (void *) "L3", 1.0);
56 R_1_2_3 = lmm_variable_new(Sys, (void *) "R 1->2->3", 1.0 , -1.0 , 3);
57 R_1 = lmm_variable_new(Sys, (void *) "R 1", 1.0 , -1.0 , 1);
58 R_2 = lmm_variable_new(Sys, (void *) "R 2", 1.0 , -1.0 , 1);
59 R_3 = lmm_variable_new(Sys, (void *) "R 3", 1.0 , -1.0 , 1);
61 lmm_expand(Sys, L1, R_1_2_3, 1.0);
62 lmm_expand(Sys, L2, R_1_2_3, 1.0);
63 lmm_expand(Sys, L3, R_1_2_3, 1.0);
65 lmm_expand(Sys, L1, R_1, 1.0);
67 lmm_expand(Sys, L2, R_2, 1.0);
69 lmm_expand(Sys, L3, R_3, 1.0);
83 else if(method==LAGRANGE)
86 xbt_assert0(0,"Invalid method");
96 void test2(method_t method);
97 void test2(method_t method)
99 lmm_system_t Sys = NULL ;
100 lmm_constraint_t CPU1 = NULL;
101 lmm_constraint_t CPU2 = NULL;
103 lmm_variable_t T1 = NULL;
104 lmm_variable_t T2 = NULL;
106 Sys = lmm_system_new();
107 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
108 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
110 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
111 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
113 lmm_expand(Sys, CPU1, T1, 1.0);
114 lmm_expand(Sys, CPU2, T2, 1.0);
126 else if(method==LAGRANGE)
129 xbt_assert0(0,"Invalid method");
136 lmm_system_free(Sys);
139 void test3(method_t method);
140 void test3(method_t method)
142 int flows=11; //flows and conexions are synonnims ?
143 int links=10; //topology info
145 //just to be carefull
151 lmm_system_t Sys = NULL ;
152 lmm_constraint_t *tmp_cnst = NULL;
153 lmm_variable_t *tmp_var = NULL;
157 /*array to add the the constraints of fictiv variables */
158 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
161 A = (double **)calloc(links+5, sizeof(double));
163 for(i=0 ; i< links+5; i++){
164 A[i] = (double *)calloc(flows+5, sizeof(double));
166 for(j=0 ; j< flows+5; j++){
169 if(i >= links || j >= flows){
175 /*matrix that store the constraints/topollogy*/
177 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
178 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
179 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
180 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
181 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
182 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
183 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
184 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
185 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
186 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
188 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
189 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
190 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
191 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
192 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
245 Sys = lmm_system_new();
249 tmp_name = (char **) calloc(31, sizeof(char *));
251 tmp_name[i] = (char *) calloc(10, sizeof(char));
255 * Creates the constraints
257 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
259 sprintf(tmp_name[i], "C_%03d", i);
260 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name[i], B[i]);
265 * Creates the variables
267 tmp_var = calloc(16, sizeof(lmm_variable_t));
269 sprintf(tmp_name[i+j], "X_%03d", j);
270 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name[i+j], 1.0, -1.0 , 15);
274 * Link constraints and variables
279 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
289 PRINT_VAR(tmp_var[j]);
298 else if(method==LAGRANGE)
301 xbt_assert0(0,"Invalid method");
304 PRINT_VAR(tmp_var[j]);
310 lmm_system_free(Sys);
317 int main(int argc, char **argv)
319 xbt_init(&argc,argv);
321 /* DEBUG0("***** Test 1 (Max-Min) ***** \n"); */
323 /* #ifdef HAVE_SDP */
324 /* DEBUG0("***** Test 1 (SDP) ***** \n"); */
327 /* DEBUG0("***** Test 1 (Lagrange - dicotomi) ***** \n"); */
328 /* test1(LAGRANGE); */
331 /* DEBUG0("***** Test 2 (Max-Min) ***** \n"); */
333 /* #ifdef HAVE_SDP */
334 /* DEBUG0("***** Test 2 (SDP) ***** \n"); */
337 /* DEBUG0("***** Test 2 (Lagrange) ***** \n"); */
338 /* test2(LAGRANGE); */
341 /* DEBUG0("***** Test 3 (Max-Min) ***** \n"); */
344 DEBUG0("***** Test 3 (SDP) ***** \n");
347 DEBUG0("***** Test 3 (Lagrange) ***** \n");