# Class IP_Param

## Class Documentation

class IP_Param : public MathOpt::MP_Param

This class handles parametrized integer programs, and inherits from MP_Param. A parametrized Integer Program is defined as as.

$\min_y c^Ty + (Cx)^T y$
Subject to
$\begin{split}\begin{eqnarray} By &\leq& b \\ y &\geq& 0 \\ y_i &\in& &\mathbb{Z}& &\forall& i &\in& I \end{eqnarray}\end{split}$
Where the shape of C is $$Ny \times numParams$$.

Public Functions

inline explicit IP_Param(GRBEnv *env = nullptr)

A constructor initializing only the size. Everything else is empty (can be updated later)

Parameters

env – The pointer to the Gurobi environment

IP_Param(const arma::sp_mat &C_in, const arma::sp_mat &B_in, const arma::vec &b_in, const arma::vec &c_in, const arma::vec &integers_in, const VariableBounds &Bounds_in, GRBEnv *env_in)

Alternative constructor.

Parameters
• C_in – The objective C matrix

• B_in – The constraint matrix

• b_in – The constraint RHS

• c_in – The objective c vector

• integers_in – The indexes of integer variables

• Bounds_in – The input bounds

• env_in – A pointer to the Gurobi environment

virtual bool finalize() override

This method creates the (mixed)-integer program for the game, where the objective omits the bilinear part. The flag Finalized in the object is then set to true.

Returns

True if checks are completed

IP_Param &setBounds(const VariableBounds &boundIn)
bool addConstraints(const arma::sp_mat &A_in, const arma::vec &b_in)

Adds a constraints to the IP_Param. It stores a description of the new cut $$A_{in} x \leq b_{in}$$ of A_in (and RHS b_in) in B and b, respectively.

Parameters
• A_in – The vector of LHS

• b_in – The RHS value

Returns

true if the constraint has been added This works also when the IP_Param is Finalized.

Returns

True if the constraint is added

IP_Param(const IP_Param &ipg) = default

A copy constructor from anoter IP_Param.

Parameters

ipg – The model to be copied

MathOpt::IP_Param &set(const arma::sp_mat &C_in, const arma::sp_mat &B_in, const arma::vec &b_in, const arma::vec &c_in, const arma::vec &integers_in, const VariableBounds &Bounds_in)

A setter method with copy arguments.

Parameters
• C_in – Bi-linear term for x-y in the objective

• B_in – Matrix of constraints for the variables y

• c_in – Vector of linear terms for y in the objective

• b_in – Vector of RHS in the constraints

• integers_in – A vector containing the indexes of integer variables

• Bounds_in – Variable bounds

Returns

A pointer to this

IP_Param &set(arma::sp_mat &&C_in, arma::sp_mat &&B_in, arma::vec &&b_in, arma::vec &&c_in, arma::vec &&integers_in, VariableBounds &&Bounds_in)

A move constructor.

Parameters
• C_in – Bi-linear term for x-y in the objective

• B_in – Matrix of constraints for the variables y

• c_in – Vector of linear terms for y in the objective

• b_in – Vector of RHS in the constraints

• integers_in – A vector containing the indexes of integer variables

• Bounds_in – Variable bounds

Returns

A pointer to this

bool operator==(const IP_Param &IPG2) const

Compares two IP_param objects.

Parameters

IPG2 – The second IP_Param

Returns

True if the objects are identical

virtual double computeObjective(const arma::vec &y, const arma::vec &x, bool checkFeas = true, double tol = 1e-6) const override

Computes $$(Cx)^Ty + c^Ty$$ given the input values y and x. checkFeas if true, checks if the given $$(x,y)$$ satisfies the constraints of the problem, namely $$Ax + By \leq b$$.

Parameters
• y – The values for the variables y

• x – The values for the parameters x

• checkFeas – True if feasibility should be checked

• tol – A numerical tolerance for the feasibility

Returns

A double value for the objective

virtual void save(const std::string &filename, bool append) const override

A save method for the IP_Param.

Parameters
• filename – The filename

• append – If true, the file will be appended

long load(const std::string &filename, long pos = 0) override

Loads the IP_Param from a file.

Warning

int main()
{
GRBEnv Env;
MathOpt::IP_Param ip(&Env);
std::cout<<ip<<'\n';
return 0;
}


