- /**
- * @brief Get the data associated to a variable
- * @return The data associated to the variable
- */
- simgrid::kernel::resource::Action* get_id() const { return id; }
-
- /**
- * @brief Get the weight of a variable
- * @return The weight of the variable
- */
- double get_weight() const { return sharing_weight; }
-
- /** @brief Measure the minimum concurrency slack across all constraints where the given var is involved */
- int get_min_concurrency_slack() const;
-
- /** @brief Check if a variable can be enabled
- * Make sure to set staged_weight before, if your intent is only to check concurrency
- */
- int can_enable() const { return staged_weight > 0 && get_min_concurrency_slack() >= concurrency_share; }
-
- /* hookup to system */
- boost::intrusive::list_member_hook<> variable_set_hook;
- boost::intrusive::list_member_hook<> saturated_variable_set_hook;
-
- std::vector<Element> cnsts;
-
- // sharing_weight: variable's impact on the resource during the sharing
- // if == 0, the variable is not considered by LMM
- // on CPU, actions with N threads have a sharing of N
- // on network, the actions with higher latency have a lesser sharing_weight
- double sharing_weight;
-
- double staged_weight; /* If non-zero, variable is staged for addition as soon as maxconcurrency constraints will be
- * met */
- double bound;
- double value;
- short int concurrency_share; /* The maximum number of elements that variable will add to a constraint */
- simgrid::kernel::resource::Action* id;
- int id_int;
- unsigned visited; /* used by System::update_modified_set() */
- /* \begin{For Lagrange only} */
- double mu;
- double new_mu;
- double (*func_f)(const Variable& var, double x); /* (f) */
- double (*func_fp)(const Variable& var, double x); /* (f') */
- double (*func_fpi)(const Variable& var, double x); /* (f')^{-1} */
- /* \end{For Lagrange only} */
-
-private:
- static int Global_debug_id;
-};
-
-inline void Element::make_active()
-{
- constraint->active_element_set.push_front(*this);
-}
-inline void Element::make_inactive()
-{
- if (active_element_set_hook.is_linked())
- simgrid::xbt::intrusive_erase(constraint->active_element_set, *this);
-}
-
-/**
- * @brief LMM system
- */
-class XBT_PUBLIC System {
-public:
- /**
- * @brief Create a new Linear MaxMim system
- * @param selective_update whether we should do lazy updates
- */
- explicit System(bool selective_update);
- /** @brief Free an existing Linear MaxMin system */
- ~System();
-
- /**
- * @brief Create a new Linear MaxMin constraint
- * @param id Data associated to the constraint (e.g.: a network link)
- * @param bound_value The bound value of the constraint
- */
- Constraint* constraint_new(void* id, double bound_value);
-
- /**
- * @brief Create a new Linear MaxMin variable
- * @param id Data associated to the variable (e.g.: a network communication)
- * @param weight_value The weight of the variable (0.0 if not used)
- * @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
- */
- Variable* variable_new(simgrid::kernel::resource::Action * id, double weight_value, double bound,
- int number_of_constraints);
-
- /**
- * @brief Free a variable
- * @param var The variable to free
- */
- void variable_free(Variable * var);
-
- /**
- * @brief Associate a variable to a constraint with a coefficient
- * @param cnst A constraint
- * @param var A variable
- * @param value The coefficient associated to the variable in the constraint
- */
- void expand(Constraint * cnst, Variable * var, double value);
-
- /**
- * @brief Add value to the coefficient between a constraint and a variable or create one
- * @param cnst A constraint
- * @param var A variable
- * @param value The value to add to the coefficient associated to the variable in the constraint
- */
- void expand_add(Constraint * cnst, Variable * var, double value);
-
- /**
- * @brief Update the bound of a variable
- * @param var A constraint
- * @param bound The new bound
- */
- void update_variable_bound(Variable * var, double bound);
-
- /**
- * @brief Update the weight of a variable
- * @param var A variable
- * @param weight The new weight of the variable
- */
- void update_variable_weight(Variable * var, double weight);
-
- /**
- * @brief Update a constraint bound
- * @param cnst A constraint
- * @param bound The new bound of the consrtaint
- */
- void update_constraint_bound(Constraint * cnst, double bound);
-
- /**
- * @brief [brief description]
- * @param cnst A constraint
- * @return [description]
- */
- int constraint_used(Constraint * cnst) { return cnst->active_constraint_set_hook.is_linked(); }
-
- /** @brief Print the lmm system */
- void print() const;
-
- /** @brief Solve the lmm system */
- void solve();
-
-private:
- static void* variable_mallocator_new_f();
- static void variable_mallocator_free_f(void* var);
-
- void var_free(Variable * var);
- void cnst_free(Constraint * cnst);
- Variable* extract_variable()
- {
- if (variable_set.empty())
- return nullptr;
- Variable* res = &variable_set.front();
- variable_set.pop_front();
- return res;
- }
- Constraint* extract_constraint()
- {
- if (constraint_set.empty())
- return nullptr;
- Constraint* res = &constraint_set.front();
- constraint_set.pop_front();
- return res;
- }
- void insert_constraint(Constraint * cnst) { constraint_set.push_back(*cnst); }
- void remove_variable(Variable * var)
- {
- if (var->variable_set_hook.is_linked())
- simgrid::xbt::intrusive_erase(variable_set, *var);
- if (var->saturated_variable_set_hook.is_linked())
- simgrid::xbt::intrusive_erase(saturated_variable_set, *var);
- }
- void make_constraint_active(Constraint * cnst)
- {
- if (not cnst->active_constraint_set_hook.is_linked())
- active_constraint_set.push_back(*cnst);
- }
- void make_constraint_inactive(Constraint * cnst)
- {
- if (cnst->active_constraint_set_hook.is_linked())
- simgrid::xbt::intrusive_erase(active_constraint_set, *cnst);
- if (cnst->modified_constraint_set_hook.is_linked())
- simgrid::xbt::intrusive_erase(modified_constraint_set, *cnst);
- }
-
- void enable_var(Variable * var);
- void disable_var(Variable * var);
- void on_disabled_var(Constraint * cnstr);
-
- /**
- * @brief Update the value of element linking the constraint and the variable
- * @param cnst A constraint
- * @param var A variable
- * @param value The new value
- */
- void update(Constraint * cnst, Variable * var, double value);
-
- void update_modified_set(Constraint * cnst);
- void update_modified_set_rec(Constraint * cnst);
-
- /** @brief Remove all constraints of the modified_constraint_set. */
- void remove_all_modified_set();
- void check_concurrency() const;
-
- template <class CnstList> void solve(CnstList& cnst_list);
-public:
- bool modified;
- boost::intrusive::list<Variable, boost::intrusive::member_hook<Variable, boost::intrusive::list_member_hook<>,
- &Variable::variable_set_hook>>
- variable_set;
- boost::intrusive::list<Constraint, boost::intrusive::member_hook<Constraint, boost::intrusive::list_member_hook<>,
- &Constraint::active_constraint_set_hook>>
- active_constraint_set;
- boost::intrusive::list<Variable, boost::intrusive::member_hook<Variable, boost::intrusive::list_member_hook<>,
- &Variable::saturated_variable_set_hook>>
- saturated_variable_set;
- boost::intrusive::list<Constraint, boost::intrusive::member_hook<Constraint, boost::intrusive::list_member_hook<>,
- &Constraint::saturated_constraint_set_hook>>
- saturated_constraint_set;
-
- simgrid::kernel::resource::ActionLmmListPtr keep_track;
-
- void (*solve_fun)(lmm_system_t self);
-
-private:
- bool selective_update_active; /* flag to update partially the system only selecting changed portions */
- unsigned visited_counter; /* used by System::update_modified_set() and System::remove_all_modified_set() to
- * cleverly (un-)flag the constraints (more details in these functions) */
- boost::intrusive::list<Constraint, boost::intrusive::member_hook<Constraint, boost::intrusive::list_member_hook<>,
- &Constraint::constraint_set_hook>>
- constraint_set;
- boost::intrusive::list<Constraint, boost::intrusive::member_hook<Constraint, boost::intrusive::list_member_hook<>,
- &Constraint::modified_constraint_set_hook>>
- modified_constraint_set;
- xbt_mallocator_t variable_mallocator;