-/* Copyright (c) 2004-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2004-2017. The SimGrid Team. 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. */
-#ifndef _SURF_MAXMIN_H
-#define _SURF_MAXMIN_H
+#ifndef SURF_MAXMIN_H
+#define SURF_MAXMIN_H
-#include "src/portable.h"
+#include "src/internal_config.h"
#include "xbt/misc.h"
#include "xbt/asserts.h"
#include "surf/datatypes.h"
#include <math.h>
-/** @addtogroup SURF_lmm
- * @details
+namespace simgrid {
+namespace surf {
+class Action;
+}
+}
+
+/** @addtogroup SURF_lmm
+ * @details
* A linear maxmin solver to resolve inequations systems.
- *
+ *
* Most SimGrid model rely on a "fluid/steady-state" modeling that simulate the sharing of 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$
* 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:
+ * Constraint:
* - bound (set)
* - shared (set)
* - usage (computed)
*
* Element:
* - value (set)
- *
+ *
* A possible system could be:
* - three variables: `var1`, `var2`, `var3`
* - two constraints: `cons1`, `cons2`
* - `elem2` linking `var2` and `cons1`
* - `elem3` linking `var2` and `cons2`
* - `elem4` linking `var3` and `cons2`
- *
+ *
* And the corresponding inequations will be:
- *
+ *
* var1.value <= var1.bound
* var2.value <= var2.bound
* var3.value <= var3.bound
* var1.weight * var1.value * elem1.value + var2.weight * var2.value * elem2.value <= cons1.bound
* var2.weight * var2.value * elem3.value + var3.weight * var3.value * elem4.value <= cons2.bound
- *
+ *
* where `var1.value`, `var2.value` and `var3.value` are the unknown values.
- *
- * If a constraint is not shared, the sum is replaced by a max.
- * For example, a third non-shared constraint `cons3` and the associated elements `elem5` and `elem6` could write as:
+ *
+ * If a constraint is not shared, the sum is replaced by a max.
+ * For example, a third non-shared constraint `cons3` and the associated elements `elem5` and `elem6` could write as:
*
* max( var1.weight * var1.value * elem5.value , var3.weight * var3.value * elem6.value ) <= cons3.bound
*
* (lmm_solve()) activates it when appropriate. It is possible that the variable is again disabled, e.g. to model the
* pausing of an action.
*
- * Concurrency limit and maximum
- *
- * We call concurrency, the number of variables that can be enabled at any time for each constraint.
+ * Concurrency limit and maximum
+ *
+ * We call concurrency, the number of variables that can be enabled at any time for each constraint.
* From a model perspective, this "concurrency" often represents the number of actions that actually compete for one
* constraint.
* The LMM solver is able to limit the concurrency for each constraint, and to monitor its maximum value.
- *
+ *
* One may want to limit the concurrency of constraints for essentially three reasons:
* - Keep LMM system in a size that can be solved (it does not react very well with tens of thousands of variables per
* constraint)
- * - Stay within parameters where the fluid model is accurate enough.
+ * - Stay within parameters where the fluid model is accurate enough.
* - Model serialization effects
*
* The concurrency limit can also be set to a negative value to disable concurrency limit. This can improve performance
* slightly.
- *
+ *
* Overall, each constraint contains three fields related to concurrency:
* - concurrency_limit which is the limit enforced by the solver
* - concurrency_current which is the current concurrency
- * - concurrency_maximum which is the observed maximum concurrency
+ * - concurrency_maximum which is the observed maximum concurrency
*
- * Variables also have one field related to concurrency: concurrency_share.
+ * Variables also have one field related to concurrency: concurrency_share.
* In effect, in some cases, one variable is involved multiple times (i.e. two elements) in a constraint.
* For example, cross-traffic is modeled using 2 elements per constraint.
* concurrency_share formally corresponds to the maximum number of elements that associate the variable and any given
XBT_PUBLIC_DATA(double) sg_maxmin_precision;
XBT_PUBLIC_DATA(double) sg_surf_precision;
-
-static XBT_INLINE void double_update(double *variable, double value, double precision)
+XBT_PUBLIC_DATA(int) sg_concurrency_limit;
+
+static inline void double_update(double *variable, double value, double precision)
{
//printf("Updating %g -= %g +- %g\n",*variable,value,precision);
//xbt_assert(value==0 || value>precision);
*variable = 0.0;
}
-static XBT_INLINE int double_positive(double value, double precision)
+static inline int double_positive(double value, double precision)
{
return (value > precision);
}
-static XBT_INLINE int double_equals(double value1, double value2, double precision)
+static inline int double_equals(double value1, double value2, double precision)
{
return (fabs(value1 - value2) < precision);
}
/** @{ @ingroup SURF_lmm */
/**
* @brief Create a new Linear MaxMim system
- * @param selective_update [description]
+ * @param selective_update whether we should do lazy updates
*/
-XBT_PUBLIC(lmm_system_t) lmm_system_new(int selective_update);
+XBT_PUBLIC(lmm_system_t) lmm_system_new(bool selective_update);
/**
* @brief Free an existing Linear MaxMin system
* @brief Create a new Linear MaxMin constraint
* @param sys The system in which we add a constraint
* @param id Data associated to the constraint (e.g.: a network link)
- * @param bound_value The bound value of the constraint
+ * @param bound_value The bound value of the constraint
*/
XBT_PUBLIC(lmm_constraint_t) lmm_constraint_new(lmm_system_t sys, void *id,double bound_value);
* @param bound The maximum value of the variable (-1.0 if no maximum value)
* @param number_of_constraints The maximum number of constraint to associate to the variable
*/
-XBT_PUBLIC(lmm_variable_t) lmm_variable_new(lmm_system_t sys, void *id, double weight_value, double bound,
- int number_of_constraints);
+XBT_PUBLIC(lmm_variable_t)
+lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double weight_value, double bound,
+ int number_of_constraints);
/**
* @brief Free a variable
* @param sys The system associated to the variable
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
+ * @brief Get a var associated to a constraint
* @details Get the first variable of the next variable of elem if elem is not NULL
* @param sys The system associated to the variable (not used)
* @param cnst A constraint
*
* @return A variable associated to a constraint
*/
-XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t cnst,
+XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst_safe(lmm_system_t sys, lmm_constraint_t cnst,
lmm_element_t * elem, lmm_element_t * nextelem, int * numelem);
/**
* @brief Get the next active constraint of a constraint in a system
* @param sys A system
* @param cnst An active constraint of the system
- *
+ *
* @return The next active constraint
*/
XBT_PUBLIC(lmm_constraint_t) lmm_get_next_active_constraint(lmm_system_t sys, lmm_constraint_t cnst);
/** @} */
SG_END_DECL()
-#endif /* _SURF_MAXMIN_H */
+#endif