Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Removed this file, it is just an experience of optimal step before
authorvelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 24 Apr 2007 09:17:53 +0000 (09:17 +0000)
committervelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 24 Apr 2007 09:17:53 +0000 (09:17 +0000)
achieve a formal proof that the method always converge.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3443 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/surf/lagrangedico.c [deleted file]

diff --git a/src/surf/lagrangedico.c b/src/surf/lagrangedico.c
deleted file mode 100644 (file)
index e0e2af1..0000000
+++ /dev/null
@@ -1,397 +0,0 @@
-/*     $Id$     */
-
-/* Copyright (c) 2007 Arnaud Legrand, Pedro Velho. 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. */
-
-/*
- * Modelling the proportional fairness using the Lagrange Optimization 
- * Approach. For a detailed description see:
- * "ssh://username@scm.gforge.inria.fr/svn/memo/people/pvelho/lagrange/ppf.ps".
- */
-#include "xbt/log.h"
-#include "xbt/sysdep.h"
-#include "xbt/mallocator.h"
-#include "maxmin_private.h"
-
-#include <stdlib.h>
-#ifndef MATH
-#include <math.h>
-#endif
-
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_lagrangedico, surf,
-                               "Logging specific to SURF (lagrange)");
-
-
-void lagrange_dicotomi_solve(lmm_system_t sys);
-
-double partial_diff_mu(double mu, lmm_variable_t var1);
-double partial_diff_lambda(double lambda, lmm_constraint_t cnst1);
-
-void lagrange_dicotomi_solve(lmm_system_t sys)
-{
-  /*
-   * Lagrange Variables.
-   */
-  int max_iterations= 10;
-  double epsilon_min_error = 1e-10;
-  double overall_error = 1;
-  double min, max, middle;
-
-
-  /*
-   * Variables to manipulate the data structure proposed to model the maxmin
-   * fairness. See docummentation for more details.
-   */
-  xbt_swag_t elem_list = NULL;
-  lmm_element_t elem1 = NULL;
-
-
-  xbt_swag_t cnst_list = NULL;
-  lmm_constraint_t cnst1 = NULL;
-  
-  xbt_swag_t var_list = NULL;
-_variable_t var1 = NULL;
-
-
-  /*
-   * Auxiliar variables.
-   */
-  int iteration=0;
-  double tmp=0;
-  int i;
-   
-
-  DEBUG0("Iterative method configuration snapshot =====>");
-  DEBUG1("#### Maximum number of iterations : %d", max_iterations);
-  DEBUG1("#### Minimum error tolerated      : %e", epsilon_min_error);
-
-
-  if ( !(sys->modified))
-    return;
-
-  /* 
-   * Initialize the var list variable with only the active variables. 
-   * Associate an index in the swag variables. Initialize mu.
-   */
-  var_list = &(sys->variable_set);
-  i=0;
-  xbt_swag_foreach(var1, var_list) {
-    if((var1->bound > 0.0) || (var1->weight <= 0.0)){
-      DEBUG1("#### NOTE var1(%d) is a boundless variable", i);
-      var1->mu = -1.0;
-    } else{ 
-      var1->mu =   1.0;
-      var1->new_mu = 2.0;
-    }
-    DEBUG2("#### var1(%d)->mu :  %e", i, var1->mu);
-    DEBUG2("#### var1(%d)->weight: %e", i, var1->weight);
-    i++;
-  }
-
-  /* 
-   * Initialize lambda.
-   */
-  cnst_list=&(sys->active_constraint_set); 
-  xbt_swag_foreach(cnst1, cnst_list) {
-    cnst1->lambda = 1.0;
-    cnst1->new_lambda = 2.0;
-    DEBUG2("#### cnst1(%p)->lambda :  %e", cnst1, cnst1->lambda);
-  }
-
-
-  
-  /*
-   * While doesn't reach a minimun error or a number maximum of iterations.
-   */
-  while(overall_error > epsilon_min_error && iteration < max_iterations){
-   
-    iteration++;
-
-
-    /*                        d Dual
-     * Compute the value of ----------- (\lambda^k, \mu^k) this portion
-     *                       d \mu_i^k
-     * of code depends on function f(x).
-     */
-    var_list = &(sys->variable_set);
-    //forall mu_i in mu_1, mu_2, ..., mu_n
-    xbt_swag_foreach(var1, var_list) {
-      if((var1->bound >= 0) && (var1->weight > 0) ){
-       //for each link with capacity cnsts[i] that uses flow of variable var1 do
-       //begin dicotomi
-       min = max = var1->mu;
-       overall_error = 1;
-       while(overall_error < epsilon_min_error){
-         if( partial_diff_mu(min, var1)>0 && partial_diff_mu(max, var1)>0 ){
-           if(min == max){
-             min = min / 2;
-           }else{
-             max = min;
-           }
-         }else if( partial_diff_mu(min, var1)<0 && partial_diff_mu(max, var1)<0 ){
-           if(min == max){
-             max = max * 2;
-           }else{
-             max = min;
-           }
-         }else if( partial_diff_mu(min,var1)<0 && partial_diff_mu(max,var1) > 0 ){
-           if(min == max){
-             middle =  partial_diff_mu((fabs(min - max)/2), var1);
-             if( middle > 0 ){
-               max = (fabs(min - max)/2);
-             }else if( middle < 0 ){
-               min = (fabs(min - max)/2);
-             }else{
-               WARN0("Found an optimal solution with 0 error!");
-               overall_error = 0;
-             }
-             overall_error = fabs(min - max);
-           }
-         }else{
-           WARN0("The impossible happened, partial_diff(min) >0 && partial_diff(max) < 0");
-         }
-       }
-
-       var1->mu = max;
-
-       if(var1->mu < 0){
-         var1->mu = 0;
-       }
-      }
-    }
-
-
-    /*                         d Dual
-     * Compute the value of ------------- (\lambda^k, \mu^k) this portion
-     *                      d \lambda_i^k
-     * of code depends on function f(x).
-     */
-    xbt_swag_foreach(cnst1, cnst_list) {
-      
-
-      DEBUG2("cnst1 (id=%s) (%p)", (char *)cnst1->id, cnst1);
-
-      //begin dicotomi
-      i=0;
-      overall_error = 1;
-      min = max = cnst1->lambda;
-      while(overall_error > epsilon_min_error){
-       i++;
-
-       //      DEBUG4("====> Dicotomi debug. [%e, %e], D(min,max) = [%e, %e]", min, max, partial_diff_lambda(min, cnst1), partial_diff_lambda(max, cnst1));
-       
-       if( partial_diff_lambda(min, cnst1) > 0 && partial_diff_lambda(max, cnst1) > 0 ){
-         if(min == max){
-           min = min / 2.0;
-         }else{
-           max = min;
-         }
-       }else if( partial_diff_lambda(min, cnst1) < 0 && partial_diff_lambda(max, cnst1) < 0 ){
-         if(min == max){
-           max = max * 2.0;
-         }else{
-           min = max;
-         }
-       }else if( partial_diff_lambda(min,cnst1) < 0 && partial_diff_lambda(max,cnst1) > 0 ){
-         middle = (max + min)/2.0;
-
-
-         //DEBUG2("Ideal state reached middle = %e, D(fabs(min-max)/2.0) = %e", middle, partial_diff_lambda(middle, cnst1));
-         if( partial_diff_lambda(middle, cnst1) < 0 ){
-           min = middle;
-         }else if( partial_diff_lambda(middle, cnst1) > 0 ){
-           max = middle;
-         }else{
-           WARN0("Found an optimal solution with 0 error!");
-           overall_error = 0;
-         }
-         overall_error = fabs(min - max);
-       }else{
-         WARN0("The impossible happened, partial_diff(min) >0 && partial_diff(max) < 0");
-       }
-      }
-      
-
-      DEBUG1("Number of iteration in the dicotomi %d", i);
-      
-      cnst1->lambda = min;
-    
-      if(cnst1->lambda < 0){
-       cnst1->lambda = 0;
-      }
-    }
-
-
-    /*
-     * Now computes the values of each variable (\rho) based on
-     * the values of \lambda and \mu.
-     */
-    overall_error=0;
-    DEBUG1("Iteration %d ", iteration);
-    xbt_swag_foreach(var1, var_list) {
-      if(var1->weight <=0) 
-       var1->value = 0.0;
-      else {
-       tmp = 0;
-       for(i=0; i<var1->cnsts_number; i++){
-         tmp += (var1->cnsts[i].constraint)->lambda;
-         if(var1->bound > 0) 
-           tmp+=var1->mu;
-       }
-       
-       //computes de overall_error
-       if(overall_error < fabs(var1->value - 1.0/tmp)){
-         overall_error = fabs(var1->value - 1.0/tmp);
-       }
-
-       var1->value = 1.0 / tmp;
-      }
-
-
-      DEBUG2("======> value of var1 (%p)  = %e", var1, var1->value);      
-    }
-  }
-
-
-
-
-
-  //verify the KKT property
-  xbt_swag_foreach(cnst1, cnst_list){
-    tmp = 0;
-    elem_list = &(cnst1->element_set);
-    xbt_swag_foreach(elem1, elem_list) {
-      var1 = elem1->variable;
-      if(var1->weight<=0) continue;
-      tmp += var1->value;
-    }
-
-    tmp = tmp - cnst1->bound;
-
-    if(tmp != 0 ||  cnst1->lambda != 0){
-      WARN4("The link %s(%p) doesn't match the KKT property, value expected (=0) got (lambda=%e) (sum_rho=%e)", (char *)cnst1->id, cnst1, cnst1->lambda, tmp);
-    }
-    
-  }
-
-    
-  xbt_swag_foreach(var1, var_list){
-    if(var1->bound <= 0 || var1->weight <= 0) continue;
-    tmp = 0;
-    tmp = (var1->value - var1->bound);
-
-    
-    if(tmp != 0 ||  var1->mu != 0){
-      WARN4("The flow %s(%p) doesn't match the KKT property, value expected (=0) got (lambda=%e) (sum_rho=%e)", (char *)var1->id, var1, var1->mu, tmp);
-    }
-
-  }
-
-
-  if(overall_error <= epsilon_min_error){
-    DEBUG1("The method converge in %d iterations.", iteration);
-  }else{
-    WARN1("Method reach %d iterations, which is the maxmimun number of iterations allowed.", iteration);
-  }
-
-
-
-}
-
-
-double dicotomi(double init, void *diff(double, void*), void *var_cnst){
-  double min, max;
-  double overall_error;
-
-  min = max = init;
-  overall_error = 1;
-
-  while(overall_error > epsilon_min_error){
-    if( diff(min, var_cnst) > 0 && diff(max, var_cnst) > 0 ){
-      if(min == max){
-       min = min / 2.0;
-      }else{
-       max = min;
-      }
-    }else if( diff(min, var_cnst) < 0 && diff(max, var_cnst) < 0 ){
-      if(min == max){
-       max = max * 2.0;
-      }else{
-       min = max;
-      }
-    }else if( diff(min, var_cnst) < 0 && diff(max, var_cnst) > 0 ){
-      middle = (max + min)/2.0;
-      
-      if( diff(middle, var_cnst) < 0 ){
-       min = middle;
-      }else if( diff(middle, var_cnst) > 0 ){
-       max = middle;
-      }else{
-       WARN0("Found an optimal solution with 0 error!");
-       overall_error = 0;
-      }
-      overall_error = fabs(min - max);
-    }else{
-      WARN0("The impossible happened, partial_diff(min) >0 && partial_diff(max) < 0");
-    }
-  }
-}
-
-double partial_diff_mu(double mu, lmm_variable_t var1){
-  double mu_partial=0.0;
-  int i;
-
-  //for each link with capacity cnsts[i] that uses flow of variable var1 do
-  for(i=0; i<var1->cnsts_number; i++)
-    mu_partial += (var1->cnsts[i].constraint)->lambda + mu;
-  
-  mu_partial = (-1.0/mu_partial) + var1->bound;
-
-  return mu_partial;
-}
-
-
-double partial_diff_lambda(double lambda, lmm_constraint_t cnst1){
-
-  double tmp=0.0;
-  int i;
-  double lambda_partial=0.0;
-  xbt_swag_t elem_list = NULL;
-  lmm_element_t elem1 = NULL;
-  lmm_variable_t var1 = NULL;
-
-
-  elem_list = &(cnst1->element_set);
-  
-  xbt_swag_foreach(elem1, elem_list) {
-    var1 = elem1->variable;
-    if(var1->weight<=0) continue;
-    
-    tmp = 0;
-    for(i=0; i<var1->cnsts_number; i++){
-      tmp += (var1->cnsts[i].constraint)->lambda;
-    }
-       
-    if(var1->bound > 0)
-      tmp += var1->mu;
-    
-    tmp = tmp - cnst1->lambda + lambda;
-    
-    //un peux du bricolage pour evite la catastrophe
-    if(tmp==0) lambda_partial = 10e-8;
-    
-    lambda_partial += (-1.0 /tmp);
-  }
-
-
-  lambda_partial += cnst1->bound;
-
-  //DEBUG3("Partial diff lambda result cnst1 %s (%p) : %e", (char *)cnst1->id, cnst1, lambda_partial);
-  return lambda_partial;
-}
-