EPEC solve
Solving Equilibrium Problems with Equilibrium Constraints (EPECs)
|
Class to handle a Nash game between leaders of Stackelberg games. More...
#include <games.h>
Public Member Functions | |
EPEC ()=delete | |
EPEC (EPEC &)=delete | |
~EPEC () | |
void | finalize () |
Finalizes the creation of a Game::EPEC object. More... | |
void | findNashEq () |
std::unique_ptr< GRBModel > | Respond (const unsigned int i, const arma::vec &x) const |
double | RespondSol (arma::vec &sol, unsigned int player, const arma::vec &x, const arma::vec &prevDev) const |
bool | isSolved (unsigned int *countryNumber, arma::vec *ProfDevn, double tol=51e-4) const |
bool | isSolved (double tol=51e-4) const |
const arma::vec | getx () const |
void | reset () |
const arma::vec | getz () const |
const EPECStatistics | getStatistics () const |
Get the EPECStatistics object for the current instance. More... | |
void | setAlgorithm (Game::EPECalgorithm algorithm) |
Game::EPECalgorithm | getAlgorithm () const |
void | setRecoverStrategy (Game::EPECRecoverStrategy strategy) |
Game::EPECRecoverStrategy | getRecoverStrategy () const |
void | setAggressiveness (unsigned int a) |
unsigned int | getAggressiveness () const |
void | setNumThreads (unsigned int t) |
unsigned int | getNumThreads () const |
void | setAddPolyMethodSeed (unsigned int t) |
unsigned int | getAddPolyMethodSeed () const |
void | setIndicators (bool val) |
bool | getIndicators () const |
void | setPureNE (bool val) |
bool | getPureNE () const |
void | setBoundPrimals (bool val) |
bool | getBoundPrimals () const |
void | setBoundBigM (double val) |
double | getBoundBigM () const |
void | setTimeLimit (double val) |
double | getTimeLimit () const |
void | setAddPolyMethod (Game::EPECAddPolyMethod add) |
Game::EPECAddPolyMethod | getAddPolyMethod () const |
unsigned int | getnVarinEPEC () const noexcept |
unsigned int | getNcountries () const noexcept |
unsigned int | getPosition_LeadFoll (const unsigned int i, const unsigned int j) const |
unsigned int | getPosition_LeadLead (const unsigned int i, const unsigned int j) const |
unsigned int | getPosition_LeadFollPoly (const unsigned int i, const unsigned int j, const unsigned int k) const |
unsigned int | getPosition_LeadLeadPoly (const unsigned int i, const unsigned int j, const unsigned int k) const |
unsigned int | getNPoly_Lead (const unsigned int i) const |
unsigned int | getPosition_Probab (const unsigned int i, const unsigned int k) const |
double | getVal_LeadFoll (const unsigned int i, const unsigned int j) const |
double | getVal_LeadLead (const unsigned int i, const unsigned int j) const |
double | getVal_LeadFollPoly (const unsigned int i, const unsigned int j, const unsigned int k, const double tol=1e-5) const |
double | getVal_LeadLeadPoly (const unsigned int i, const unsigned int j, const unsigned int k, const double tol=1e-5) const |
double | getVal_Probab (const unsigned int i, const unsigned int k) const |
bool | isPureStrategy (const unsigned int i, const double tol=1e-5) const |
bool | isPureStrategy (const double tol=1e-5) const |
std::vector< unsigned int > | mixedStratPoly (const unsigned int i, const double tol=1e-5) const |
const LCP & | getLcpDescr () const |
const GRBModel & | getLcpModel () const |
void | writeLcpModel (std::string filename) const |
Protected Member Functions | |
bool | warmstart (const arma::vec x) |
Warmstarts EPEC with a solution. More... | |
EPEC (GRBEnv *env) | |
virtual void | make_obj_leader (const unsigned int i, Game::QP_objective &QP_obj)=0 |
Can be instantiated by a derived class only! More... | |
virtual void | prefinalize () |
Empty function - optionally reimplementable in derived class. More... | |
virtual void | postfinalize () |
Empty function - optionally reimplementable in derived class. More... | |
virtual void | updateLocs ()=0 |
virtual void | make_MC_cons (arma::sp_mat &MC, arma::vec &RHS) const |
bool | hasLCP () const |
Protected Attributes | |
std::vector< std::shared_ptr< Game::NashGame > > | countries_LL {} |
std::vector< std::unique_ptr< Game::LCP > > | countries_LCP {} |
std::vector< std::shared_ptr< Game::QP_Param > > | country_QP {} |
The QP corresponding to each player. More... | |
std::vector< std::shared_ptr< Game::QP_objective > > | LeadObjec {} |
Objective of each leader. More... | |
std::vector< std::shared_ptr< Game::QP_objective > > | LeadObjec_ConvexHull {} |
std::unique_ptr< Game::NashGame > | nashgame |
The EPEC nash game. More... | |
std::vector< unsigned int > | LeaderLocations {} |
std::vector< const unsigned int * > | LocEnds {} |
std::vector< unsigned int > | convexHullVariables {} |
unsigned int | n_MCVar {0} |
GRBEnv * | env |
bool | finalized {false} |
bool | nashEq {false} |
std::chrono::high_resolution_clock::time_point | initTime |
EPECStatistics | Stats {} |
Store run time information. More... | |
arma::vec | sol_z |
Solution equation values. More... | |
arma::vec | sol_x |
Solution variable values. More... | |
Private Member Functions | |
void | add_Dummy_Lead (const unsigned int i) |
Add Dummy variables for the leaders. More... | |
void | make_country_QP (const unsigned int i) |
Makes the Game::QP_Param corresponding to the i-th country. More... | |
void | make_country_QP () |
Makes the Game::QP_Param for all the countries. More... | |
void | make_country_LCP () |
void | resetLCP () |
void | iterativeNash () |
void | fullEnumerationNash () |
void | combinatorial_pure_NE (const std::vector< long int > combination, const std::vector< std::set< unsigned long int >> &excludeList) |
void | combinatorialPNE (const std::vector< long int > combination={}, const std::vector< std::set< unsigned long int >> &excludeList={}) |
void | make_pure_LCP (bool indicators=false) |
void | computeLeaderLocations (const unsigned int addSpaceForMC=0) |
bool | getAllDevns (std::vector< arma::vec > &devns, const arma::vec &guessSol, const std::vector< arma::vec > &prevDev={}) const |
Given a potential solution vector, returns a profitable deviation (if it exists) for all players. More... | |
unsigned int | addDeviatedPolyhedron (const std::vector< arma::vec > &devns, bool &infeasCheck) const |
void | get_x_minus_i (const arma::vec &x, const unsigned int &i, arma::vec &solOther) const |
bool | computeNashEq (bool pureNE=false, double localTimeLimit=-1.0, bool check=false) |
bool | addRandomPoly2All (unsigned int aggressiveLevel=1, bool stopOnSingleInfeasibility=false) |
Private Attributes | |
std::vector< unsigned int > | SizesWithoutHull {} |
Game::EPECalgorithm | algorithm |
used by the EPEC. More... | |
std::unique_ptr< Game::LCP > | lcp |
The EPEC nash game written as an LCP. More... | |
std::unique_ptr< GRBModel > | lcpmodel |
A Gurobi mode object of the LCP form of EPEC. More... | |
std::unique_ptr< GRBModel > | lcpmodel_base |
unsigned int | nVarinEPEC {0} |
unsigned int | nCountr {0} |
Class to handle a Nash game between leaders of Stackelberg games.
|
delete |
|
delete |
|
private |
|
private |
Given a profitable deviation for each country, adds a polyhedron in the feasible region of each country to the corresponding country's Game::LCP object (this->countries_LCP.at(i)) 's vector of feasible polyhedra.
Naturally, this makes the inner approximation of the Game::LCP better, by including one additional polyhedron.
devns | devns.at(i) is a profitable deviation for the i-th country from the current this->sol_x |
infeasCheck | Useful for the first iteration of iterativeNash. If true, at least one player has no polyhedron that can be added. In the first iteration, this translates to infeasability |
|
private |
Makes a call to to Game::LCP::addAPoly for each member in Game::EPEC::countries_LCP and tries to add a polyhedron to get a better inner approximation for the LCP. aggressiveLevel
is the maximum number of polyhedra it will try to add to each country. Setting it to an arbitrarily high value will mimic complete enumeration.
If stopOnSingleInfeasibility
is true, then the function returns false and aborts all operation as soon as it finds that it cannot add polyhedra to some country. On the other hand if stopOnSingleInfeasibility
is false, the function returns false, only if it is not possible to add polyhedra to any of the countries.
|
private |
|
private |
|
private |
|
private |
Given that Game::EPEC::country_QP are all filled with a each country's Game::QP_Param problem (either exact or approximate), computes the Nash equilibrium.
pureNE | True if we search for a PNE |
localTimeLimit | Allowed time limit to run this function |
check | If true, the algorithm will seek for the maximum number of NE. Then, it will check they are equilibria for the original problem |
void Game::EPEC::finalize | ( | ) |
Finalizes the creation of a Game::EPEC object.
Performs a bunch of job after all data for a Game::EPEC object are given, namely. Models::EPEC::computeLeaderLocations - Adds the required dummy variables to each leader's problem so that a game among the leaders can be defined. Calls Game::EPEC::add_Dummy_Lead
Game::EPEC::prefinalize() can be overridden, and that code will run before calling Game::EPEC::finalize()
Game::EPEC::postfinalize() can be overridden, and that code will run after calling Game::EPEC::finalize()
void Game::EPEC::findNashEq | ( | ) |
Computes Nash equilibrium using the algorithm set in Game::EPEC::algorithm
Checks the value of Game::EPEC::algorithm and delegates the task to appropriate algorithm wrappers.
|
private |
|
inline |
|
inline |
|
inline |
|
private |
|
inline |
|
inline |
|
inlinenoexcept |
unsigned int Game::EPEC::getNPoly_Lead | ( | const unsigned int | i | ) | const |
|
inlinenoexcept |
unsigned int Game::EPEC::getPosition_LeadFoll | ( | const unsigned int | i, |
const unsigned int | j | ||
) | const |
Get the position of the j-th Follower variable in the i-th leader Querying Game::EPEC::lcpmodel for x[return-value] variable gives the appropriate variable
unsigned int Game::EPEC::getPosition_LeadFollPoly | ( | const unsigned int | i, |
const unsigned int | j, | ||
const unsigned int | k | ||
) | const |
unsigned int Game::EPEC::getPosition_LeadLead | ( | const unsigned int | i, |
const unsigned int | j | ||
) | const |
Get the position of the j-th Follower variable in the i-th leader Querying Game::EPEC::lcpmodel for x[return-value] variable gives the appropriate variable
unsigned int Game::EPEC::getPosition_LeadLeadPoly | ( | const unsigned int | i, |
const unsigned int | j, | ||
const unsigned int | k | ||
) | const |
unsigned int Game::EPEC::getPosition_Probab | ( | const unsigned int | i, |
const unsigned int | k | ||
) | const |
|
inline |
|
inline |
Get the EPECStatistics object for the current instance.
double Game::EPEC::getVal_LeadFoll | ( | const unsigned int | i, |
const unsigned int | j | ||
) | const |
double Game::EPEC::getVal_LeadFollPoly | ( | const unsigned int | i, |
const unsigned int | j, | ||
const unsigned int | k, | ||
const double | tol = 1e-5 |
||
) | const |
double Game::EPEC::getVal_LeadLead | ( | const unsigned int | i, |
const unsigned int | j | ||
) | const |
double Game::EPEC::getVal_LeadLeadPoly | ( | const unsigned int | i, |
const unsigned int | j, | ||
const unsigned int | k, | ||
const double | tol = 1e-5 |
||
) | const |
double Game::EPEC::getVal_Probab | ( | const unsigned int | i, |
const unsigned int | k | ||
) | const |
bool Game::EPEC::isPureStrategy | ( | const unsigned int | i, |
const double | tol = 1e-5 |
||
) | const |
bool Game::EPEC::isPureStrategy | ( | const double | tol = 1e-5 | ) | const |
bool Game::EPEC::isSolved | ( | unsigned int * | countryNumber, |
arma::vec * | ProfDevn, | ||
double | tol = 51e-4 |
||
) | const |
Checks if Game::EPEC is solved, else returns proof of unsolvedness.
Analogous to Game::NashGame::isSolved but checks if the given Game::EPEC is solved. If it is solved, then retruns true. If not, it returns the country which has a profitable deviation in countryNumber
and the profitable deviation in ProfDevn
. tol
is the tolerance for the check. If the improved objective after the deviation is less than tol
, then it is not considered as a profitable deviation.
Thus we check if the given point is an -equilibrium. Value of can be chosen sufficiently close to 0.
tol
= 0 might even reject a real solution as not solved. This is due to numerical issues arising from the LCP solver (Gurobi).
|
private |
|
private |
Makes the Game::QP_Param corresponding to the i-th
country.
Game::EPEC::countries_LL
and makes a Game::QP_Param with this LCP as the lower levelGame::EPEC::LeadObjec
|
private |
Makes the Game::QP_Param for all the countries.
Calls are made to Models::EPEC::make_country_QP(const unsigned int i) for each valid i
|
inlineprotectedvirtual |
Reimplemented in Models::EPEC.
|
protectedpure virtual |
Can be instantiated by a derived class only!
Implemented in Models::EPEC, and My_EPEC_Prob.
|
private |
Given that Game::EPEC::lcpmodel is filled with the final LCP, directs the search toward a pure nash EQ. If such an equilibrium does not exist, then the model will return anyway a MNE. The original LCP is stored in the field Game::EPEC::lcpmodel_base. indicators
dictates whether the resulting LCP should use indicator constraints instead of general binaries. In general, there are advantages in using the binary variables instead of such constraints, since there is no bigM involved in the formulation.
std::vector< unsigned int > Game::EPEC::mixedStratPoly | ( | const unsigned int | i, |
const double | tol = 1e-5 |
||
) | const |
|
protectedvirtual |
Empty function - optionally reimplementable in derived class.
This function can be optionally implemented by the derived class. Code in this class will be run after calling Game::EPEC::finalize().
Reimplemented in Models::EPEC.
|
protectedvirtual |
Empty function - optionally reimplementable in derived class.
This function can be optionally implemented by the derived class. Code in this class will be run before calling Game::EPEC::finalize().
Reimplemented in Models::EPEC.
|
private |
unique_ptr< GRBModel > Game::EPEC::Respond | ( | const unsigned int | i, |
const arma::vec & | x | ||
) | const |
double Game::EPEC::RespondSol | ( | arma::vec & | sol, |
unsigned int | player, | ||
const arma::vec & | x, | ||
const arma::vec & | prevDev = {} |
||
) | const |
Returns the optimal objective value that is obtainable for the player player
given the decision x
of all other players.
Calls Game::EPEC::Respond and obtains the unique_ptr to GRBModel of best response by player player
. Then solves the model and returns the appropriate objective value.
player
.sol | Optimal response |
player | Player whose optimal response is to be computed |
x | A vector of pure strategies (either for all players or all other players |
|
inline |
|
inline |
void Game::EPEC::setAlgorithm | ( | Game::EPECalgorithm | algorithm | ) |
Decides the algorithm to be used for solving the given instance of the problem. The choice of algorithms are documented in Game::EPECalgorithm
void Game::EPEC::setRecoverStrategy | ( | Game::EPECRecoverStrategy | strategy | ) |
|
protectedpure virtual |
Implemented in Models::EPEC, and My_EPEC_Prob.
|
protected |
Warmstarts EPEC with a solution.
|
inline |
|
private |
used by the EPEC.
Stores the type of algorithm
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
private |
|
private |
|
private |
|
protected |
|
protected |
|
protected |
|
protected |
Number of variables in the current player, including any number of convex hull variables at the current moment. The used, i.e., the inheritor of Game::EPEC has the responsibility to keep this correct by implementing an override of Game::EPEC::updateLocs.
|
protected |
|
private |
|
protected |
|
protected |
|
protected |