EPEC solve
Solving Equilibrium Problems with Equilibrium Constraints (EPECs)
|
Class to handle and solve linear complementarity problems. More...
#include <lcptolp.h>
Public Member Functions | |
LCP ()=delete | |
Class has no default constructors. More... | |
LCP (GRBEnv *e) | |
LCP (GRBEnv *env, arma::sp_mat M, arma::vec q, unsigned int LeadStart, unsigned LeadEnd, arma::sp_mat A={}, arma::vec b={}) | |
This constructor flor loading LCP from a file. More... | |
LCP (GRBEnv *env, arma::sp_mat M, arma::vec q, perps Compl, arma::sp_mat A={}, arma::vec b={}) | |
LCP (GRBEnv *env, const Game::NashGame &N) | |
Constructer given a NashGame. More... | |
~LCP () | |
Destructor of LCP. More... | |
arma::sp_mat | getM () |
Read-only access to LCP::M. More... | |
arma::sp_mat * | getMstar () |
Reference access to LCP::M. More... | |
arma::vec | getq () |
Read-only access to LCP::q. More... | |
arma::vec * | getqstar () |
Reference access to LCP::q. More... | |
unsigned int | getLStart () |
Read-only access to LCP::LeadStart. More... | |
unsigned int | getLEnd () |
Read-only access to LCP::LeadEnd. More... | |
perps | getCompl () |
Read-only access to LCP::Compl. More... | |
void | print (std::string end="\) |
Print a summary of the LCP. More... | |
unsigned int | getNcol () |
unsigned int | getNrow () |
bool | extractSols (GRBModel *model, arma::vec &z, arma::vec &x, bool extractZ=false) const |
Extracts variable and equation values from a solved Gurobi model for LCP. More... | |
std::unique_ptr< GRBModel > | LCPasQP (bool solve=false) |
Solves the LCP as a QP using Gurobi. More... | |
std::unique_ptr< GRBModel > | LCPasMIP (bool solve=false) |
Helps solving an LCP as an MIP using bigM constraints. More... | |
std::unique_ptr< GRBModel > | MPECasMILP (const arma::sp_mat &C, const arma::vec &c, const arma::vec &x_minus_i, bool solve=false) |
Helps solving an LCP as an MIP. More... | |
std::unique_ptr< GRBModel > | MPECasMIQP (const arma::sp_mat &Q, const arma::sp_mat &C, const arma::vec &c, const arma::vec &x_minus_i, bool solve=false) |
Helps solving an LCP as an MIQPs. More... | |
unsigned int | ConvexHull (arma::sp_mat &A, arma::vec &b) |
unsigned int | conv_Npoly () const |
unsigned int | conv_PolyPosition (const unsigned long int i) const |
unsigned int | conv_PolyWt (const unsigned long int i) const |
std::set< unsigned long int > | getAllPolyhedra () const |
unsigned long int | getNumTheoreticalPoly () const noexcept |
LCP & | makeQP (Game::QP_objective &QP_obj, Game::QP_Param &QP) |
std::set< std::vector< short int > > | addAPoly (unsigned long int nPoly=1, Game::EPECAddPolyMethod method=Game::EPECAddPolyMethod::sequential, std::set< std::vector< short int >> Polys={}) |
bool | addThePoly (const unsigned long int &decimalEncoding) |
bool | checkPolyFeas (const unsigned long int &decimalEncoding) |
bool | checkPolyFeas (const std::vector< short int > &Fix) |
void | clearPolyhedra () |
LCP & | addPolyFromX (const arma::vec &x, bool &ret) |
LCP & | EnumerateAll (bool solveLP=true) |
Brute force computation of LCP feasible region. More... | |
std::string | feas_detail_str () const |
unsigned int | getFeasiblePolyhedra () const |
void | write (std::string filename, bool append=true) const |
void | save (std::string filename, bool erase=true) const |
long int | load (std::string filename, long int pos=0) |
Data Fields | |
long double | bigM {1e7} |
bigM used to rewrite the LCP as MIP More... | |
long double | eps |
The threshold for optimality and feasability tollerances. More... | |
long double | eps_int {1e-8} |
bool | useIndicators |
constraints. BigM formulation otherwise More... | |
long int | addPolyMethodSeed |
Private Types | |
using | spmat_Vec = std::vector< std::unique_ptr< arma::sp_mat > > |
using | vec_Vec = std::vector< std::unique_ptr< arma::vec > > |
Private Member Functions | |
bool | errorCheck (bool throwErr=true) const |
void | defConst (GRBEnv *env) |
Assign default values to LCP attributes. More... | |
void | makeRelaxed () |
Makes a Gurobi object that relaxes complementarity constraints in an LCP. More... | |
void | initializeNotProcessed () |
std::unique_ptr< GRBModel > | LCPasMIP (std::vector< unsigned int > FixEq={}, std::vector< unsigned int > FixVar={}, bool solve=false) |
std::unique_ptr< GRBModel > | LCPasMIP (std::vector< short int > Fixes, bool solve) |
std::unique_ptr< GRBModel > | LCP_Polyhed_fixed (std::vector< unsigned int > FixEq={}, std::vector< unsigned int > FixVar={}) |
std::unique_ptr< GRBModel > | LCP_Polyhed_fixed (arma::Col< int > FixEq, arma::Col< int > FixVar) |
template<class T > | |
bool | isZero (const T val) const |
std::vector< short int > | solEncode (GRBModel *model) const |
Given a Gurobi model, extracts variable values and equation values, encodes it in 0/+1/-1 format and returns it. More... | |
std::vector< short int > | solEncode (const arma::vec &x) const |
Given variable values, encodes it in 0/+1/-1 format and returns it. More... | |
std::vector< short int > | solEncode (const arma::vec &z, const arma::vec &x) const |
Given variable values and equation values, encodes it in 0/+1/-1 format and returns it. More... | |
bool | FixToPoly (const std::vector< short int > Fix, bool checkFeas=false, bool custom=false, spmat_Vec *custAi={}, vec_Vec *custbi={}) |
Computes the equation of the feasibility polyhedron corresponding to the given Fix . More... | |
LCP & | FixToPolies (const std::vector< short int > Fix, bool checkFeas=false, bool custom=false, spmat_Vec *custAi={}, vec_Vec *custbi={}) |
Computes the equation of the feasibility polyhedron corresponding to the given Fix . More... | |
unsigned long int | getNextPoly (Game::EPECAddPolyMethod method) |
Private Attributes | |
GRBEnv * | env |
Gurobi env. More... | |
arma::sp_mat | M |
M in that defines the LCP. More... | |
arma::vec | q |
q in that defines the LCP More... | |
perps | Compl |
Compl stores data in <Eqn, Var> form. More... | |
unsigned int | LeadStart {1} |
unsigned int | LeadEnd {0} |
unsigned int | nLeader {0} |
arma::sp_mat | _A = {} |
arma::vec | _b = {} |
bool | madeRlxdModel {false} |
Keep track if LCP::RlxdModel is made. More... | |
unsigned int | nR |
unsigned int | nC |
int | polyCounter {0} |
unsigned int | feasiblePolyhedra {0} |
unsigned int | sequentialPolyCounter {0} |
int | reverseSequentialPolyCounter {0} |
std::set< unsigned long int > | AllPolyhedra |
Decimal encoding of polyhedra that have been enumerated. More... | |
std::set< unsigned long int > | feasiblePoly |
Decimal encoding of polyhedra that have been enumerated. More... | |
std::set< unsigned long int > | knownInfeas |
Decimal encoding of polyhedra known to be infeasible. More... | |
unsigned long int | maxTheoreticalPoly {0} |
std::unique_ptr< spmat_Vec > | Ai |
Vector to contain the LHS of inner approx polyhedra. More... | |
std::unique_ptr< vec_Vec > | bi |
Vector to contain the RHS of inner approx polyhedra. More... | |
GRBModel | RlxdModel |
Class to handle and solve linear complementarity problems.
A class to handle linear complementarity problems (LCP) especially as MIPs with bigM constraints Also provides the convex hull of the feasible space, restricted feasible space etc.
|
private |
|
private |
|
delete |
Class has no default constructors.
Constructors
Game::LCP::LCP | ( | GRBEnv * | env, |
arma::sp_mat | M, | ||
arma::vec | q, | ||
unsigned int | LeadStart, | ||
unsigned | LeadEnd, | ||
arma::sp_mat | A = {} , |
||
arma::vec | b = {} |
||
) |
This constructor flor loading LCP from a file.
env | Gurobi environment required |
M | M in |
q | q in |
LeadStart | Position where variables which are not complementary to any equation starts |
LeadEnd | Position where variables which are not complementary to any equation ends |
A | Any equations without a complemntarity variable |
b | RHS of equations without complementarity variables |
Definition at line 101 of file LCPtoLP.cpp.
Game::LCP::LCP | ( | GRBEnv * | env, |
arma::sp_mat | M, | ||
arma::vec | q, | ||
perps | Compl, | ||
arma::sp_mat | A = {} , |
||
arma::vec | b = {} |
||
) |
env | Gurobi environment required |
M | M in |
q | q in |
Compl | Pairing equations and variables for complementarity |
A | Any equations without a complemntarity variable |
b | RHS of equations without complementarity variables |
Definition at line 73 of file LCPtoLP.cpp.
Game::LCP::LCP | ( | GRBEnv * | env, |
const Game::NashGame & | N | ||
) |
Constructer given a NashGame.
Given a NashGame, computes the KKT of the lower levels, and makes the appropriate LCP object.
This constructor is the most suited for highlevel usage. @note Most preferred constructor for user interface.
Definition at line 135 of file LCPtoLP.cpp.
Game::LCP::~LCP | ( | ) |
Destructor of LCP.
Destructor - to delete the objects created with new operator
LCP object owns the pointers to definitions of its polyhedra that it owns It has to be deleted and freed.
Definition at line 174 of file LCPtoLP.cpp.
std::set< std::vector< short int > > Game::LCP::addAPoly | ( | unsigned long int | nPoly = 1 , |
Game::EPECAddPolyMethod | method = Game::EPECAddPolyMethod::sequential , |
||
std::set< std::vector< short int >> | Polys = {} |
||
) |
Tries to add at most nPoly
number of polyhedra to the inner approximation representation of the current LCP. The set of added polyhedra (+1/-1 encoding) is appended to Polys
and returned. The only reason fewer polyhedra might be added is that the fewer polyhedra already represent the feasible region of the LCP. method
is casted from Game::EPEC::EPECAddPolyMethod
Definition at line 1169 of file LCPtoLP.cpp.
LCP & Game::LCP::addPolyFromX | ( | const arma::vec & | x, |
bool & | ret | ||
) |
Given a feasible point x
, checks if any polyhedron that contains x
is already a part of this->Ai and this-> bi. If it is, then this does nothing, except for printing a log message. If not, it adds a polyhedron containing this vector.
Definition at line 859 of file LCPtoLP.cpp.
bool Game::LCP::addThePoly | ( | const unsigned long int & | decimalEncoding | ) |
Definition at line 1224 of file LCPtoLP.cpp.
bool Game::LCP::checkPolyFeas | ( | const unsigned long int & | decimalEncoding | ) |
decimalEncoding | Decimal encoding for the polyhedron |
Definition at line 990 of file LCPtoLP.cpp.
bool Game::LCP::checkPolyFeas | ( | const std::vector< short int > & | Fix | ) |
unsigned int Game::LCP::conv_Npoly | ( | ) | const |
To be used in interaction with Game::LCP::ConvexHull. Gives the number of polyhedra in the current inner approximation of the LCP feasible region.
Definition at line 1518 of file LCPtoLP.cpp.
unsigned int Game::LCP::conv_PolyPosition | ( | const unsigned long int | i | ) | const |
For the convex hull of the LCP feasible region computed, a bunch of variables are added for extended formulation and the added variables c
Definition at line 1527 of file LCPtoLP.cpp.
unsigned int Game::LCP::conv_PolyWt | ( | const unsigned long int | i | ) | const |
To be used in interaction with Game::LCP::ConvexHull. Gives the position of the variable, which assigns the convex weight to the i-th polyhedron.
However, if the inner approximation has exactly one polyhedron, then returns 0.
Definition at line 1543 of file LCPtoLP.cpp.
unsigned int Game::LCP::ConvexHull | ( | arma::sp_mat & | A, |
arma::vec & | b | ||
) |
Computes the convex hull of the feasible region of the LCP
A | Convex hull inequality description LHS to be stored here |
b | Convex hull inequality description RHS to be stored here |
Definition at line 484 of file LCPtoLP.cpp.
|
private |
Assign default values to LCP attributes.
Internal member that can be called from multiple constructors to assign default values to some attributes of the class.
Definition at line 58 of file LCPtoLP.cpp.
Game::LCP & Game::LCP::EnumerateAll | ( | bool | solveLP = true | ) |
|
private |
Checks if the M
and q
given to create the LCP object are of compatible size, given the number of leader variables
throwErr | If this is true, function throws an error, else, it just returns false |
Definition at line 455 of file LCPtoLP.cpp.
bool Game::LCP::extractSols | ( | GRBModel * | model, |
arma::vec & | z, | ||
arma::vec & | x, | ||
bool | extractZ = false |
||
) | const |
Extracts variable and equation values from a solved Gurobi model for LCP.
false
if the model is not solved to optimality. true
otherwise model | The Gurobi Model that was solved (perhaps using Game::LCP::LCPasMIP) |
z | Output variable - where the equation values are stored |
x | Output variable - where the variable values are stored |
extractZ | z values are filled only if this is true |
Definition at line 771 of file LCPtoLP.cpp.
std::string Game::LCP::feas_detail_str | ( | ) | const |
Definition at line 1506 of file LCPtoLP.cpp.
|
private |
Computes the equation of the feasibility polyhedron corresponding to the given Fix
.
The computed polyhedron are always pushed into a vector of arma::sp_mat
and arma::vec
If custom
is false, this is the internal attribute of LCP, which are LCP::Ai and LCP::bi. Otherwise, the vectors can be provided as arguments. true
value to checkFeas
ensures that each polyhedron that is pushed is feasible. not meant for high level code. Instead use LCP::FixToPolies.
*Fix
implies that polyhedron corresponding to fixing the corresponding variable as well as the equation become candidates to pushed into the vector. Hence this is preferred over LCP::FixToPoly for high-level usage. Definition at line 1061 of file LCPtoLP.cpp.
|
private |
Computes the equation of the feasibility polyhedron corresponding to the given Fix
.
The computed polyhedron is always pushed into a vector of arma::sp_mat
and arma::vec
If custom
is false, this is the internal attribute of LCP, which are LCP::Ai and LCP::bi. Otherwise, the vectors can be provided as arguments. true
value to checkFeas
ensures that the polyhedron is pushed only if it is feasible.
true
if successfully added, else false Definition at line 900 of file LCPtoLP.cpp.
|
inline |
|
inline |
Read-only access to LCP::Compl.
|
inline |
|
inline |
Read-only access to LCP::LeadEnd.
|
inline |
Read-only access to LCP::LeadStart.
|
inline |
|
inline |
|
private |
Returns a polyhedron (in its decimal encoding) that is neither already known to be infeasible, nor already added in the inner approximation representation.
Definition at line 1109 of file LCPtoLP.cpp.
|
inlinenoexcept |
|
inline |
|
inline |
|
inlineprivate |
|
private |
|
private |
Returs a model created from a given model The returned model has constraints corresponding to the non-zero elements of FixEq set to equality and variables corresponding to the non-zero elements of FixVar set to equality (=0)
LCP::LCP_Polyhed_fixed({0,...,0},{0,...,0})
is equivalent to accessing LCP::RlxdModel FixEq | If non zero, equality imposed on variable |
FixVar | If non zero, equality imposed on equation |
Definition at line 286 of file LCPtoLP.cpp.
|
private |
|
private |
unique_ptr< GRBModel > Game::LCP::LCPasMIP | ( | bool | solve = false | ) |
Helps solving an LCP as an MIP using bigM constraints.
The MIP problem that is returned by this function is equivalent to the LCP problem provided the value of bigM is large enough.
Definition at line 1343 of file LCPtoLP.cpp.
unique_ptr< GRBModel > Game::LCP::LCPasQP | ( | bool | solve = false | ) |
Solves the LCP as a QP using Gurobi.
Removes all complementarity constraints from the QP's constraints. Instead, the sum of products of complementarity pairs is minimized. If the optimal value turns out to be 0, then it is actually a solution of the LCP. Else the LCP is infeasible.
Definition at line 1295 of file LCPtoLP.cpp.
long int Game::LCP::load | ( | std::string | filename, |
long int | pos = 0 |
||
) |
Definition at line 1463 of file LCPtoLP.cpp.
Game::LCP & Game::LCP::makeQP | ( | Game::QP_objective & | QP_obj, |
Game::QP_Param & | QP | ||
) |
QP_obj | The objective function of the QP to be returned. |
QP | The output parameter where the final Game::QP_Param object is stored |
Definition at line 1265 of file LCPtoLP.cpp.
|
private |
Makes a Gurobi object that relaxes complementarity constraints in an LCP.
A Gurobi object is stored in the LCP object, that has all complementarity constraints removed. A copy of this object is used by other member functions
Definition at line 180 of file LCPtoLP.cpp.
unique_ptr< GRBModel > Game::LCP::MPECasMILP | ( | const arma::sp_mat & | C, |
const arma::vec & | c, | ||
const arma::vec & | x_minus_i, | ||
bool | solve = false |
||
) |
Helps solving an LCP as an MIP.
The MIP problem that is returned by this function is equivalent to the LCP problem. The function differs from LCP::LCPasMIP by the fact that, this explicitly takes a leader objective, and returns an object with this objective.
Definition at line 1357 of file LCPtoLP.cpp.
unique_ptr< GRBModel > Game::LCP::MPECasMIQP | ( | const arma::sp_mat & | Q, |
const arma::sp_mat & | C, | ||
const arma::vec & | c, | ||
const arma::vec & | x_minus_i, | ||
bool | solve = false |
||
) |
Helps solving an LCP as an MIQPs.
The MIQP problem that is returned by this function is equivalent to the LCP problem provided the value of bigM is large enough. The function differs from LCP::LCPasMIP by the fact that, this explicitly takes a leader objective, and returns an object with this objective. This allows quadratic leader objective. If you are aware that the leader's objective is linear, use the faster method LCP::MPECasMILP
Note that if the matrix Q is a zero matrix, then this returns a Gurobi MILP model as opposed to MIQP model. This enables Gurobi to use its much advanced MIP solver
Definition at line 1399 of file LCPtoLP.cpp.
void Game::LCP::print | ( | std::string | end = "\n" | ) |
Print a summary of the LCP.
Definition at line 478 of file LCPtoLP.cpp.
void Game::LCP::save | ( | std::string | filename, |
bool | erase = true |
||
) | const |
Definition at line 1449 of file LCPtoLP.cpp.
|
inlineprivate |
Given a Gurobi model, extracts variable values and equation values, encodes it in 0/+1/-1 format and returns it.
Definition at line 845 of file LCPtoLP.cpp.
|
private |
Given variable values, encodes it in 0/+1/-1 format and returns it.
Gives the 0/+1/-1 notation. The notation is defined as follows. Note that, if the input is feasible, then in each complementarity pair (Eqn, Var), at least one of the two is zero.
Definition at line 803 of file LCPtoLP.cpp.
|
private |
Given variable values and equation values, encodes it in 0/+1/-1 format and returns it.
z | Equation values |
x | Variable values |
Definition at line 819 of file LCPtoLP.cpp.
void Game::LCP::write | ( | std::string | filename, |
bool | append = true |
||
) | const |
Definition at line 1431 of file LCPtoLP.cpp.
|
private |
long int Game::LCP::addPolyMethodSeed |
|
private |
|
private |
|
private |
long double Game::LCP::bigM {1e7} |
|
private |
long double Game::LCP::eps |
long double Game::LCP::eps_int {1e-8} |
|
private |
|
private |
|
private |
|
private |
Keep track if LCP::RlxdModel is made.
|
private |
|
private |
bool Game::LCP::useIndicators |