- double staged_penalty_; /* 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 */
- resource::Action* id_;
- int rank_; // Only used in debug messages to identify the variable
- unsigned visited_; /* used by System::update_modified_set() */
- double mu_;
-
-private:
- static int next_rank_; // To give a separate rank_ to each variable
-};
-
-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 */
- virtual ~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(resource::Resource* id, double bound_value);
-
- /**
- * @brief Create a new Linear MaxMin variable
- * @param id Data associated to the variable (e.g.: a network communication)
- * @param sharing_penalty 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 constraints to associate to the variable
- */
- Variable* variable_new(resource::Action* id, double sharing_penalty, double bound = -1.0,
- size_t number_of_constraints = 1);
-
- /**
- * @brief Free a variable
- * @param var The variable to free
- */
- void variable_free(Variable * var);
-
- /** @brief Free all variables */
- void variable_free_all();
-
- /**
- * @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 */
- void update_variable_bound(Variable * var, double bound);
-
- /** @brief Update the sharing penalty of a variable */
- void update_variable_penalty(Variable* var, double penalty);
-
- /** @brief Update a constraint bound */
- void update_constraint_bound(Constraint * cnst, double bound);
-
- 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 lmm_solve();
-
- /** @brief Solve the lmm system. May be specialized in subclasses. */
- virtual void solve() { lmm_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 lmm_solve(CnstList& cnst_list);
-
-public:
- bool modified_ = false;
- 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;
-
- resource::Action::ModifiedSet* modified_set_ = nullptr;
-
-private:
-
- typedef std::vector<int> dyn_light_t;
-
- //Data used in lmm::solve