EPEC solve
Solving Equilibrium Problems with Equilibrium Constraints (EPECs)
|
Class to model Nash-cournot games with each player playing a QP. More...
#include <games.h>
Public Member Functions | |
NashGame (GRBEnv *e) noexcept | |
To be used only when NashGame is being loaded from a file. More... | |
NashGame (GRBEnv *e, std::vector< std::shared_ptr< QP_Param >> Players, arma::sp_mat MC, arma::vec MCRHS, unsigned int n_LeadVar=0, arma::sp_mat LeadA={}, arma::vec LeadRHS={}) | |
NashGame (const NashGame &N) | |
~NashGame () | |
unsigned int | getNprimals () const |
Return the number of primal variables. More... | |
unsigned int | getNshadow () const |
Gets the number of Market clearing Shadow prices. More... | |
unsigned int | getNleaderVars () const |
Gets the number of leader variables. More... | |
unsigned int | getNduals () const |
Gets the number of dual variables in the problem. More... | |
unsigned int | getPrimalLoc (unsigned int i=0) const |
Gets the position of the primal variable of i th player. More... | |
unsigned int | getMCdualLoc () const |
Gets the positin where the Market-clearing dual variables start. More... | |
unsigned int | getLeaderLoc () const |
Gets the positin where the Leader variables start. More... | |
unsigned int | getDualLoc (unsigned int i=0) const |
Gets the location where the dual variables start. More... | |
const NashGame & | FormulateLCP (arma::sp_mat &M, arma::vec &q, perps &Compl, bool writeToFile=false, std::string M_name="dat/LCP.txt", std::string q_name="dat/q.txt") const |
arma::sp_mat | RewriteLeadCons () const |
Rewrites leader constraint adjusting for dual variables. Rewrites leader constraints given earlier with added empty columns and spaces corresponding to Market clearing duals and other equation duals. More... | |
arma::vec | getLeadRHS () const |
arma::vec | getMCLeadRHS () const |
std::unique_ptr< GRBModel > | Respond (unsigned int player, const arma::vec &x, bool fullvec=true) const |
Given the decision of other players, find the optimal response for player in position player . More... | |
double | RespondSol (arma::vec &sol, unsigned int player, const arma::vec &x, bool fullvec=true) const |
arma::vec | ComputeQPObjvals (const arma::vec &x, bool checkFeas=false) const |
bool | isSolved (const arma::vec &sol, unsigned int &violPlayer, arma::vec &violSol, double tol=1e-4) const |
NashGame & | addDummy (unsigned int par=0, int position=-1) |
Add dummy variables in a NashGame object. More... | |
NashGame & | addLeadCons (const arma::vec &a, double b) |
Adds Leader constraint to a NashGame object. More... | |
void | write (std::string filename, bool append=true, bool KKT=false) const |
void | save (std::string filename, bool erase=true) const |
Saves the Game::NashGame object in a loadable file. More... | |
long int | load (std::string filename, long int pos=0) |
Loads the Game::NashGame object stored in a file. More... | |
Private Member Functions | |
void | set_positions () |
Private Attributes | |
GRBEnv * | env = nullptr |
arma::sp_mat | LeaderConstraints |
Upper level leader constraints LHS. More... | |
arma::vec | LeaderConsRHS |
Upper level leader constraints RHS. More... | |
unsigned int | Nplayers |
Number of players in the Nash Game. More... | |
std::vector< std::shared_ptr< QP_Param > > | Players |
The QP that each player solves. More... | |
arma::sp_mat | MarketClearing |
Market clearing constraints. More... | |
arma::vec | MCRHS |
RHS to the Market Clearing constraints. More... | |
std::vector< unsigned int > | primal_position |
std::vector< unsigned int > | dual_position |
unsigned int | MC_dual_position |
unsigned int | Leader_position |
unsigned int | n_LeadVar |
Friends | |
std::ostream & | operator<< (std::ostream &os, const NashGame &N) |
Class to model Nash-cournot games with each player playing a QP.
Stores a vector of QPs with each player's optimization problem. Potentially common (leader) constraints can be stored too.
Helpful in rewriting the Nash-Cournot game as an LCP Helpful in rewriting leader constraints after incorporating dual variables etc
|
inlineexplicitnoexcept |
|
explicit |
Constructing a NashGame from a set of Game::QP_Param, Market clearing constraints
Game::NashGame & Game::NashGame::addDummy | ( | unsigned int | par = 0 , |
int | position = -1 |
||
) |
Add dummy variables in a NashGame object.
Add extra variables at the end of the problem. These are just zero columns that don't feature in the problem anywhere. They are of importance only where the NashGame gets converted into an LCP and gets parametrized. Typically, they appear in the upper level objective in such a case.
Game::NashGame & Game::NashGame::addLeadCons | ( | const arma::vec & | a, |
double | b | ||
) |
arma::vec Game::NashGame::ComputeQPObjvals | ( | const arma::vec & | x, |
bool | checkFeas = false |
||
) | const |
Computes players' objective
Computes the objective value of each player in the Game::NashGame object.
const Game::NashGame & Game::NashGame::FormulateLCP | ( | arma::sp_mat & | M, |
arma::vec & | q, | ||
perps & | Compl, | ||
bool | writeToFile = false , |
||
std::string | M_name = "dat/LCP.txt" , |
||
std::string | q_name = "dat/q.txt" |
||
) | const |
Formulates the LCP corresponding to the Nash game.
Computes the KKT conditions for each Player, calling QP_Param::KKT. Arranges them systematically to return M, q as an LCP . The way the variables of the players get distributed is shown in the image below
|
inline |
|
inline |
|
inline |
|
inline |
Gets the number of dual variables in the problem.
This is the count of number of dual variables and that is indeed the sum of the number dual variables each player has. And the number of dual variables for any player is equal to the number of linear constraints they have which is given by the number of rows in the player's Game::QP_Param::A
|
inline |
|
inline |
|
inline |
|
inline |
bool Game::NashGame::isSolved | ( | const arma::vec & | sol, |
unsigned int & | violPlayer, | ||
arma::vec & | violSol, | ||
double | tol = 1e-4 |
||
) | const |
Checks if the Nash game is solved.
Checks if the Nash game is solved, if not provides a proof of deviation
[in] | sol | - The vector of pure strategies for the Nash Game |
[out] | violPlayer | - Index of the player with profitable deviation |
[out] | violSol | - The pure strategy for that player - which gives a profitable deviation |
[in] | tol | - If the additional profit is smaller than this, then it is not considered a profitable deviation. |
long int Game::NashGame::load | ( | std::string | filename, |
long int | pos = 0 |
||
) |
Loads the Game::NashGame
object stored in a file.
Loads the NashGame
object stored in a file. Before calling this function, use the constructor NashGame::NashGame(GRBEnv *env) to initialize.
Loads the NashGame
object stored in a file. Before calling this function, use the constructor NashGame::NashGame(GRBEnv *env) to initialize. Example usage:
unique_ptr< GRBModel > Game::NashGame::Respond | ( | unsigned int | player, |
const arma::vec & | x, | ||
bool | fullvec = true |
||
) | const |
Given the decision of other players, find the optimal response for player in position player
.
Given the strategy of each player, returns a Gurobi Model that has the optimal strategy of the player at position player
.
player | Player whose optimal response is to be computed |
x | A vector of pure strategies (either for all players or all other players) |
fullvec | Is x strategy of all players? (including player player ) |
double Game::NashGame::RespondSol | ( | arma::vec & | sol, |
unsigned int | player, | ||
const arma::vec & | x, | ||
bool | fullvec = true |
||
) | const |
Returns the optimal objective value that is obtainable for the player player
given the decision x
of all other players.
Calls Game::NashGame::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
.[out] | 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) | |
fullvec | Is x strategy of all players? (including player player ) |
arma::sp_mat Game::NashGame::RewriteLeadCons | ( | ) | const |
Rewrites leader constraint adjusting for dual variables. Rewrites leader constraints given earlier with added empty columns and spaces corresponding to Market clearing duals and other equation duals.
This becomes important if the Lower level complementarity problem is passed to LCP with upper level constraints.
void Game::NashGame::save | ( | std::string | filename, |
bool | erase = true |
||
) | const |
Saves the Game::NashGame
object in a loadable file.
|
private |
void Game::NashGame::write | ( | std::string | filename, |
bool | append = true , |
||
bool | KKT = false |
||
) | const |
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |