EPEC solve
Solving Equilibrium Problems with Equilibrium Constraints (EPECs)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
Game::QP_Param Class Reference

Class to handle parameterized quadratic programs(QP) More...

#include <games.h>

Inheritance diagram for Game::QP_Param:
Game::MP_Param

Public Member Functions

 QP_Param (GRBEnv *env=nullptr)
 Initialize only the size. Everything else is empty (can be updated later) More...
 
 QP_Param (arma::sp_mat Q, arma::sp_mat C, arma::sp_mat A, arma::sp_mat B, arma::vec c, arma::vec b, GRBEnv *env=nullptr)
 Set data at construct time. More...
 
 QP_Param (const QP_Param &Qu)
 Copy constructor. More...
 
QP_Paramset (const arma::sp_mat &Q, const arma::sp_mat &C, const arma::sp_mat &A, const arma::sp_mat &B, const arma::vec &c, const arma::vec &b) final
 Setting the data, while keeping the input objects intact. More...
 
QP_Paramset (arma::sp_mat &&Q, arma::sp_mat &&C, arma::sp_mat &&A, arma::sp_mat &&B, arma::vec &&c, arma::vec &&b) final
 Faster means to set data. But the input objects might be corrupted now. More...
 
QP_Paramset (const QP_objective &obj, const QP_constraints &cons) final
 
QP_Paramset (QP_objective &&obj, QP_constraints &&cons) final
 
bool operator== (const QP_Param &Q2) const
 
unsigned int KKT (arma::sp_mat &M, arma::sp_mat &N, arma::vec &q) const
 Compute the KKT conditions for the given QP. More...
 
std::unique_ptr< GRBModel > solveFixed (arma::vec x)
 
double computeObjective (const arma::vec &y, const arma::vec &x, bool checkFeas=true, double tol=1e-6) const
 
bool is_Playable (const QP_Param &P) const
 
QP_ParamaddDummy (unsigned int pars, unsigned int vars=0, int position=-1) override
 
void write (std::string filename, bool append) const
 Writes a given parameterized Mathematical program to a set of files. More...
 
void save (std::string filename, bool erase=true) const
 Saves the Game::QP_Param object in a loadable file. More...
 
long int load (std::string filename, long int pos=0)
 Loads the Game::QP_Param object stored in a file. More...
 
void bound (double bigM, unsigned int primals)
 
arma::sp_mat getQ () const
 Read-only access to the private variable Q. More...
 
arma::sp_mat getC () const
 Read-only access to the private variable C. More...
 
arma::sp_mat getA () const
 Read-only access to the private variable A. More...
 
arma::sp_mat getB () const
 Read-only access to the private variable B. More...
 
arma::vec getc () const
 Read-only access to the private variable c. More...
 
arma::vec getb () const
 Read-only access to the private variable b. More...
 
unsigned int getNx () const
 Read-only access to the private variable Nx. More...
 
unsigned int getNy () const
 Read-only access to the private variable Ny. More...
 
MP_ParamsetQ (const arma::sp_mat &Q)
 Set the private variable Q. More...
 
MP_ParamsetC (const arma::sp_mat &C)
 Set the private variable C. More...
 
MP_ParamsetA (const arma::sp_mat &A)
 Set the private variable A. More...
 
MP_ParamsetB (const arma::sp_mat &B)
 Set the private variable B. More...
 
MP_Paramsetc (const arma::vec &c)
 Set the private variable c. More...
 
MP_Paramsetb (const arma::vec &b)
 Set the private variable b. More...
 

Static Public Member Functions

static bool dataCheck (const QP_objective &obj, const QP_constraints &cons, bool checkObj=true, bool checkCons=true)
 

Protected Member Functions

unsigned int size ()
 Calculates Nx, Ny and Ncons Computes parameters in MP_Param: More...
 
bool dataCheck (bool forcesymm=true) const
 Check that the data for the MP_Param class is valid Always works after calls to MP_Param::size() Checks that are done: More...
 
