Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make s_lmm_variable_t a class with its methods.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 23 Nov 2017 10:58:17 +0000 (11:58 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 26 Nov 2017 20:32:57 +0000 (21:32 +0100)
13 files changed:
src/include/surf/maxmin.hpp
src/plugins/vm/VirtualMachineImpl.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/maxmin.cpp
src/surf/maxmin_private.hpp
src/surf/network_cm02.cpp
src/surf/network_interface.cpp
src/surf/ptask_L07.cpp
src/surf/storage_n11.cpp
src/surf/surf_interface.cpp
teshsuite/surf/lmm_usage/lmm_usage.cpp
teshsuite/surf/maxmin_bench/maxmin_bench.cpp

index e5e896b..8e03a7d 100644 (file)
@@ -149,67 +149,6 @@ static inline int double_equals(double value1, double value2, double precision)
 
 /** @{ @ingroup SURF_lmm */
 
-/**
- * @brief Get the value of the variable after the last lmm solve
- * @param var A variable
- * @return The value of the variable
- */
-XBT_PUBLIC(double) lmm_variable_getvalue(lmm_variable_t var);
-
-/**
- * @brief Get the maximum value of the variable (-1.0 if no maximum value)
- * @param var A variable
- * @return The bound of the variable
- */
-XBT_PUBLIC(double) lmm_variable_getbound(lmm_variable_t var);
-
-/**
- * @brief Set the concurrent share of the variable
- * @param var A variable
- * @param concurrency_share The new concurrency share
- */
-XBT_PUBLIC(void) lmm_variable_concurrency_share_set(lmm_variable_t var, short int concurrency_share);
-
-/**
- * @brief Get the numth constraint associated to the variable
- * @param sys The system associated to the variable (not used)
- * @param var A variable
- * @param num The rank of constraint we want to get
- * @return The numth constraint
- */
-XBT_PUBLIC(lmm_constraint_t) lmm_get_cnst_from_var(lmm_system_t sys, lmm_variable_t var, unsigned num);
-
-/**
- * @brief Get the weigth of the numth constraint associated to the variable
- * @param sys The system associated to the variable (not used)
- * @param var A variable
- * @param num The rank of constraint we want to get
- * @return The numth constraint
- */
-XBT_PUBLIC(double) lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var, unsigned num);
-
-/**
- * @brief Get the number of constraint associated to a variable
- * @param sys The system associated to the variable (not used)
- * @param var A variable
- * @return The number of constraint associated to the variable
- */
-XBT_PUBLIC(int) lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
-
-/**
- * @brief Get the data associated to a variable
- * @param var A variable
- * @return The data associated to the variable
- */
-XBT_PUBLIC(void*) lmm_variable_id(lmm_variable_t var);
-
-/**
- * @brief Get the weight of a variable
- * @param var A variable
- * @return The weight of the variable
- */
-XBT_PUBLIC(double) lmm_get_variable_weight(lmm_variable_t var);
-
 /**
  * @brief Solve the lmm system
  * @param sys The lmm system to solve
index 08ee5a1..2cccd60 100644 (file)
@@ -93,8 +93,8 @@ double VMModel::nextOccuringEvent(double now)
     surf::Cpu* cpu = ws_vm->pimpl_cpu;
     xbt_assert(cpu, "cpu-less host");
 
-    double solved_value = ws_vm->pimpl_vm_->action_->getVariable()
-                              ->value; // this is X1 in comment above, what this VM got in the sharing on the PM
+    double solved_value = ws_vm->pimpl_vm_->action_->getVariable()->get_value(); // this is X1 in comment above, what
+                                                                                 // this VM got in the sharing on the PM
     XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->getCname(), ws_vm->pimpl_vm_->getPm()->getCname());
 
     xbt_assert(cpu->model() == surf_cpu_model_vm);
index 69a16b3..ac8de2f 100644 (file)
@@ -108,7 +108,7 @@ void CpuCas01::onSpeedChange() {
 
   model()->getMaxminSystem()->update_constraint_bound(constraint(), coresAmount_ * speed_.scale * speed_.peak);
   while ((var = constraint()->get_variable(&elem))) {
-    CpuCas01Action* action = static_cast<CpuCas01Action*>(lmm_variable_id(var));
+    CpuCas01Action* action = static_cast<CpuCas01Action*>(var->get_id());
 
     model()->getMaxminSystem()->update_variable_bound(action->getVariable(),
                                                       action->requestedCore() * speed_.scale * speed_.peak);
@@ -144,7 +144,7 @@ void CpuCas01::apply_event(tmgr_trace_event_t event, double value)
       turnOff();
 
       while ((var = cnst->get_variable(&elem))) {
-        Action *action = static_cast<Action*>(lmm_variable_id(var));
+        Action* action = static_cast<Action*>(var->get_id());
 
         if (action->getState() == Action::State::running ||
             action->getState() == Action::State::ready ||
index 4ef732c..6708124 100644 (file)
@@ -28,10 +28,9 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
     CpuAction* action = static_cast<CpuAction*>(actionHeapPop());
     XBT_CDEBUG(surf_kernel, "Something happened to action %p", action);
     if (TRACE_is_enabled()) {
-      Cpu* cpu = static_cast<Cpu*>(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0)->get_id());
-      TRACE_surf_host_set_utilization(cpu->getCname(), action->getCategory(),
-                                      lmm_variable_getvalue(action->getVariable()), action->getLastUpdate(),
-                                      now - action->getLastUpdate());
+      Cpu* cpu = static_cast<Cpu*>(action->getVariable()->get_constraint(0)->get_id());
+      TRACE_surf_host_set_utilization(cpu->getCname(), action->getCategory(), action->getVariable()->get_value(),
+                                      action->getLastUpdate(), now - action->getLastUpdate());
     }
 
     action->finish(Action::State::done);
@@ -60,18 +59,18 @@ void CpuModel::updateActionsStateFull(double now, double delta)
     CpuAction& action = static_cast<CpuAction&>(*it);
     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
     if (TRACE_is_enabled()) {
-      Cpu* cpu = static_cast<Cpu*>(lmm_get_cnst_from_var(getMaxminSystem(), action.getVariable(), 0)->get_id());
-      TRACE_surf_host_set_utilization(cpu->getCname(), action.getCategory(),
-                                      lmm_variable_getvalue(action.getVariable()), now - delta, delta);
+      Cpu* cpu = static_cast<Cpu*>(action.getVariable()->get_constraint(0)->get_id());
+      TRACE_surf_host_set_utilization(cpu->getCname(), action.getCategory(), action.getVariable()->get_value(),
+                                      now - delta, delta);
       TRACE_last_timestamp_to_dump = now - delta;
     }
 
-    action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta);
+    action.updateRemains(action.getVariable()->get_value() * delta);
 
     if (action.getMaxDuration() != NO_MAX_DURATION)
       action.updateMaxDuration(delta);
 
-    if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+    if (((action.getRemainsNoUpdate() <= 0) && (action.getVariable()->get_weight() > 0)) ||
         ((action.getMaxDuration() != NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
       action.finish(Action::State::done);
     }
@@ -188,7 +187,7 @@ void CpuAction::updateRemainingLazy(double now)
     updateRemains(getLastValue() * delta);
 
     if (TRACE_is_enabled()) {
-      Cpu* cpu = static_cast<Cpu*>(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0)->get_id());
+      Cpu* cpu = static_cast<Cpu*>(getVariable()->get_constraint(0)->get_id());
       TRACE_surf_host_set_utilization(cpu->getCname(), getCategory(), getLastValue(), getLastUpdate(),
                                       now - getLastUpdate());
     }
@@ -196,7 +195,7 @@ void CpuAction::updateRemainingLazy(double now)
   }
 
   refreshLastUpdate();
-  setLastValue(lmm_variable_getvalue(getVariable()));
+  setLastValue(getVariable()->get_value());
 }
 
 simgrid::xbt::signal<void(simgrid::surf::CpuAction*, Action::State)> CpuAction::onStateChange;
@@ -221,13 +220,12 @@ void CpuAction::setState(Action::State state){
 /** @brief returns a list of all CPUs that this action is using */
 std::list<Cpu*> CpuAction::cpus() {
   std::list<Cpu*> retlist;
-  lmm_system_t sys = getModel()->getMaxminSystem();
-  int llen = lmm_get_number_of_cnst_from_var(sys, getVariable());
+  int llen = getVariable()->get_number_of_constraint();
 
   for (int i = 0; i < llen; i++) {
     /* Beware of composite actions: ptasks put links and cpus together */
     // extra pb: we cannot dynamic_cast from void*...
-    Resource* resource = static_cast<Resource*>(lmm_get_cnst_from_var(sys, getVariable(), i)->get_id());
+    Resource* resource = static_cast<Resource*>(getVariable()->get_constraint(i)->get_id());
     Cpu* cpu           = dynamic_cast<Cpu*>(resource);
     if (cpu != nullptr)
       retlist.push_back(cpu);
index c28faae..e0d5d58 100644 (file)
@@ -25,12 +25,9 @@ double sg_maxmin_precision = 0.00001; /* Change this with --cfg=maxmin/precision
 double sg_surf_precision   = 0.00001; /* Change this with --cfg=surf/precision:VALUE */
 int sg_concurrency_limit   = -1;      /* Change this with --cfg=maxmin/concurrency-limit:VALUE */
 
-static int Global_debug_id = 1;
+int s_lmm_variable_t::Global_debug_id   = 1;
 int s_lmm_constraint_t::Global_debug_id = 1;
 
-static int lmm_can_enable_var(lmm_variable_t var);
-static int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var);
-
 int s_lmm_element_t::get_concurrency() const
 {
   //Ignore element with weight less than one (e.g. cross-traffic)
@@ -85,7 +82,7 @@ void s_lmm_system_t::check_concurrency()
       lmm_element_t elem = (lmm_element_t)elemIt;
       // 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 ||
-                     lmm_cnstrs_min_concurrency_slack(elem->variable) < elem->variable->concurrency_share,
+                     elem->variable->get_min_concurrency_slack() < elem->variable->concurrency_share,
                  "should not have staged variable!");
     }
 
