Class QP_Param

Inheritance Relationships

Base Type

Class Documentation

class QP_Param : public MathOpt::MP_Param

A class to handle parameterized quadratic programs (QP), defined as.

\[ \min_y \frac{1}{2}y^TQy + c^Ty + (Cx)^T y + d^T x \]
Subject to
\[\begin{split}\begin{eqnarray} Ax + By &\leq& b \\ y &\geq& 0 \end{eqnarray}\end{split}\]
The shape of C is \(numVars \times numParams\)

Public Functions

inline explicit QP_Param(GRBEnv *env = nullptr)

Standard void constructor.

Parameters

env – A pointer to the Gurobi environment

QP_Param(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, const arma::vec &d_in, GRBEnv *env = nullptr)

Empty constructor initializing only the Gurobi environment.

Constructor to set the data with copies.

Set data at construct time

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

  • env – A Gurobi Environment pointer

Returns

A pointer to this

inline QP_Param(const QP_Param &Qu)

A copy constructor given a QP_Param.

Parameters

Qu – The copied model

virtual QP_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, const arma::vec &d_in) final

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

  • d_in – Vector of linear terms for x in the objective

Returns

A pointer to this

virtual QP_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, arma::vec &&d_in) final

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

  • d_in – Vector of linear terms for x in the objective

Returns

A pointer to this

virtual QP_Param &set(const QP_Objective &obj, const QP_Constraints &cons) final

A copy constructor given a QP_Objective and QP_Constraints.

Parameters
  • obj – The objective

  • cons – The constraints object

Returns

A pointer to this

virtual QP_Param &set(QP_Objective &&obj, QP_Constraints &&cons) final

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

bool operator==(const QP_Param &Q2) const

Compares two QP_param objects.

Parameters

Q2 – The second QP_Param

Returns

True if the objects are identical

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

Writes the KKT condition of the parameterized QP. As per the convention, y is the decision variable for the QP 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 std::unique_ptr<GRBModel> solveFixed(arma::vec x, bool solve) override

Given a value for the parameters \(x\) in the definition of QP_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

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

Writes a given parameterized QP 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::QP_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) override

Inverses the operation of QP_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 QP_Param in the file

Returns

The position after the QP_Param in the file

Private Functions

void makeyQy()

Creates the quadratic term (in the y variables) and sets QP_Param::MadeyQy to true.

Private Members

GRBModel Model

Gurobi pointer to the QP model.

bool MadeyQy

True if the objective quadratic term has been generated.