#include "xbt/log.h"
#include "xbt/mallocator.h"
#include "xbt/sysdep.h"
+#include "xbt/utility.hpp"
#include <algorithm>
#include <cmath>
#include <cstdlib>
typedef std::vector<int> dyn_light_t;
-int s_lmm_variable_t::Global_debug_id = 1;
-int s_lmm_constraint_t::Global_debug_id = 1;
+int Variable::Global_debug_id = 1;
+int Constraint::Global_debug_id = 1;
int s_lmm_element_t::get_concurrency() const
{
if (not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug))
return;
- for (s_lmm_constraint_t const& cnst : constraint_set) {
+ for (Constraint const& cnst : constraint_set) {
int concurrency = 0;
for (s_lmm_element_t const& elem : cnst.enabled_element_set) {
xbt_assert(elem.variable->sharing_weight > 0);
}
// Check that for each variable, all corresponding elements are in the same state (i.e. same element sets)
- for (s_lmm_variable_t const& var : variable_set) {
+ for (Variable const& var : variable_set) {
if (var.cnsts.empty())
continue;
for (s_lmm_element_t& elem : var->cnsts) {
if (var->sharing_weight > 0)
elem.decrease_concurrency();
- if (elem.enabled_element_set_hook.is_linked()) {
- auto& set = elem.constraint->enabled_element_set;
- set.erase(set.iterator_to(elem));
- }
- if (elem.disabled_element_set_hook.is_linked()) {
- auto& set = elem.constraint->disabled_element_set;
- set.erase(set.iterator_to(elem));
- }
- if (elem.active_element_set_hook.is_linked()) {
- auto& set = elem.constraint->active_element_set;
- set.erase(set.iterator_to(elem));
- }
+ if (elem.enabled_element_set_hook.is_linked())
+ simgrid::xbt::intrusive_erase(elem.constraint->enabled_element_set, elem);
+ if (elem.disabled_element_set_hook.is_linked())
+ simgrid::xbt::intrusive_erase(elem.constraint->disabled_element_set, elem);
+ if (elem.active_element_set_hook.is_linked())
+ simgrid::xbt::intrusive_erase(elem.constraint->active_element_set, elem);
int nelements = elem.constraint->enabled_element_set.size() + elem.constraint->disabled_element_set.size();
if (nelements == 0)
make_constraint_inactive(elem.constraint);
s_lmm_system_t::s_lmm_system_t(bool selective_update) : selective_update_active(selective_update)
{
- s_lmm_variable_t var;
- s_lmm_constraint_t cnst;
-
modified = false;
visited_counter = 1;
delete cnst;
}
-s_lmm_constraint_t::s_lmm_constraint_t(void* id_value, double bound_value) : bound(bound_value), id(id_value)
+Constraint::Constraint(void* id_value, double bound_value) : bound(bound_value), id(id_value)
{
- s_lmm_element_t elem;
-
id_int = Global_debug_id++;
remaining = 0.0;
lmm_constraint_t s_lmm_system_t::constraint_new(void* id, double bound_value)
{
- lmm_constraint_t cnst = new s_lmm_constraint_t(id, bound_value);
+ lmm_constraint_t cnst = new Constraint(id, bound_value);
insert_constraint(cnst);
return cnst;
}
void* s_lmm_system_t::variable_mallocator_new_f()
{
- return new s_lmm_variable_t;
+ return new Variable;
}
void s_lmm_system_t::variable_mallocator_free_f(void* var)
check_concurrency();
}
-lmm_variable_t s_lmm_constraint_t::get_variable(const_lmm_element_t* elem) const
+lmm_variable_t Constraint::get_variable(const_lmm_element_t* elem) const
{
if (*elem == nullptr) {
// That is the first call, pick the first element among enabled_element_set (or disabled_element_set if
// if we modify the list between calls, normal version may loop forever
// this safe version ensures that we browse the list elements only once
-lmm_variable_t s_lmm_constraint_t::get_variable_safe(const_lmm_element_t* elem, const_lmm_element_t* nextelem,
- int* numelem) const
+lmm_variable_t Constraint::get_variable_safe(const_lmm_element_t* elem, const_lmm_element_t* nextelem,
+ int* numelem) const
{
if (*elem == nullptr) {
*numelem = enabled_element_set.size() + disabled_element_set.size() - 1;
// Look at enabled_element_set, and jump to disabled_element_set when finished
auto iter = std::next(enabled_element_set.iterator_to(**elem));
if (iter != std::end(enabled_element_set))
- *elem = &*iter;
+ *nextelem = &*iter;
else if (not disabled_element_set.empty())
- *elem = &disabled_element_set.front();
+ *nextelem = &disabled_element_set.front();
else
- *elem = nullptr;
+ *nextelem = nullptr;
} else {
auto iter = std::next(disabled_element_set.iterator_to(**elem));
- *elem = iter != std::end(disabled_element_set) ? &*iter : nullptr;
+ *nextelem = iter != std::end(disabled_element_set) ? &*iter : nullptr;
}
return (*elem)->variable;
} else
}
}
-static inline void saturated_variable_set_update(s_lmm_constraint_light_t* cnst_light_tab,
+static inline void saturated_variable_set_update(ConstraintLight* cnst_light_tab,
const dyn_light_t& saturated_constraints, lmm_system_t sys)
{
/* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate
* (cnst_light_tab)*/
for (int const& saturated_cnst : saturated_constraints) {
- s_lmm_constraint_light_t& cnst = cnst_light_tab[saturated_cnst];
+ ConstraintLight& cnst = cnst_light_tab[saturated_cnst];
for (s_lmm_element_t const& elem : cnst.cnst->active_element_set) {
// Visiting active_element_set, so, by construction, should never get a zero weight, correct?
xbt_assert(elem.variable->sharing_weight > 0);
std::string buf = std::string("MAX-MIN ( ");
/* Printing Objective */
- for (s_lmm_variable_t const& var : variable_set)
+ for (Variable const& var : variable_set)
buf += "'" + std::to_string(var.id_int) + "'(" + std::to_string(var.sharing_weight) + ") ";
buf += ")";
XBT_DEBUG("%20s", buf.c_str());
XBT_DEBUG("Constraints");
/* Printing Constraints */
- for (s_lmm_constraint_t const& cnst : active_constraint_set) {
+ for (Constraint const& cnst : active_constraint_set) {
double sum = 0.0;
// Show the enabled variables
buf += "\t";
XBT_DEBUG("Variables");
/* Printing Result */
- for (s_lmm_variable_t const& var : variable_set) {
+ for (Variable const& var : variable_set) {
if (var.bound > 0) {
XBT_DEBUG("'%d'(%f) : %f (<=%f)", var.id_int, var.sharing_weight, var.value, var.bound);
xbt_assert(not double_positive(var.value - var.bound, var.bound * sg_maxmin_precision),
XBT_DEBUG("Active constraints : %zu", cnst_list.size());
/* Init: Only modified code portions: reset the value of active variables */
- for (s_lmm_constraint_t const& cnst : cnst_list) {
+ for (Constraint const& cnst : cnst_list) {
for (s_lmm_element_t const& elem : cnst.enabled_element_set) {
xbt_assert(elem.variable->sharing_weight > 0.0);
elem.variable->value = 0.0;
}
}
- s_lmm_constraint_light_t* cnst_light_tab = new s_lmm_constraint_light_t[cnst_list.size()]();
- int cnst_light_num = 0;
+ ConstraintLight* cnst_light_tab = new ConstraintLight[cnst_list.size()]();
+ int cnst_light_num = 0;
dyn_light_t saturated_constraints;
- for (s_lmm_constraint_t& cnst : cnst_list) {
+ for (Constraint& cnst : cnst_list) {
/* INIT: Collect constraints that actually need to be saturated (i.e remaining and usage are strictly positive)
* into cnst_light_tab. */
cnst.remaining = cnst.bound;
do {
/* Fix the variables that have to be */
auto& var_list = saturated_variable_set;
- for (s_lmm_variable_t const& var : var_list) {
+ for (Variable const& var : var_list) {
if (var.sharing_weight <= 0.0)
DIE_IMPOSSIBLE;
/* First check if some of these variables could reach their upper bound and update min_bound accordingly. */
}
while (not var_list.empty()) {
- s_lmm_variable_t& var = var_list.front();
+ Variable& var = var_list.front();
if (min_bound < 0) {
// If no variable could reach its bound, deal iteratively the constraints usage ( at worst one constraint is
// saturated at each cycle)
update_modified_set(var->cnsts[0].constraint);
}
-void s_lmm_variable_t::initialize(simgrid::surf::Action* id_value, double sharing_weight_value, double bound_value,
- int number_of_constraints, unsigned visited_value)
+void Variable::initialize(simgrid::surf::Action* id_value, double sharing_weight_value, double bound_value,
+ int number_of_constraints, unsigned visited_value)
{
id = id_value;
id_int = Global_debug_id++;
xbt_assert(not saturated_variable_set_hook.is_linked());
}
-int s_lmm_variable_t::get_min_concurrency_slack() const
+int Variable::get_min_concurrency_slack() const
{
int minslack = std::numeric_limits<int>::max();
for (s_lmm_element_t const& elem : cnsts) {
// Enabling the variable, move var to list head. Subtlety is: here, we need to call update_modified_set AFTER
// moving at least one element of var.
- variable_set.erase(variable_set.iterator_to(*var));
+ simgrid::xbt::intrusive_erase(variable_set, *var);
variable_set.push_front(*var);
for (s_lmm_element_t& elem : var->cnsts) {
- auto& set = elem.constraint->disabled_element_set;
- set.erase(set.iterator_to(elem));
+ simgrid::xbt::intrusive_erase(elem.constraint->disabled_element_set, elem);
elem.constraint->enabled_element_set.push_front(elem);
elem.increase_concurrency();
}
xbt_assert(not var->staged_weight, "Staged weight should have been cleared");
// Disabling the variable, move to var to list tail. Subtlety is: here, we need to call update_modified_set
// BEFORE moving the last element of var.
- variable_set.erase(variable_set.iterator_to(*var));
+ simgrid::xbt::intrusive_erase(variable_set, *var);
variable_set.push_back(*var);
if (not var->cnsts.empty())
update_modified_set(var->cnsts[0].constraint);
for (s_lmm_element_t& elem : var->cnsts) {
- auto& set = elem.constraint->enabled_element_set;
- set.erase(set.iterator_to(elem));
+ simgrid::xbt::intrusive_erase(elem.constraint->enabled_element_set, elem);
elem.constraint->disabled_element_set.push_back(elem);
- if (elem.active_element_set_hook.is_linked()) {
- auto& set = elem.constraint->active_element_set;
- set.erase(set.iterator_to(elem));
- }
+ if (elem.active_element_set_hook.is_linked())
+ simgrid::xbt::intrusive_erase(elem.constraint->active_element_set, elem);
elem.decrease_concurrency();
}
// (i.e. not readibily reproducible, and requiring a lot of run time before happening).
if (++visited_counter == 1) {
/* the counter wrapped around, reset each variable->visited */
- for (s_lmm_variable_t& var : variable_set)
+ for (Variable& var : variable_set)
var.visited = 0;
}
modified_constraint_set.clear();
*
* \param cnst the lmm_constraint_t associated to the resource
*/
-double s_lmm_constraint_t::get_usage() const
+double Constraint::get_usage() const
{
double result = 0.0;
if (sharing_policy) {
return result;
}
-int s_lmm_constraint_t::get_variable_amount() const
+int Constraint::get_variable_amount() const
{
return std::count_if(std::begin(enabled_element_set), std::end(enabled_element_set),
[](const s_lmm_element_t& elem) { return elem.consumption_weight > 0; });