Annotation
Annotations are additional information associated to an optimization object (e.g., a constraint or a variable).
The Annotation class takes two template arguments: an optimization object type and a value type. For instance, we
can create an annotation for constraints of type unsigned int
as follows.
Env env;
const unsigned int default_value = 0;
Annotation<Ctr, unsigned int> annotation(env, "my_annotation", default_value);
Note that annotations are global, i.e., they do not relate to a given optimization model and can, therefore, be accessed
anywhere in the code. Thus, given a constraint called constraint
, the value of the annotation can be accessed
by calling the Ctr::get
method.
std::cout << "My annotation is " << constraint.get(annotation) << std::endl; // "0", i.e., the default_value value
Annotations are, in particular, used to give decomposition instructions to idol when designing a Branch-and-Price algorithm. To learn more, check our Branch-and-Price tutorials.
-
template<class ObjectT, class ValueT = unsigned int>
class Annotation : public idol::impl::Annotation Public Functions
-
inline Annotation(Env &t_env, std::string t_name)
Constructor.
Creates a new annotation stored in
t_env
with namet_name
. No default value is given.- Parameters:
t_env – The environment which will store the annotation
t_name – The given name to the annotation
-
template<class ...ArgsT>
inline Annotation(Env &t_env, std::string t_name, ArgsT&&... t_args) Constructor.
Creates a new annotation stored in
t_env
with namet_name
and a default value. The default value is built “in place” by calling the constructor ofValueT
with the arguments given aftert_name
.- Template Parameters:
ArgsT – Parameter pack template types for constructing the default value of the annotation
- Parameters:
t_env – The environment which will store the annotation
t_name – The given name to the annotation
t_args – Parameter pack arguments for constructing the default value of the annotation
-
inline virtual bool is_var_annotation() const override
Returns true if the annotation is for variables, false otherwise.
- Returns:
true if the annotation is for variables, false otherwise
-
inline virtual bool is_ctr_annotation() const override
Returns true if the annotation is for constraints, false otherwise.
- Returns:
true if the annotation is for constraints, false otherwise
-
inline const ValueT &default_value() const
Returns the default value of the annotation.
- Returns:
The default value of the annotation
-
inline unsigned int id() const
Returns the id of the annotation.
The id is unique within the environment.
- Returns:
The id of the annotation
-
inline const std::string &name() const
Returns the given name of the annotation.
- Returns:
The given name of the annotation
-
inline bool has_default() const
Returns true if the annotation has a default value, false otherwise.
- Returns:
true if the annotation has a default value, false otherwise
-
void free()
Frees the memory kept for the annotation in the environment.
Public Static Functions
-
template<class ...ArgsT>
static inline Annotation<ObjectT, ValueT> make_with_default_value(Env &t_env, std::string t_name, ArgsT&&... t_args) Creates a new annotation stored in
t_env
with namet_name
and a default value. The default value is built “in place” by calling the constructor ofValueT
with the arguments given aftert_name
.- Template Parameters:
ArgsT – Parameter pack template types for constructing the default value of the annotation
- Parameters:
t_env – The environment which will store the annotation
t_name – The given name to the annotation
t_args – Parameter pack arguments for constructing the default value of the annotation
- Returns:
The created annotation
-
inline Annotation(Env &t_env, std::string t_name)