Class MP_Param

Inheritance Relationships

Derived Types

Class Documentation

class MathOpt::MP_Param

This class handles parameterized mathematical programs (MP) Their form is the one of.

\[ \min_y \frac{1}{2}y^TQy + c^Ty + (Cx)^T y \]
Subject to
\[\begin{split}\begin{eqnarray} Ax + By &\leq& b \\ y &\geq& 0 \end{eqnarray}\end{split}\]

Subclassed by MathOpt::IP_Param, MathOpt::QP_Param

Public Functions

inline MP_Param(GRBEnv *env = nullptr)

Default constructor.

Parameters

env – The pointer to the Gurobi environment

MP_Param(const MP_Param &M) = default

Default copy constructor.

Parameters

M – The origin object Default copy constructor

arma::sp_mat getA(bool bounds = true) const

Read-only access to the private variable A.

Returns the matrix A.

Parameters

bounds – True if one needs to include the bounds in the matrix A

Returns

A const object with A

arma::sp_mat getB(bool bounds = true) const

Read-only access to the private variable B.

Returns the matrix B.

Parameters

bounds – True if one needs to include the bounds in the matrix B

Returns

A const object with B

arma::vec getb(bool bounds = true) const

Read-only access to the private variable b.

Returns the vector b.

Parameters

bounds – True if one needs to include the bounds in the vector b

Returns

A const object with b

virtual 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

virtual 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

virtual 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

virtual 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

virtual MP_Param &addDummy(unsigned int pars, unsigned int vars = 0, int position = -1)

Adds dummy variables to a parameterized mathematical program position dictates the position at which the parameters can be added.

Parameters
  • pars – Number of parameters to be added (e.g., MP_Param::numParams)

  • vars – Number of variables to be added (e.g., MP_Param::numVars)

  • position – The position at which the parameters should be added. -1 for adding at the end.

Returns

A pointer to the object

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

Writes a given parameterized Mathematical program to a set of files. Writes a given parameterized Mathematical program to a set of files. One file is written for each attribute namely.

  1. MathOpt::MP_Param::Q

  2. MathOpt::MP_Param::C

  3. MathOpt::MP_Param::A

  4. MathOpt::MP_Param::B

  5. MathOpt::MP_Param::c

  6. MathOpt::MP_Param::b

  7. MathOpt::MP_Param::Bounds

To contrast see, MathOpt::MP_Param::save where all details are written to a single loadable file

Parameters
  • filename – The filename

  • append – True if the content is appended

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

Inverses the operation of MP_Param::save by loading the object from a file.

Warning

Call MP_Param(GRBEnv *env) before loading

Parameters
  • filename – The filename

  • pos – The position of the MP_Param in the file

Returns

The position after the MP_Param in the file

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

A virtual method to take the KKT of the program, in a complementarity form.

Parameters
  • M – Output M matrix for variables

  • N – Output N matrix for parameters

  • q – Output q vector

Returns

The rows of M

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

Returns the optimal Gurobi model where the paramers are fixed to x.

Parameters
  • x – The input parameters

  • solve – True if the model needs to be solved

Returns

The best response model

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

Computes \(\frac{1}{2} y^TQy + (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

  • checkFeasibility – True if feasibility should be checked

  • tol – A numerical tolerance for the feasibility

Returns

A double value for the objective

void forceDataCheck() const

Forces the datacheck on the object. Otherwise, it throws an error.

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

Given a parameter value x, and variables values y, returns true whenever the point is feasible for the program.

Parameters
  • y – The variables’ values

  • x – The parameters’ values

  • tol – A numerical tolerance

Returns

True if the point is feasible

Protected Functions

unsigned int size()

Calculates numParams, numVars and numConstr Computes parameters in MP_Param:

Returns

numVars, Number of variables in the quadratic program, QP

bool dataCheck(bool forceSymmetry = true) const

Check that the data for the MP_Param class is valid Always works after calls to MP_Param::size().

Parameters

forceSymmetry

Returns

True if data structures are correctly sized.

void detectBounds()

Detects explicit bounds stated in the MP_Param formulation, and stores them implicitly. This is useful when the formulation of the parametrized mathematical program is processed through other steps (e.g., KKT conditions, LCPs, etc…) since any bound constraint can possibly slow down the final problem solving.

void rewriteBounds()

Given the description of the object, renders the bounds explicitly. This method is useful when building the KKT conditions for the MP_Param. In particular, after bounds are detected and their respective rows are shedded by MP_Param::detectBounds, the explicit constraints should be added again.

Warning

The size of Bounds should be the future numVars.

virtual bool finalize()

Finalizes the MP_Param object. Can be overriden by inheritors.

Finalizes the MP_Param object, computing the object sizes and eventually shedding trivial bound constraints.

Returns

True if the object is Finalized and checks are passed.

Protected Attributes

arma::sp_mat Q

The Q matrix in the objective.

arma::sp_mat A

The A matrix for the parameters’ constraints.

arma::sp_mat B

The B matrix for the variables’ constraints.

arma::sp_mat C

The C matrix in the objective.

arma::sp_mat B_bounds

Implicit rows of B accounting for variables’ bounds.

arma::vec b_bounds

The implicit rows of b accounting for the variables’ bounds.

arma::vec c

The c vector in the objective.

arma::vec b

The constraints’ RHS.

GRBEnv *Env

A pointer to the Gurobi environment.

VariableBounds Bounds

Bounds on the y variables.

unsigned int numParams

Number of x parameters.

unsigned int numVars

Number of y variables.

unsigned int numConstr

Number of constraints.

Private Members

double Eps = {1e-6}

A numerical tolerance.