Model

Example:

Here is a short example which builds and solves the following optimization problem.

\[\begin{split}\begin{array}{ll} \textrm{minimize } & -x_0 - 1.5 x_1 + 3 \\ \textrm{subject to } & x_0 + 2 x_1 \le 1.5 \\ & 0 \le x_0 \le 1 \\ & 0 \le x_1 \le 1 \end{array}\end{split}\]
Env env;

Model model(env);

auto x = model.add_vars(Dim<1>(2), 0, 1, Continuous, "x");

auto c = model.add_ctr(x[0] + 2 * x[1] <= 1.5);

model.set_obj_expr(-x[0] - 1.5 * x[1] + 3);

model.use(Gurobi());

model.optimize();

std::cout << "Best obj = " << model.get_best_obj() << std::endl;
class Model : public idol::Matrix

This class is used to represent a mathematical optimization model.

Public Functions

explicit Model(Env &t_env)

Creates a new model for a mathematical optimization problem.

Example:

Env env;
Model model(env);

Parameters:

t_env – the optimization environment which will store the model

Model(Env &t_env, ObjectiveSense t_sense)
Model(Model&&) noexcept
Model &operator=(const Model&) = delete
Model &operator=(Model&&) noexcept = delete
~Model() override
Var add_var(double t_lb, double t_ub, VarType t_type, std::string t_name = "")

Creates a new decision variable in the model and returns it.

Example:

model.add_var(0, 1, Binary, "x");

Parameters:
  • t_lb – the lower bound in the model

  • t_ub – the upper bound in the model

  • t_type – the type in the model

  • t_name – the name of the variable

Returns:

the created variable

Var add_var(double t_lb, double t_ub, VarType t_type, Column t_column, std::string t_name = "")

Creates a new decision variable in the model and returns it.

Example:

model.add_var(0, 1, Binary, Column(-2), "x"); // Adds an objective coefficient of -2

Attention: every constraint involved in t_column must already be part of the model.

Parameters:
  • t_lb – the lower bound in the model

  • t_ub – the upper bound in the model

  • t_type – the type in the model

  • t_column – the column in the model

  • t_name – the name of the variable

Returns:

the created variable

template<unsigned int N>
Vector<Var, N> add_vars(Dim<N> t_dim, double t_lb, double t_ub, VarType t_type, const std::string &t_name = "")

Creates multiple decision variables in the model and returns them.

Example:

auto x = model.add_vars(Dim<2>(n, m), 0, 1, Binary, "x");

for (unsigned int i = 0 ; i < n ; ++i) {
     for (unsigned int j = 0 ; j < m ; ++j) {
         std::cout << x[i][j].name() << std::endl;
     }
}

Template Parameters:

N – the number of dimensions for the indices (e.g., N = 2 will create variables with 2 indices, \( x_{ij} \))

Parameters:
  • t_dim – the dimensions for the indices

  • t_lb – the lower bound for the variables in the model

  • t_ub – the upper bound for the variables in the model

  • t_type – the type for the variables in the model

  • t_name – the base name for the variables (variables are then named by a combination of this name and indices)

Returns:

the create variables

void add(const Var &t_var)

Adds an existing variable to the model.

Example:

Env env;

Model model1(env);
auto x = model1.add_var(0, Inf, Continuous, "x");

Model model2(env);
model2.add(x);

Note that the default version of the variable is added to the model (i.e., the variable is added identical to its first version as defined at creation time).

Parameters:

t_var – the variable to add

void add(const Var &t_var, TempVar t_temp_var)

Adds an existing variable to the model with different attributes than the default version (i.e., the variable is added to the model and has the attributes defined in t_temp_var).

Example:

Env env;

Model model1(env);
auto x = model1.add_var(0, Inf, Continuous, Column(-2), "x"); // x has an objective cost of -2 in model1

Model model2(env);
model2.add(x, TempVar(0, Inf, Continuous, Column(0))); // x has an objective cost of 0 in model2