@@ -245,27 +242,8 @@ lmm_variable_t s_lmm_system_t::variable_new(simgrid::surf::Action* id, double sh
 {
   XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", this, id, sharing_weight, bound, number_of_constraints);
 
-  lmm_variable_t var = (lmm_variable_t)xbt_mallocator_get(variable_mallocator);
-  var->id = id;
-  var->id_int = Global_debug_id++;
-  var->cnsts.reserve(number_of_constraints);
-  var->sharing_weight    = sharing_weight;
-  var->staged_weight = 0.0;
-  var->bound = bound;
-  var->concurrency_share = 1;
-  var->value = 0.0;
-  var->visited           = visited_counter - 1;
-  var->mu = 0.0;
-  var->new_mu = 0.0;
-  var->func_f = func_f_def;
-  var->func_fp = func_fp_def;
-  var->func_fpi = func_fpi_def;
-
-  var->variable_set_hookup.next = nullptr;
-  var->variable_set_hookup.prev = nullptr;
-  var->saturated_variable_set_hookup.next = nullptr;
-  var->saturated_variable_set_hookup.prev = nullptr;
-
+  lmm_variable_t var = static_cast<lmm_variable_t>(xbt_mallocator_get(variable_mallocator));
+  var->initialize(id, sharing_weight, bound, number_of_constraints, visited_counter - 1);
   if (sharing_weight)
     xbt_swag_insert_at_head(var, &variable_set);
   else
@@ -281,21 +259,6 @@ void s_lmm_system_t::variable_free(lmm_variable_t var)
   var_free(var);
 }
 
-double lmm_variable_getvalue(lmm_variable_t var)
-{
-  return (var->value);
-}
-
-void lmm_variable_concurrency_share_set(lmm_variable_t var, short int concurrency_share)
-{
-  var->concurrency_share=concurrency_share;
-}
-
-double lmm_variable_getbound(lmm_variable_t var)
-{
-  return (var->bound);
-}
-
 void s_lmm_system_t::expand(lmm_constraint_t cnst, lmm_variable_t var, double consumption_weight)
 {
   modified = 1;
@@ -387,27 +350,6 @@ void s_lmm_system_t::expand_add(lmm_constraint_t cnst, lmm_variable_t var, doubl
   check_concurrency();
 }
 
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var, unsigned num)
-{
-  if (num < var->cnsts.size())
-    return (var->cnsts[num].constraint);
-  else
-    return nullptr;
-}
-
-double lmm_get_cnst_weight_from_var(lmm_system_t /*sys*/, lmm_variable_t var, unsigned num)
-{
-  if (num < var->cnsts.size())
-    return (var->cnsts[num].consumption_weight);
-  else
-    return 0.0;
-}
-
-int lmm_get_number_of_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var)
-{
-  return (var->cnsts.size());
-}
-
 lmm_variable_t s_lmm_constraint_t::get_variable(lmm_element_t* elem) const
 {
   if (*elem == nullptr) {
@@ -464,11 +406,6 @@ lmm_variable_t s_lmm_constraint_t::get_variable_safe(lmm_element_t* elem, lmm_el
     return nullptr;
 }
 
-void *lmm_variable_id(lmm_variable_t var)
-{
-  return var->id;
-}
-
 static inline void saturated_constraint_set_update(double usage, int cnst_light_num,
                                                    dyn_light_t& saturated_constraint_set, double* min_usage)
 {
@@ -807,11 +744,34 @@ void s_lmm_system_t::update_variable_bound(lmm_variable_t var, double bound)
     update_modified_set(var->cnsts[0].constraint);
 }
 
-/** \brief Measure the minimum concurrency slack across all constraints where the given var is involved */
-int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var)
+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)
+{
+  id     = id_value;
+  id_int = s_lmm_variable_t::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;
+  func_f            = func_f_def;
+  func_fp           = func_fp_def;
+  func_fpi          = func_fpi_def;
+
+  variable_set_hookup.next           = nullptr;
+  variable_set_hookup.prev           = nullptr;
+  saturated_variable_set_hookup.next = nullptr;
+  saturated_variable_set_hookup.prev = nullptr;
+}
+
+int s_lmm_variable_t::get_min_concurrency_slack() const
 {
   int minslack = std::numeric_limits<int>::max();
-  for (s_lmm_element_t const& elem : var->cnsts) {
+  for (s_lmm_element_t 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
@@ -823,21 +783,13 @@ int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var)
   return minslack;
 }
 
-/* /Check if a variable can be enabled
- *
- * Make sure to set staged_weight before, if your intent is only to check concurrency
- */
-int lmm_can_enable_var(lmm_variable_t var){
-  return var->staged_weight>0 && lmm_cnstrs_min_concurrency_slack(var)>=var->concurrency_share;
-}
-
 //Small remark: In this implementation of lmm_enable_var and lmm_disable_var, we will meet multiple times with var when
 // running sys->update_modified_set.
 // A priori not a big performance issue, but we might do better by calling sys->update_modified_set within the for loops
 // (after doing the first for enabling==1, and before doing the last for disabling==1)
 void s_lmm_system_t::enable_var(lmm_variable_t var)
 {
-  xbt_assert(not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug) || lmm_can_enable_var(var));
+  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;
@@ -907,7 +859,7 @@ void s_lmm_system_t::on_disabled_var(lmm_constraint_t cnstr)
 
     lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
 
-    if (elem->variable->staged_weight > 0 && lmm_can_enable_var(elem->variable)) {
+    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?
@@ -946,7 +898,7 @@ void s_lmm_system_t::update_variable_weight(lmm_variable_t var, double weight)
   //Are we enabling this variable?
   if (enabling_var){
     var->staged_weight = weight;
-    int minslack       = lmm_cnstrs_min_concurrency_slack(var);
+    int minslack       = var->get_min_concurrency_slack();
     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);
@@ -966,11 +918,6 @@ void s_lmm_system_t::update_variable_weight(lmm_variable_t var, double weight)
   XBT_OUT();
 }
 
-double lmm_get_variable_weight(lmm_variable_t var)
-{
-  return var->sharing_weight;
-}
-
 void s_lmm_system_t::update_constraint_bound(lmm_constraint_t cnst, double bound)
 {
   modified = 1;
index ba129b0..1ef4324 100644 (file)
@@ -174,7 +174,69 @@ private:
  *
  * When something prevents us from enabling a variable, we "stage" the weight that we would have like to set, so that as soon as possible we enable the variable with desired weight
  */
-struct s_lmm_variable_t {
+class s_lmm_variable_t {
+public:
+  void initialize(simgrid::surf::Action* id_value, double sharing_weight_value, double bound_value,
+                  int number_of_constraints, unsigned visited_value);
+
+  /**
+   * @brief Get the value of the variable after the last lmm solve
+   * @return The value of the variable
+   */
+  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; }
+
+  /**
+   * @brief Set the concurrent share of the variable
+   * @param concurrency_share The new concurrency share
+   */
+  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
+   */
+  lmm_constraint_t 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; }
+
+  /**
+   * @brief Get the number of constraint associated to a variable
+   * @return The number of constraint associated to the variable
+   */
+  int get_number_of_constraint() const { return cnsts.size(); }
+
+  /**
+   * @brief Get the data associated to a variable
+   * @return The data associated to the variable
+   */
+  simgrid::surf::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 */
   s_xbt_swag_hookup_t variable_set_hookup;
   s_xbt_swag_hookup_t saturated_variable_set_hookup;
@@ -201,6 +263,9 @@ struct s_lmm_variable_t {
   double (*func_fp)(s_lmm_variable_t* var, double x);  /* (f')    */
   double (*func_fpi)(s_lmm_variable_t* var, double x); /* (f')^{-1}    */
   /* \end{For Lagrange only} */
+
+private:
+  static int Global_debug_id;
 };
 
 inline void s_lmm_element_t::make_active()
index 91bcb42..0f2fc25 100644 (file)
@@ -176,13 +176,12 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
     NetworkCm02Action* action = static_cast<NetworkCm02Action*>(actionHeapPop());
     XBT_DEBUG("Something happened to action %p", action);
     if (TRACE_is_enabled()) {
-      int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable());
+      int n = action->getVariable()->get_number_of_constraint();
 
       for (int i = 0; i < n; i++){
-        lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action->getVariable(), i);
+        lmm_constraint_t constraint = action->getVariable()->get_constraint(i);
         NetworkCm02Link* link       = static_cast<NetworkCm02Link*>(constraint->get_id());
-        double value = lmm_variable_getvalue(action->getVariable())*
-            lmm_get_cnst_weight_from_var(maxminSystem_, action->getVariable(), i);
+        double value = action->getVariable()->get_value() * action->getVariable()->get_constraint_weight(i);
         TRACE_surf_link_set_utilization(link->getCname(), action->getCategory(), value, action->getLastUpdate(),
                                         now - action->getLastUpdate());
       }
@@ -227,29 +226,28 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
         maxminSystem_->update_variable_weight(action.getVariable(), action.weight_);
     }
     if (TRACE_is_enabled()) {
-      int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action.getVariable());
+      int n = action.getVariable()->get_number_of_constraint();
       for (int i = 0; i < n; i++) {
-        lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
-
+        lmm_constraint_t constraint = action.getVariable()->get_constraint(i);
         NetworkCm02Link* link = static_cast<NetworkCm02Link*>(constraint->get_id());
-        TRACE_surf_link_set_utilization(link->getCname(), action.getCategory(),
-                                        (lmm_variable_getvalue(action.getVariable()) *
-                                         lmm_get_cnst_weight_from_var(maxminSystem_, action.getVariable(), i)),
-                                        action.getLastUpdate(), now - action.getLastUpdate());
+        TRACE_surf_link_set_utilization(
+            link->getCname(), action.getCategory(),
+            (action.getVariable()->get_value() * action.getVariable()->get_constraint_weight(i)),
+            action.getLastUpdate(), now - action.getLastUpdate());
       }
     }
