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);
92 }else if(method==SDP){
95 }else if(method==LAGRANGE_VEGAS){
96 //set default functions for TCP Vegas
98 }else if(method==LAGRANGE_RENO){
99 //set default functions for TCP Reno
102 xbt_assert0(0,"Invalid method");
110 lmm_system_free(Sys);
113 void test2(method_t method);
114 void test2(method_t method)
116 lmm_system_t Sys = NULL ;
117 lmm_constraint_t CPU1 = NULL;
118 lmm_constraint_t CPU2 = NULL;
120 lmm_variable_t T1 = NULL;
121 lmm_variable_t T2 = NULL;
124 if(method==LAGRANGE_VEGAS){
125 //set default functions for TCP Vegas
126 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
127 }else if(method==LAGRANGE_RENO){
128 //set default functions for TCP Reno
129 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
132 Sys = lmm_system_new();
133 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
134 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
136 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
137 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
139 lmm_expand(Sys, CPU1, T1, 1.0);
140 lmm_expand(Sys, CPU2, T2, 1.0);
151 }else if(method==SDP){
154 }else if(method==LAGRANGE_VEGAS){
155 //set default functions for TCP Vegas
157 }else if(method==LAGRANGE_RENO){
158 //set default functions for TCP Reno
161 xbt_assert0(0,"Invalid method");
169 lmm_system_free(Sys);
172 void test3(method_t method);
173 void test3(method_t method)
175 int flows=11; //flows and conexions are synonnims ?
176 int links=10; //topology info
178 //just to be carefull
184 lmm_system_t Sys = NULL ;
185 lmm_constraint_t *tmp_cnst = NULL;
186 lmm_variable_t *tmp_var = NULL;
190 /*array to add the the constraints of fictiv variables */
191 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
195 A = (double **)calloc(links+5, sizeof(double));
197 for(i=0 ; i< links+5; i++){
198 A[i] = (double *)calloc(flows+5, sizeof(double));
200 for(j=0 ; j< flows+5; j++){
203 if(i >= links || j >= flows){
209 /*matrix that store the constraints/topollogy*/
211 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
212 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
213 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
214 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
215 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
216 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
217 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
218 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
219 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
220 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
222 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
223 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
224 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
225 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
226 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
279 if(method==LAGRANGE_VEGAS){
280 //set default functions for TCP Vegas
281 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
282 }else if(method==LAGRANGE_RENO){
283 //set default functions for TCP Reno
284 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
287 Sys = lmm_system_new();
291 tmp_name = (char **) calloc(31, sizeof(char *));
293 tmp_name[i] = (char *) calloc(10, sizeof(char));
297 * Creates the constraints
299 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
301 sprintf(tmp_name[i], "C_%03d", i);
302 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name[i], B[i]);
307 * Creates the variables
309 tmp_var = calloc(16, sizeof(lmm_variable_t));
311 sprintf(tmp_name[i+j], "X_%03d", j);
312 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name[i+j], 1.0, -1.0 , 15);
316 * Link constraints and variables
321 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
331 PRINT_VAR(tmp_var[j]);
337 }else if(method==SDP){
340 }else if(method==LAGRANGE_VEGAS){
341 //set default functions for TCP Vegas
343 }else if(method==LAGRANGE_RENO){
344 //set default functions for TCP Reno
347 xbt_assert0(0,"Invalid method");
351 PRINT_VAR(tmp_var[j]);
357 lmm_system_free(Sys);
364 int main(int argc, char **argv)
366 xbt_init(&argc,argv);
370 DEBUG0("***** Test 1 (Max-Min) ***** \n");
373 DEBUG0("***** Test 1 (SDP) ***** \n");
376 DEBUG0("***** Test 1 (Lagrange - Vegas) ***** \n");
377 test1(LAGRANGE_VEGAS);
378 DEBUG0("***** Test 1 (Lagrange - Reno) ***** \n");
379 test1(LAGRANGE_RENO);
381 DEBUG0("***** Test 2 (Max-Min) ***** \n");
384 DEBUG0("***** Test 2 (SDP) ***** \n");
387 DEBUG0("***** Test 2 (Lagrange - Vegas) ***** \n");
388 test2(LAGRANGE_VEGAS);
389 DEBUG0("***** Test 2 (Lagrange - Reno) ***** \n");
390 test2(LAGRANGE_RENO);
392 DEBUG0("***** Test 3 (Max-Min) ***** \n");
395 DEBUG0("***** Test 3 (SDP) ***** \n");
398 DEBUG0("***** Test 3 (Lagrange - Vegas) ***** \n");
399 test3(LAGRANGE_VEGAS);
400 DEBUG0("***** Test 3 (Lagrange - Reno) ***** \n");
401 test3(LAGRANGE_RENO);