Attention: every constraint involved in t_temp_var must already be part of the model.

Parameters:
  • t_var – the variable to add

  • t_temp_var – the attributes of the variable in the model

bool has(const Var &t_var) const

Returns true if and only if the variable is part of the model

Example:

auto x = model.add_var(-Inf, Inf, Continuous, "x");

std::cout << model.has(x) << std::endl; // output: 1

Parameters:

t_var – the variable

Returns:

true if and only if the variable is part of the model

void remove(const Var &t_var)

Removes a variable from the model.

Example:

auto x = model.add_var(0, 1, Binary, "x");

std::cout << model.has(x) << std::endl; // output: 1

model.remove(x);

std::cout << model.has(x) << std::endl; // output: 0

This also removes every reference to the variable in the objective and within the constraints.

Parameters:

t_var

inline ConstIteratorForward<std::vector<Var>> vars() const

Returns an object able to construct iterators over the set of variables of the model.

Example:

for (const Var& var : model.vars()) {
     std::cout << var.name() << std::endl;
}

Returns:

an object able to construct iterators over the set of variables of the model.

Ctr add_ctr(TempCtr t_temp_ctr, std::string t_name = "")

Creates a new constraint in the model and returns it.

Example:

auto constraint = model.add_ctr(x[0] + 2 * x[1] <= 1.5, "constraint");

Attention: every variable involved in t_temp_ctr must already be part of the model.

Parameters:
  • t_temp_ctr – the constraint attributes in the model

  • t_name – the name of the constraint

Returns:

Ctr add_ctr(Row &&t_row, CtrType t_type, std::string t_name = "")

Creates a new constraint in the model and returns it.

Example:

auto constraint = model.add_ctr(Row(x[0] + 2 * x[1], 1.5), LessOrEqual);

Parameters:
  • t_row – the row of the constraint in the model

  • t_type – the type of the constraint in the model

  • t_name – the name of the constraint

Returns:

the created constraint

template<unsigned int N>
Vector<Ctr, N> add_ctrs(Dim<N> t_dim, CtrType t_type, const Constant &t_constant, const std::string &t_name = "")

Creates multiple constraints in the model and returns them.

Example:

auto constraints = model.add_ctrs(Dim<2>(m, n), EqualTo, 1, "constraint");

for (unsigned int i = 0 ; i < n ; ++i) {
     for (unsigned int j = 0 ; j < m ; ++j) {
         std::cout << constraints[i][j].name() << std::endl;
     }
}

Template Parameters:

N – the number of dimensions for the indices

Parameters:
  • t_dim – the dimensions for the indices

  • t_type – the type of the constraints in the model

  • t_constant – the right hand-side of the constraints in the model

  • t_name – the base name for the constraints (constraints are then named by a combination of this name and indices)

Returns:

the created constraints

void add(const Ctr &t_ctr)

Adds an existing variable to the model.

Example:

Env env;

Model model1(env);
auto x = model.add_vars(Dim<1>(2), 0, Inf, Continuous, "x");
auto constraint = model1.add_ctr(x[0] + 2 * x[1] <= 1.5);

Model model2(env)
model2.add(x[0]);
model2.add(x[1]);
model2.add(constraint);

Note that the default version of the constraint is added to the model (i.e., the constraint is added identical to its first version as defined at creation time).

Attention: every variable involved in the default version must already be part of the model.

Parameters:

t_ctr

void add(const Ctr &t_ctr, TempCtr t_temp_ctr)

Adds an existing constraint to the model with different attributes than the default version (i.e., the constraint is added to the model and has the attributes defined in t_temp_ctr).

Example:

Env env;

Model model1(env);
auto x = model.add_vars(Dim<1>(2), 0, Inf, Continuous, "x");
auto constraint = model1.add_ctr(x[0] + 2 * x[1] <= 1.5);

Model model2(env)
model2.add(x[0]);
model2.add(x[1]);
model2.add(constraint, x[0] - x[1] >= 0);

Attention: every variable involved in t_temp_var must already be part of the model.