-    if (not lmm_get_number_of_cnst_from_var(maxminSystem_, action.getVariable())) {
+    if (not action.getVariable()->get_number_of_constraint()) {
       /* There is actually no link used, hence an infinite bandwidth. This happens often when using models like
        * vivaldi. In such case, just make sure that the action completes immediately.
        */
       action.updateRemains(action.getRemains());
     }
-    action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta);
+    action.updateRemains(action.getVariable()->get_value() * delta);
 
     if (action.getMaxDuration() > NO_MAX_DURATION)
       action.updateMaxDuration(delta);
 
-    if (((action.getRemains() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+    if (((action.getRemains() <= 0) && (action.getVariable()->get_weight() > 0)) ||
         ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
       action.finish(Action::State::done);
     }
@@ -384,7 +382,7 @@ void NetworkCm02Link::apply_event(tmgr_trace_event_t triggered, double value)
 
       turnOff();
       while ((var = constraint()->get_variable(&elem))) {
-        Action *action = static_cast<Action*>( lmm_variable_id(var) );
+        Action* action = static_cast<Action*>(var->get_id());
 
         if (action->getState() == Action::State::running ||
             action->getState() == Action::State::ready) {
@@ -417,7 +415,7 @@ void NetworkCm02Link::setBandwidth(double value)
     lmm_element_t nextelem = nullptr;
     int numelem = 0;
     while ((var = constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
-      NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_variable_id(var));
+      NetworkCm02Action* action = static_cast<NetworkCm02Action*>(var->get_id());
       action->weight_ += delta;
       if (not action->isSuspended())
         model()->getMaxminSystem()->update_variable_weight(action->getVariable(), action->weight_);
@@ -436,7 +434,7 @@ void NetworkCm02Link::setLatency(double value)
   latency_.peak = value;
 
   while ((var = constraint()->get_variable_safe(&elem, &nextelem, &numelem))) {
-    NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_variable_id(var));
+    NetworkCm02Action* action = static_cast<NetworkCm02Action*>(var->get_id());
     action->latCurrent_ += delta;
     action->weight_ += delta;
     if (action->rate_ < 0)
@@ -481,14 +479,14 @@ void NetworkCm02Action::updateRemainingLazy(double now)
     setMaxDuration(max_duration);
   }
 
-  if ((getRemainsNoUpdate() <= 0 && (lmm_get_variable_weight(getVariable()) > 0)) ||
+  if ((getRemainsNoUpdate() <= 0 && (getVariable()->get_weight() > 0)) ||
       ((max_duration > NO_MAX_DURATION) && (max_duration <= 0))) {
     finish(Action::State::done);
     heapRemove(getModel()->getActionHeap());
   }
 
   refreshLastUpdate();
-  setLastValue(lmm_variable_getvalue(getVariable()));
+  setLastValue(getVariable()->get_value());
 }
 
 }
index 66e1e0b..17d8b67 100644 (file)
@@ -202,13 +202,12 @@ namespace simgrid {
     std::list<LinkImpl*> NetworkAction::links()
     {
       std::list<LinkImpl*> retlist;
-      lmm_system_t sys = getModel()->getMaxminSystem();
-      int llen         = lmm_get_number_of_cnst_from_var(sys, getVariable());
+      int llen = getVariable()->get_number_of_constraint();
 
       for (int i = 0; i < llen; i++) {
         /* Beware of composite actions: ptasks put links and cpus together */
         // extra pb: we cannot dynamic_cast from void*...
-        Resource* resource = static_cast<Resource*>(lmm_get_cnst_from_var(sys, getVariable(), i)->get_id());
+        Resource* resource = static_cast<Resource*>(getVariable()->get_constraint(i)->get_id());
         LinkImpl* link     = dynamic_cast<LinkImpl*>(resource);
         if (link != nullptr)
           retlist.push_back(link);
index 57b4b5b..513d3db 100644 (file)
@@ -105,8 +105,8 @@ void HostL07Model::updateActionsState(double /*now*/, double delta)
       }
     }
     XBT_DEBUG("Action (%p) : remains (%g) updated by %g.", &action, action.getRemains(),
-              lmm_variable_getvalue(action.getVariable()) * delta);
-    action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta);
+              action.getVariable()->get_value() * delta);
+    action.updateRemains(action.getVariable()->get_value() * delta);
 
     if (action.getMaxDuration() > NO_MAX_DURATION)
       action.updateMaxDuration(delta);
@@ -119,13 +119,13 @@ void HostL07Model::updateActionsState(double /*now*/, double delta)
      * If it's not done, it may have failed.
      */
 
-    if (((action.getRemains() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+    if (((action.getRemains() <= 0) && (action.getVariable()->get_weight() > 0)) ||
         ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
       action.finish(Action::State::done);
     } else {
       /* Need to check that none of the model has failed */
       int i = 0;
-      lmm_constraint_t cnst = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
+      lmm_constraint_t cnst = action.getVariable()->get_constraint(i);
       while (cnst != nullptr) {
         i++;
         void* constraint_id = cnst->get_id();
@@ -134,7 +134,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta)
           action.finish(Action::State::failed);
           break;
         }
-        cnst = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
+        cnst = action.getVariable()->get_constraint(i);
       }
     }
   }
@@ -299,7 +299,7 @@ void CpuL07::onSpeedChange() {
 
   model()->getMaxminSystem()->update_constraint_bound(constraint(), speed_.peak * speed_.scale);
   while ((var = constraint()->get_variable(&elem))) {
-    Action* action = static_cast<Action*>(lmm_variable_id(var));
+    Action* action = static_cast<Action*>(var->get_id());
 
     model()->getMaxminSystem()->update_variable_bound(action->getVariable(), speed_.scale * speed_.peak);
   }
@@ -369,7 +369,7 @@ void LinkL07::setLatency(double value)
 
   latency_.peak = value;
   while ((var = constraint()->get_variable(&elem))) {
-    action = static_cast<L07Action*>(lmm_variable_id(var));
+    action = static_cast<L07Action*>(var->get_id());
     action->updateBound();
   }
 }
index 9bad4ae..cb5d245 100644 (file)
@@ -79,12 +79,12 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta)
   for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
     StorageAction& action = static_cast<StorageAction&>(*it);
     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
-    action.updateRemains(lrint(lmm_variable_getvalue(action.getVariable()) * delta));
+    action.updateRemains(lrint(action.getVariable()->get_value() * delta));
 
     if (action.getMaxDuration() > NO_MAX_DURATION)
       action.updateMaxDuration(delta);
 
-    if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+    if (((action.getRemainsNoUpdate() <= 0) && (action.getVariable()->get_weight() > 0)) ||
         ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
       action.finish(Action::State::done);
     }
index 4381f7c..cb5ed0e 100644 (file)
@@ -416,7 +416,7 @@ double Model::nextOccuringEventLazy(double now)
     action->updateRemainingLazy(now);
 
     double min = -1;
-    double share = lmm_variable_getvalue(action->getVariable());
+    double share = action->getVariable()->get_value();
 
     if (share > 0) {
       double time_to_completion;
@@ -465,7 +465,7 @@ double Model::nextOccuringEventFull(double /*now*/) {
   double min = -1;
 
   for (Action& action : *getRunningActionSet()) {
-    double value = lmm_variable_getvalue(action.getVariable());
+    double value = action.getVariable()->get_value();
     if (value > 0) {
       if (action.getRemains() > 0)
         value = action.getRemainsNoUpdate() / value;
@@ -646,7 +646,7 @@ void Action::setState(Action::State state)
 
 double Action::getBound() const
 {
-  return (variable_) ? lmm_variable_getbound(variable_) : 0;
+  return variable_ ? variable_->get_bound() : 0;
 }
 
 void Action::setBound(double bound)
index dc6ce16..3f255fa 100644 (file)
@@ -18,7 +18,7 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
 
-#define PRINT_VAR(var) XBT_DEBUG(#var " = %g",lmm_variable_getvalue(var))
+#define PRINT_VAR(var) XBT_DEBUG(#var " = %g", (var)->get_value())
 #define SHOW_EXPR(expr) XBT_DEBUG(#expr " = %g",expr)
 
 /*        ______                 */
@@ -147,20 +147,18 @@ static void test1(method_t method)
     lagrange_solve(Sys);
 
     double max_deviation = 0.0;
-    max_deviation        = std::max(max_deviation, fabs(lmm_variable_getvalue(R_1) - x));
-    max_deviation        = std::max(max_deviation, fabs(lmm_variable_getvalue(R_3) - x));
-    max_deviation        = std::max(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x)));
-    max_deviation        = std::max(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x)));
+    max_deviation        = std::max(max_deviation, fabs(R_1->get_value() - x));
+    max_deviation        = std::max(max_deviation, fabs(R_3->get_value() - x));
+    max_deviation        = std::max(max_deviation, fabs(R_2->get_value() - (b - a + x)));
+    max_deviation        = std::max(max_deviation, fabs(R_1_2_3->get_value() - (a - x)));
 
     if (max_deviation > 0.00001) { // Legacy value used in lagrange.c
       XBT_WARN("Max Deviation from optimal solution : %g", max_deviation);
       XBT_WARN("Found x = %1.20f", x);
-      XBT_WARN("Deviation from optimal solution (R_1 = %g): %1.20f", x, lmm_variable_getvalue(R_1) - x);
-      XBT_WARN("Deviation from optimal solution (R_2 = %g): %1.20f", b - a + x,
-               lmm_variable_getvalue(R_2) - (b - a + x));
-      XBT_WARN("Deviation from optimal solution (R_3 = %g): %1.20f", x, lmm_variable_getvalue(R_3) - x);
-      XBT_WARN("Deviation from optimal solution (R_1_2_3 = %g): %1.20f", a - x,
-               lmm_variable_getvalue(R_1_2_3) - (a - x));
+      XBT_WARN("Deviation from optimal solution (R_1 = %g): %1.20f", x, R_1->get_value() - x);
+      XBT_WARN("Deviation from optimal solution (R_2 = %g): %1.20f", b - a + x, R_2->get_value() - (b - a + x));
+      XBT_WARN("Deviation from optimal solution (R_3 = %g): %1.20f", x, R_3->get_value() - x);
+      XBT_WARN("Deviation from optimal solution (R_1_2_3 = %g): %1.20f", a - x, R_1_2_3->get_value() - (a - x));
     }
   }
 
index df51dde..8f0984e 100644 (file)
@@ -63,7 +63,7 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi
     var[i] = Sys->variable_new(NULL, 1.0, -1.0, nb_elem);
     //Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases)
     int concurrency_share = 1 + int_random(max_share);
-    lmm_variable_concurrency_share_set(var[i],concurrency_share);
+    var[i]->set_concurrency_share(concurrency_share);
 
     for (int j = 0; j < nb_cnst; j++)
       used[j] = 0;