/* 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;
*
* @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;
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,
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;
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;
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");
* 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);
}
}
-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;
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);
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;
} 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;