Parameters:
  • t_ctr – the constraint to add

  • t_temp_ctr – the attributes for the constraint in the model

bool has(const Ctr &t_ctr) const

Returns true if and only if the constraint is part of the model.

Example:

auto c = model.add_ctr(x[0] + 1.5 * x[1] <= 2);

std::cout << model.has(c) << std::endl; // output: 1

Parameters:

t_ctr – the constraint

Returns:

true if and only if the constraint is part of the model

void remove(const Ctr &t_ctr)

Removes a constraint from the model.

Example:

auto c = model.add_ctr(x[0] + 1.5 * x[1] <= 2);

std::cout << model.has(c) << std::endl; // output: 1

model.remove(c);

std::cout << model.has(c) << std::endl; // output: 0

Parameters:

t_ctr

inline ConstIteratorForward<std::vector<Ctr>> ctrs() const

Returns an object able to construct iterators over the set of constraints of the model.

Example:

for (const Ctr& ctr : model.ctrs()) {
     std::cout << ctr.name() << std::endl;
}

Returns:

an object able to construct iterators over the set of constraints of the model.

inline unsigned int id() const

Returns the unique id (within a given environment) of the model.

Example:

std::cout << model.id() << std::endl;

Returns:

Model *clone() const

Creates a new identical model.

Example:

Model* copy = model.clone();
// ...
delete copy;

Returns:

a pointer to the new copy

Model copy() const
void reserve_vars(unsigned int t_size)
void reserve_ctrs(unsigned int t_size)
inline Env &env() const

Returns the optimization environment of the model

Example:

Env& env = model.env();
Var x(env, 0, 1, Binary, "x");

Returns:

the optimization environment

void use(const OptimizerFactory &t_optimizer_factory)

Sets the optimizer for the model.

The optimizer is directly created using t_optimizer_factory. If an optimizer was already created, it is replaced by the new one.

Example:

model.use(Gurobi());

Parameters:

t_optimizer_factory

bool has_optimizer() const

Returns true if and only if the model currently has an optimizer.

Example:

model.use(Gurobi());

std::cout << model.has_optimizer() << std::endl; // output: 1

Returns:

true if and only if the model currently has an optimizer.

inline bool has_optimizer_factory() const
inline const OptimizerFactory &optimizer_factory() const
void unuse()

Removes an existing optimizer.

The model is therefore left without any optimizer.

Example:

model.use(Gurobi());

std::cout << model.has_optimizer() << std::endl; // output: 1

model.unuse();

std::cout << model.has_optimizer() << std::endl; // output: 0

template<class T, unsigned int N>
void add_vector(const Vector<T, N> &t_vector)

Adds a vector of optimization objects to the model (i.e., variables or constraints).

Example:

std::vector<std::vector<Var>> x = Var::make_vector(Dim<2>(n, m), 0, 1, Binary, "x");

model.add_vector<Var, 2>(x);

Template Parameters:
  • T – the type of optimization objects to add

  • N – the number of dimensions

Parameters:

t_vector – the vector of objects

inline Optimizer &optimizer()

Returns a reference to the model’s optimizer.

Example:

std::cout << model.optimizer().as<Optimizers::BranchAndBound>().n_solved_nodes() << std::endl;

Returns:

a reference to the model’s optimizer

inline const Optimizer &optimizer() const

Returns a const reference to the model’s optimizer.

Example:

std::cout << model.optimizer().as<Optimizers::BranchAndBound>().n_solved_nodes() << std::endl;

Returns:

a const reference to the model’s optimizer

void optimize()

Solves the model using the model’s optimizer

Example:

model.use(Gurobi());

model.optimize();
Attention: an optimizer must have been set beforehand.

void write(const std::string &t_name)

Asks the model’s optimizer to write the model (or any useful piece of information) to a file.

Example:

model.use(Gurobi());

model.write("model.lp");

Attention: an optimizer must have been set beforehand.

Parameters:

t_name – the destination file

void update()