virtual bool finalize ()
 Finalize the MP_Param object. More...
 

Protected Attributes

arma::sp_mat Q
 
arma::sp_mat A
 
arma::sp_mat B
 
arma::sp_mat C
 
arma::vec c
 
arma::vec b
 
unsigned int Nx
 
unsigned int Ny
 
unsigned int Ncons
 

Private Member Functions

int make_yQy ()
 Adds the Gurobi Quadratic objective to the Gurobi model QuadModel. More...
 

Private Attributes

GRBEnv * env
 
GRBModel QuadModel
 
bool made_yQy
 

Detailed Description

Class to handle parameterized quadratic programs(QP)

Represents a Parameterized QP as

\[ \min_y \frac{1}{2}y^TQy + c^Ty + (Cx)^T y \]

Subject to

\begin{eqnarray} Ax + By &\leq& b \\ y &\geq& 0 \end{eqnarray}

Definition at line 146 of file games.h.

Constructor & Destructor Documentation

◆ QP_Param() [1/3]

Game::QP_Param::QP_Param ( GRBEnv *  env = nullptr)
inline

Initialize only the size. Everything else is empty (can be updated later)

Definition at line 169 of file games.h.

◆ QP_Param() [2/3]

Game::QP_Param::QP_Param ( arma::sp_mat  Q,
arma::sp_mat  C,
arma::sp_mat  A,
arma::sp_mat  B,
arma::vec  c,
arma::vec  b,
GRBEnv *  env = nullptr 
)
inline

Set data at construct time.

Definition at line 175 of file games.h.

◆ QP_Param() [3/3]

Game::QP_Param::QP_Param ( const QP_Param Qu)
inline

Copy constructor.

Definition at line 186 of file games.h.

Member Function Documentation

◆ addDummy()

Game::QP_Param & Game::QP_Param::addDummy ( unsigned int  pars,
unsigned int  vars = 0,
int  position = -1 
)
overridevirtual
Warning
You might have to rerun QP_Param::KKT since you have now changed the QP.
This implies you might have to rerun NashGame::FormulateLCP again too.

Reimplemented from Game::MP_Param.

Definition at line 386 of file Games.cpp.

◆ bound()

void Game::MP_Param::bound ( double  bigM,
unsigned int  primals 
)
inherited

◆ computeObjective()

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

Computes the objective value, given a vector y and a parameterizing vector x

Computes $\frac{1}{2} y^TQy + (Cx)^Ty $ given the input values y and x.

Parameters
checkFeasif true, checks if the given $(x,y)$ satisfies the constraints of the problem, namely $Ax + By \leq b$.

Definition at line 490 of file Games.cpp.

◆ dataCheck() [1/2]

bool Game::MP_Param::dataCheck ( bool  forcesymm = true) const
protectedinherited

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

  • Number of columns in Q is same as Ny (Q should be square)
  • Number of columns of A should be Nx
  • Number of columns of B should be Ny
  • Number of rows in C should be Ny
  • Size of c should be Ny
  • A and B should have the same number of rows, equal to Ncons
  • if forcesymm is true, then Q should be symmetric
Returns
true if all above checks are cleared. false otherwise.

Definition at line 219 of file Games.cpp.

◆ dataCheck() [2/2]

bool Game::MP_Param::dataCheck ( const QP_objective obj,
const QP_constraints cons,
bool  checkObj = true,
bool  checkCons = true 
)
staticinherited

Definition at line 262 of file Games.cpp.

◆ finalize()

virtual bool Game::MP_Param::finalize ( )
inlineprotectedvirtualinherited

Finalize the MP_Param object.

Definition at line 61 of file games.h.

◆ getA()

arma::sp_mat Game::MP_Param::getA ( ) const
inlineinherited

Read-only access to the private variable A.

Definition at line 80 of file games.h.

◆ getB()

arma::sp_mat Game::MP_Param::getB ( ) const
inlineinherited

