Var
-
class Var : public idol::Object<VarVersion, Var>
Variable modeling-old object.
The class is used to represent a variable in an optimization model.
Variables can be created by calling a constructor of
Var
, passing the optimization environment which will store the variable’s versions as argument. The variable can then be added to a model using theModel::add
method.Another approach is to directly use the
Model::add_var
method.Var x = model.add_var(0, 1, Continuous, "x");
Public Functions
-
Var(Env &t_env, double t_lb, double t_ub, VarType t_type, std::string t_name = "")
Constructor.
Creates a new variable in the optimization environment.
If no name is given, a unique name in the environment is given.
- Parameters:
t_env – The optimization environment.
t_lb – The lower bound (possibly
-Inf
) for the default version of the variable.t_ub – The upper bound (possibly
+Inf
) for the default version of the variable.t_type – The type for the default version of the variable.
t_name – The given name of the variable.
-
Var(Env &t_env, double t_lb, double t_ub, VarType t_type, Column &&t_column, std::string t_name = "")
Constructor.
Creates a new variable in the optimization environment.
If no name is given, a unique name in the environment is given.
- Parameters:
t_env – The optimization environment.
t_lb – The lower bound (possibly
-Inf
) for the default version of the variable.t_ub – The upper bound (possibly
+Inf
) for the default version of the variable.t_type – The type for the default version of the variable.
t_column – The column for the default version of the variable.
t_name – The given name of the variable.
-
Var(Env &t_env, double t_lb, double t_ub, VarType t_type, const Column &t_column, std::string t_name = "")
Constructor.
Creates a new variable in the optimization environment.
If no name is given, a unique name in the environment is given.
- Parameters:
t_env – The optimization environment.
t_lb – The lower bound (possibly
-Inf
) for the default version of the variable.t_ub – The upper bound (possibly
+Inf
) for the default version of the variable.t_type – The type for the default version of the variable.
t_column – The column for the default version of the variable.
t_name – The given name of the variable.
-
inline const std::string &name() const
Returns the name of the optimization object.
- Returns:
The name of the optimization object.
-
inline unsigned int id() const
Returns the id of the optimization object.
- Returns:
The id of the optimization object.
-
inline bool is_in(const Model &t_model) const
Returns true if the optimization object is part of the model
t_model
, false otherwise.- Parameters:
t_model – The model.
- Returns:
True if the optimization object is part of the model
t_model
, false otherwise.
-
inline const ValueT &get(const Annotation<Var, ValueT> &t_annotation) const
Returns the value of the given annotation
t_annotation
associated to the object.If no value is found, the default value of the annotation is returned. If no default value was set, an exception is thrown.
- Template Parameters:
ValueT – The value type of the annotation.
- Parameters:
t_annotation – The annotation.
- Returns:
The value of the annotation.
-
inline void set(const Annotation<Var, ValueT> &t_annotation, ArgsT&&... t_args) const
Sets the value of the given annotation
t_annotation
associated to the object.- Template Parameters:
ValueT – The value type of the annotation.
ArgsT – The parameter pack types for constructing the value of the annotation.
- Parameters:
t_annotation – The annotation.
t_args – The parameter pack arguments used to construct “in place” the value of the annotation.
Public Static Functions
-
template<unsigned int N = 1, unsigned int I = 0>
static inline Vector<Var, N - I> make_vector(Env &t_env, const Dim<N> &t_dim, double t_lb, double t_ub, VarType t_type, const std::string &t_name = "") Creates a (nested) vector of variables.
Example:
Env env; auto x = Var::make_vector(env, Dim<2>(m, n), 0., 1., Continuous, "x"); std::cout << x[1][4].name() << std::endl; // "x_1_4"
- Template Parameters:
N – The dimension of the (nested) vector.
I – Used for recursion.
- Parameters:
t_env – The environment to store the variables.
t_dim – The number of elements in each dimension.
t_lb – The lower bound.
t_ub – The upper bound.
t_type – The type of the variables.
t_name – The given name of the variables.
- Returns:
A (nested) vector of variables.
Friends
- friend class impl::Env
-
Var(Env &t_env, double t_lb, double t_ub, VarType t_type, std::string t_name = "")