{
for (Constraint const& cnst : active_constraint_set) {
double tmp = 0;
- for (Element const& elem : cnst.enabled_element_set) {
+ for (Element const& elem : cnst.enabled_element_set_) {
Variable* var = elem.variable;
- xbt_assert(var->sharing_weight > 0);
- tmp += var->value;
+ xbt_assert(var->sharing_weight_ > 0);
+ tmp += var->value_;
}
- if (double_positive(tmp - cnst.bound, sg_maxmin_precision)) {
+ if (double_positive(tmp - cnst.bound_, sg_maxmin_precision)) {
if (warn)
- XBT_WARN("The link (%p) is over-used. Expected less than %f and got %f", &cnst, cnst.bound, tmp);
+ XBT_WARN("The link (%p) is over-used. Expected less than %f and got %f", &cnst, cnst.bound_, tmp);
return false;
}
- XBT_DEBUG("Checking feasability for constraint (%p): sat = %f, lambda = %f ", &cnst, tmp - cnst.bound, cnst.lambda);
+ XBT_DEBUG("Checking feasability for constraint (%p): sat = %f, lambda = %f ", &cnst, tmp - cnst.bound_,
+ cnst.lambda_);
}
for (Variable const& var : variable_set) {
- if (not var.sharing_weight)
+ if (not var.sharing_weight_)
break;
- if (var.bound < 0)
+ if (var.bound_ < 0)
continue;
- XBT_DEBUG("Checking feasability for variable (%p): sat = %f mu = %f", &var, var.value - var.bound, var.mu);
+ XBT_DEBUG("Checking feasability for variable (%p): sat = %f mu = %f", &var, var.value_ - var.bound_, var.mu_);
- if (double_positive(var.value - var.bound, sg_maxmin_precision)) {
+ if (double_positive(var.value_ - var.bound_, sg_maxmin_precision)) {
if (warn)
- XBT_WARN("The variable (%p) is too large. Expected less than %f and got %f", &var, var.bound, var.value);
+ XBT_WARN("The variable (%p) is too large. Expected less than %f and got %f", &var, var.bound_, var.value_);
return false;
}
}
{
double tmp = 0;
- for (Element const& elem : var.cnsts) {
- tmp += elem.constraint->lambda;
+ for (Element const& elem : var.cnsts_) {
+ tmp += elem.constraint->lambda_;
}
- if (var.bound > 0)
- tmp += var.mu;
- XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", &var, tmp, var.sharing_weight);
+ if (var.bound_ > 0)
+ tmp += var.mu_;
+ XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", &var, tmp, var.sharing_weight_);
// uses the partial differential inverse function
return func_fpi(var, tmp);
}
double mu_i = 0.0;
double sigma_i = 0.0;
- for (Element const& elem : var.cnsts) {
- sigma_i += elem.constraint->lambda;
+ for (Element const& elem : var.cnsts_) {
+ sigma_i += elem.constraint->lambda_;
}
- mu_i = func_fp(var, var.bound) - sigma_i;
+ mu_i = func_fp(var, var.bound_) - sigma_i;
if (mu_i < 0.0)
return 0.0;
return mu_i;
for (Variable const& var : variable_set) {
double sigma_i = 0.0;
- if (not var.sharing_weight)
+ if (not var.sharing_weight_)
break;
- for (Element const& elem : var.cnsts)
- sigma_i += elem.constraint->lambda;
+ for (Element const& elem : var.cnsts_)
+ sigma_i += elem.constraint->lambda_;
- if (var.bound > 0)
- sigma_i += var.mu;
+ if (var.bound_ > 0)
+ sigma_i += var.mu_;
XBT_DEBUG("var %p : sigma_i = %1.20f", &var, sigma_i);
obj += func_f(var, func_fpi(var, sigma_i)) - sigma_i * func_fpi(var, sigma_i);
- if (var.bound > 0)
- obj += var.mu * var.bound;
+ if (var.bound_ > 0)
+ obj += var.mu_ * var.bound_;
}
for (Constraint const& cnst : active_constraint_set)
- obj += cnst.lambda * cnst.bound;
+ obj += cnst.lambda_ * cnst.bound_;
return obj;
}
/* Initialize lambda. */
for (Constraint& cnst : active_constraint_set) {
- cnst.lambda = 1.0;
- cnst.new_lambda = 2.0;
- XBT_DEBUG("#### cnst(%p)->lambda : %e", &cnst, cnst.lambda);
+ cnst.lambda_ = 1.0;
+ cnst.new_lambda_ = 2.0;
+ XBT_DEBUG("#### cnst(%p)->lambda : %e", &cnst, cnst.lambda_);
}
/*
* Initialize the active variables. Initialize mu.
*/
for (Variable& var : variable_set) {
- if (not var.sharing_weight)
- var.value = 0.0;
+ if (not var.sharing_weight_)
+ var.value_ = 0.0;
else {
- if (var.bound < 0.0) {
+ if (var.bound_ < 0.0) {
XBT_DEBUG("#### NOTE var(%p) is a boundless variable", &var);
- var.mu = -1.0;
+ var.mu_ = -1.0;
} else {
- var.mu = 1.0;
- var.new_mu = 2.0;
+ var.mu_ = 1.0;
+ var.new_mu_ = 2.0;
}
- var.value = new_value(var);
- XBT_DEBUG("#### var(%p) ->weight : %e", &var, var.sharing_weight);
- XBT_DEBUG("#### var(%p) ->mu : %e", &var, var.mu);
- XBT_DEBUG("#### var(%p) ->weight: %e", &var, var.sharing_weight);
- XBT_DEBUG("#### var(%p) ->bound: %e", &var, var.bound);
- auto weighted =
- std::find_if(begin(var.cnsts), end(var.cnsts), [](Element const& x) { return x.consumption_weight != 0.0; });
- if (weighted == end(var.cnsts))
- var.value = 1.0;
+ var.value_ = new_value(var);
+ XBT_DEBUG("#### var(%p) ->weight : %e", &var, var.sharing_weight_);
+ XBT_DEBUG("#### var(%p) ->mu : %e", &var, var.mu_);
+ XBT_DEBUG("#### var(%p) ->weight: %e", &var, var.sharing_weight_);
+ XBT_DEBUG("#### var(%p) ->bound: %e", &var, var.bound_);
+ auto weighted = std::find_if(begin(var.cnsts_), end(var.cnsts_),
+ [](Element const& x) { return x.consumption_weight != 0.0; });
+ if (weighted == end(var.cnsts_))
+ var.value_ = 1.0;
}
}
/* Improve the value of mu_i */
for (Variable& var : variable_set) {
- if (var.sharing_weight && var.bound >= 0) {
+ if (var.sharing_weight_ && var.bound_ >= 0) {
XBT_DEBUG("Working on var (%p)", &var);
- var.new_mu = new_mu(var);
- XBT_DEBUG("Updating mu : var->mu (%p) : %1.20f -> %1.20f", &var, var.mu, var.new_mu);
- var.mu = var.new_mu;
+ var.new_mu_ = new_mu(var);
+ XBT_DEBUG("Updating mu : var->mu (%p) : %1.20f -> %1.20f", &var, var.mu_, var.new_mu_);
+ var.mu_ = var.new_mu_;
double new_obj = dual_objective();
XBT_DEBUG("Improvement for Objective (%g -> %g) : %g", obj, new_obj, obj - new_obj);
/* Improve the value of lambda_i */
for (Constraint& cnst : active_constraint_set) {
XBT_DEBUG("Working on cnst (%p)", &cnst);
- cnst.new_lambda = dichotomy(cnst.lambda, cnst, dichotomy_min_error);
- XBT_DEBUG("Updating lambda : cnst->lambda (%p) : %1.20f -> %1.20f", &cnst, cnst.lambda, cnst.new_lambda);
- cnst.lambda = cnst.new_lambda;
+ cnst.new_lambda_ = dichotomy(cnst.lambda_, cnst, dichotomy_min_error);
+ XBT_DEBUG("Updating lambda : cnst->lambda (%p) : %1.20f -> %1.20f", &cnst, cnst.lambda_, cnst.new_lambda_);
+ cnst.lambda_ = cnst.new_lambda_;
double new_obj = dual_objective();
XBT_DEBUG("Improvement for Objective (%g -> %g) : %g", obj, new_obj, obj - new_obj);
XBT_DEBUG("-------------- Check convergence ----------");
overall_modification = 0;
for (Variable& var : variable_set) {
- if (var.sharing_weight <= 0)
- var.value = 0.0;
+ if (var.sharing_weight_ <= 0)
+ var.value_ = 0.0;
else {
double tmp = new_value(var);
- overall_modification = std::max(overall_modification, fabs(var.value - tmp));
+ overall_modification = std::max(overall_modification, fabs(var.value_ - tmp));
- var.value = tmp;
- XBT_DEBUG("New value of var (%p) = %e, overall_modification = %e", &var, var.value, overall_modification);
+ var.value_ = tmp;
+ XBT_DEBUG("New value of var (%p) = %e, overall_modification = %e", &var, var.value_, overall_modification);
}
}
XBT_CDEBUG(surf_lagrange_dichotomy, "Computing diff of cnst (%p)", &cnst);
- for (Element const& elem : cnst.enabled_element_set) {
+ for (Element const& elem : cnst.enabled_element_set_) {
Variable& var = *elem.variable;
- xbt_assert(var.sharing_weight > 0);
+ xbt_assert(var.sharing_weight_ > 0);
XBT_CDEBUG(surf_lagrange_dichotomy, "Computing sigma_i for var (%p)", &var);
// Initialize the summation variable
double sigma_i = 0.0;
// Compute sigma_i
- for (Element const& elem2 : var.cnsts)
- sigma_i += elem2.constraint->lambda;
+ for (Element const& elem2 : var.cnsts_)
+ sigma_i += elem2.constraint->lambda_;
// add mu_i if this flow has a RTT constraint associated
- if (var.bound > 0)
- sigma_i += var.mu;
+ if (var.bound_ > 0)
+ sigma_i += var.mu_;
// replace value of cnst.lambda by the value of parameter lambda
- sigma_i = (sigma_i - cnst.lambda) + lambda;
+ sigma_i = (sigma_i - cnst.lambda_) + lambda;
diff += -func_fpi(var, sigma_i);
}
- diff += cnst.bound;
+ diff += cnst.bound_;
XBT_CDEBUG(surf_lagrange_dichotomy, "d D/d lambda for cnst (%p) at %1.20f = %1.20f", &cnst, lambda, diff);
XBT_OUT();
double func_vegas_f(const Variable& var, double x)
{
xbt_assert(x > 0.0, "Don't call me with stupid values! (%1.20f)", x);
- return VEGAS_SCALING * var.sharing_weight * log(x);
+ return VEGAS_SCALING * var.sharing_weight_ * log(x);
}
double func_vegas_fp(const Variable& var, double x)
{
xbt_assert(x > 0.0, "Don't call me with stupid values! (%1.20f)", x);
- return VEGAS_SCALING * var.sharing_weight / x;
+ return VEGAS_SCALING * var.sharing_weight_ / x;
}
double func_vegas_fpi(const Variable& var, double x)
{
xbt_assert(x > 0.0, "Don't call me with stupid values! (%1.20f)", x);
- return var.sharing_weight / (x / VEGAS_SCALING);
+ return var.sharing_weight_ / (x / VEGAS_SCALING);
}
/*
*/
double func_reno_f(const Variable& var, double x)
{
- xbt_assert(var.sharing_weight > 0.0, "Don't call me with stupid values!");
+ xbt_assert(var.sharing_weight_ > 0.0, "Don't call me with stupid values!");
- return RENO_SCALING * sqrt(3.0 / 2.0) / var.sharing_weight * atan(sqrt(3.0 / 2.0) * var.sharing_weight * x);
+ return RENO_SCALING * sqrt(3.0 / 2.0) / var.sharing_weight_ * atan(sqrt(3.0 / 2.0) * var.sharing_weight_ * x);
}
double func_reno_fp(const Variable& var, double x)
{
- return RENO_SCALING * 3.0 / (3.0 * var.sharing_weight * var.sharing_weight * x * x + 2.0);
+ return RENO_SCALING * 3.0 / (3.0 * var.sharing_weight_ * var.sharing_weight_ * x * x + 2.0);
}
double func_reno_fpi(const Variable& var, double x)
{
double res_fpi;
- xbt_assert(var.sharing_weight > 0.0, "Don't call me with stupid values!");
+ xbt_assert(var.sharing_weight_ > 0.0, "Don't call me with stupid values!");
xbt_assert(x > 0.0, "Don't call me with stupid values!");
- res_fpi = 1.0 / (var.sharing_weight * var.sharing_weight * (x / RENO_SCALING)) -
- 2.0 / (3.0 * var.sharing_weight * var.sharing_weight);
+ res_fpi = 1.0 / (var.sharing_weight_ * var.sharing_weight_ * (x / RENO_SCALING)) -
+ 2.0 / (3.0 * var.sharing_weight_ * var.sharing_weight_);
if (res_fpi <= 0.0)
return 0.0;
return sqrt(res_fpi);
*/
double func_reno2_f(const Variable& var, double x)
{
- xbt_assert(var.sharing_weight > 0.0, "Don't call me with stupid values!");
- return RENO2_SCALING * (1.0 / var.sharing_weight) *
- log((x * var.sharing_weight) / (2.0 * x * var.sharing_weight + 3.0));
+ xbt_assert(var.sharing_weight_ > 0.0, "Don't call me with stupid values!");
+ return RENO2_SCALING * (1.0 / var.sharing_weight_) *
+ log((x * var.sharing_weight_) / (2.0 * x * var.sharing_weight_ + 3.0));
}
double func_reno2_fp(const Variable& var, double x)
{
- return RENO2_SCALING * 3.0 / (var.sharing_weight * x * (2.0 * var.sharing_weight * x + 3.0));
+ return RENO2_SCALING * 3.0 / (var.sharing_weight_ * x * (2.0 * var.sharing_weight_ * x + 3.0));
}
double func_reno2_fpi(const Variable& var, double x)
{
xbt_assert(x > 0.0, "Don't call me with stupid values!");
- double tmp = x * var.sharing_weight * var.sharing_weight;
+ double tmp = x * var.sharing_weight_ * var.sharing_weight_;
double res_fpi = tmp * (9.0 * x + 24.0);
if (res_fpi <= 0.0)
typedef std::vector<int> dyn_light_t;
-int Variable::Global_debug_id = 1;
-int Constraint::Global_debug_id = 1;
+int Variable::Global_debug_id_ = 1;
+int Constraint::Global_debug_id_ = 1;
System* make_new_maxmin_system(bool selective_update)
{
void Element::decrease_concurrency()
{
- xbt_assert(constraint->concurrency_current >= get_concurrency());
- constraint->concurrency_current -= get_concurrency();
+ xbt_assert(constraint->concurrency_current_ >= get_concurrency());
+ constraint->concurrency_current_ -= get_concurrency();
}
void Element::increase_concurrency()
{
- constraint->concurrency_current += get_concurrency();
+ constraint->concurrency_current_ += get_concurrency();
- if (constraint->concurrency_current > constraint->concurrency_maximum)
- constraint->concurrency_maximum = constraint->concurrency_current;
+ if (constraint->concurrency_current_ > constraint->concurrency_maximum_)
+ constraint->concurrency_maximum_ = constraint->concurrency_current_;
xbt_assert(constraint->get_concurrency_limit() < 0 ||
- constraint->concurrency_current <= constraint->get_concurrency_limit(),
+ constraint->concurrency_current_ <= constraint->get_concurrency_limit(),
"Concurrency limit overflow!");
}
for (Constraint const& cnst : constraint_set) {
int concurrency = 0;
- for (Element const& elem : cnst.enabled_element_set) {
- xbt_assert(elem.variable->sharing_weight > 0);
+ for (Element const& elem : cnst.enabled_element_set_) {
+ xbt_assert(elem.variable->sharing_weight_ > 0);
concurrency += elem.get_concurrency();
}
- for (Element const& elem : cnst.disabled_element_set) {
+ for (Element const& elem : cnst.disabled_element_set_) {
// We should have staged variables only if concurrency is reached in some constraint
- xbt_assert(cnst.get_concurrency_limit() < 0 || elem.variable->staged_weight == 0 ||
- elem.variable->get_min_concurrency_slack() < elem.variable->concurrency_share,
+ xbt_assert(cnst.get_concurrency_limit() < 0 || elem.variable->staged_weight_ == 0 ||
+ elem.variable->get_min_concurrency_slack() < elem.variable->concurrency_share_,
"should not have staged variable!");
}
xbt_assert(cnst.get_concurrency_limit() < 0 || cnst.get_concurrency_limit() >= concurrency,
"concurrency check failed!");
- xbt_assert(cnst.concurrency_current == concurrency, "concurrency_current is out-of-date!");
+ xbt_assert(cnst.concurrency_current_ == concurrency, "concurrency_current is out-of-date!");
}
// Check that for each variable, all corresponding elements are in the same state (i.e. same element sets)
for (Variable const& var : variable_set) {
- if (var.cnsts.empty())
+ if (var.cnsts_.empty())
continue;
- const Element& elem = var.cnsts[0];
+ const Element& elem = var.cnsts_[0];
int belong_to_enabled = elem.enabled_element_set_hook.is_linked();
int belong_to_disabled = elem.disabled_element_set_hook.is_linked();
int belong_to_active = elem.active_element_set_hook.is_linked();
- for (Element const& elem2 : var.cnsts) {
+ for (Element const& elem2 : var.cnsts_) {
xbt_assert(belong_to_enabled == elem2.enabled_element_set_hook.is_linked(),
"Variable inconsistency (1): enabled_element_set");
xbt_assert(belong_to_disabled == elem2.disabled_element_set_hook.is_linked(),
// TODOLATER Can do better than that by leaving only the variable in only one enabled_element_set, call
// update_modified_set, and then remove it..
- if (not var->cnsts.empty())
- update_modified_set(var->cnsts[0].constraint);
+ if (not var->cnsts_.empty())
+ update_modified_set(var->cnsts_[0].constraint);
- for (Element& elem : var->cnsts) {
- if (var->sharing_weight > 0)
+ for (Element& elem : var->cnsts_) {
+ if (var->sharing_weight_ > 0)
elem.decrease_concurrency();
if (elem.enabled_element_set_hook.is_linked())
- simgrid::xbt::intrusive_erase(elem.constraint->enabled_element_set, elem);
+ 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);
+ 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();
+ 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);
else
on_disabled_var(elem.constraint);
}
- var->cnsts.clear();
+ var->cnsts_.clear();
check_concurrency();
Constraint* cnst;
while ((var = extract_variable())) {
- auto demangled = simgrid::xbt::demangle(typeid(*var->id).name());
+ auto demangled = simgrid::xbt::demangle(typeid(*var->id_).name());
XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.get(),
- var->id_int);
+ var->id_int_);
var_free(var);
}
while ((cnst = extract_constraint()))
delete cnst;
}
-Constraint::Constraint(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)
{
- id_int = Global_debug_id++;
+ id_int_ = Global_debug_id_++;
- remaining = 0.0;
- usage = 0.0;
- concurrency_limit = sg_concurrency_limit;
- concurrency_current = 0;
- concurrency_maximum = 0;
- sharing_policy = s4u::Link::SharingPolicy::SHARED;
+ remaining_ = 0.0;
+ usage_ = 0.0;
+ concurrency_limit_ = sg_concurrency_limit;
+ concurrency_current_ = 0;
+ concurrency_maximum_ = 0;
+ sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
- lambda = 0.0;
- new_lambda = 0.0;
- cnst_light = nullptr;
+ lambda_ = 0.0;
+ new_lambda_ = 0.0;
+ cnst_light_ = nullptr;
}
Constraint* System::constraint_new(void* id, double bound_value)
// Check if this variable already has an active element in this constraint
// If it does, substract it from the required slack
int current_share = 0;
- if (var->concurrency_share > 1) {
- for (Element& elem : var->cnsts) {
+ if (var->concurrency_share_ > 1) {
+ for (Element& elem : var->cnsts_) {
if (elem.constraint == cnst && elem.enabled_element_set_hook.is_linked())
current_share += elem.get_concurrency();
}
}
// Check if we need to disable the variable
- if (var->sharing_weight > 0 && var->concurrency_share - current_share > cnst->get_concurrency_slack()) {
- double weight = var->sharing_weight;
+ if (var->sharing_weight_ > 0 && var->concurrency_share_ - current_share > cnst->get_concurrency_slack()) {
+ double weight = var->sharing_weight_;
disable_var(var);
- for (Element const& elem : var->cnsts)
+ for (Element const& elem : var->cnsts_)
on_disabled_var(elem.constraint);
consumption_weight = 0;
- var->staged_weight = weight;
- xbt_assert(not var->sharing_weight);
+ var->staged_weight_ = weight;
+ xbt_assert(not var->sharing_weight_);
}
- xbt_assert(var->cnsts.size() < var->cnsts.capacity(), "Too much constraints");
+ xbt_assert(var->cnsts_.size() < var->cnsts_.capacity(), "Too much constraints");
- var->cnsts.resize(var->cnsts.size() + 1);
- Element& elem = var->cnsts.back();
+ var->cnsts_.resize(var->cnsts_.size() + 1);
+ Element& elem = var->cnsts_.back();
elem.consumption_weight = consumption_weight;
elem.constraint = cnst;
elem.variable = var;
- if (var->sharing_weight) {
- elem.constraint->enabled_element_set.push_front(elem);
+ if (var->sharing_weight_) {
+ elem.constraint->enabled_element_set_.push_front(elem);
elem.increase_concurrency();
} else
- elem.constraint->disabled_element_set.push_back(elem);
+ elem.constraint->disabled_element_set_.push_back(elem);
if (not selective_update_active) {
make_constraint_active(cnst);
- } else if (elem.consumption_weight > 0 || var->sharing_weight > 0) {
+ } else if (elem.consumption_weight > 0 || var->sharing_weight_ > 0) {
make_constraint_active(cnst);
update_modified_set(cnst);
// TODOLATER: Why do we need this second call?
- if (var->cnsts.size() > 1)
- update_modified_set(var->cnsts[0].constraint);
+ if (var->cnsts_.size() > 1)
+ update_modified_set(var->cnsts_[0].constraint);
}
check_concurrency();
// BEWARE: In case you have multiple elements in one constraint, this will always add value to the first element.
auto elem_it =
- std::find_if(begin(var->cnsts), end(var->cnsts), [&cnst](Element const& x) { return x.constraint == cnst; });
- if (elem_it != end(var->cnsts)) {
+ std::find_if(begin(var->cnsts_), end(var->cnsts_), [&cnst](Element const& x) { return x.constraint == cnst; });
+ if (elem_it != end(var->cnsts_)) {
Element& elem = *elem_it;
- if (var->sharing_weight)
+ if (var->sharing_weight_)
elem.decrease_concurrency();
- if (cnst->sharing_policy != s4u::Link::SharingPolicy::FATPIPE)
+ if (cnst->sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE)
elem.consumption_weight += value;
else
elem.consumption_weight = std::max(elem.consumption_weight, value);
// We need to check that increasing value of the element does not cross the concurrency limit
- if (var->sharing_weight) {
+ if (var->sharing_weight_) {
if (cnst->get_concurrency_slack() < elem.get_concurrency()) {
- double weight = var->sharing_weight;
+ double weight = var->sharing_weight_;
disable_var(var);
- for (Element const& elem2 : var->cnsts)
+ for (Element const& elem2 : var->cnsts_)
on_disabled_var(elem2.constraint);
- var->staged_weight = weight;
- xbt_assert(not var->sharing_weight);
+ var->staged_weight_ = weight;
+ xbt_assert(not var->sharing_weight_);
}
elem.increase_concurrency();
}
if (*elem == nullptr) {
// That is the first call, pick the first element among enabled_element_set (or disabled_element_set if
// enabled_element_set is empty)
- if (not enabled_element_set.empty())
- *elem = &enabled_element_set.front();
- else if (not disabled_element_set.empty())
- *elem = &disabled_element_set.front();
+ if (not enabled_element_set_.empty())
+ *elem = &enabled_element_set_.front();
+ else if (not disabled_element_set_.empty())
+ *elem = &disabled_element_set_.front();
else
*elem = nullptr;
} else {
// elem is not null, so we carry on
if ((*elem)->enabled_element_set_hook.is_linked()) {
// 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))
+ auto iter = std::next(enabled_element_set_.iterator_to(**elem));
+ if (iter != std::end(enabled_element_set_))
*elem = &*iter;
- else if (not disabled_element_set.empty())
- *elem = &disabled_element_set.front();
+ else if (not disabled_element_set_.empty())
+ *elem = &disabled_element_set_.front();
else
*elem = nullptr;
} else {
- auto iter = std::next(disabled_element_set.iterator_to(**elem));
- *elem = iter != std::end(disabled_element_set) ? &*iter : nullptr;
+ auto iter = std::next(disabled_element_set_.iterator_to(**elem));
+ *elem = iter != std::end(disabled_element_set_) ? &*iter : nullptr;
}
}
if (*elem)
Variable* Constraint::get_variable_safe(const Element** elem, const Element** nextelem, int* numelem) const
{
if (*elem == nullptr) {
- *numelem = enabled_element_set.size() + disabled_element_set.size() - 1;
- if (not enabled_element_set.empty())
- *elem = &enabled_element_set.front();
- else if (not disabled_element_set.empty())
- *elem = &disabled_element_set.front();
+ *numelem = enabled_element_set_.size() + disabled_element_set_.size() - 1;
+ if (not enabled_element_set_.empty())
+ *elem = &enabled_element_set_.front();
+ else if (not disabled_element_set_.empty())
+ *elem = &disabled_element_set_.front();
else
*elem = nullptr;
} else {
// elem is not null, so we carry on
if ((*elem)->enabled_element_set_hook.is_linked()) {
// 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))
+ auto iter = std::next(enabled_element_set_.iterator_to(**elem));
+ if (iter != std::end(enabled_element_set_))
*nextelem = &*iter;
- else if (not disabled_element_set.empty())
- *nextelem = &disabled_element_set.front();
+ else if (not disabled_element_set_.empty())
+ *nextelem = &disabled_element_set_.front();
else
*nextelem = nullptr;
} else {
- auto iter = std::next(disabled_element_set.iterator_to(**elem));
- *nextelem = iter != std::end(disabled_element_set) ? &*iter : nullptr;
+ auto iter = std::next(disabled_element_set_.iterator_to(**elem));
+ *nextelem = iter != std::end(disabled_element_set_) ? &*iter : nullptr;
}
return (*elem)->variable;
} else
* (cnst_light_tab)*/
for (int const& saturated_cnst : saturated_constraints) {
ConstraintLight& cnst = cnst_light_tab[saturated_cnst];
- for (Element const& elem : cnst.cnst->active_element_set) {
+ for (Element 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);
- if (elem.consumption_weight > 0 && not elem.variable->saturated_variable_set_hook.is_linked())
+ xbt_assert(elem.variable->sharing_weight_ > 0);
+ if (elem.consumption_weight > 0 && not elem.variable->saturated_variable_set_hook_.is_linked())
sys->saturated_variable_set.push_back(*elem.variable);
}
}
std::string& buf)
{
for (Element const& elem : elem_list) {
- buf += std::to_string(elem.consumption_weight) + ".'" + std::to_string(elem.variable->id_int) + "'(" +
- std::to_string(elem.variable->value) + ")" +
+ buf += std::to_string(elem.consumption_weight) + ".'" + std::to_string(elem.variable->id_int_) + "'(" +
+ std::to_string(elem.variable->value_) + ")" +
(sharing_policy != s4u::Link::SharingPolicy::FATPIPE ? " + " : " , ");
if (sharing_policy != s4u::Link::SharingPolicy::FATPIPE)
- sum += elem.consumption_weight * elem.variable->value;
+ sum += elem.consumption_weight * elem.variable->value_;
else
- sum = std::max(sum, elem.consumption_weight * elem.variable->value);
+ sum = std::max(sum, elem.consumption_weight * elem.variable->value_);
}
}
/* Printing Objective */
for (Variable const& var : variable_set)
- buf += "'" + std::to_string(var.id_int) + "'(" + std::to_string(var.sharing_weight) + ") ";
+ buf += "'" + std::to_string(var.id_int_) + "'(" + std::to_string(var.sharing_weight_) + ") ";
buf += ")";
XBT_DEBUG("%20s", buf.c_str());
buf.clear();
double sum = 0.0;
// Show the enabled variables
buf += "\t";
- buf += cnst.sharing_policy != s4u::Link::SharingPolicy::FATPIPE ? "(" : "max(";
- format_element_list(cnst.enabled_element_set, cnst.sharing_policy, sum, buf);
+ buf += cnst.sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE ? "(" : "max(";
+ format_element_list(cnst.enabled_element_set_, cnst.sharing_policy_, sum, buf);
// TODO: Adding disabled elements only for test compatibility, but do we really want them to be printed?
- format_element_list(cnst.disabled_element_set, cnst.sharing_policy, sum, buf);
+ format_element_list(cnst.disabled_element_set_, cnst.sharing_policy_, sum, buf);
- buf += "0) <= " + std::to_string(cnst.bound) + " ('" + std::to_string(cnst.id_int) + "')";
+ buf += "0) <= " + std::to_string(cnst.bound_) + " ('" + std::to_string(cnst.id_int_) + "')";
- if (cnst.sharing_policy == s4u::Link::SharingPolicy::FATPIPE) {
+ if (cnst.sharing_policy_ == s4u::Link::SharingPolicy::FATPIPE) {
buf += " [MAX-Constraint]";
}
XBT_DEBUG("%s", buf.c_str());
buf.clear();
- xbt_assert(not double_positive(sum - cnst.bound, cnst.bound * sg_maxmin_precision),
- "Incorrect value (%f is not smaller than %f): %g", sum, cnst.bound, sum - cnst.bound);
+ xbt_assert(not double_positive(sum - cnst.bound_, cnst.bound_ * sg_maxmin_precision),
+ "Incorrect value (%f is not smaller than %f): %g", sum, cnst.bound_, sum - cnst.bound_);
}
XBT_DEBUG("Variables");
/* Printing Result */
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),
- "Incorrect value (%f is not smaller than %f", var.value, var.bound);
+ 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),
+ "Incorrect value (%f is not smaller than %f", var.value_, var.bound_);
} else {
- XBT_DEBUG("'%d'(%f) : %f", var.id_int, var.sharing_weight, var.value);
+ XBT_DEBUG("'%d'(%f) : %f", var.id_int_, var.sharing_weight_, var.value_);
}
}
}
XBT_DEBUG("Active constraints : %zu", cnst_list.size());
/* Init: Only modified code portions: reset the value of active variables */
for (Constraint const& cnst : cnst_list) {
- for (Element const& elem : cnst.enabled_element_set) {
- xbt_assert(elem.variable->sharing_weight > 0.0);
- elem.variable->value = 0.0;
+ for (Element const& elem : cnst.enabled_element_set_) {
+ xbt_assert(elem.variable->sharing_weight_ > 0.0);
+ elem.variable->value_ = 0.0;
}
}
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;
- if (not double_positive(cnst.remaining, cnst.bound * sg_maxmin_precision))
+ cnst.remaining_ = cnst.bound_;
+ if (not double_positive(cnst.remaining_, cnst.bound_ * sg_maxmin_precision))
continue;
- cnst.usage = 0;
- for (Element& elem : cnst.enabled_element_set) {
- xbt_assert(elem.variable->sharing_weight > 0);
+ cnst.usage_ = 0;
+ for (Element& elem : cnst.enabled_element_set_) {
+ xbt_assert(elem.variable->sharing_weight_ > 0);
if (elem.consumption_weight > 0) {
- if (cnst.sharing_policy != s4u::Link::SharingPolicy::FATPIPE)
- cnst.usage += elem.consumption_weight / elem.variable->sharing_weight;
- else if (cnst.usage < elem.consumption_weight / elem.variable->sharing_weight)
- cnst.usage = elem.consumption_weight / elem.variable->sharing_weight;
+ if (cnst.sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE)
+ cnst.usage_ += elem.consumption_weight / elem.variable->sharing_weight_;
+ else if (cnst.usage_ < elem.consumption_weight / elem.variable->sharing_weight_)
+ cnst.usage_ = elem.consumption_weight / elem.variable->sharing_weight_;
elem.make_active();
- resource::Action* action = static_cast<resource::Action*>(elem.variable->id);
+ resource::Action* action = static_cast<resource::Action*>(elem.variable->id_);
if (modified_set_ && not action->is_within_modified_set())
modified_set_->push_back(*action);
}
}
- XBT_DEBUG("Constraint '%d' usage: %f remaining: %f concurrency: %i<=%i<=%i", cnst.id_int, cnst.usage,
- cnst.remaining, cnst.concurrency_current, cnst.concurrency_maximum, cnst.get_concurrency_limit());
+ XBT_DEBUG("Constraint '%d' usage: %f remaining: %f concurrency: %i<=%i<=%i", cnst.id_int_, cnst.usage_,
+ cnst.remaining_, cnst.concurrency_current_, cnst.concurrency_maximum_, cnst.get_concurrency_limit());
/* Saturated constraints update */
- if (cnst.usage > 0) {
+ if (cnst.usage_ > 0) {
cnst_light_tab[cnst_light_num].cnst = &cnst;
- cnst.cnst_light = &cnst_light_tab[cnst_light_num];
- cnst_light_tab[cnst_light_num].remaining_over_usage = cnst.remaining / cnst.usage;
+ cnst.cnst_light_ = &cnst_light_tab[cnst_light_num];
+ cnst_light_tab[cnst_light_num].remaining_over_usage = cnst.remaining_ / cnst.usage_;
saturated_constraints_update(cnst_light_tab[cnst_light_num].remaining_over_usage, cnst_light_num,
saturated_constraints, &min_usage);
- xbt_assert(not cnst.active_element_set.empty(),
+ xbt_assert(not cnst.active_element_set_.empty(),
"There is no sense adding a constraint that has no active element!");
cnst_light_num++;
}
/* Fix the variables that have to be */
auto& var_list = saturated_variable_set;
for (Variable const& var : var_list) {
- if (var.sharing_weight <= 0.0)
+ 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. */
- XBT_DEBUG("var=%d, var.bound=%f, var.weight=%f, min_usage=%f, var.bound*var.weight=%f", var.id_int, var.bound,
- var.sharing_weight, min_usage, var.bound * var.sharing_weight);
- if ((var.bound > 0) && (var.bound * var.sharing_weight < min_usage)) {
+ XBT_DEBUG("var=%d, var.bound=%f, var.weight=%f, min_usage=%f, var.bound*var.weight=%f", var.id_int_, var.bound_,
+ var.sharing_weight_, min_usage, var.bound_ * var.sharing_weight_);
+ if ((var.bound_ > 0) && (var.bound_ * var.sharing_weight_ < min_usage)) {
if (min_bound < 0)
- min_bound = var.bound * var.sharing_weight;
+ min_bound = var.bound_ * var.sharing_weight_;
else
- min_bound = std::min(min_bound, (var.bound * var.sharing_weight));
+ min_bound = std::min(min_bound, (var.bound_ * var.sharing_weight_));
XBT_DEBUG("Updated min_bound=%f", min_bound);
}
}
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)
- var.value = min_usage / var.sharing_weight;
- XBT_DEBUG("Setting var (%d) value to %f\n", var.id_int, var.value);
+ var.value_ = min_usage / var.sharing_weight_;
+ XBT_DEBUG("Setting var (%d) value to %f\n", var.id_int_, var.value_);
} else {
// If there exist a variable that can reach its bound, only update it (and other with the same bound) for now.
- if (double_equals(min_bound, var.bound * var.sharing_weight, sg_maxmin_precision)) {
- var.value = var.bound;
- XBT_DEBUG("Setting %p (%d) value to %f\n", &var, var.id_int, var.value);
+ if (double_equals(min_bound, var.bound_ * var.sharing_weight_, sg_maxmin_precision)) {
+ var.value_ = var.bound_;
+ XBT_DEBUG("Setting %p (%d) value to %f\n", &var, var.id_int_, var.value_);
} else {
// Variables which bound is different are not considered for this cycle, but they will be afterwards.
- XBT_DEBUG("Do not consider %p (%d) \n", &var, var.id_int);
+ XBT_DEBUG("Do not consider %p (%d) \n", &var, var.id_int_);
var_list.pop_front();
continue;
}
}
- XBT_DEBUG("Min usage: %f, Var(%d).weight: %f, Var(%d).value: %f ", min_usage, var.id_int, var.sharing_weight,
- var.id_int, var.value);
+ XBT_DEBUG("Min usage: %f, Var(%d).weight: %f, Var(%d).value: %f ", min_usage, var.id_int_, var.sharing_weight_,
+ var.id_int_, var.value_);
/* Update the usage of contraints where this variable is involved */
- for (Element& elem : var.cnsts) {
+ for (Element& elem : var.cnsts_) {
Constraint* cnst = elem.constraint;
- if (cnst->sharing_policy != s4u::Link::SharingPolicy::FATPIPE) {
+ if (cnst->sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE) {
// Remember: shared constraints require that sum(elem.value * var.value) < cnst->bound
- double_update(&(cnst->remaining), elem.consumption_weight * var.value, cnst->bound * sg_maxmin_precision);
- double_update(&(cnst->usage), elem.consumption_weight / var.sharing_weight, sg_maxmin_precision);
+ double_update(&(cnst->remaining_), elem.consumption_weight * var.value_, cnst->bound_ * sg_maxmin_precision);
+ double_update(&(cnst->usage_), elem.consumption_weight / var.sharing_weight_, sg_maxmin_precision);
// If the constraint is saturated, remove it from the set of active constraints (light_tab)
- if (not double_positive(cnst->usage, sg_maxmin_precision) ||
- not double_positive(cnst->remaining, cnst->bound * sg_maxmin_precision)) {
- if (cnst->cnst_light) {
- int index = (cnst->cnst_light - cnst_light_tab);
+ if (not double_positive(cnst->usage_, sg_maxmin_precision) ||
+ not double_positive(cnst->remaining_, cnst->bound_ * sg_maxmin_precision)) {
+ if (cnst->cnst_light_) {
+ int index = (cnst->cnst_light_ - cnst_light_tab);
XBT_DEBUG("index: %d \t cnst_light_num: %d \t || usage: %f remaining: %f bound: %f ", index,
- cnst_light_num, cnst->usage, cnst->remaining, cnst->bound);
+ cnst_light_num, cnst->usage_, cnst->remaining_, cnst->bound_);
cnst_light_tab[index] = cnst_light_tab[cnst_light_num - 1];
- cnst_light_tab[index].cnst->cnst_light = &cnst_light_tab[index];
+ cnst_light_tab[index].cnst->cnst_light_ = &cnst_light_tab[index];
cnst_light_num--;
- cnst->cnst_light = nullptr;
+ cnst->cnst_light_ = nullptr;
}
} else {
- cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage;
+ cnst->cnst_light_->remaining_over_usage = cnst->remaining_ / cnst->usage_;
}
elem.make_inactive();
} else {
// Remember: non-shared constraints only require that max(elem.value * var.value) < cnst->bound
- cnst->usage = 0.0;
+ cnst->usage_ = 0.0;
elem.make_inactive();
- for (Element& elem2 : cnst->enabled_element_set) {
- xbt_assert(elem2.variable->sharing_weight > 0);
- if (elem2.variable->value > 0)
+ for (Element& elem2 : cnst->enabled_element_set_) {
+ xbt_assert(elem2.variable->sharing_weight_ > 0);
+ if (elem2.variable->value_ > 0)
continue;
if (elem2.consumption_weight > 0)
- cnst->usage = std::max(cnst->usage, elem2.consumption_weight / elem2.variable->sharing_weight);
+ cnst->usage_ = std::max(cnst->usage_, elem2.consumption_weight / elem2.variable->sharing_weight_);
}
// If the constraint is saturated, remove it from the set of active constraints (light_tab)
- if (not double_positive(cnst->usage, sg_maxmin_precision) ||
- not double_positive(cnst->remaining, cnst->bound * sg_maxmin_precision)) {
- if (cnst->cnst_light) {
- int index = (cnst->cnst_light - cnst_light_tab);
+ if (not double_positive(cnst->usage_, sg_maxmin_precision) ||
+ not double_positive(cnst->remaining_, cnst->bound_ * sg_maxmin_precision)) {
+ if (cnst->cnst_light_) {
+ int index = (cnst->cnst_light_ - cnst_light_tab);
XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p "
"\t cnst_light_tab: %p usage: %f remaining: %f bound: %f ",
- index, cnst_light_num, cnst, cnst->cnst_light, cnst_light_tab, cnst->usage, cnst->remaining,
- cnst->bound);
+ index, cnst_light_num, cnst, cnst->cnst_light_, cnst_light_tab, cnst->usage_, cnst->remaining_,
+ cnst->bound_);
cnst_light_tab[index] = cnst_light_tab[cnst_light_num - 1];
- cnst_light_tab[index].cnst->cnst_light = &cnst_light_tab[index];
+ cnst_light_tab[index].cnst->cnst_light_ = &cnst_light_tab[index];
cnst_light_num--;
- cnst->cnst_light = nullptr;
+ cnst->cnst_light_ = nullptr;
}
} else {
- cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage;
- xbt_assert(not cnst->active_element_set.empty(),
+ cnst->cnst_light_->remaining_over_usage = cnst->remaining_ / cnst->usage_;
+ xbt_assert(not cnst->active_element_set_.empty(),
"Should not keep a maximum constraint that has no active"
" element! You want to check the maxmin precision and possible rounding effects.");
}
saturated_constraints.clear();
int pos;
for (pos = 0; pos < cnst_light_num; pos++) {
- xbt_assert(not cnst_light_tab[pos].cnst->active_element_set.empty(),
+ xbt_assert(not cnst_light_tab[pos].cnst->active_element_set_.empty(),
"Cannot saturate more a constraint that has"
" no active element! You may want to change the maxmin precision (--cfg=maxmin/precision:<new_value>)"
" because of possible rounding effects.\n\tFor the record, the usage of this constraint is %g while "
"the maxmin precision to which it is compared is %g.\n\tThe usage of the previous constraint is %g.",
- cnst_light_tab[pos].cnst->usage, sg_maxmin_precision, cnst_light_tab[pos - 1].cnst->usage);
+ cnst_light_tab[pos].cnst->usage_, sg_maxmin_precision, cnst_light_tab[pos - 1].cnst->usage_);
saturated_constraints_update(cnst_light_tab[pos].remaining_over_usage, pos, saturated_constraints, &min_usage);
}
void System::update_variable_bound(Variable* var, double bound)
{
modified_ = true;
- var->bound = bound;
+ var->bound_ = bound;
- if (not var->cnsts.empty())
- update_modified_set(var->cnsts[0].constraint);
+ if (not var->cnsts_.empty())
+ update_modified_set(var->cnsts_[0].constraint);
}
void Variable::initialize(resource::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++;
- cnsts.reserve(number_of_constraints);
- sharing_weight = sharing_weight_value;
- staged_weight = 0.0;
- bound = bound_value;
- concurrency_share = 1;
- value = 0.0;
- visited = visited_value;
- mu = 0.0;
- new_mu = 0.0;
+ id_ = id_value;
+ id_int_ = Global_debug_id_++;
+ cnsts_.reserve(number_of_constraints);
+ sharing_weight_ = sharing_weight_value;
+ staged_weight_ = 0.0;
+ bound_ = bound_value;
+ concurrency_share_ = 1;
+ value_ = 0.0;
+ visited_ = visited_value;
+ mu_ = 0.0;
+ new_mu_ = 0.0;
- xbt_assert(not variable_set_hook.is_linked());
- xbt_assert(not saturated_variable_set_hook.is_linked());
+ xbt_assert(not variable_set_hook_.is_linked());
+ xbt_assert(not saturated_variable_set_hook_.is_linked());
}
int Variable::get_min_concurrency_slack() const
{
int minslack = std::numeric_limits<int>::max();
- for (Element const& elem : cnsts) {
+ for (Element const& elem : cnsts_) {
int slack = elem.constraint->get_concurrency_slack();
if (slack < minslack) {
// This is only an optimization, to avoid looking at more constraints when slack is already zero
{
xbt_assert(not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug) || var->can_enable());
- var->sharing_weight = var->staged_weight;
- var->staged_weight = 0;
+ var->sharing_weight_ = var->staged_weight_;
+ var->staged_weight_ = 0;
// 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.
simgrid::xbt::intrusive_erase(variable_set, *var);
variable_set.push_front(*var);
- for (Element& elem : var->cnsts) {
- simgrid::xbt::intrusive_erase(elem.constraint->disabled_element_set, elem);
- elem.constraint->enabled_element_set.push_front(elem);
+ for (Element& elem : var->cnsts_) {
+ simgrid::xbt::intrusive_erase(elem.constraint->disabled_element_set_, elem);
+ elem.constraint->enabled_element_set_.push_front(elem);
elem.increase_concurrency();
}
- if (not var->cnsts.empty())
- update_modified_set(var->cnsts[0].constraint);
+ if (not var->cnsts_.empty())
+ update_modified_set(var->cnsts_[0].constraint);
// When used within on_disabled_var, we would get an assertion fail, because transiently there can be variables
// that are staged and could be activated.
void System::disable_var(Variable* var)
{
- xbt_assert(not var->staged_weight, "Staged weight should have been cleared");
+ 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.
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 (Element& elem : var->cnsts) {
- simgrid::xbt::intrusive_erase(elem.constraint->enabled_element_set, elem);
- elem.constraint->disabled_element_set.push_back(elem);
+ if (not var->cnsts_.empty())
+ update_modified_set(var->cnsts_[0].constraint);
+ for (Element& elem : var->cnsts_) {
+ 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())
- simgrid::xbt::intrusive_erase(elem.constraint->active_element_set, elem);
+ simgrid::xbt::intrusive_erase(elem.constraint->active_element_set_, elem);
elem.decrease_concurrency();
}
- var->sharing_weight = 0.0;
- var->staged_weight = 0.0;
- var->value = 0.0;
+ var->sharing_weight_ = 0.0;
+ var->staged_weight_ = 0.0;
+ var->value_ = 0.0;
check_concurrency();
}
if (cnstr->get_concurrency_limit() < 0)
return;
- int numelem = cnstr->disabled_element_set.size();
+ int numelem = cnstr->disabled_element_set_.size();
if (not numelem)
return;
- Element* elem = &cnstr->disabled_element_set.front();
+ Element* elem = &cnstr->disabled_element_set_.front();
// Cannot use foreach loop, because System::enable_var() will modify disabled_element_set.. within the loop
while (numelem-- && elem) {
Element* nextelem;
if (elem->disabled_element_set_hook.is_linked()) {
- auto iter = std::next(cnstr->disabled_element_set.iterator_to(*elem));
- nextelem = iter != std::end(cnstr->disabled_element_set) ? &*iter : nullptr;
+ auto iter = std::next(cnstr->disabled_element_set_.iterator_to(*elem));
+ nextelem = iter != std::end(cnstr->disabled_element_set_) ? &*iter : nullptr;
} else {
nextelem = nullptr;
}
- if (elem->variable->staged_weight > 0 && elem->variable->can_enable()) {
+ if (elem->variable->staged_weight_ > 0 && elem->variable->can_enable()) {
// Found a staged variable
// TODOLATER: Add random timing function to model reservation protocol fuzziness? Then how to make sure that
// staged variables will eventually be called?
enable_var(elem->variable);
}
- xbt_assert(cnstr->concurrency_current <= cnstr->get_concurrency_limit(), "Concurrency overflow!");
- if (cnstr->concurrency_current == cnstr->get_concurrency_limit())
+ xbt_assert(cnstr->concurrency_current_ <= cnstr->get_concurrency_limit(), "Concurrency overflow!");
+ if (cnstr->concurrency_current_ == cnstr->get_concurrency_limit())
break;
elem = nextelem;
{
xbt_assert(weight >= 0, "Variable weight should not be negative!");
- if (weight == var->sharing_weight)
+ if (weight == var->sharing_weight_)
return;
- int enabling_var = (weight > 0 && var->sharing_weight <= 0);
- int disabling_var = (weight <= 0 && var->sharing_weight > 0);
+ int enabling_var = (weight > 0 && var->sharing_weight_ <= 0);
+ int disabling_var = (weight <= 0 && var->sharing_weight_ > 0);
XBT_IN("(sys=%p, var=%p, weight=%f)", this, var, weight);
// Are we enabling this variable?
if (enabling_var) {
- var->staged_weight = weight;
+ var->staged_weight_ = weight;
int minslack = var->get_min_concurrency_slack();
- if (minslack < var->concurrency_share) {
+ if (minslack < var->concurrency_share_) {
XBT_DEBUG("Staging var (instead of enabling) because min concurrency slack %i, with weight %f and concurrency"
" share %i",
- minslack, weight, var->concurrency_share);
+ minslack, weight, var->concurrency_share_);
return;
}
XBT_DEBUG("Enabling var with min concurrency slack %i", minslack);
// Are we disabling this variable?
disable_var(var);
} else {
- var->sharing_weight = weight;
+ var->sharing_weight_ = weight;
}
check_concurrency();
{
modified_ = true;
update_modified_set(cnst);
- cnst->bound = bound;
+ cnst->bound_ = bound;
}
/** @brief Update the constraint set propagating recursively to other constraints so the system should not be entirely
*/
void System::update_modified_set_rec(Constraint* cnst)
{
- for (Element const& elem : cnst->enabled_element_set) {
+ for (Element const& elem : cnst->enabled_element_set_) {
Variable* var = elem.variable;
- for (Element const& elem2 : var->cnsts) {
- if (var->visited == visited_counter_)
+ for (Element const& elem2 : var->cnsts_) {
+ if (var->visited_ == visited_counter_)
break;
- if (elem2.constraint != cnst && not elem2.constraint->modified_constraint_set_hook.is_linked()) {
+ if (elem2.constraint != cnst && not elem2.constraint->modified_constraint_set_hook_.is_linked()) {
modified_constraint_set.push_back(*elem2.constraint);
update_modified_set_rec(elem2.constraint);
}
}
// var will be ignored in later visits as long as sys->visited_counter does not move
- var->visited = visited_counter_;
+ var->visited_ = visited_counter_;
}
}
void System::update_modified_set(Constraint* cnst)
{
/* nothing to do if selective update isn't active */
- if (selective_update_active && not cnst->modified_constraint_set_hook.is_linked()) {
+ if (selective_update_active && not cnst->modified_constraint_set_hook_.is_linked()) {
modified_constraint_set.push_back(*cnst);
update_modified_set_rec(cnst);
}
if (++visited_counter_ == 1) {
/* the counter wrapped around, reset each variable->visited */
for (Variable& var : variable_set)
- var.visited = 0;
+ var.visited_ = 0;
}
modified_constraint_set.clear();
}
double Constraint::get_usage() const
{
double result = 0.0;
- if (sharing_policy != s4u::Link::SharingPolicy::FATPIPE) {
- for (Element const& elem : enabled_element_set)
+ if (sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE) {
+ for (Element const& elem : enabled_element_set_)
if (elem.consumption_weight > 0)
- result += elem.consumption_weight * elem.variable->value;
+ result += elem.consumption_weight * elem.variable->value_;
} else {
- for (Element const& elem : enabled_element_set)
+ for (Element const& elem : enabled_element_set_)
if (elem.consumption_weight > 0)
- result = std::max(result, elem.consumption_weight * elem.variable->value);
+ result = std::max(result, elem.consumption_weight * elem.variable->value_);
}
return result;
}
int Constraint::get_variable_amount() const
{
- return std::count_if(std::begin(enabled_element_set), std::end(enabled_element_set),
+ return std::count_if(std::begin(enabled_element_set_), std::end(enabled_element_set_),
[](const Element& elem) { return elem.consumption_weight > 0; });
}
}
Constraint(void* id_value, double bound_value);
/** @brief Unshare a constraint. */
- void unshare() { sharing_policy = s4u::Link::SharingPolicy::FATPIPE; }
+ void unshare() { sharing_policy_ = s4u::Link::SharingPolicy::FATPIPE; }
/**
* @brief Check if a constraint is shared (shared by default)
* @return 1 if shared, 0 otherwise
*/
- s4u::Link::SharingPolicy get_sharing_policy() const { return sharing_policy; }
+ s4u::Link::SharingPolicy get_sharing_policy() const { return sharing_policy_; }
/**
* @brief Get the usage of the constraint after the last lmm solve
*/
void set_concurrency_limit(int limit)
{
- xbt_assert(limit < 0 || concurrency_maximum <= limit,
+ xbt_assert(limit < 0 || concurrency_maximum_ <= limit,
"New concurrency limit should be larger than observed concurrency maximum. Maybe you want to call"
" concurrency_maximum_reset() to reset the maximum?");
- concurrency_limit = limit;
+ concurrency_limit_ = limit;
}
/**
* @brief Gets the concurrency limit for this constraint
* @return The concurrency limit used by this constraint
*/
- int get_concurrency_limit() const { return concurrency_limit; }
+ int get_concurrency_limit() const { return concurrency_limit_; }
/**
* @brief Reset the concurrency maximum for a given variable (we will update the maximum to reflect constraint
* evolution).
*/
- void reset_concurrency_maximum() { concurrency_maximum = 0; }
+ void reset_concurrency_maximum() { concurrency_maximum_ = 0; }
/**
* @brief Get the concurrency maximum for a given variable (which reflects constraint evolution).
*/
int get_concurrency_maximum() const
{
- xbt_assert(concurrency_limit < 0 || concurrency_maximum <= concurrency_limit,
+ xbt_assert(concurrency_limit_ < 0 || concurrency_maximum_ <= concurrency_limit_,
"Very bad: maximum observed concurrency is higher than limit. This is a bug of SURF, please report it.");
- return concurrency_maximum;
+ return concurrency_maximum_;
}
int get_concurrency_slack() const
{
- return concurrency_limit < 0 ? std::numeric_limits<int>::max() : concurrency_limit - concurrency_current;
+ return concurrency_limit_ < 0 ? std::numeric_limits<int>::max() : concurrency_limit_ - concurrency_current_;
}
/**
* @brief Get the data associated to a constraint
* @return The data associated to the constraint
*/
- void* get_id() const { return id; }
+ void* get_id() const { return id_; }
/* hookup to system */
- boost::intrusive::list_member_hook<> constraint_set_hook;
- boost::intrusive::list_member_hook<> active_constraint_set_hook;
- boost::intrusive::list_member_hook<> modified_constraint_set_hook;
- boost::intrusive::list_member_hook<> saturated_constraint_set_hook;
+ boost::intrusive::list_member_hook<> constraint_set_hook_;
+ boost::intrusive::list_member_hook<> active_constraint_set_hook_;
+ boost::intrusive::list_member_hook<> modified_constraint_set_hook_;
+ boost::intrusive::list_member_hook<> saturated_constraint_set_hook_;
boost::intrusive::list<Element, boost::intrusive::member_hook<Element, boost::intrusive::list_member_hook<>,
&Element::enabled_element_set_hook>>
- enabled_element_set;
+ enabled_element_set_;
boost::intrusive::list<Element, boost::intrusive::member_hook<Element, boost::intrusive::list_member_hook<>,
&Element::disabled_element_set_hook>>
- disabled_element_set;
+ disabled_element_set_;
boost::intrusive::list<Element, boost::intrusive::member_hook<Element, boost::intrusive::list_member_hook<>,
&Element::active_element_set_hook>>
- active_element_set;
- double remaining;
- double usage;
- double bound;
+ active_element_set_;
+ double remaining_;
+ double usage_;
+ double bound_;
// TODO MARTIN Check maximum value across resources at the end of simulation and give a warning is more than e.g. 500
- int concurrency_current; /* The current concurrency */
- int concurrency_maximum; /* The maximum number of (enabled and disabled) variables associated to the constraint at any
- * given time (essentially for tracing)*/
+ int concurrency_current_; /* The current concurrency */
+ int concurrency_maximum_; /* The maximum number of (enabled and disabled) variables associated to the constraint at
+ * any given time (essentially for tracing)*/
- s4u::Link::SharingPolicy sharing_policy;
- int id_int;
- double lambda;
- double new_lambda;
- ConstraintLight* cnst_light;
+ s4u::Link::SharingPolicy sharing_policy_;
+ int id_int_;
+ double lambda_;
+ double new_lambda_;
+ ConstraintLight* cnst_light_;
private:
- static int Global_debug_id;
- int concurrency_limit; /* The maximum number of variables that may be enabled at any time (stage variables if
- * necessary) */
- void* id;
+ static int Global_debug_id_;
+ int concurrency_limit_; /* The maximum number of variables that may be enabled at any time (stage variables if
+ * necessary) */
+ void* id_;
};
/**
* @brief Get the value of the variable after the last lmm solve
* @return The value of the variable
*/
- double get_value() const { return value; }
+ double get_value() const { return value_; }
/**
* @brief Get the maximum value of the variable (-1.0 if no maximum value)
* @return The bound of the variable
*/
- double get_bound() const { return bound; }
+ double get_bound() const { return bound_; }
/**
* @brief Set the concurrent share of the variable
* @param value The new concurrency share
*/
- void set_concurrency_share(short int value) { concurrency_share = value; }
+ void set_concurrency_share(short int value) { concurrency_share_ = value; }
/**
* @brief Get the numth constraint associated to the variable
* @param num The rank of constraint we want to get
* @return The numth constraint
*/
- Constraint* get_constraint(unsigned num) const { return num < cnsts.size() ? cnsts[num].constraint : nullptr; }
+ Constraint* get_constraint(unsigned num) const { return num < cnsts_.size() ? cnsts_[num].constraint : nullptr; }
/**
* @brief Get the weigth of the numth constraint associated to the variable
* @param num The rank of constraint we want to get
* @return The numth constraint
*/
- double get_constraint_weight(unsigned num) const { return num < cnsts.size() ? cnsts[num].consumption_weight : 0.0; }
+ double get_constraint_weight(unsigned num) const
+ {
+ return num < cnsts_.size() ? cnsts_[num].consumption_weight : 0.0;
+ }
/**
* @brief Get the number of constraint associated to a variable
* @return The number of constraint associated to the variable
*/
- size_t get_number_of_constraint() const { return cnsts.size(); }
+ size_t get_number_of_constraint() const { return cnsts_.size(); }
/**
* @brief Get the data associated to a variable
* @return The data associated to the variable
*/
- resource::Action* get_id() const { return id; }
+ 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; }
+ 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; }
+ 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;
+ boost::intrusive::list_member_hook<> variable_set_hook_;
+ boost::intrusive::list_member_hook<> saturated_variable_set_hook_;
- std::vector<Element> cnsts;
+ 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 */
- resource::Action* id;
- int id_int;
- unsigned visited; /* used by System::update_modified_set() */
+ 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 */
+ resource::Action* id_;
+ int id_int_;
+ unsigned visited_; /* used by System::update_modified_set() */
/* \begin{For Lagrange only} */
- double mu;
- double new_mu;
+ double mu_;
+ double new_mu_;
/* \end{For Lagrange only} */
private:
- static int Global_debug_id;
+ static int Global_debug_id_;
};
inline void Element::make_active()
{
- constraint->active_element_set.push_front(*this);
+ 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);
+ simgrid::xbt::intrusive_erase(constraint->active_element_set_, *this);
}
/**
* @param cnst A constraint
* @return [description]
*/
- int constraint_used(Constraint * cnst) { return cnst->active_constraint_set_hook.is_linked(); }
+ int constraint_used(Constraint* cnst) { return cnst->active_constraint_set_hook_.is_linked(); }
/** @brief Print the lmm system */
void print() const;
void insert_constraint(Constraint * cnst) { constraint_set.push_back(*cnst); }
void remove_variable(Variable * var)
{
- if (var->variable_set_hook.is_linked())
+ if (var->variable_set_hook_.is_linked())
simgrid::xbt::intrusive_erase(variable_set, *var);
- if (var->saturated_variable_set_hook.is_linked())
+ 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())
+ 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())
+ if (cnst->active_constraint_set_hook_.is_linked())
simgrid::xbt::intrusive_erase(active_constraint_set, *cnst);
- if (cnst->modified_constraint_set_hook.is_linked())
+ if (cnst->modified_constraint_set_hook_.is_linked())
simgrid::xbt::intrusive_erase(modified_constraint_set, *cnst);
}
public:
bool modified_ = false;
boost::intrusive::list<Variable, boost::intrusive::member_hook<Variable, boost::intrusive::list_member_hook<>,
- &Variable::variable_set_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>>
+ &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>>
+ &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>>
+ &Constraint::saturated_constraint_set_hook_>>
saturated_constraint_set;
resource::Action::ModifiedSet* modified_set_ = nullptr;
unsigned visited_counter_ = 1; /* 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::constraint_set_hook_>>
constraint_set;
boost::intrusive::list<Constraint, boost::intrusive::member_hook<Constraint, boost::intrusive::list_member_hook<>,
- &Constraint::modified_constraint_set_hook>>
+ &Constraint::modified_constraint_set_hook_>>
modified_constraint_set;
xbt_mallocator_t variable_mallocator_ =
xbt_mallocator_new(65536, System::variable_mallocator_new_f, System::variable_mallocator_free_f, nullptr);