Read-only access to the private variable B.

Definition at line 83 of file games.h.

◆ getb()

arma::vec Game::MP_Param::getb ( ) const
inlineinherited

Read-only access to the private variable b.

Definition at line 89 of file games.h.

◆ getC()

arma::sp_mat Game::MP_Param::getC ( ) const
inlineinherited

Read-only access to the private variable C.

Definition at line 77 of file games.h.

◆ getc()

arma::vec Game::MP_Param::getc ( ) const
inlineinherited

Read-only access to the private variable c.

Definition at line 86 of file games.h.

◆ getNx()

unsigned int Game::MP_Param::getNx ( ) const
inlineinherited

Read-only access to the private variable Nx.

Definition at line 92 of file games.h.

◆ getNy()

unsigned int Game::MP_Param::getNy ( ) const
inlineinherited

Read-only access to the private variable Ny.

Definition at line 95 of file games.h.

◆ getQ()

arma::sp_mat Game::MP_Param::getQ ( ) const
inlineinherited

Read-only access to the private variable Q.

Definition at line 74 of file games.h.

◆ is_Playable()

bool Game::QP_Param::is_Playable ( const QP_Param P) const
inline

Checks if the current object can play a game with another Game::QP_Param object P.

Definition at line 215 of file games.h.

◆ KKT()

unsigned int Game::QP_Param::KKT ( arma::sp_mat &  M,
arma::sp_mat &  N,
arma::vec &  q 
) const

Compute the KKT conditions for the given QP.

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$

Definition at line 417 of file Games.cpp.

◆ load()

long int Game::QP_Param::load ( std::string  filename,
long int  pos = 0 
)

Loads the Game::QP_Param object stored in a file.

Before calling this function, use the constructor QP_Param::QP_Param(GRBEnv *env) to initialize.

Example usage:

int main()
{
GRBEnv env;
Game::QP_Param q1(&env);
q1.load("./dat/q1data.dat");
std::cout<<q1<<'\n';
return 0;
}

Definition at line 529 of file Games.cpp.

◆ make_yQy()

int Game::QP_Param::make_yQy ( )
private

Adds the Gurobi Quadratic objective to the Gurobi model QuadModel.

Definition at line 308 of file Games.cpp.

◆ operator==()

bool Game::QP_Param::operator== ( const QP_Param Q2) const

Definition at line 292 of file Games.cpp.

◆ save()

void Game::QP_Param::save ( std::string  filename,
bool  erase = true 
) const

Saves the Game::QP_Param object in a loadable file.

The Game::QP_Param object hence stored can be loaded back using Game::QP_Param::load

Definition at line 514 of file Games.cpp.

◆ set() [1/4]

Game::QP_Param & Game::QP_Param::set ( const arma::sp_mat &  Q,
const arma::sp_mat &  C,
const arma::sp_mat &  A,
const arma::sp_mat &  B,
const arma::vec &  c,
const arma::vec &  b 
)
finalvirtual

Setting the data, while keeping the input objects intact.

Reimplemented from Game::MP_Param.

Definition at line 447 of file Games.cpp.

◆ set() [2/4]

Game::QP_Param & Game::QP_Param::set ( arma::sp_mat &&  Q,
arma::sp_mat &&  C,
arma::sp_mat &&  A,
arma::sp_mat &&  B,
arma::vec &&  c,
arma::vec &&  b 
)
finalvirtual

Faster means to set data. But the input objects might be corrupted now.

Reimplemented from Game::MP_Param.

Definition at line 462 of file Games.cpp.

◆ set() [3/4]

Game::QP_Param & Game::QP_Param::set ( const QP_objective obj,
const QP_constraints cons 
)
finalvirtual

Reimplemented from Game::MP_Param.

Definition at line 485 of file Games.cpp.

◆ set() [4/4]

Game::QP_Param & Game::QP_Param::set ( QP_objective &&  obj,
QP_constraints &&  cons 
)
finalvirtual

