Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove some unbreakable spaces breaking the pdf generation
[simgrid.git] / src / include / surf / maxmin.h
index 86600a4..7f58d7c 100644 (file)
  * @details 
  * A linear maxmin solver to resolves inequations systems.
  * 
- * A system is composed of variables, constraints and elements linking them.
+ * Most SimGrid model rely on a "fluid/steady-state" modeling that
+ * samount to share resources between actions at relatively
+ * coarse-grain.  Such sharing is generally done by solving a set of
+ * linear inequations. Let's take an example and assume we have the
+ * variables \f$x_1\f$, \f$x_2\f$, \f$x_3\f$, and \f$x_4\f$ . Let's
+ * say that \f$x_1\f$ and \f$x_2\f$ correspond to activities running
+ * and the same CPU \f$A\f$ whose capacity is \f$C_A\f$ . In such a
+ * case, we need to enforce:
+ *
+ *   \f[ x_1 + x_2 \leq C_A \f]
+ *
+ * Likewise, if \f$x_3\f$ (resp. \f$x_4\f$) corresponds to a network
+ * flow \f$F_3\f$ (resp. \f$F_4\f$) that goes through a set of links
+ * \f$L_1\f$ and \f$L_2\f$ (resp. \f$L_2\f$ and \f$L_3\f$), then we
+ * need to enforce:
+ *
+ *   \f[ x_3  \leq C_{L_1} \f]
+ *   \f[ x_3 + x_4 \leq C_{L_2} \f]
+ *   \f[ x_4 \leq C_{L_3} \f]
+ * 
+ * One could set every variable to 0 to make sure the constraints are
+ * satisfied but this would obviously not be very realistic. A
+ * possible objective is to try to maximize the minimum of the
+ * \f$x_i\f$ . This ensures that all the \f$x_i\f$ are positive and "as
+ * large as possible". 
+ *
+ * This is called *max-min fairness* and is the most commonly used
+ * objective in SimGrid. Another possibility is to maximize
+ * \f$\sum_if(x_i)\f$, where \f$f\f$ is a strictly increasing concave
+ * function.
+ *
  * Constraint: 
  *  - bound (set)
  *  - shared (set)
  */
 
 extern double sg_maxmin_precision;
-#define MAXMIN_PRECISION sg_maxmin_precision
-static XBT_INLINE void double_update(double *variable, double value)
+extern double sg_surf_precision;
+
+static XBT_INLINE void double_update(double *variable, double value, double precision)
 {
   *variable -= value;
-  if (*variable < MAXMIN_PRECISION)
+  if (*variable < precision)
     *variable = 0.0;
 }
 
-static XBT_INLINE int double_positive(double value)
+static XBT_INLINE int double_positive(double value, double precision)
 {
-  return (value > MAXMIN_PRECISION);
+  return (value > precision);
 }
 
-static XBT_INLINE int double_equals(double value1, double value2)
+static XBT_INLINE int double_equals(double value1, double value2, double precision)
 {
-  return (fabs(value1 - value2) < MAXMIN_PRECISION);
+  return (fabs(value1 - value2) < precision);
 }
 
 SG_BEGIN_DECL()
@@ -107,7 +138,7 @@ XBT_PUBLIC(lmm_constraint_t) lmm_constraint_new(lmm_system_t sys, void *id,
  * 
  * @param cnst The constraint to share
  */
-void lmm_constraint_shared(lmm_constraint_t cnst);
+XBT_PUBLIC(void) lmm_constraint_shared(lmm_constraint_t cnst);
 
 /**
  * @brief Check if a constraint is shared (shared by default)
@@ -115,7 +146,7 @@ void lmm_constraint_shared(lmm_constraint_t cnst);
  * @param cnst The constraint to share
  * @return 1 if shared, 0 otherwise
  */
-int lmm_constraint_is_shared(lmm_constraint_t cnst);
+XBT_PUBLIC(int) lmm_constraint_is_shared(lmm_constraint_t cnst);
 
 /**
  * @brief Free a constraint
@@ -123,7 +154,7 @@ int lmm_constraint_is_shared(lmm_constraint_t cnst);
  * @param sys The system associated to the constraint
  * @param cnst The constraint to free
  */
-void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
+XBT_PUBLIC(void) lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
 
 /**
  * @brief Get the usage of the constraint after the last lmm solve
@@ -131,7 +162,7 @@ void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
  * @param cnst A constraint
  * @return The usage of the constraint
  */
-double lmm_constraint_get_usage(lmm_constraint_t cnst);
+XBT_PUBLIC(double) lmm_constraint_get_usage(lmm_constraint_t cnst);
 
 /**
  * @brief Create a new Linear MaxMin variable
@@ -200,7 +231,7 @@ XBT_PUBLIC(void) lmm_expand(lmm_system_t sys, lmm_constraint_t cnst,
  * @param var A variable
  * @param value The value to add to the coefficient associated to the variable in the constraint
  */
-void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
+XBT_PUBLIC(void) lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
                     lmm_variable_t var, double value);
 
 /**
@@ -211,7 +242,7 @@ void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
  * @param num The rank of constraint we want to get
  * @return The numth constraint
  */
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
+XBT_PUBLIC(lmm_constraint_t) lmm_get_cnst_from_var(lmm_system_t sys,
                                        lmm_variable_t var, int num);
 
 /**
@@ -222,7 +253,7 @@ lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
  * @param num The rank of constraint we want to get
  * @return The numth constraint
  */