Asks the model’s optimizer to update his current version of the model.

Note that you typically do not need to call this method since updates are automatically done. While some external-mip perform “lazy updates” and actually update their representation of the model only when necessary (e.g., before solving or writing to file), even in this case, updates are automatically done so that the user should not need to use this method.

Example:

model.add(x);

model.update();

Attention: an optimizer must have been set beforehand.

ObjectiveSense get_obj_sense() const

Returns the objective sense of the model (Minimize or Maximize).

Example:

ObjectiveSense sense = model.get_obj_sense();

if (sense == Minimize) {
     std::cout << "This is a minimization problem" << std::endl;
}

Returns:

the objective sense of the model

const Expr<Var, Var> &get_obj_expr() const

Returns the objective function of the model.

Example:

const Expr& objective = model.get_obj_expr();

std::cout << "The objective function is " << objective << std::endl;

Returns:

the objective function of the model

const LinExpr<Ctr> &get_rhs_expr() const

Returns the right hand-side of the model.

Example:

const LinExpr<Ctr> rhs = model.get_rhs_expr();

std::cout << "The model RHS is " << rhs << std::endl;

Returns:

the right hand-side of the model

const Constant &get_mat_coeff(const Ctr &t_ctr, const Var &t_var) const

Returns a specific coefficient in the model’s matrix.

Example:

const Constant& coeff = model.get_mat_coeff(c1, x[0]);
std::cout << "The coefficient of x_0 in constraint c1 is " << coeff << std::endl;

Parameters:
  • t_ctr – the constraint corresponding to the row

  • t_var – the column corresponding to the column

Returns:

the matrix coefficient

SolutionStatus get_status() const

Returns the current status of the optimizer.

Example:

model.optimize();

if (model.get_status() == Optimal) {
     std::cout << "Optimal solution found!" << std::endl;
}

Attention: an optimizer must have been set beforehand.

Returns:

SolutionReason get_reason() const

Returns the reason for the current status of the optimizer.

Example:

model.optimize();

if (get_status() == Fail) {
     std::cout << "The optimizer failed because of " << get_reason() << std::endl; // e.g. output: Numeric
}

Attention: an optimizer must have been set beforehand.

Returns:

double get_best_obj() const

Returns the best objective value currently known by the optimizer (i.e., feasible solution objective value)

Example:

model.optimize();

if (model.get_status() == Optimal) {
    std::cout << "Optimum = " << model.get_best_obj() << std::endl;
}

Attention: an optimizer must have been set beforehand.

Returns:

the best objective value currently known by the optimizer

double get_best_bound() const

Returns the best bound currently known by the optimizer (e.g., dual bound).

Example:

model.optimize();

if (get_status() == Feasible) {
     const double best_obj = model.get_best_obj();
     const double best_bound = model.get_best_bound();
     std::cout << "Gap: " << relative_gap(best_bound, best_obj) * 100 << " % << std::endl;
}

Returns:

the best bound currently known by the optimizer

void set_obj_sense(ObjectiveSense t_value)

Sets the objective sense of the model.

Example:

model.set_obj_sense(Maximize);

Parameters:

t_value – the new objective sense

void set_obj_expr(const Expr<Var, Var> &t_objective)

Sets the objective expression of the model.

The expression is copied.

Example:

Expr objective = - x[0] - 2 * x[2];
model.set_obj_expr(objective);

Attention: every variable involved in t_objective must already be part of the model.

Parameters:

t_objective

void set_obj_expr(Expr<Var, Var> &&t_objective)

Sets the objective expression of the model.

The expression is moved.

Example:

model.set_obj_expr(- x[0] - 2 * x[2]);

Attention: every variable involved in t_objective must already be part of the model.

Parameters:

t_objective

void set_rhs_expr(const LinExpr<Ctr> &t_rhs)

Sets the right hand-side of the model

The expression is copied.

Example:

Lin<Ctr> rhs = 2 * c1 + 3 * c2;

