X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/40b9540a553006e50628eb13c451c354a0671d3e..2dc4cabe32926d0c2a8be832f87cbca916d638f8:/testsuite/surf/lmm_usage.c diff --git a/testsuite/surf/lmm_usage.c b/testsuite/surf/lmm_usage.c index 3b534d9f48..5e8f6ab63a 100644 --- a/testsuite/surf/lmm_usage.c +++ b/testsuite/surf/lmm_usage.c @@ -1,8 +1,7 @@ -/* $Id$ */ - /* A few tests for the maxmin library */ -/* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */ +/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -18,7 +17,7 @@ #include XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, - "Messages specific for surf example"); + "Messages specific for surf example"); #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var)); #define SHOW_EXPR(expr) DEBUG1(#expr " = %g",expr); @@ -31,13 +30,12 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, typedef enum { MAXMIN, - SDP, LAGRANGE_RENO, LAGRANGE_VEGAS, } method_t; static double dichotomy(double func(double), double min, double max, - double min_error) + double min_error) { double middle; double min_func, max_func, middle_func; @@ -59,7 +57,7 @@ static double dichotomy(double func(double), double min, double max, while (overall_error > min_error) { SHOW_EXPR(overall_error); if ((min_func > 0 && max_func > 0) || - (min_func < 0 && max_func < 0) || (min_func > 0 && max_func < 0)) { + (min_func < 0 && max_func < 0) || (min_func > 0 && max_func < 0)) { abort(); } @@ -83,7 +81,7 @@ static double dichotomy(double func(double), double min, double max, } else if (middle_func > 0) { max = middle; max_func = middle_func; - overall_error = middle_func-min_func; + overall_error = middle_func - min_func; } else { overall_error = 0; } @@ -96,10 +94,10 @@ double b_test_1 = 0; static double diff_lagrange_test_1(double x) { return -(3 / (1 + 3 * x * x / 2) - - 3 / (2 * (3 * (a_test_1 - x) * (a_test_1 - x) / 2 + 1)) + - 3 / (2 * - (3 * (b_test_1 - a_test_1 + x) * - (b_test_1 - a_test_1 + x) / 2 + 1))); + 3 / (2 * (3 * (a_test_1 - x) * (a_test_1 - x) / 2 + 1)) + + 3 / (2 * + (3 * (b_test_1 - a_test_1 + x) * + (b_test_1 - a_test_1 + x) / 2 + 1))); } void test1(method_t method); @@ -119,10 +117,10 @@ void test1(method_t method) if (method == LAGRANGE_VEGAS) lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, - func_vegas_fpi); + func_vegas_fpi); else if (method == LAGRANGE_RENO) lmm_set_default_protocol_function(func_reno_f, func_reno_fpi, - func_reno_fpi); + func_reno_fpi); Sys = lmm_system_new(); L1 = lmm_constraint_new(Sys, (void *) "L1", a); @@ -152,13 +150,9 @@ void test1(method_t method) if (method == MAXMIN) { lmm_solve(Sys); -#ifdef HAVE_SDP - } else if (method == SDP) { - sdp_solve(Sys); -#endif } else if (method == LAGRANGE_VEGAS) { double x = 3 * a / 4 - 3 * b / 8 + - sqrt(9 * b * b + 4 * a * a - 4 * a * b) / 8; + sqrt(9 * b * b + 4 * a * a - 4 * a * b) / 8; /* Computed with mupad and D_f=1.0 */ double max_deviation = 0.0; if (x > a) { @@ -171,25 +165,25 @@ void test1(method_t method) lagrange_solve(Sys); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); if (max_deviation > MAXMIN_PRECISION) { WARN1("Max Deviation from optimal solution : %g", max_deviation); WARN1("Found x = %1.20f", x); WARN2("Deviation from optimal solution (R_1 = %g): %1.20f", x, - lmm_variable_getvalue(R_1) - x); + lmm_variable_getvalue(R_1) - x); WARN2("Deviation from optimal solution (R_2 = %g): %1.20f", - b - a + x, lmm_variable_getvalue(R_2) - (b - a + x)); + b - a + x, lmm_variable_getvalue(R_2) - (b - a + x)); WARN2("Deviation from optimal solution (R_3 = %g): %1.20f", x, - lmm_variable_getvalue(R_3) - x); + lmm_variable_getvalue(R_3) - x); WARN2("Deviation from optimal solution (R_1_2_3 = %g): %1.20f", - a - x, lmm_variable_getvalue(R_1_2_3) - (a - x)); + a - x, lmm_variable_getvalue(R_1_2_3) - (a - x)); } } else if (method == LAGRANGE_RENO) { double x; @@ -206,25 +200,25 @@ void test1(method_t method) lagrange_solve(Sys); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); if (max_deviation > MAXMIN_PRECISION) { WARN1("Max Deviation from optimal solution : %g", max_deviation); WARN1("Found x = %1.20f", x); WARN2("Deviation from optimal solution (R_1 = %g): %1.20f", x, - lmm_variable_getvalue(R_1) - x); + lmm_variable_getvalue(R_1) - x); WARN2("Deviation from optimal solution (R_2 = %g): %1.20f", - b - a + x, lmm_variable_getvalue(R_2) - (b - a + x)); + b - a + x, lmm_variable_getvalue(R_2) - (b - a + x)); WARN2("Deviation from optimal solution (R_3 = %g): %1.20f", x, - lmm_variable_getvalue(R_3) - x); + lmm_variable_getvalue(R_3) - x); WARN2("Deviation from optimal solution (R_1_2_3 = %g): %1.20f", - a - x, lmm_variable_getvalue(R_1_2_3) - (a - x)); + a - x, lmm_variable_getvalue(R_1_2_3) - (a - x)); } } else { xbt_assert0(0, "Invalid method"); @@ -251,10 +245,10 @@ void test2(method_t method) if (method == LAGRANGE_VEGAS) lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, - func_vegas_fpi); + func_vegas_fpi); else if (method == LAGRANGE_RENO) lmm_set_default_protocol_function(func_reno_f, func_reno_fp, - func_reno_fpi); + func_reno_fpi); Sys = lmm_system_new(); CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0); @@ -274,10 +268,6 @@ void test2(method_t method) if (method == MAXMIN) { lmm_solve(Sys); -#ifdef HAVE_SDP - } else if (method == SDP) { - sdp_solve(Sys); -#endif } else if (method == LAGRANGE_VEGAS) { lagrange_solve(Sys); } else if (method == LAGRANGE_RENO) { @@ -316,9 +306,9 @@ void test3(method_t method) 1, 1, 1, 1, 1 }; - - /*A = xbt_new0(double*, links + 5);*/ - A = xbt_new0(double*, links + 5); + + /*A = xbt_new0(double*, links + 5); */ + A = xbt_new0(double *, links + 5); for (i = 0; i < links + 5; i++) { A[i] = xbt_new0(double, flows + 5); @@ -326,7 +316,7 @@ void test3(method_t method) A[i][j] = 0.0; if (i >= links || j >= flows) { - A[i][j] = 0.0; + A[i][j] = 0.0; } } } @@ -403,21 +393,21 @@ void test3(method_t method) if (method == LAGRANGE_VEGAS) lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, - func_vegas_fpi); + func_vegas_fpi); else if (method == LAGRANGE_RENO) lmm_set_default_protocol_function(func_reno_f, func_reno_fp, - func_reno_fpi); + func_reno_fpi); Sys = lmm_system_new(); - tmp_name = xbt_new0(char *,31); + tmp_name = xbt_new0(char *, 31); /* * Creates the constraints */ - tmp_cnst = xbt_new0(lmm_constraint_t,15); + tmp_cnst = xbt_new0(lmm_constraint_t, 15); for (i = 0; i < 15; i++) { tmp_name[i] = bprintf("C_%03d", i); tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name[i], B[i]); @@ -427,11 +417,11 @@ void test3(method_t method) /* * Creates the variables */ - tmp_var = xbt_new0(lmm_variable_t,16); + tmp_var = xbt_new0(lmm_variable_t, 16); for (j = 0; j < 16; j++) { tmp_name[i + j] = bprintf("X_%03d", j); tmp_var[j] = - lmm_variable_new(Sys, (void *) tmp_name[i + j], 1.0, -1.0, 15); + lmm_variable_new(Sys, (void *) tmp_name[i + j], 1.0, -1.0, 15); lmm_update_variable_weight(Sys, tmp_var[j], 1.0); } @@ -441,7 +431,7 @@ void test3(method_t method) for (i = 0; i < 15; i++) { for (j = 0; j < 16; j++) { if (A[i][j]) { - lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0); + lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0); } } } @@ -450,10 +440,6 @@ void test3(method_t method) if (method == MAXMIN) { lmm_solve(Sys); -#ifdef HAVE_SDP - } else if (method == SDP) { - sdp_solve(Sys); -#endif } else if (method == LAGRANGE_VEGAS) { lagrange_solve(Sys); } else if (method == LAGRANGE_RENO) { @@ -482,23 +468,15 @@ int main(int argc, char **argv) INFO0("***** Test 1 (Max-Min)"); test1(MAXMIN); -#ifdef HAVE_SDP - INFO0("***** Test 1 (SDP)"); - test1(SDP); -#endif INFO0("***** Test 1 (Lagrange - Vegas)"); test1(LAGRANGE_VEGAS); INFO0("***** Test 1 (Lagrange - Reno)"); test1(LAGRANGE_RENO); - - + + INFO0("***** Test 2 (Max-Min)"); test2(MAXMIN); -#ifdef HAVE_SDP - INFO0("***** Test 2 (SDP)"); - test2(SDP); -#endif INFO0("***** Test 2 (Lagrange - Vegas)"); test2(LAGRANGE_VEGAS); INFO0("***** Test 2 (Lagrange - Reno)"); @@ -507,10 +485,6 @@ int main(int argc, char **argv) INFO0("***** Test 3 (Max-Min)"); test3(MAXMIN); -#ifdef HAVE_SDP - INFO0("***** Test 3 (SDP)"); - test3(SDP); -#endif INFO0("***** Test 3 (Lagrange - Vegas)"); test3(LAGRANGE_VEGAS); INFO0("***** Test 3 (Lagrange - Reno)");