-double lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var,
+XBT_PUBLIC(double) lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var,
                                     int num);
 
 /**
@@ -232,7 +263,7 @@ double lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var,
  * @param var A variable
  * @return The number of constraint associated to the variable
  */
-int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
+XBT_PUBLIC(int) lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
 
 /**
  * @brief Get a var associated to a constraint 
@@ -243,7 +274,7 @@ int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
  * @param elem A element of constraint of the constraint or NULL
  * @return A variable associated to a constraint
  */
-lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys,
+XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst(lmm_system_t sys,
                                      lmm_constraint_t cnst,
                                      lmm_element_t * elem);
 
@@ -253,7 +284,7 @@ lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys,
  * @param sys A system
  * @return The first active constraint
  */
-lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys);
+XBT_PUBLIC(lmm_constraint_t) lmm_get_first_active_constraint(lmm_system_t sys);
 
 /**
  * @brief Get the next active constraint of a constraint in a system
@@ -263,7 +294,7 @@ lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys);
  * 
  * @return The next active constraint
  */
-lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys,
+XBT_PUBLIC(lmm_constraint_t) lmm_get_next_active_constraint(lmm_system_t sys,
                                                 lmm_constraint_t cnst);
 
 #ifdef HAVE_LATENCY_BOUND_TRACKING
@@ -276,7 +307,7 @@ XBT_PUBLIC(int) lmm_is_variable_limited_by_latency(lmm_variable_t var);
  * @param cnst A constraint
  * @return The data associated to the constraint
  */
-void *lmm_constraint_id(lmm_constraint_t cnst);
+XBT_PUBLIC(void *) lmm_constraint_id(lmm_constraint_t cnst);
 
 /**
  * @brief Get the data associated to a variable
@@ -284,7 +315,7 @@ void *lmm_constraint_id(lmm_constraint_t cnst);
  * @param var A variable
  * @return The data associated to the variable
  */
-void *lmm_variable_id(lmm_variable_t var);
+XBT_PUBLIC(void *) lmm_variable_id(lmm_variable_t var);
 
 /**
  * @brief Update the value of element linking the constraint and the variable
@@ -294,7 +325,7 @@ void *lmm_variable_id(lmm_variable_t var);
  * @param var A variable
  * @param value The new value
  */
-void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
+XBT_PUBLIC(void) lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
                 lmm_variable_t var, double value);
 
 /**
@@ -304,14 +335,14 @@ void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
  * @param var A constraint
  * @param bound The new bound
  */
-void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
+XBT_PUBLIC(void) lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
                                double bound);
 
 /**
  * @brief Update the weight of a variable
  * 
  * @param sys A system
- * @param var A variable
+ * @param var A variable
  * @param weight The new weight of the variable
  */
 XBT_PUBLIC(void) lmm_update_variable_weight(lmm_system_t sys,
@@ -324,7 +355,7 @@ XBT_PUBLIC(void) lmm_update_variable_weight(lmm_system_t sys,
  * @param var A variable
  * @return The weight of the variable
  */
-double lmm_get_variable_weight(lmm_variable_t var);
+XBT_PUBLIC(double) lmm_get_variable_weight(lmm_variable_t var);
 
 /**
  * @brief Update a constraint bound
@@ -344,7 +375,7 @@ XBT_PUBLIC(void) lmm_update_constraint_bound(lmm_system_t sys,
  * @param cnst A constraint
  * @return [description]
  */
-int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
+XBT_PUBLIC(int) lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
 
 /**
  * @brief Solve the lmm system