Parameters
• filename – The filename

• pos – The position of the IP_Param in the file

Returns

The position after the IP_Param

void updateModelObjective(const arma::vec &x)

This method updates the model objective in IP_Param::IPModel by setting x to x.

Parameters

x – The parametrized values of x

virtual std::unique_ptr<GRBModel> solveFixed(arma::vec x, bool solve = false) override

Given a value for the parameters $$x$$ in the definition of IP_Param, returns a pointer to the parameterized MIP program . Note that the method.

Parameters
• x – The parametrized values of x

• solve – If the returned model is solved

Returns

a pointer to a copy of the model. In this way, valid cuts and cut pools are kept each time the method is invoked. In terms of game theory, this can be viewed as the best response for a set of decisions by other players.

Returns

A pointer to the Gurobi model

std::unique_ptr<GRBModel> getIPModel(const arma::vec &x, bool relax = false)

Given a value for the parameters $$x$$ in the definition of IP_Param, returns a pointer to the parameterized MIP program . Note that the method.

Parameters
• x – The values for the parametrized x

• relax – True if the model relaxes integrality requirements

Returns

a pointer to a copy of the model. In this way, valid cuts and cut pools are kept each time the method is invoked. If relax is true, then the model is the linear relaxation of the MIP.

Returns

A pointer to the Gurobi model

virtual unsigned int KKT(arma::sp_mat &M, arma::sp_mat &N, arma::vec &q) const override

Writes the KKT condition of the relaxation of the parameterized IP. As per the convention, y is the decision variable for the IP and that is parameterized in x. The KKT conditions are $$0 \leq y \perp My + Nx + q \geq 0$$.

Parameters
• M – The output M term

• N – The output N term

• q – The output q term

Returns

An int containing the rows of M

virtual bool isFeasible(const arma::vec &y, const arma::vec &x, double tol) const override

Given a parameter value x, and variables values y, returns true whenever the point is feasible for the program. This method overrides the MathOpt::MP_Param to manage integral requirements.

Parameters
• y – The variables’ values

• x – The parameters’ values

• tol – A numerical tolerance

Returns

True if the point is feasible

void presolve()

Presolved the IP model and replaces the object in the class with the (possibly) simplified model. Note: this should be used with care. First, it can mess the sizes of the variables/constraints. Second, it may be resource consuming.

Todo:

currently disabled. check the method

Private Functions

MP_Param &set(const arma::sp_mat &Q_in, const arma::sp_mat &C_in, const arma::sp_mat &A_in, const arma::sp_mat &B_in, const arma::vec &c_in, const arma::vec &b_in)

Constructor to set the data, while keeping the input objects intact.

Parameters
• Q_in – Quadratic term for y in the objective

• C_in – Bi-linear term for x-y in the objective

• A_in – Matrix of constraints for the parameters x

• B_in – Matrix of constraints for the variables y

• c_in – Vector of linear terms for y in the objective

• b_in – Vector of RHS in the constraints

Returns

A pointer to this

MP_Param &set(arma::sp_mat &&Q_in, arma::sp_mat &&C_in, arma::sp_mat &&A_in, arma::sp_mat &&B_in, arma::vec &&c_in, arma::vec &&b_in)

Constructor to set the data through std::move.

Warning

The input data may be corrupted after

Parameters
• Q_in – Quadratic term for y in the objective

• C_in – Bi-linear term for x-y in the objective

• A_in – Matrix of constraints for the parameters x

• B_in – Matrix of constraints for the variables y

• c_in – Vector of linear terms for y in the objective

• b_in – Vector of RHS in the constraints

Returns

A pointer to this

MP_Param &set(const QP_Objective &obj, const QP_Constraints &cons)

A copy constructor given a QP_Objective and QP_Constraints.

Parameters
• obj – The objective

• cons – The constraints object

Returns

A pointer to this

MP_Param &set(QP_Objective &&obj, QP_Constraints &&cons)

A move constructor given a QP_Objective and QP_Constraints.

Warning

The input data may be corrupted after

Parameters
• obj – The objective

• cons – The constraints object

Returns

A pointer to this

Private Members

GRBModel IPModel

Stores the IP model associated with the object.

arma::vec Integers

Stores the indexes of integer variables.

bool Finalized = {false}

True if the model has been made and constraints cannot be changed.