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== */
39 void test1(method_t method);
40 void test1(method_t method)
42 lmm_system_t Sys = NULL ;
43 lmm_constraint_t L1 = NULL;
44 lmm_constraint_t L2 = NULL;
45 lmm_constraint_t L3 = NULL;
47 lmm_variable_t R_1_2_3 = NULL;
48 lmm_variable_t R_1 = NULL;
49 lmm_variable_t R_2 = NULL;
50 lmm_variable_t R_3 = NULL;
52 if(method==LAGRANGE_VEGAS){
53 //set default functions for TCP Vegas
54 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
55 }else if(method==LAGRANGE_RENO){
56 //set default functions for TCP Reno
57 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
61 Sys = lmm_system_new();
62 L1 = lmm_constraint_new(Sys, (void *) "L1", 1.0);
63 L2 = lmm_constraint_new(Sys, (void *) "L2", 10.0);
64 L3 = lmm_constraint_new(Sys, (void *) "L3", 1.0);
66 R_1_2_3 = lmm_variable_new(Sys, (void *) "R 1->2->3", 1.0 , -1.0 , 3);
67 R_1 = lmm_variable_new(Sys, (void *) "R 1", 1.0 , -1.0 , 1);
68 R_2 = lmm_variable_new(Sys, (void *) "R 2", 1.0 , -1.0 , 1);
69 R_3 = lmm_variable_new(Sys, (void *) "R 3", 1.0 , -1.0 , 1);
71 lmm_expand(Sys, L1, R_1_2_3, 1.0);
72 lmm_expand(Sys, L2, R_1_2_3, 1.0);
73 lmm_expand(Sys, L3, R_1_2_3, 1.0);
75 lmm_expand(Sys, L1, R_1, 1.0);
77 lmm_expand(Sys, L2, R_2, 1.0);
79 lmm_expand(Sys, L3, R_3, 1.0);
85 }else if(method==SDP){
88 }else if(method==LAGRANGE_VEGAS){
89 //set default functions for TCP Vegas
91 }else if(method==LAGRANGE_RENO){
92 //set default functions for TCP Reno
95 xbt_assert0(0,"Invalid method");
103 lmm_system_free(Sys);
106 void test2(method_t method);
107 void test2(method_t method)
109 lmm_system_t Sys = NULL ;
110 lmm_constraint_t CPU1 = NULL;
111 lmm_constraint_t CPU2 = NULL;
113 lmm_variable_t T1 = NULL;
114 lmm_variable_t T2 = NULL;
117 if(method==LAGRANGE_VEGAS){
118 //set default functions for TCP Vegas
119 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
120 }else if(method==LAGRANGE_RENO){
121 //set default functions for TCP Reno
122 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
125 Sys = lmm_system_new();
126 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
127 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
129 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
130 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
132 lmm_expand(Sys, CPU1, T1, 1.0);
133 lmm_expand(Sys, CPU2, T2, 1.0);
140 }else if(method==SDP){
143 }else if(method==LAGRANGE_VEGAS){
144 //set default functions for TCP Vegas
146 }else if(method==LAGRANGE_RENO){
147 //set default functions for TCP Reno
150 xbt_assert0(0,"Invalid method");
158 lmm_system_free(Sys);
161 void test3(method_t method);
162 void test3(method_t method)
164 int flows=11; //flows and conexions are synonnims ?
165 int links=10; //topology info
167 //just to be carefull
173 lmm_system_t Sys = NULL ;
174 lmm_constraint_t *tmp_cnst = NULL;
175 lmm_variable_t *tmp_var = NULL;
179 /*array to add the the constraints of fictiv variables */
180 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
184 A = (double **)calloc(links+5, sizeof(double));
186 for(i=0 ; i< links+5; i++){
187 A[i] = (double *)calloc(flows+5, sizeof(double));
189 for(j=0 ; j< flows+5; j++){
192 if(i >= links || j >= flows){
198 /*matrix that store the constraints/topollogy*/
200 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
201 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
202 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
203 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
204 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
205 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
206 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
207 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
208 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
209 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
211 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
212 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
213 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
214 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
215 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
268 if(method==LAGRANGE_VEGAS){
269 //set default functions for TCP Vegas
270 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
271 }else if(method==LAGRANGE_RENO){
272 //set default functions for TCP Reno
273 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
276 Sys = lmm_system_new();
280 tmp_name = (char **) calloc(31, sizeof(char *));
282 tmp_name[i] = (char *) calloc(10, sizeof(char));
286 * Creates the constraints
288 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
290 sprintf(tmp_name[i], "C_%03d", i);
291 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name[i], B[i]);
296 * Creates the variables
298 tmp_var = calloc(16, sizeof(lmm_variable_t));
300 sprintf(tmp_name[i+j], "X_%03d", j);
301 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name[i+j], 1.0, -1.0 , 15);
305 * Link constraints and variables
310 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
320 }else if(method==SDP){
323 }else if(method==LAGRANGE_VEGAS){
324 //set default functions for TCP Vegas
326 }else if(method==LAGRANGE_RENO){
327 //set default functions for TCP Reno
330 xbt_assert0(0,"Invalid method");
334 PRINT_VAR(tmp_var[j]);
340 lmm_system_free(Sys);
347 int main(int argc, char **argv)
349 xbt_init(&argc,argv);
352 DEBUG0("**************************** \n");
353 DEBUG0("***** ***** \n");
354 DEBUG0("***** TEST 1 ***** \n");
355 DEBUG0("***** ***** \n");
356 DEBUG0("**************************** \n");
359 DEBUG0("***** Test 1 (Max-Min) ***** \n");
362 DEBUG0("***** Test 1 (SDP) ***** \n");
365 DEBUG0("***** Test 1 (Lagrange - Vegas) ***** \n");
366 test1(LAGRANGE_VEGAS);
367 DEBUG0("***** Test 1 (Lagrange - Reno) ***** \n");
368 test1(LAGRANGE_RENO);
371 DEBUG0("**************************** \n");
372 DEBUG0("***** ***** \n");
373 DEBUG0("***** TEST 2 ***** \n");
374 DEBUG0("***** ***** \n");
375 DEBUG0("**************************** \n");
378 DEBUG0("***** Test 2 (Max-Min) ***** \n");
381 DEBUG0("***** Test 2 (SDP) ***** \n");
384 DEBUG0("***** Test 2 (Lagrange - Vegas) ***** \n");
385 test2(LAGRANGE_VEGAS);
386 DEBUG0("***** Test 2 (Lagrange - Reno) ***** \n");
387 test2(LAGRANGE_RENO);
391 DEBUG0("**************************** \n");
392 DEBUG0("***** ***** \n");
393 DEBUG0("***** TEST 3 ***** \n");
394 DEBUG0("***** ***** \n");
395 DEBUG0("**************************** \n");
398 DEBUG0("***** Test 3 (Max-Min) ***** \n");
401 DEBUG0("***** Test 3 (SDP) ***** \n");
404 DEBUG0("***** Test 3 (Lagrange - Vegas) ***** \n");
405 test3(LAGRANGE_VEGAS);
406 DEBUG0("***** Test 3 (Lagrange - Reno) ***** \n");
407 test3(LAGRANGE_RENO);