From: Arnaud Giersch Date: Thu, 14 Mar 2019 13:53:33 +0000 (+0100) Subject: Remove useless function pointer. X-Git-Tag: v3_22~96^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/af5a9f0adb28866ee3dea430d51df4863dd47e64 Remove useless function pointer. --- diff --git a/src/kernel/lmm/lagrange.cpp b/src/kernel/lmm/lagrange.cpp index 9df8fb429a..fdab111a34 100644 --- a/src/kernel/lmm/lagrange.cpp +++ b/src/kernel/lmm/lagrange.cpp @@ -207,7 +207,7 @@ void Lagrange::lagrange_solve() /* Improve the value of lambda_i */ for (Constraint& cnst : active_constraint_set) { XBT_DEBUG("Working on cnst (%p)", &cnst); - cnst.new_lambda = dichotomy(cnst.lambda, partial_diff_lambda, cnst, dichotomy_min_error); + cnst.new_lambda = dichotomy(cnst.lambda, cnst, dichotomy_min_error); XBT_DEBUG("Updating lambda : cnst->lambda (%p) : %1.20f -> %1.20f", &cnst, cnst.lambda, cnst.new_lambda); cnst.lambda = cnst.new_lambda; @@ -264,8 +264,7 @@ void Lagrange::lagrange_solve() * * @return a double corresponding to the result of the dichotomy process */ -double Lagrange::dichotomy(double init, double diff(double, const Constraint&), const Constraint& cnst, - double min_error) +double Lagrange::dichotomy(double init, const Constraint& cnst, double min_error) { double min = init; double max = init; @@ -283,15 +282,15 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&), overall_error = 1; - diff_0 = diff(1e-16, cnst); + diff_0 = partial_diff_lambda(1e-16, cnst); if (diff_0 >= 0) { XBT_CDEBUG(surf_lagrange_dichotomy, "returning 0.0 (diff = %e)", diff_0); XBT_OUT(); return 0.0; } - double min_diff = diff(min, cnst); - double max_diff = diff(max, cnst); + double min_diff = partial_diff_lambda(min, cnst); + double max_diff = partial_diff_lambda(max, cnst); while (overall_error > min_error) { XBT_CDEBUG(surf_lagrange_dichotomy, "[min, max] = [%1.20f, %1.20f] || diffmin, diffmax = %1.20f, %1.20f", min, max, @@ -301,7 +300,7 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&), if (min == max) { XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing min"); min = min / 2.0; - min_diff = diff(min, cnst); + min_diff = partial_diff_lambda(min, cnst); } else { XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing max"); max = min; @@ -311,7 +310,7 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&), if (min == max) { XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing max"); max = max * 2.0; - max_diff = diff(max, cnst); + max_diff = partial_diff_lambda(max, cnst); } else { XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min"); min = max; @@ -328,7 +327,7 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&), min, max - min, min_diff, max_diff); break; } - middle_diff = diff(middle, cnst); + middle_diff = partial_diff_lambda(middle, cnst); if (middle_diff < 0) { XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min"); diff --git a/src/kernel/lmm/maxmin.hpp b/src/kernel/lmm/maxmin.hpp index 1e3b0d3707..123169d291 100644 --- a/src/kernel/lmm/maxmin.hpp +++ b/src/kernel/lmm/maxmin.hpp @@ -633,8 +633,7 @@ private: * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy. */ // computes the value of the dichotomy using a initial values, init, with a specific variable or constraint - static double dichotomy(double init, double diff(double, const Constraint&), const Constraint& cnst, - double min_error); + static double dichotomy(double init, const Constraint& cnst, double min_error); // computes the value of the differential of constraint cnst applied to lambda static double partial_diff_lambda(double lambda, const Constraint& cnst); diff --git a/teshsuite/surf/lmm_usage/lmm_usage.cpp b/teshsuite/surf/lmm_usage/lmm_usage.cpp index ff7a329fe4..7c7c8c6fd9 100644 --- a/teshsuite/surf/lmm_usage/lmm_usage.cpp +++ b/teshsuite/surf/lmm_usage/lmm_usage.cpp @@ -41,12 +41,20 @@ static lmm::System* new_system(method_t method) } } -static double dichotomy(double func(double), double min, double max, double min_error) +double a_test_1 = 0; +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))); +} + +static double dichotomy(double min, double max, double min_error) { double overall_error = 2 * min_error; - double min_func = func(min); - double max_func = func(max); + double min_func = diff_lagrange_test_1(min); + double max_func = diff_lagrange_test_1(max); if (min_func > 0 && max_func > 0) return min - 1.0; @@ -72,7 +80,7 @@ static double dichotomy(double func(double), double min, double max, double min_ if (fabs(min - middle) < 1e-12 || fabs(max - middle) < 1e-12) { break; } - double middle_func = func(middle); + double middle_func = diff_lagrange_test_1(middle); SHOW_EXPR(middle); SHOW_EXPR(middle_func); @@ -91,14 +99,6 @@ static double dichotomy(double func(double), double min, double max, double min_ return ((min + max) / 2.0); } -double a_test_1 = 0; -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))); -} - static void test1(method_t method) { double a = 1.0; @@ -148,7 +148,7 @@ static void test1(method_t method) } else if (method == LAGRANGE_RENO) { a_test_1 = a; b_test_1 = b; - x = dichotomy(diff_lagrange_test_1, 0, a, 1e-13); + x = dichotomy(0, a, 1e-13); if (x < 0) x = 0;