EPEC solve
Solving Equilibrium Problems with Equilibrium Constraints (EPECs)
|
#include <models.h>
Public Member Functions | |
EPEC ()=delete | |
EPEC (GRBEnv *env, arma::sp_mat TranspCosts={}) | |
void | testLCP (const unsigned int i) |
EPEC & | addCountry (LeadAllPar Params, const unsigned int addnlLeadVars=0) |
Models a Standard Nash-Cournot game within a country More... | |
EPEC & | addTranspCosts (const arma::sp_mat &costs) |
Adds intercountry transportation costs matrix. More... | |
unsigned int | getPosition (const unsigned int countryCount, const LeaderVars var=LeaderVars::FollowerStart) const |
Gets position of a variable in a country. More... | |
unsigned int | getPosition (const std::string countryCount, const LeaderVars var=LeaderVars::FollowerStart) const |
EPEC & | unlock () |
Unlocks an EPEC model. More... | |
std::unique_ptr< GRBModel > | Respond (const std::string name, const arma::vec &x) const |
Game::NashGame * | get_LowerLevelNash (const unsigned int i) const |
Returns a non-owning pointer to the i -th country's lower level NashGame. More... | |
Game::LCP * | playCountry (std::vector< Game::LCP *> countries) |
void | write (const std::string filename, const unsigned int i, bool append=true) const |
void | write (const std::string filename, bool append=true) const |
void | readSolutionJSON (const std::string filename) |
void | writeSolutionJSON (std::string filename, const arma::vec x, const arma::vec z) const |
void | writeSolution (const int writeLevel, std::string filename) const |
const EPECInstance | getInstance () const |
Get the current EPECInstance loaded. More... | |
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 |
Data Fields | |
bool | quadraticTax = {false} |
Protected Member Functions | |
bool | warmstart (const arma::vec x) |
Warmstarts EPEC with a solution. More... | |
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 | make_obj_leader (const unsigned int i, Game::QP_objective &QP_obj) final |
virtual void | updateLocs () override |
virtual void | prefinalize () override |
Empty function - optionally reimplementable in derived class. More... | |
virtual void | postfinalize () override |
Empty function - optionally reimplementable in derived class. More... | |
bool | dataCheck (const bool chkAllLeadPars=true, const bool chkcountriesLL=true, const bool chkMC_QP=true, const bool chkLeadConses=true, const bool chkLeadRHSes=true, const bool chknImportMarkets=true, const bool chkLocations=true, const bool chkLeaderLocations=true, const bool chkLeadObjec=true) const |
bool | ParamValid (const LeadAllPar &Param) const |
Checks the Validity of Models::LeadAllPar object. More... | |
void | make_LL_QP (const LeadAllPar &Params, const unsigned int follower, Game::QP_Param *Foll, const LeadLocs &Loc) const noexcept |
Makes the lower level quadratic program object for each follower. More... | |
void | make_LL_LeadCons (arma::sp_mat &LeadCons, arma::vec &LeadRHS, const LeadAllPar &Param, const Models::LeadLocs &Loc={}, const unsigned int import_lim_cons=1, const unsigned int export_lim_cons=1, const unsigned int price_lim_cons=1, const unsigned int activeTaxCaps=0) const noexcept |
Makes the leader constraint matrix and RHS. More... | |
void | add_Leaders_tradebalance_constraints (const unsigned int i) |
Adds leaders' trade balance constraints for import-exports. More... | |
void | make_MC_leader (const unsigned int i) |
Makes the market clearing constraint for country i . More... | |
void | make_MC_cons (arma::sp_mat &MCLHS, arma::vec &MCRHS) const override |
Returns leader's Market clearing constraints in matrix form. More... | |
void | WriteCountry (const unsigned int i, const std::string filename, const arma::vec x, const bool append=true) const |
void | WriteFollower (const unsigned int i, const unsigned int j, const std::string filename, const arma::vec x) const |
Private Attributes | |
std::vector< LeadAllPar > | AllLeadPars |
The parameters of each leader in the EPEC game. More... | |
std::vector< std::shared_ptr< Game::QP_Param > > | MC_QP |
arma::sp_mat | TranspCosts |
Transportation costs between pairs of countries. More... | |
std::vector< unsigned int > | nImportMarkets |
Number of countries from which the i-th country imports. More... | |
std::vector< LeadLocs > | Locations |
Location of variables for each country. More... | |
std::map< std::string, unsigned int > | name2nos = {} |
unsigned int | taxVars = {0} |
std::vector< arma::sp_mat > | LeadConses {} |
Stores each leader's constraint LHS. More... | |
std::vector< arma::vec > | LeadRHSes {} |
Stores each leader's constraint RHS. More... | |
|
delete |
|
inline |
|
private |
Adds leaders' trade balance constraints for import-exports.
Does the following job:
i
to store in Models::EPEC::nImportMarkets - Adds the trade balance constraint. Total quantity imported by country i
= Sum of Total quantity exported by each country to country i. - Updates the LeadLocs in Models::EPEC::Locations.at(i) Definition at line 711 of file Models.cpp.
Models::EPEC & Models::EPEC::addCountry | ( | Models::LeadAllPar | Params, |
const unsigned int | addnlLeadVars = 0 |
||
) |
Models a Standard Nash-Cournot game within a country
A Nash cournot game is played among the followers, for the leader-decided values of import export, caps and taxations on all players. The total quantity used in the demand equation is the sum of quantity produced by all followers + any import - any export.
Use to denote the -th element in costs_lin
and for the -th element in costs_quad
. Then to produce quantity , the -th producer's cost will be
In addition to this, the leader may impose "tax", which could increase for each player.
Total quantity in the market is given by sum of quantities produced by all producers adjusted by imports and exports
The demand curve in the market is given by
Each follower is also constrained by a maximum production capacity her infrastructure allows. And each follower is constrained by a cap on their production, that is imposed by the leader.
Each follower decides noncooperatively maximizing profits.
The leader decides quantity imported , quantity exported , cap on each player, , and the tax for each player .
The leader is also constrained to not export or import anything more than the limits set by export_limit
and import_limit
. A negative value to these input variables imply that there is no such limit.
Similarly the leader cannot also impose tax on any player greater than what is dictated by the input variable max_tax
.
new
. Params | The Parameter structure for the leader |
addnlLeadVars | Create columns with 0s in it. To handle additional dummy leader variables. |
Definition at line 445 of file Models.cpp.
Models::EPEC & Models::EPEC::addTranspCosts | ( | const arma::sp_mat & | costs | ) |
Adds intercountry transportation costs matrix.
Adds the transportation cost matrix. Entry in row i and column j of this matrix corresponds to the unit transportation costs for sending fuel from country i to country j.
costs | The transportation cost matrix |
Definition at line 639 of file Models.cpp.
|
private |
Checks the data in Models::EPEC object, based on checking flags, n
is the number of countries in the Models::EPEC object.
chkAllLeadPars | Checks if Models::EPEC::AllLeadPars has size n |
chkcountries_LL | Checks if Models::EPEC::countries_LL has size n |
chkMC_QP | Checks if Models::EPEC::MC_QP has size n |
chkLeadConses | Checks if Models::EPEC::LeadConses has size n |
chkLeadRHSes | Checks if Models::EPEC::LeadRHSes has size n |
chknImportMarkets | Checks if Models::EPEC::nImportMarkets has size n |
chkLocations | Checks if Models::EPEC::Locations has size n |
chkLeaderLocations | Checks if Models::EPEC::LeaderLocations has size n and Models::EPEC::nVarinEPEC is set |
chkLeadObjec | Checks if Models::EPEC::LeadObjec has size n |
Definition at line 864 of file Models.cpp.
|
inherited |
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()
|
inherited |
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.
Game::NashGame * Models::EPEC::get_LowerLevelNash | ( | const unsigned int | i | ) | const |
Returns a non-owning pointer to the i
-th country's lower level NashGame.
Definition at line 933 of file Models.cpp.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inline |
Get the current EPECInstance loaded.
|
inlineinherited |
|
inlineinherited |
|
inlinenoexceptinherited |
|
inherited |
|
inlineinherited |
|
inlinenoexceptinherited |
unsigned int Models::EPEC::getPosition | ( | const unsigned int | countryCount, |
const LeaderVars | var = LeaderVars::FollowerStart |
||
) | const |
Gets position of a variable in a country.
Definition at line 911 of file Models.cpp.
unsigned int Models::EPEC::getPosition | ( | const std::string | countryCount, |
const LeaderVars | var = LeaderVars::FollowerStart |
||
) | const |
|
inherited |
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
|
inherited |
|
inherited |
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
|
inherited |
|
inherited |
|
inlineinherited |
|
inlineinherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
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).
|
inherited |
|
privatenoexcept |
Makes the leader constraint matrix and RHS.
Makes the leader level constraints for a country. The constraints added are as follows:
Here and denote the net import limit and export limit respectively. is the maximum local price that the government desires to have.
The first two constraints above limit net imports and exports respectively. The third constraint limits local price. These constraints are added only if the RHS parameters are given as non-negative value. A default value of -1 to any of these parameters (given in Models::LeadAllPar Params
object) ensures that these constraints are not added. The last constraint is always added. It ensures that the country does not export more than what it has produced + imported!
LeadCons | The LHS matrix of leader constraints (for output) |
LeadRHS | RHS vector for leader constraints (for output) |
Params | All country specific parameters |
Loc | Location of variables |
import_lim_cons | Does a constraint on import limit exist or no limit? |
export_lim_cons | Does a constraint on export limit exist or no limit? |
price_lim_cons | Does a constraint on price limit exist or no limit? |
activeTaxCaps | Number of active Tax Caps constraints. If strictly positive, tax cap constraint(s) will be enforced |
Definition at line 284 of file Models.cpp.
|
privatenoexcept |
Makes the lower level quadratic program object for each follower.
Makes Lower Level Quadratic Programs.
Sets the constraints and objective for the lower level problem (i.e., the follower)
Params | The Parameters object |
follower | Which follower's QP has to be made? |
Foll | Non-owning pointer to the Follower QP_Param object |
Loc | LeadLocs object for accessing different leader locations. |
Definition at line 221 of file Models.cpp.
|
overrideprivatevirtual |
Returns leader's Market clearing constraints in matrix form.
Reimplemented from Game::EPEC.
Definition at line 763 of file Models.cpp.
|
private |
Makes the market clearing constraint for country i
.
Writes the market clearing constraint as a Game::QP_Param and stores it in Models::EPEC::MC_QP
Definition at line 801 of file Models.cpp.
|
finalprivatevirtual |
Makes the objective function of each country.
i | The location of the country whose objective is to be made |
QP_obj | The object where the objective parameters are to be stored. |
Implements Game::EPEC.
Definition at line 955 of file Models.cpp.
|
inherited |
|
private |
Checks the Validity of Models::LeadAllPar object.
Checks that the parameter given to add a country is valid. Does not have obvious errors
Checks the following:
Params.n_followers
- DemandParam.alpha
and DemandParam.beta
are greater than zero - name
is not empty - name
does not match with the name of any other existing countries in the EPEC object. Params | Object whose validity is to be tested |
Definition at line 188 of file Models.cpp.
|
inlineoverrideprivatevirtual |
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 from Game::EPEC.
|
overrideprivatevirtual |
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().
Does the following:
Reimplemented from Game::EPEC.
Definition at line 679 of file Models.cpp.
void Models::EPEC::readSolutionJSON | ( | const std::string | filename | ) |
Reads the solution file and load it in the current EPEC instance
Definition at line 1195 of file Models.cpp.
std::unique_ptr<GRBModel> Models::EPEC::Respond | ( | const std::string | name, |
const arma::vec & | x | ||
) | const |
|
inherited |
|
inherited |
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 |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inherited |
Decides the algorithm to be used for solving the given instance of the problem. The choice of algorithms are documented in Game::EPECalgorithm
|
inlineinherited |
|
inlineinherited |
|
inherited |
void Models::EPEC::testLCP | ( | const unsigned int | i | ) |
Definition at line 1595 of file Models.cpp.
Models::EPEC & Models::EPEC::unlock | ( | ) |
Unlocks an EPEC model.
A finalized model cannot be edited unless it is unlocked first.
EPEC::finalize() performs "finalizing" acts on an object.
Definition at line 942 of file Models.cpp.
|
overrideprivatevirtual |
This function is called after make_country_QP()
Implements Game::EPEC.
Definition at line 1018 of file Models.cpp.
|
protectedinherited |
Warmstarts EPEC with a solution.
void Models::EPEC::write | ( | const std::string | filename, |
const unsigned int | i, | ||
bool | append = true |
||
) | const |
void Models::EPEC::write | ( | const std::string | filename, |
bool | append = true |
||
) | const |
|
private |
Definition at line 1456 of file Models.cpp.
|
private |
Definition at line 1520 of file Models.cpp.
|
inlineinherited |
void Models::EPEC::writeSolution | ( | const int | writeLevel, |
std::string | filename | ||
) | const |
Writes the computed Nash Equilibrium in the EPEC instance writeLevel
is an integer representing the write configuration. 0: only Json solution; 1: only human readable solution; 2:both
Definition at line 1237 of file Models.cpp.
void Models::EPEC::writeSolutionJSON | ( | std::string | filename, |
const arma::vec | x, | ||
const arma::vec | z | ||
) | const |
Writes the computed Nash Equilibrium in the standard JSON solution file filename
dictates the name of the .JSON solution file
Definition at line 1122 of file Models.cpp.
|
private |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
private |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
private |
|
private |
|
protectedinherited |
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.
|
private |
|
private |
|
protectedinherited |
|
private |
bool Models::EPEC::quadraticTax = {false} |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
private |