model.set_rhs_expr(rhs); // RHS is then 2 for constraint c1, 2 for constraint c2, 0 for others

Attention: every constraint involved in t_rhs must already be part of the model.

Parameters:

t_rhs – the right hand-side

void set_rhs_expr(LinExpr<Ctr> &&t_rhs)

Sets the right hand-side of the model

The expression is moved.

Example:

Lin<Ctr> rhs = 2 * c1 + 3 * c2;

model.set_rhs_expr(std::move(rhs)); // RHS is then 2 for constraint c1, 2 for constraint c2, 0 for others

Attention: every constraint involved in t_rhs must already be part of the model.

Parameters:

t_rhs – the right hand-side

void set_obj_const(const Constant &t_constant)

Sets the objective constant.

The constant is copied.

Example:

Constant constant = 10;
model.set_obj_const(constant);

Parameters:

t_constant – the constant

void set_obj_const(Constant &&t_constant)

Sets the objective constant.

The constant is moved.

Example:

model.set_obj_const(10);

Parameters:

t_constant – the constant

void set_mat_coeff(const Ctr &t_ctr, const Var &t_var, const Constant &t_coeff)

Sets a specific matrix coefficient.

The coefficient is copied.

Example:

Constant coeff = 3;
model.set_mat_coeff(c1, x[0], coeff); // The coefficient of x_0 in constraint c1 is 3

Parameters:
  • t_ctr – the constraint corresponding to the row

  • t_var – the variable corresponding to the column

  • t_coeff – the coefficient

void set_mat_coeff(const Ctr &t_ctr, const Var &t_var, Constant &&t_coeff)

Sets a specific matrix coefficient.

The coefficient is moved.

Example:

model.set_mat_coeff(c1, x[0], 3); // The coefficient of x_0 in constraint c1 is 3

Parameters:
  • t_ctr – the constraint corresponding to the row

  • t_var – the variable corresponding to the column

  • t_coeff – the coefficient

Ctr get_ctr_by_index(unsigned int t_index) const
Var get_var_by_index(unsigned int t_index) const
unsigned int get_ctr_index(const Ctr &t_ctr) const

Returns the current index of the constraint in the model.

Example:

unsigned int index = model.get_ctr_index(c1);

std::cout << "The current index of c1 is " << index << std::endl;

Note that the index of the constraint may change over time (in particular, when objects are removed from the model)

Parameters:

t_ctr – the constraint

Returns:

the constraint’s index

CtrType get_ctr_type(const Ctr &t_ctr) const

Returns the type of the constraint in the model

Example:

CtrType.rst.rst type = model.get_ctr_type(c1);

if (type == LessOrEqual) {
     std::cout << "c1 is a <= constraint" << std::endl;
}

Parameters:

t_ctr – the constraint

Returns:

the type of the constraint

const Row &get_ctr_row(const Ctr &t_ctr) const

Returns the row of the constraint in the model.

Example:

const Row& row = model.get_ctr_row(c1);

std::cout << "The linear part of c1 is " << row.linear() << std::endl;
std::cout << "The quadratic part of c1 is " << row.quadratic() << std::endl;
std::cout << "The RHS of c1 is " << row.rhs() << std::endl;

Parameters:

t_ctr – the constraint

Returns:

the constraint’s row

double get_ctr_dual(const Ctr &t_ctr) const

Returns the dual value of a constraint

Example:

model.optimize();

const double dual = model.get_ctr_dual(c1);

Parameters:

t_ctr – the constraint

Returns:

the constraint’s dual value

double get_ctr_farkas(const Ctr &t_ctr) const

Returns the Farkas certificate of the constraint

Example:

model.optimize();

if (model.get_status() == Infeasible) {
     std::cout << "The Farkas certificate for c1 is " << model.get_ctr_farkas(c1) << std::endl;
}

Parameters:

t_ctr – the constraint

Returns:

the farkas certificate for the constraint

void set_ctr_rhs(const Ctr &t_ctr, const Constant &t_rhs)

