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"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
21 #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var));
25 /* ==l1== L2 ==L3== */
34 void test1(method_t method);
35 void test1(method_t method)
37 lmm_system_t Sys = NULL ;
38 lmm_constraint_t L1 = NULL;
39 lmm_constraint_t L2 = NULL;
40 lmm_constraint_t L3 = NULL;
42 lmm_variable_t R_1_2_3 = NULL;
43 lmm_variable_t R_1 = NULL;
44 lmm_variable_t R_2 = NULL;
45 lmm_variable_t R_3 = NULL;
47 Sys = lmm_system_new();
48 L1 = lmm_constraint_new(Sys, (void *) "L1", 1.0);
49 L2 = lmm_constraint_new(Sys, (void *) "L2", 10.0);
50 L3 = lmm_constraint_new(Sys, (void *) "L3", 1.0);
52 R_1_2_3 = lmm_variable_new(Sys, (void *) "R 1->2->3", 1.0 , -1.0 , 3);
53 R_1 = lmm_variable_new(Sys, (void *) "R 1", 1.0 , -1.0 , 1);
54 R_2 = lmm_variable_new(Sys, (void *) "R 2", 1.0 , -1.0 , 1);
55 R_3 = lmm_variable_new(Sys, (void *) "R 3", 1.0 , -1.0 , 1);
57 lmm_expand(Sys, L1, R_1_2_3, 1.0);
58 lmm_expand(Sys, L2, R_1_2_3, 1.0);
59 lmm_expand(Sys, L3, R_1_2_3, 1.0);
61 lmm_expand(Sys, L1, R_1, 1.0);
63 lmm_expand(Sys, L2, R_2, 1.0);
65 lmm_expand(Sys, L3, R_3, 1.0);
80 xbt_assert0(0,"Invalid method");
88 /* lmm_update_variable_weight(Sys,R_1_2_3,.5); */
91 /* PRINT_VAR(R_1_2_3); */
99 void test2(method_t method);
100 void test2(method_t method)
102 lmm_system_t Sys = NULL ;
103 lmm_constraint_t CPU1 = NULL;
104 lmm_constraint_t CPU2 = NULL;
106 lmm_variable_t T1 = NULL;
107 lmm_variable_t T2 = NULL;
109 Sys = lmm_system_new();
110 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
111 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
113 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
114 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
116 lmm_expand(Sys, CPU1, T1, 1.0);
117 lmm_expand(Sys, CPU2, T2, 1.0);
130 xbt_assert0(0,"Invalid method");
137 lmm_system_free(Sys);
140 void test3(method_t method);
141 void test3(method_t method)
143 int flows=11; //flows and conexions are synonnims ?
144 int links=10; //topology info
146 //just to be carefull
152 lmm_system_t Sys = NULL ;
153 lmm_constraint_t *tmp_cnst = NULL;
154 lmm_variable_t *tmp_var = NULL;
158 /*array to add the the constraints of fictiv variables */
159 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
162 A = (double **)calloc(links+5, sizeof(double));
164 for(i=0 ; i< links+5; i++){
165 A[i] = (double *)calloc(flows+5, sizeof(double));
167 for(j=0 ; j< flows+5; j++){
170 if(i >= links || j >= flows){
176 /*matrix that store the constraints/topollogy*/
178 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
179 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
180 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
181 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
182 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
183 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
184 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
185 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
186 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
187 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
189 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
190 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
191 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
192 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
193 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
250 Sys = lmm_system_new();
254 * Creates the constraints
256 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
258 sprintf(tmp_name, "C_%03d", i);
259 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name, B[i]);
264 * Creates the variables
266 tmp_var = calloc(16, sizeof(lmm_variable_t));
268 sprintf(tmp_name, "X_%03d", j);
269 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name, 1.0, -1.0 , 15);
273 * Link constraints and variables
278 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
284 PRINT_VAR(tmp_var[j]);
294 xbt_assert0(0,"Invalid method");
297 PRINT_VAR(tmp_var[j]);
302 lmm_system_free(Sys);
309 int main(int argc, char **argv)
311 xbt_init(&argc,argv);
313 DEBUG0("***** Test 1 (Max-Min) ***** \n");
316 DEBUG0("***** Test 1 (SDP) ***** \n");
319 DEBUG0("***** Test 2 (Max-Min) ***** \n");
322 DEBUG0("***** Test 2 (SDP) ***** \n");
325 DEBUG0("***** Test 3 (Max-Min) ***** \n");
328 DEBUG0("***** Test 3 (SDP) ***** \n");