Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added the generic method to model fairness depending on the
[simgrid.git] / testsuite / surf / simeng_usage.c
1 /*      $Id$     */
2
3 /* A few tests for the maxmin library                                       */
4
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
6
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. */
9
10 #ifdef __BORLANDC__
11 #pragma hdrstop
12 #endif
13
14 #include "xbt/sysdep.h"
15 #include "surf/maxmin.h"
16 #include "surf/maxmin_private.h"
17
18 #include "xbt/log.h"
19 #include "xbt/module.h"
20
21
22 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
23
24 #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var));
25
26 /*                               */
27 /*        ______                 */
28 /*  ==l1==  L2  ==L3==           */
29 /*        ------                 */
30 /*                               */
31
32 typedef enum {
33   MAXMIN,
34   SDP,
35   LAGRANGE_RENO,
36   LAGRANGE_VEGAS,
37 } method_t;
38
39 void test1(method_t method);
40 void test1(method_t method)
41 {
42   lmm_system_t Sys = NULL ;
43   lmm_constraint_t L1 = NULL;
44   lmm_constraint_t L2 = NULL;
45   lmm_constraint_t L3 = NULL;
46
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;
51
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);
58   }
59
60
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);
65
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);
70
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);
74
75   lmm_expand(Sys, L1, R_1, 1.0);
76
77   lmm_expand(Sys, L2, R_2, 1.0);
78
79   lmm_expand(Sys, L3, R_3, 1.0);
80
81   PRINT_VAR(R_1_2_3);
82   PRINT_VAR(R_1);
83   PRINT_VAR(R_2);
84   PRINT_VAR(R_3);
85
86   DEBUG0("\n");
87
88
89 Added the generic method to model fairness depending on the
90 transport protocol specific constraints and behavior. Protocols
91 TCP Reno and Vegas already implemented. Seems to work
92 with the testbed in src/testsuite/surf/simeng_usage. Still
93 need to be tested using a msg application.
94
95
96
97
98   if(method==MAXMIN){
99     lmm_solve(Sys);
100 #ifdef HAVE_SDP
101   }else if(method==SDP){
102     sdp_solve(Sys);    
103 #endif
104   }else if(method==LAGRANGE_VEGAS){
105     //set default functions for TCP Vegas
106     lagrange_solve(Sys);  
107   }else if(method==LAGRANGE_RENO){
108     //set default functions for TCP Reno
109     lagrange_solve(Sys);  
110   }else{ 
111     xbt_assert0(0,"Invalid method");
112   }
113
114   PRINT_VAR(R_1_2_3);
115   PRINT_VAR(R_1);
116   PRINT_VAR(R_2);
117   PRINT_VAR(R_3);
118
119   lmm_system_free(Sys);
120
121
122 void test2(method_t method);
123 void test2(method_t method)
124 {
125   lmm_system_t Sys = NULL ;
126   lmm_constraint_t CPU1 = NULL;
127   lmm_constraint_t CPU2 = NULL;
128
129   lmm_variable_t T1 = NULL;
130   lmm_variable_t T2 = NULL;
131
132
133   if(method==LAGRANGE_VEGAS){
134     //set default functions for TCP Vegas
135     lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
136   }else if(method==LAGRANGE_RENO){
137     //set default functions for TCP Reno
138     lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
139   }
140
141   Sys = lmm_system_new();
142   CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
143   CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
144
145   T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
146   T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
147
148   lmm_expand(Sys, CPU1, T1, 1.0);
149   lmm_expand(Sys, CPU2, T2, 1.0);
150
151   PRINT_VAR(T1);
152   PRINT_VAR(T2);
153
154   DEBUG0("\n");
155
156
157   if(method==MAXMIN){
158     lmm_solve(Sys);
159 #ifdef HAVE_SDP
160   }else if(method==SDP){
161     sdp_solve(Sys);    
162 #endif
163   }else if(method==LAGRANGE_VEGAS){
164     //set default functions for TCP Vegas
165     lagrange_solve(Sys);  
166   }else if(method==LAGRANGE_RENO){
167     //set default functions for TCP Reno
168     lagrange_solve(Sys);  
169   }else{ 
170     xbt_assert0(0,"Invalid method");
171   }
172
173   PRINT_VAR(T1);
174   PRINT_VAR(T2);
175
176   DEBUG0("\n");
177
178   lmm_system_free(Sys);
179 }
180
181 void test3(method_t method);
182 void test3(method_t method)
183 {
184   int flows=11;  //flows and conexions are synonnims ?
185   int links=10;  //topology info
186   
187   //just to be carefull
188   int i = 0;
189   int j = 0;
190
191   double **A;
192
193   lmm_system_t Sys = NULL ;
194   lmm_constraint_t *tmp_cnst = NULL;
195   lmm_variable_t   *tmp_var  = NULL;
196   char **tmp_name;
197
198
199   /*array to add the the constraints of fictiv variables */
200   double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
201
202                 1, 1, 1, 1, 1};
203
204   A = (double **)calloc(links+5, sizeof(double));
205  
206   for(i=0 ; i< links+5; i++){
207     A[i] = (double *)calloc(flows+5, sizeof(double));
208
209     for(j=0 ; j< flows+5; j++){
210       A[i][j] = 0.0;
211
212       if(i >= links || j >= flows){
213           A[i][j] = 0.0;
214       }
215     }
216   }
217
218   /*matrix that store the constraints/topollogy*/
219   /*double A[15][16]=
220     {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,    0, 0, 0, 0, 0},
221      {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0,    0, 0, 0, 0, 0},
222      {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,    0, 0, 0, 0, 0},
223      {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,    0, 0, 0, 0, 0},
224      {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,    0, 0, 0, 0, 0},
225      {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0,    0, 0, 0, 0, 0},
226      {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1,    0, 0, 0, 0, 0},
227      {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1,    0, 0, 0, 0, 0},
228      {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,    0, 0, 0, 0, 0},
229      {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0,    0, 0, 0, 0, 0},
230      
231      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    1, 0, 0, 0, 0},
232      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    0, 1, 0, 0, 0},
233      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    0, 0, 1, 0, 0},
234      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    0, 0, 0, 1, 0},
235      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    0, 0, 0, 0, 1}
236      }; */
237
238   A[0][1]  = 1.0;
239   A[0][7]  = 1.0;
240   
241   A[1][1]  = 1.0;
242   A[1][7]  = 1.0;
243   A[1][8]  = 1.0;
244
245   A[2][1]  = 1.0;
246   A[2][8]  = 1.0;
247
248   A[2][1]  = 1.0;
249   A[2][8]  = 1.0;
250
251   A[3][8]  = 1.0;
252
253   A[4][0]  = 1.0;
254   A[4][3]  = 1.0;
255   A[4][9]  = 1.0;
256
257   A[5][0]  = 1.0;
258   A[5][3]  = 1.0;
259   A[5][4]  = 1.0;
260   A[5][9]  = 1.0;
261
262   A[6][0]  = 1.0;
263   A[6][4]  = 1.0;
264   A[6][9]  = 1.0;
265   A[6][10] = 1.0;
266
267   A[7][2]  = 1.0;
268   A[7][4]  = 1.0;
269   A[7][6]  = 1.0;
270   A[7][9]  = 1.0;
271   A[7][10] = 1.0;
272
273   A[8][2]  = 1.0;
274   A[8][10] = 1.0;
275
276   A[9][5]  = 1.0;
277   A[9][6]  = 1.0;
278   A[9][9]  = 1.0;
279
280   
281   A[10][11] = 1.0;
282   A[11][12] = 1.0;
283   A[12][13] = 1.0;
284   A[13][14] = 1.0;
285   A[14][15] = 1.0;
286
287
288   if(method==LAGRANGE_VEGAS){
289     //set default functions for TCP Vegas
290     lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
291   }else if(method==LAGRANGE_RENO){
292     //set default functions for TCP Reno
293     lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
294   }
295
296   Sys = lmm_system_new();
297   
298
299
300   tmp_name = (char **) calloc(31, sizeof(char *));
301   for(i=0; i<31; i++){
302     tmp_name[i] = (char *) calloc(10, sizeof(char));
303   }
304   
305   /*
306    * Creates the constraints
307    */
308   tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
309   for(i=0; i<15; i++){
310     sprintf(tmp_name[i], "C_%03d", i); 
311     tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name[i], B[i]);
312   }
313
314
315   /*
316    * Creates the variables
317    */
318   tmp_var = calloc(16, sizeof(lmm_variable_t));
319   for(j=0; j<16; j++){
320     sprintf(tmp_name[i+j], "X_%03d", j); 
321     tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name[i+j], 1.0, -1.0 , 15);
322   }
323
324   /*
325    * Link constraints and variables
326    */
327   for(i=0;i<15;i++) { 
328     for(j=0; j<16; j++){
329       if(A[i][j]){
330         lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0); 
331       }
332     }
333   }
334
335
336   lmm_print(Sys);
337
338
339   for(j=0; j<16; j++){
340     PRINT_VAR(tmp_var[j]);
341   }
342
343   if(method==MAXMIN){
344     lmm_solve(Sys);
345 #ifdef HAVE_SDP
346   }else if(method==SDP){
347     sdp_solve(Sys);    
348 #endif
349   }else if(method==LAGRANGE_VEGAS){
350     //set default functions for TCP Vegas
351     lagrange_solve(Sys);  
352   }else if(method==LAGRANGE_RENO){
353     //set default functions for TCP Reno
354     lagrange_solve(Sys);  
355   }else{ 
356     xbt_assert0(0,"Invalid method");
357   }
358
359   for(j=0; j<16; j++){
360     PRINT_VAR(tmp_var[j]);
361   }
362
363   free(tmp_var);
364   free(tmp_cnst);
365   free(tmp_name);
366   lmm_system_free(Sys);
367 }
368
369 #ifdef __BORLANDC__
370 #pragma argsused
371 #endif
372
373 int main(int argc, char **argv)
374 {
375   xbt_init(&argc,argv);
376
377   DEBUG0("***** Test 1 (Max-Min) ***** \n");
378   test1(MAXMIN);
379 #ifdef HAVE_SDP
380   DEBUG0("***** Test 1 (SDP) ***** \n");
381   test1(SDP);
382 #endif
383   DEBUG0("***** Test 1 (Lagrange - Vegas) ***** \n");
384   test1(LAGRANGE_VEGAS);
385   DEBUG0("***** Test 1 (Lagrange - Reno) ***** \n");
386   test1(LAGRANGE_RENO);
387
388
389
390   DEBUG0("***** Test 2 (Max-Min) ***** \n");
391   test2(MAXMIN);
392 #ifdef HAVE_SDP
393   DEBUG0("***** Test 2 (SDP) ***** \n");
394   test2(SDP);
395 #endif
396   DEBUG0("***** Test 2 (Lagrange - Vegas) ***** \n");
397   test2(LAGRANGE_VEGAS);
398   DEBUG0("***** Test 2 (Lagrange - Reno) ***** \n");
399   test2(LAGRANGE_RENO);
400
401
402   DEBUG0("***** Test 3 (Max-Min) ***** \n");
403   test3(MAXMIN);
404 #ifdef HAVE_SDP
405   DEBUG0("***** Test 3 (SDP) ***** \n");
406   test3(SDP);
407 #endif 
408   DEBUG0("***** Test 3 (Lagrange - Vegas) ***** \n");
409   test3(LAGRANGE_VEGAS);
410   DEBUG0("***** Test 3 (Lagrange - Reno) ***** \n"); 
411   test3(LAGRANGE_RENO); 
412
413   return 0;
414 }