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== */
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)
85 else if(method==LAGRANGEDICO)
86 lagrange_dicotomi_solve(Sys);
88 xbt_assert0(0,"Invalid method");
96 /* lmm_update_variable_weight(Sys,R_1_2_3,.5); */
99 /* PRINT_VAR(R_1_2_3); */
100 /* PRINT_VAR(R_1); */
101 /* PRINT_VAR(R_2); */
102 /* PRINT_VAR(R_3); */
104 lmm_system_free(Sys);
107 void test2(method_t method);
108 void test2(method_t method)
110 lmm_system_t Sys = NULL ;
111 lmm_constraint_t CPU1 = NULL;
112 lmm_constraint_t CPU2 = NULL;
114 lmm_variable_t T1 = NULL;
115 lmm_variable_t T2 = NULL;
117 Sys = lmm_system_new();
118 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
119 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
121 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
122 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
124 lmm_expand(Sys, CPU1, T1, 1.0);
125 lmm_expand(Sys, CPU2, T2, 1.0);
137 else if(method==LAGRANGE)
140 xbt_assert0(0,"Invalid method");
147 lmm_system_free(Sys);
150 void test3(method_t method);
151 void test3(method_t method)
153 int flows=11; //flows and conexions are synonnims ?
154 int links=10; //topology info
156 //just to be carefull
162 lmm_system_t Sys = NULL ;
163 lmm_constraint_t *tmp_cnst = NULL;
164 lmm_variable_t *tmp_var = NULL;
168 /*array to add the the constraints of fictiv variables */
169 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
172 A = (double **)calloc(links+5, sizeof(double));
174 for(i=0 ; i< links+5; i++){
175 A[i] = (double *)calloc(flows+5, sizeof(double));
177 for(j=0 ; j< flows+5; j++){
180 if(i >= links || j >= flows){
186 /*matrix that store the constraints/topollogy*/
188 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
189 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
190 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
191 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
192 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
193 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
194 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
195 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
196 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
197 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
199 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
200 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
201 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
202 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
203 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
256 Sys = lmm_system_new();
260 * Creates the constraints
262 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
264 sprintf(tmp_name, "C_%03d", i);
265 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name, B[i]);
270 * Creates the variables
272 tmp_var = calloc(16, sizeof(lmm_variable_t));
274 sprintf(tmp_name, "X_%03d", j);
275 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name, 1.0, -1.0 , 15);
279 * Link constraints and variables
284 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
290 PRINT_VAR(tmp_var[j]);
299 else if(method==LAGRANGE)
302 xbt_assert0(0,"Invalid method");
305 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"); */
324 DEBUG0("***** Test 1 (SDP) ***** \n");
327 DEBUG0("***** Test 1 (Lagrange - dicotomi) ***** \n");
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); */
342 /* DEBUG0("***** Test 3 (Max-Min) ***** \n"); */
344 /* #ifdef HAVE_SDP */
345 /* DEBUG0("***** Test 3 (SDP) ***** \n"); */
348 /* DEBUG0("***** Test 3 (Lagrange) ***** \n"); */
349 /* test3(LAGRANGE); */