Setting the data with the inputs being a struct Game::QP_objective and struct Game::QP_constraints

Reimplemented from Game::MP_Param.

Definition at line 477 of file Games.cpp.

◆ setA()

MP_Param& Game::MP_Param::setA ( const arma::sp_mat &  A)
inlineinherited

Set the private variable A.

Definition at line 107 of file games.h.

◆ setB()

MP_Param& Game::MP_Param::setB ( const arma::sp_mat &  B)
inlineinherited

Set the private variable B.

Definition at line 111 of file games.h.

◆ setb()

MP_Param& Game::MP_Param::setb ( const arma::vec &  b)
inlineinherited

Set the private variable b.

Definition at line 119 of file games.h.

◆ setC()

MP_Param& Game::MP_Param::setC ( const arma::sp_mat &  C)
inlineinherited

Set the private variable C.

Definition at line 103 of file games.h.

◆ setc()

MP_Param& Game::MP_Param::setc ( const arma::vec &  c)
inlineinherited

Set the private variable c.

Definition at line 115 of file games.h.

◆ setQ()

MP_Param& Game::MP_Param::setQ ( const arma::sp_mat &  Q)
inlineinherited

Set the private variable Q.

Definition at line 99 of file games.h.

◆ size()

unsigned int Game::MP_Param::size ( )
protectedinherited

Calculates Nx, Ny and Ncons Computes parameters in MP_Param:

  • Computes Ny as number of rows in MP_Param::Q
  • Computes Nx as number of columns in MP_Param::C
  • Computes Ncons as number of rows in MP_Param::b, i.e., the RHS of the constraints
    For proper working, MP_Param::dataCheck() has to be run after this.
    @returns @p Ny, Number of variables in the quadratic program, QP

Definition at line 159 of file Games.cpp.

◆ solveFixed()

unique_ptr< GRBModel > Game::QP_Param::solveFixed ( arma::vec  x)

Given a value for the parameters $x$ in the definition of QP_Param, solve the parameterized quadratic program to optimality.

In terms of game theory, this can be viewed as the best response for a set of decisions by other players.

Exceptions
GRBExceptionif argument vector size is not

compatible with the Game::QP_Param definition.

Parameters
xOther players' decisions

Definition at line 331 of file Games.cpp.

◆ write()

void Game::QP_Param::write ( std::string  filename,
bool  append 
) const

Writes a given parameterized Mathematical program to a set of files.

Definition at line 86 of file Games.cpp.

Field Documentation

◆ A

arma::sp_mat Game::MP_Param::A
protectedinherited

Definition at line 55 of file games.h.

◆ B

arma::sp_mat Game::MP_Param::B
protectedinherited

Definition at line 55 of file games.h.

◆ b

arma::vec Game::MP_Param::b
protectedinherited

Definition at line 56 of file games.h.

◆ C

arma::sp_mat Game::MP_Param::C
protectedinherited

Definition at line 55 of file games.h.

◆ c

arma::vec Game::MP_Param::c
protectedinherited

Definition at line 56 of file games.h.

◆ env

GRBEnv* Game::QP_Param::env
private

Definition at line 161 of file games.h.

◆ made_yQy

bool Game::QP_Param::made_yQy
private

Definition at line 163 of file games.h.

◆ Ncons

unsigned int Game::MP_Param::Ncons
protectedinherited

Definition at line 58 of file games.h.

◆ Nx

unsigned int Game::MP_Param::Nx
protectedinherited

Definition at line 58 of file games.h.

◆ Ny

unsigned int Game::MP_Param::Ny
protectedinherited

Definition at line 58 of file games.h.

◆ Q

arma::sp_mat Game::MP_Param::Q
protectedinherited

Definition at line 55 of file games.h.

◆ QuadModel

GRBModel Game::QP_Param::QuadModel
private

Definition at line 162 of file games.h.


The documentation for this class was generated from the following files: