Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This void* for Constraint::id_ is a Resource*.
[simgrid.git] / src / kernel / lmm / maxmin.hpp
index caa2d0d..a7b7298 100644 (file)
@@ -131,20 +131,6 @@ namespace lmm {
 
 /** @{ @ingroup SURF_lmm */
 
-/** Default functions associated to the chosen protocol. When using the lagrangian approach. */
-
-XBT_PUBLIC double func_reno_f(const Variable& var, double x);
-XBT_PUBLIC double func_reno_fp(const Variable& var, double x);
-XBT_PUBLIC double func_reno_fpi(const Variable& var, double x);
-
-XBT_PUBLIC double func_reno2_f(const Variable& var, double x);
-XBT_PUBLIC double func_reno2_fp(const Variable& var, double x);
-XBT_PUBLIC double func_reno2_fpi(const Variable& var, double x);
-
-XBT_PUBLIC double func_vegas_f(const Variable& var, double x);
-XBT_PUBLIC double func_vegas_fp(const Variable& var, double x);
-XBT_PUBLIC double func_vegas_fpi(const Variable& var, double x);
-
 /**
  * @brief LMM element
  * Elements can be seen as glue between constraint objects and variable objects.
@@ -193,28 +179,19 @@ public:
 class XBT_PUBLIC Constraint {
 public:
   Constraint() = delete;
-  Constraint(void* id_value, double bound_value);
+  Constraint(resource::Resource* id_value, double bound_value);
 
   /** @brief Unshare a constraint. */
   void unshare() { sharing_policy_ = s4u::Link::SharingPolicy::FATPIPE; }
 
-  /**
-   * @brief Check if a constraint is shared (shared by default)
-   * @return 1 if shared, 0 otherwise
-   */
+  /** @brief Check how a constraint is shared  */
   s4u::Link::SharingPolicy get_sharing_policy() const { return sharing_policy_; }
 
-  /**
-   * @brief Get the usage of the constraint after the last lmm solve
-   * @return The usage of the constraint
-   */
+  /** @brief Get the usage of the constraint after the last lmm solve */
   double get_usage() const;
   int get_variable_amount() const;
 
-  /**
-   * @brief Sets the concurrency limit for this constraint
-   * @param limit The concurrency limit to use for this constraint
-   */
+  /** @brief Sets the concurrency limit for this constraint */
   void set_concurrency_limit(int limit)
   {
     xbt_assert(limit < 0 || concurrency_maximum_ <= limit,
@@ -223,10 +200,7 @@ public:
     concurrency_limit_ = limit;
   }
 
-  /**
-   * @brief Gets the concurrency limit for this constraint
-   * @return The concurrency limit used by this constraint
-   */
+  /** @brief Gets the concurrency limit for this constraint */
   int get_concurrency_limit() const { return concurrency_limit_; }
 
   /**
@@ -235,10 +209,7 @@ public:
    */
   void reset_concurrency_maximum() { concurrency_maximum_ = 0; }
 
-  /**
-   * @brief Get the concurrency maximum for a given variable (which reflects constraint evolution).
-   * @return the maximum concurrency of the constraint
-   */
+  /** @brief Get the concurrency maximum for a given constraint (which reflects constraint evolution). */
   int get_concurrency_maximum() const
   {
     xbt_assert(concurrency_limit_ < 0 || concurrency_maximum_ <= concurrency_limit_,
@@ -273,7 +244,7 @@ public:
    * @brief Get the data associated to a constraint
    * @return The data associated to the constraint
    */
-  void* get_id() const { return id_; }
+  resource::Resource* get_id() const { return id_; }
 
   /* hookup to system */
   boost::intrusive::list_member_hook<> constraint_set_hook_;
@@ -298,16 +269,16 @@ public:
                              * any given time (essentially for tracing)*/
 
   s4u::Link::SharingPolicy sharing_policy_;
-  int id_int_;
+  int rank_; // Only used in debug messages to identify the constraint
   double lambda_;
   double new_lambda_;
   ConstraintLight* cnst_light_;
 
 private:
-  static int Global_debug_id_;
+  static int next_rank_;  // To give a separate rank_ to each contraint
   int concurrency_limit_; /* The maximum number of variables that may be enabled at any time (stage variables if
                            * necessary) */
-  void* id_;
+  resource::Resource* id_;
 };
 
 /**
@@ -318,19 +289,13 @@ private:
  */
 class XBT_PUBLIC Variable {
 public:
-  void initialize(resource::Action* id_value, double sharing_weight_value, double bound_value,
-                  int number_of_constraints, unsigned visited_value);
+  void initialize(resource::Action* id_value, double sharing_penalty, 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
-   */
+  /** @brief Get the value of the variable after the last lmm solve */
   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
-   */
+  /** @brief Get the maximum value of the variable (-1.0 if no specified maximum) */
   double get_bound() const { return bound_; }
 
   /**
@@ -356,31 +321,22 @@ public:
     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
-   */
+  /** @brief Get the number of constraint associated to a variable */
   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
-   */
+  /** @brief Get the data associated to a variable */
   resource::Action* get_id() const { return id_; }
 
-  /**
-   * @brief Get the weight of a variable
-   * @return The weight of the variable
-   */
-  double get_weight() const { return sharing_weight_; }
+  /** @brief Get the penalty of a variable */
+  double get_penalty() const { return sharing_penalty_; }
 
   /** @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
+   * Make sure to set staged_penalty 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_penalty_ > 0 && get_min_concurrency_slack() >= concurrency_share_; }
 
   /* hookup to system */
   boost::intrusive::list_member_hook<> variable_set_hook_;
@@ -388,27 +344,24 @@ public:
 
   std::vector<Element> cnsts_;
 
-  // sharing_weight: variable's impact on the resource during the sharing
+  // sharing_penalty: 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_;
+  //   on network, the actions with higher latency have a lesser sharing_penalty
+  double sharing_penalty_;
 
-  double staged_weight_; /* If non-zero, variable is staged for addition as soon as maxconcurrency constraints will be
+  double staged_penalty_; /* If non-zero, variable is staged for addition as soon as maxconcurrency constraints will be
                             met */
   double bound_;
   double value_;
   short int concurrency_share_; /* The maximum number of elements that variable will add to a constraint */
   resource::Action* id_;
-  int id_int_;
+  int rank_;         // Only used in debug messages to identify the variable
   unsigned visited_; /* used by System::update_modified_set() */
-  /* \begin{For Lagrange only} */
   double mu_;
-  double new_mu_;
-  /* \end{For Lagrange only} */
 
 private:
-  static int Global_debug_id_;
+  static int next_rank_; // To give a separate rank_ to each variable
 };
 
 inline void Element::make_active()
@@ -439,7 +392,7 @@ public:
    * @param id Data associated to the constraint (e.g.: a network link)
    * @param bound_value The bound value of the constraint
    */
-  Constraint* constraint_new(void* id, double bound_value);
+  Constraint* constraint_new(resource::Resource* id, double bound_value);
 
   /**
    * @brief Create a new Linear MaxMin variable
@@ -472,32 +425,15 @@ public:
    */
   void expand_add(Constraint * cnst, Variable * var, double value);
 
-  /**
-   * @brief Update the bound of a variable
-   * @param var A constraint
-   * @param bound The new bound
-   */
+  /** @brief Update the bound of a variable */
   void update_variable_bound(Variable * var, double bound);
 
-  /**
-   * @brief Update the weight of a variable
-   * @param var A variable
-   * @param weight The new weight of the variable
-   */
-  void update_variable_weight(Variable * var, double weight);
+  /** @brief Update the sharing penalty of a variable */
+  void update_variable_penalty(Variable* var, double penalty);
 
-  /**
-   * @brief Update a constraint bound
-   * @param cnst A constraint
-   * @param bound The new bound of the consrtaint
-   */
+  /** @brief Update a constraint bound */
   void update_constraint_bound(Constraint * cnst, double bound);
 
-  /**
-   * @brief [brief description]
-   * @param cnst A constraint
-   * @return [description]
-   */
   int constraint_used(Constraint* cnst) { return cnst->active_constraint_set_hook_.is_linked(); }
 
   /** @brief Print the lmm system */
@@ -613,40 +549,8 @@ private:
   void bottleneck_solve();
 };
 
-class XBT_PUBLIC Lagrange : public System {
-public:
-  explicit Lagrange(bool selective_update) : System(selective_update) {}
-  void solve() final { lagrange_solve(); }
-
-  static void set_default_protocol_function(double (*func_f)(const Variable& var, double x),
-                                            double (*func_fp)(const Variable& var, double x),
-                                            double (*func_fpi)(const Variable& var, double x));
-
-private:
-  void lagrange_solve();
-
-  bool check_feasible(bool warn);
-  double dual_objective();
-
-  static double (*func_f)(const Variable& var, double x);   /* (f)    */
-  static double (*func_fp)(const Variable& var, double x);  /* (f')    */
-  static double (*func_fpi)(const Variable& var, double x); /* (f')^{-1}    */
-
-  /*
-   * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy.
-   */
-  // computes the value of the dichotomy using a initial values, init, with a specific variable or constraint
-  static double dichotomy(double init, const Constraint& cnst, double min_error);
-  // computes the value of the differential of constraint cnst applied to lambda
-  static double partial_diff_lambda(double lambda, const Constraint& cnst);
-
-  static double new_value(const Variable& var);
-  static double new_mu(const Variable& var);
-};
-
 XBT_PUBLIC System* make_new_maxmin_system(bool selective_update);
 XBT_PUBLIC System* make_new_fair_bottleneck_system(bool selective_update);
-XBT_PUBLIC System* make_new_lagrange_system(bool selective_update);
 
 /** @} */
 }