11 #include <gurobi_c++.h> 25 std::vector<double> costs_quad =
27 std::vector<double> costs_lin =
30 std::vector<double> capacities =
33 std::vector<double> emission_costs =
36 std::vector<double> tax_caps = {};
38 std::vector<std::string> names = {};
39 FollPar(std::vector<double> costs_quad_ = {},
40 std::vector<double> costs_lin_ = {},
41 std::vector<double> capacities_ = {},
42 std::vector<double> emission_costs_ = {},
43 std::vector<double> tax_caps_ = {},
44 std::vector<std::string> names_ = {})
45 : costs_quad{costs_quad_}, costs_lin{costs_lin_}, capacities{capacities_},
46 emission_costs{emission_costs_}, tax_caps(tax_caps_), names{names_} {}
54 DemPar(
double alpha = 100,
double beta = 2) : alpha{alpha}, beta{beta} {};
60 double import_limit = -1;
61 double export_limit = -1;
69 bool tax_revenue =
false;
77 LeadPar(
double imp_lim = -1,
double exp_lim = -1,
double price_limit = -1,
78 bool tax_revenue =
false,
unsigned int tax_type_ = 0)
79 : import_limit{imp_lim}, export_limit{exp_lim}, price_limit{price_limit},
80 tax_revenue{tax_revenue} {
106 : n_followers{n_foll}, name{name}, FollowerParam{FP}, DemandParam{DP},
114 std::vector<Models::LeadAllPar> Countries = {};
115 arma::sp_mat TransportationCosts = {};
118 this->load(filename);
120 EPECInstance(std::vector<Models::LeadAllPar> Countries_, arma::sp_mat Transp_)
121 : Countries{Countries_}, TransportationCosts{Transp_} {}
124 void load(std::string filename);
127 void save(std::string filename);
156 using LeadLocs = std::map<LeaderVars, unsigned int>;
159 const bool startnext =
true);
161 const bool startnext =
true);
171 virtual void updateLocs()
override;
172 virtual void prefinalize()
override;
179 std::vector<LeadAllPar> AllLeadPars =
181 std::vector<std::shared_ptr<Game::QP_Param>> MC_QP =
183 arma::sp_mat TranspCosts =
186 std::vector<unsigned int> nImportMarkets =
188 std::vector<LeadLocs> Locations =
191 std::map<std::string, unsigned int> name2nos = {};
192 unsigned int taxVars = {0};
193 std::vector<arma::sp_mat>
195 std::vector<arma::vec> LeadRHSes{};
197 bool dataCheck(
const bool chkAllLeadPars =
true,
198 const bool chkcountriesLL =
true,
const bool chkMC_QP =
true,
199 const bool chkLeadConses =
true,
200 const bool chkLeadRHSes =
true,
201 const bool chknImportMarkets =
true,
202 const bool chkLocations =
true,
203 const bool chkLeaderLocations =
true,
204 const bool chkLeadObjec =
true)
const;
209 bool ParamValid(
const LeadAllPar &Param)
const;
212 void make_LL_QP(
const LeadAllPar &Params,
const unsigned int follower,
216 void make_LL_LeadCons(arma::sp_mat &LeadCons, arma::vec &LeadRHS,
219 const unsigned int import_lim_cons = 1,
220 const unsigned int export_lim_cons = 1,
221 const unsigned int price_lim_cons = 1,
222 const unsigned int activeTaxCaps = 0)
const noexcept;
224 void add_Leaders_tradebalance_constraints(
const unsigned int i);
226 void make_MC_leader(
const unsigned int i);
228 void make_MC_cons(arma::sp_mat &MCLHS, arma::vec &MCRHS)
const override;
230 void WriteCountry(
const unsigned int i,
const std::string filename,
231 const arma::vec x,
const bool append =
true)
const;
233 void WriteFollower(
const unsigned int i,
const unsigned int j,
234 const std::string filename,
const arma::vec x)
const;
237 bool quadraticTax = {
false};
244 EPEC(GRBEnv *env, arma::sp_mat TranspCosts = {})
245 :
Game::EPEC(env), TranspCosts{TranspCosts} {}
248 void testLCP(
const unsigned int i);
256 const unsigned int addnlLeadVars = 0);
258 EPEC &addTranspCosts(
const arma::sp_mat &costs);
261 getPosition(
const unsigned int countryCount,
265 getPosition(
const std::string countryCount,
270 std::unique_ptr<GRBModel> Respond(
const std::string name,
271 const arma::vec &x)
const;
275 Game::LCP *playCountry(std::vector<Game::LCP *> countries);
278 void write(
const std::string filename,
const unsigned int i,
279 bool append =
true)
const;
281 void write(
const std::string filename,
bool append =
true)
const;
283 void readSolutionJSON(
const std::string filename);
285 void writeSolutionJSON(std::string filename,
const arma::vec x,
286 const arma::vec z)
const;
288 void writeSolution(
const int writeLevel, std::string filename)
const;
292 return EPECInstance(this->AllLeadPars, this->TranspCosts);
299 std::string
to_string(
const GRBVar &var);
301 std::string
to_string(
const GRBConstr &cons,
const GRBModel &model);
Stores the parameters of the follower in a country model.
Class to handle parameterized quadratic programs(QP)
unsigned int n_followers
Number of followers in the country.
Stores the parameters of the leader in a country model.
std::map< LeaderVars, unsigned int > LeadLocs
Stores the parameters of a country model.
void increaseVal(LeadLocs &L, const LeaderVars start, const unsigned int val, const bool startnext=true)
LeadAllPar(unsigned int n_foll, std::string name, Models::FollPar FP={}, Models::DemPar DP={}, Models::LeadPar LP={})
FollPar(std::vector< double > costs_quad_={}, std::vector< double > costs_lin_={}, std::vector< double > capacities_={}, std::vector< double > emission_costs_={}, std::vector< double > tax_caps_={}, std::vector< std::string > names_={})
std::string name
Country Name.
void decreaseVal(LeadLocs &L, const LeaderVars start, const unsigned int val, const bool startnext=true)
Class to handle a Nash game between leaders of Stackelberg games.
Stores a single Instance.
Class to handle and solve linear complementarity problems.
EPEC(GRBEnv *env, arma::sp_mat TranspCosts={})
EPECInstance(std::vector< Models::LeadAllPar > Countries_, arma::sp_mat Transp_)
Constructor from instance objects.
std::string to_string(const GRBVar &var)
LeaderVars operator+(Models::LeaderVars a, int b)
struct to handle the objective params of MP_Param/QP_Param
EPECInstance(std::string filename)
Constructor from instance file.
const EPECInstance getInstance() const
Get the current EPECInstance loaded.
LeadPar(double imp_lim=-1, double exp_lim=-1, double price_limit=-1, bool tax_revenue=false, unsigned int tax_type_=0)
Stores the parameters of the demand curve in a country model.
Class to model Nash-cournot games with each player playing a QP.
virtual void postfinalize() override
Empty function - optionally reimplementable in derived class.
std::ostream & operator<<(std::ostream &ost, const FollPar P)