Sets a constraint’s right hand-side

The constant is copied.

Example:

Constant rhs = 10;
model.set_ctr_rhs(rhs);

Parameters:
  • t_ctr – the constraint

  • t_rhs – the right hand-side

void set_ctr_rhs(const Ctr &t_ctr, Constant &&t_rhs)

Sets a constraint’s right hand-side

The constant is moved.

Example:

model.set_ctr_rhs(10);

Parameters:
  • t_ctr – the constraint

  • t_rhs – the constraint’s right hand-side

void set_ctr_type(const Ctr &t_ctr, CtrType t_type)

Sets a constraint’s type.

Example:

model.set_ctr_type(LessOrEqual);

Parameters:
  • t_ctr – the constraint

  • t_type – the constraint’s type

void set_ctr_row(const Ctr &t_ctr, const Row &t_row)

Sets a constraint’s row.

The row is copied.

Example:

Row row(x[0] + 2 * x[1], 1.5);
model.set_ctr_row(row);

Attention: every variable involved in t_row must already be part of the model.

Parameters:
  • t_ctr – the constraint

  • t_row – the constraint’s row

void set_ctr_row(const Ctr &t_ctr, Row &&t_row)

Sets a constraint’s row.

The row is moved.

Example:

Row row(x[0] + 2 * x[1], 1.5);
model.set_ctr_row(std::move(row));

Attention: every variable involved in t_row must already be part of the model.

Parameters:
  • t_ctr – the constraint

  • t_row – the constraint’s row

unsigned int get_var_index(const Var &t_var) const

Returns the current index of the variable in the model.

Example:

unsigned int index = model.get_ctr_index(x[0]);

std::cout << "The current index of x_0 is " << index << std::endl;

Note that the index of the variable may change over time (in particular, when objects are removed from the model)

Parameters:

t_var – the variable

Returns:

the variable’s index

VarType get_var_type(const Var &t_var) const

Returns the variable’s type in the model

Example:

VarType type = model.get_var_type(x[0]);

if (type == Continuous) {
     std::cout << "x_0 is a continuous variable" << std::endl;
}

Parameters:

t_var – the variable

Returns:

the variable’s type

double get_var_lb(const Var &t_var) const

Returns the lower bound of a variable in the model

Example:

const double lb = model.get_var_lb(x[0]);

std::cout << "x_0 >= " << lb << " is part of the model" << std::endl;

Parameters:

t_var – the variable

Returns:

the variable’s lower bound

double get_var_ub(const Var &t_var) const

Returns the upper bound of a variable in the model

Example:

const double ub = model.get_var_ub(x[0]);

std::cout << "x_0 <= " << ub << " is part of the model" << std::endl;

Parameters:

t_var – the variable

Returns:

the variable’s upper bound

double get_var_primal(const Var &t_var) const

Returns the primal value of a variable in the model

Example:

model.optimize();

if (model.get_status() == Optimal) {
     std::cout << "Primal value of x_0 is " << model.get_var_primal(x[0]) << std::endl;
}

Parameters:

t_var – the variable

Returns:

the primal value

double get_var_reduced_cost(const Var &t_var) const

Returns the reduced cost of a variable in the model

Example:

model.optimize();

if (model.get_status() == Optimal) {
     std::cout << "Reduced cost of x_0 is " << model.get_var_reduced_cost(x[0]) << std::endl;
}

Parameters:

t_var – the variable

Returns:

the reduced cost

double get_var_ray(const Var &t_var) const

When the model is unbounded, returns the ray value of a variable of the model

Example:

model.optimize();

if (model.get_status() == Unbounded) {
     std::cout << "Ray value of x_0 is " << model.get_var_ray(x[0]) << std::endl;
}

Parameters:

t_var – the variable

Returns:

the ray value

const Column &get_var_column(const Var &t_var) const

Returns the column of a variable in the model.

Example:

const Column& column = model.get_var_column(t_var);

std::cout << "The objective coefficient of x_0 is " << column.obj() << std::endl;

