+ DEBUG0("-------------- Check convergence ----------");
+ overall_modification = 0;
+ xbt_swag_foreach(var, var_list) {
+ if (var->weight <= 0)
+ var->value = 0.0;
+ else {
+ tmp = new_value(var);
+
+ overall_modification =
+ MAX(overall_modification, fabs(var->value - tmp));
+
+ var->value = tmp;
+ DEBUG3("New value of var (%p) = %e, overall_modification = %e",
+ var, var->value, overall_modification);
+ }
+ }
+
+ DEBUG0("-------------- Check feasability ----------");
+ if (!__check_feasible(cnst_list, var_list, 0))
+ overall_modification = 1.0;
+ DEBUG2("Iteration %d: overall_modification : %f", iteration,
+ overall_modification);
+/* if(!dual_updated) { */
+/* WARN1("Could not improve the convergence at iteration %d. Drop it!",iteration); */
+/* break; */
+/* } */
+ }
+
+ __check_feasible(cnst_list, var_list, 1);
+
+ if (overall_modification <= epsilon_min_error) {
+ DEBUG1("The method converges in %d iterations.", iteration);
+ }
+ if (iteration >= max_iterations) {
+ DEBUG1
+ ("Method reach %d iterations, which is the maximum number of iterations allowed.",
+ iteration);
+ }
+/* INFO1("Method converged after %d iterations", iteration); */
+
+ if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) {
+ lmm_print(sys);
+ }
+}
+
+/*
+ * Returns a double value corresponding to the result of a dichotomy proccess with
+ * respect to a given variable/constraint (\mu in the case of a variable or \lambda in
+ * case of a constraint) and a initial value init.
+ *
+ * @param init initial value for \mu or \lambda
+ * @param diff a function that computes the differential of with respect a \mu or \lambda
+ * @param var_cnst a pointer to a variable or constraint
+ * @param min_erro a minimun error tolerated
+ *
+ * @return a double correponding to the result of the dichotomyal process
+ */
+static double dichotomy(double init, double diff(double, void *),
+ void *var_cnst, double min_error)
+{
+ double min, max;
+ double overall_error;
+ double middle;
+ double min_diff, max_diff, middle_diff;
+ double diff_0 = 0.0;
+ min = max = init;
+
+ XBT_IN;
+
+ if (init == 0.0) {
+ min = max = 0.5;
+ }
+
+ min_diff = max_diff = middle_diff = 0.0;
+ overall_error = 1;
+
+ if ((diff_0 = diff(1e-16, var_cnst)) >= 0) {
+ CDEBUG1(surf_lagrange_dichotomy, "returning 0.0 (diff = %e)", diff_0);
+ XBT_OUT;
+ return 0.0;
+ }
+
+ min_diff = diff(min, var_cnst);
+ max_diff = diff(max, var_cnst);
+
+ while (overall_error > min_error) {
+ CDEBUG4(surf_lagrange_dichotomy,
+ "[min, max] = [%1.20f, %1.20f] || diffmin, diffmax = %1.20f, %1.20f",
+ min, max, min_diff, max_diff);
+
+ if (min_diff > 0 && max_diff > 0) {
+ if (min == max) {
+ CDEBUG0(surf_lagrange_dichotomy, "Decreasing min");
+ min = min / 2.0;
+ min_diff = diff(min, var_cnst);
+ } else {
+ CDEBUG0(surf_lagrange_dichotomy, "Decreasing max");
+ max = min;
+ max_diff = min_diff;
+ }
+ } else if (min_diff < 0 && max_diff < 0) {
+ if (min == max) {
+ CDEBUG0(surf_lagrange_dichotomy, "Increasing max");
+ max = max * 2.0;
+ max_diff = diff(max, var_cnst);
+ } else {
+ CDEBUG0(surf_lagrange_dichotomy, "Increasing min");
+ min = max;
+ min_diff = max_diff;
+ }
+ } else if (min_diff < 0 && max_diff > 0) {
+ middle = (max + min) / 2.0;
+ CDEBUG1(surf_lagrange_dichotomy, "Trying (max+min)/2 : %1.20f",
+ middle);
+
+ if ((min == middle) || (max == middle)) {
+ CWARN4(surf_lagrange_dichotomy,
+ "Cannot improve the convergence! min=max=middle=%1.20f, diff = %1.20f."
+ " Reaching the 'double' limits. Maybe scaling your function would help ([%1.20f,%1.20f]).",
+ min, max - min, min_diff, max_diff);
+ break;