Parameters:

t_var – the variable

Returns:

the variable’s column

void set_var_type(const Var &t_var, VarType t_type)

Sets a variable’s type in the model.

Example:

model.set_var_type(x[0], Binary); // x_0 is now binary

Parameters:
  • t_var – the variable

  • t_type – the variable’s type

void set_var_lb(const Var &t_var, double t_lb)

Sets a variable’s lower bound in the model

Example:

model.set_var_lb(x[0], 1); // Set the restriction x_0 >= 1

Parameters:
  • t_var – the variable

  • t_lb – the variable’s lower bound

void set_var_ub(const Var &t_var, double t_ub)

Sets a variable’s upper bound in the model

Example:

model.set_var_ub(x[0], 0); // Set the restriction x_0 <= 1

Parameters:
  • t_var – the variable

  • t_lb – the variable’s upper bound

void set_var_obj(const Var &t_var, const Constant &t_obj)

Sets a variable’s objective coefficient in the model.

The constant is copied.

Example:

Constant obj = 10;
model.set_var_obj(x[0], obj);

Parameters:
  • t_var – the variable

  • t_obj – the variable’s objective coefficient

void set_var_obj(const Var &t_var, Constant &&t_obj)

Sets a variable’s objective coefficient in the model.

The constant is moved.

Example:

model.set_var_obj(x[0], 10);

Parameters:
  • t_var – the variable

  • t_obj – the variable’s objective coefficient

void set_var_column(const Var &t_var, const Column &t_column)

Sets a variable’s column in the model.

The column is copied.

Example:

Column column(10);
model.set_var_column(x[0], column);

Attention: every constraint involved in t_column must already be part of the model.

Parameters:
  • t_var – the variable

  • t_column – the variable’s column

void set_var_column(const Var &t_var, Column &&t_column)

Sets a variable’s column in the model.

The column is moved.

Example:

Column column(10);
model.set_var_column(x[0], std::move(column));

Attention: every constraint involved in t_column must already be part of the model.

Parameters:
  • t_var – the variable

  • t_column – the variable’s column

unsigned int get_n_solutions() const

Returns the number of available primal solutions.

Some external-mip can find several optimal or sub-optimal solutions (e.g., in branch-and-bound algorithms with solution pools). This function can be used to query the number of available solutions. The solution is selected with Model::set_solution_index and retrieved via get_var_primal and get_best_obj.

Example:

model.optimize();

std::cout << n_solutions << " solution(s) have been found" << std::endl;

Returns:

the number of available solution primal solutions

unsigned int get_solution_index() const

Returns the current solution index.

Some external-mip can find several optimal or sub-optimal solutions (e.g., in branch-and-bound algorithms with solution pools). This function return the current solution index which is being returned by the model.

Example:

model.optimize();

std::cout << model.get_solution_index() << std::endl; // output: 0

Returns:

void set_solution_index(unsigned int t_index)

Sets the index of the solution returned by get_var_primal, get_status and get_reason.

Some external-mip can find several optimal or sub-optimal solutions (e.g., in branch-and-bound algorithms with solution pools). This method can be used to change the solution index which is being returned by the model.

Example:

model.optimize();

const unsigned int n_solutions = model.get_n_solutions();

std::cout << n_solutions << " solution(s) have been found" << std::endl;

for (unsigned int i = 0 ; i < n_solutions ; ++i) {
     model.set_solution_index(i);
     std::cout << save_primal(model) << std::endl;
}

Returns:

the number of available solution primal solutions

void scale_to_integers(unsigned int t_n_digits)
Model fix(const Solution::Primal &t_primals) const
template<unsigned int N>
idol::Vector<idol::Var, N> add_vars(Dim<N> t_dim, double t_lb, double t_ub, VarType t_type, const std::string &t_name)
template<unsigned int N>
idol::Vector<idol::Ctr, N> add_ctrs(Dim<N> t_dim, CtrType t_type, const Constant &t_constant, const std::string &t_name)