EPEC solve
Solving Equilibrium Problems with Equilibrium Constraints (EPECs)
games.h
Go to the documentation of this file.
1 #pragma once
2 
6 // #include"epecsolve.h"
7 #include "lcptolp.h"
8 #include <armadillo>
9 #include <gurobi_c++.h>
10 #include <iostream>
11 #include <memory>
12 #include <set>
13 #include <string>
14 
15 using namespace Game;
16 
17 template <class T>
18 std::ostream &operator<<(std::ostream &ost, std::vector<T> v) {
19  for (auto elem : v)
20  ost << elem << " ";
21  ost << '\n';
22  return ost;
23 }
24 
25 template <class T, class S>
26 std::ostream &operator<<(std::ostream &ost, std::pair<T, S> p) {
27  ost << "<" << p.first << ", " << p.second << ">";
28  return ost;
29 }
30 
31 namespace Game {
32 bool isZero(arma::mat M, double tol = 1e-6) noexcept;
33 
34 bool isZero(arma::sp_mat M, double tol = 1e-6) noexcept;
35 
36 // bool isZero(arma::vec M, double tol = 1e-6);
39 typedef struct QP_objective {
40  arma::sp_mat Q;
41  arma::sp_mat C;
42  arma::vec c;
43 } QP_objective;
46 typedef struct QP_constraints {
47  arma::sp_mat A, B;
48  arma::vec b;
50 
52 class MP_Param {
53 protected:
54  // Data representing the parameterized QP
55  arma::sp_mat Q, A, B, C;
56  arma::vec c, b;
57  // Object for sizes and integrity check
58  unsigned int Nx, Ny, Ncons;
59  unsigned int size();
60  bool dataCheck(bool forcesymm = true) const;
61  virtual inline bool finalize() {
62  this->size();
63  return this->dataCheck();
64  }
65 
66 public:
67  // Default constructors
68  MP_Param() = default;
69 
70  MP_Param(const MP_Param &M) = default;
71  void bound(double bigM, unsigned int primals);
72 
73  // Getters and setters
74  arma::sp_mat getQ() const {
75  return this->Q;
76  }
77  arma::sp_mat getC() const {
78  return this->C;
79  }
80  arma::sp_mat getA() const {
81  return this->A;
82  }
83  arma::sp_mat getB() const {
84  return this->B;
85  }
86  arma::vec getc() const {
87  return this->c;
88  }
89  arma::vec getb() const {
90  return this->b;
91  }
92  unsigned int getNx() const {
93  return this->Nx;
94  }
95  unsigned int getNy() const {
96  return this->Ny;
97  }
98 
99  MP_Param &setQ(const arma::sp_mat &Q) {
100  this->Q = Q;
101  return *this;
102  }
103  MP_Param &setC(const arma::sp_mat &C) {
104  this->C = C;
105  return *this;
106  }
107  MP_Param &setA(const arma::sp_mat &A) {
108  this->A = A;
109  return *this;
110  }
111  MP_Param &setB(const arma::sp_mat &B) {
112  this->B = B;
113  return *this;
114  }
115  MP_Param &setc(const arma::vec &c) {
116  this->c = c;
117  return *this;
118  }
119  MP_Param &setb(const arma::vec &b) {
120  this->b = b;
121  return *this;
122  }
123 
124  // Setters and advanced constructors
125  virtual MP_Param &set(const arma::sp_mat &Q, const arma::sp_mat &C,
126  const arma::sp_mat &A, const arma::sp_mat &B,
127  const arma::vec &c,
128  const arma::vec &b); // Copy data into this
129  virtual MP_Param &set(arma::sp_mat &&Q, arma::sp_mat &&C, arma::sp_mat &&A,
130  arma::sp_mat &&B, arma::vec &&c,
131  arma::vec &&b); // Move data into this
132  virtual MP_Param &set(const QP_objective &obj, const QP_constraints &cons);
133 
134  virtual MP_Param &set(QP_objective &&obj, QP_constraints &&cons);
135 
136  virtual MP_Param &addDummy(unsigned int pars, unsigned int vars = 0,
137  int position = -1);
138 
139  void write(std::string filename, bool append = true) const;
140 
141  static bool dataCheck(const QP_objective &obj, const QP_constraints &cons,
142  bool checkObj = true, bool checkCons = true);
143 };
144 
146 class QP_Param : public MP_Param
147 // Shape of C is Ny\times Nx
158 {
159 private:
160  // Gurobi environment and model
161  GRBEnv *env;
162  GRBModel QuadModel;
163  bool made_yQy;
164 
165  int make_yQy();
166 
167 public: // Constructors
169  QP_Param(GRBEnv *env = nullptr)
170  : env{env}, QuadModel{(*env)}, made_yQy{false} {
171  this->size();
172  }
173 
175  QP_Param(arma::sp_mat Q, arma::sp_mat C, arma::sp_mat A, arma::sp_mat B,
176  arma::vec c, arma::vec b, GRBEnv *env = nullptr)
177  : env{env}, QuadModel{(*env)}, made_yQy{false} {
178  this->set(Q, C, A, B, c, b);
179  this->size();
180  if (!this->dataCheck())
181  throw std::string(
182  "Error in QP_Param::QP_Param: Invalid data for constructor");
183  }
184 
186  QP_Param(const QP_Param &Qu)
187  : MP_Param(Qu), env{Qu.env}, QuadModel{Qu.QuadModel}, made_yQy{
188  Qu.made_yQy} {
189  this->size();
190  };
191 
192  // Override setters
193  QP_Param &set(const arma::sp_mat &Q, const arma::sp_mat &C,
194  const arma::sp_mat &A, const arma::sp_mat &B,
195  const arma::vec &c,
196  const arma::vec &b) final; // Copy data into this
197  QP_Param &set(arma::sp_mat &&Q, arma::sp_mat &&C, arma::sp_mat &&A,
198  arma::sp_mat &&B, arma::vec &&c,
199  arma::vec &&b) final; // Move data into this
200  QP_Param &set(const QP_objective &obj, const QP_constraints &cons) final;
201 
202  QP_Param &set(QP_objective &&obj, QP_constraints &&cons) final;
203 
204  bool operator==(const QP_Param &Q2) const;
205 
206  // Other methods
207  unsigned int KKT(arma::sp_mat &M, arma::sp_mat &N, arma::vec &q) const;
208 
209  std::unique_ptr<GRBModel> solveFixed(arma::vec x);
210 
213  double computeObjective(const arma::vec &y, const arma::vec &x,
214  bool checkFeas = true, double tol = 1e-6) const;
215  inline bool is_Playable(const QP_Param &P) const
218  {
219  bool b1, b2, b3;
220  b1 = (this->Nx + this->Ny) == (P.getNx() + P.getNy());
221  b2 = this->Nx >= P.getNy();
222  b3 = this->Ny <= P.getNx();
223  return b1 && b2 && b3;
224  }
225  QP_Param &addDummy(unsigned int pars, unsigned int vars = 0,
226  int position = -1) override;
229  void write(std::string filename, bool append) const;
231  void save(std::string filename, bool erase = true) const;
233  long int load(std::string filename, long int pos = 0);
234 };
235 
249 class NashGame {
250 private:
251  GRBEnv *env = nullptr;
252  arma::sp_mat LeaderConstraints;
253  arma::vec LeaderConsRHS;
254  unsigned int Nplayers;
255  std::vector<std::shared_ptr<QP_Param>>
257  arma::sp_mat MarketClearing;
258  arma::vec MCRHS;
259 
262  std::vector<unsigned int> primal_position;
265  std::vector<unsigned int> dual_position;
267  unsigned int MC_dual_position;
269  unsigned int Leader_position;
272  unsigned int n_LeadVar;
273 
274  void set_positions();
275 
276 public: // Constructors
278  explicit NashGame(GRBEnv *e) noexcept : env{e} {};
281  explicit NashGame(GRBEnv *e, std::vector<std::shared_ptr<QP_Param>> Players,
282  arma::sp_mat MC, arma::vec MCRHS,
283  unsigned int n_LeadVar = 0, arma::sp_mat LeadA = {},
284  arma::vec LeadRHS = {});
285  // Copy constructor
286  NashGame(const NashGame &N);
288 
289  // Verbose declaration
290  friend std::ostream &operator<<(std::ostream &os, const NashGame &N) {
291  os << '\n';
292  os << "--------------------------------------------------------------------"
293  "---"
294  << '\n';
295  os << "Nash Game with " << N.Nplayers << " players" << '\n';
296  os << "--------------------------------------------------------------------"
297  "---"
298  << '\n';
299  os << "Number of primal variables:\t\t\t " << N.getNprimals() << '\n';
300  os << "Number of dual variables:\t\t\t " << N.getNduals() << '\n';
301  os << "Number of shadow price dual variables:\t\t " << N.getNshadow()
302  << '\n';
303  os << "Number of leader variables:\t\t\t " << N.getNleaderVars() << '\n';
304  os << "--------------------------------------------------------------------"
305  "---"
306  << '\n';
307  return os;
308  }
309 
311  inline unsigned int getNprimals() const {
312  /***
313  * Number of primal variables is the sum of the "y" variables present in
314  * each player's Game::QP_Param
315  */
316  return this->primal_position.back();
317  }
319 
323  inline unsigned int getNshadow() const { return this->MCRHS.n_rows; }
325 
329  inline unsigned int getNleaderVars() const { return this->n_LeadVar; }
331  inline unsigned int getNduals() const {
339  return this->dual_position.back() - this->dual_position.front() + 0;
340  }
341 
342  // Position of variables
344  inline unsigned int getPrimalLoc(unsigned int i = 0) const {
345  return primal_position.at(i);
346  }
348  inline unsigned int getMCdualLoc() const { return MC_dual_position; }
350  inline unsigned int getLeaderLoc() const { return Leader_position; }
352  inline unsigned int getDualLoc(unsigned int i = 0) const {
353  return dual_position.at(i);
354  }
355 
356  // Members
357  const NashGame &FormulateLCP(arma::sp_mat &M, arma::vec &q, perps &Compl,
358  bool writeToFile = false,
359  std::string M_name = "dat/LCP.txt",
360  std::string q_name = "dat/q.txt") const;
361  arma::sp_mat RewriteLeadCons() const;
362  inline arma::vec getLeadRHS() const { return this->LeaderConsRHS; }
363  inline arma::vec getMCLeadRHS() const {
364  return arma::join_cols(arma::join_cols(this->LeaderConsRHS, this->MCRHS),
365  -this->MCRHS);
366  }
367 
368  // Check solution and correctness
369  std::unique_ptr<GRBModel> Respond(unsigned int player, const arma::vec &x,
370  bool fullvec = true) const;
371  double RespondSol(arma::vec &sol, unsigned int player, const arma::vec &x,
372  bool fullvec = true) const;
373  arma::vec ComputeQPObjvals(const arma::vec &x, bool checkFeas = false) const;
374  bool isSolved(const arma::vec &sol, unsigned int &violPlayer,
375  arma::vec &violSol, double tol = 1e-4) const;
376  // Modify NashGame members
377  NashGame &addDummy(unsigned int par = 0, int position = -1);
378  NashGame &addLeadCons(const arma::vec &a, double b);
379  // Read/Write Nashgame functions
380  void write(std::string filename, bool append = true, bool KKT = false) const;
382  void save(std::string filename, bool erase = true) const;
384  long int load(std::string filename, long int pos = 0);
385 };
386 
387 std::ostream &operator<<(std::ostream &os, const QP_Param &Q);
388 
389 std::ostream &operator<<(std::ostream &ost, const perps &C);
390 
391 void print(const perps &C) noexcept;
392 } // namespace Game
393 
394 // The EPEC stuff
395 namespace Game {
396 
397 enum class EPECsolveStatus {
402  nashEqFound,
403  timeLimit,
404  numerical,
406 };
407 
408 enum class EPECalgorithm {
414 };
416 
421 };
423 
427  Game::EPECRecoverStrategy recoverStrategy =
431  bool boundPrimals{false};
432  double boundBigM{1e5};
434  long int addPolyMethodSeed{
435  -1};
436  bool indicators{true};
438  double timeLimit{
440  -1};
441  unsigned int threads{
442  0};
443  unsigned int aggressiveness{
444  1};
445  bool pureNE{false};
447 };
449 
453  int numVar = {-1};
454  int numIteration = {-1};
455  int numConstraints = {-1};
457  int numNonZero = {-1};
458  int lostIntermediateEq = {0};
460  bool numericalIssuesEncountered = {
462  false};
463  std::vector<unsigned int> feasiblePolyhedra =
465  {};
466  double wallClockTime = {0};
468  bool pureNE{false};
469  EPECAlgorithmParams AlgorithmParam =
470  {};
471 };
473 
475 class EPEC {
476 private:
477  std::vector<unsigned int> SizesWithoutHull{};
480  std::unique_ptr<Game::LCP> lcp;
482  std::unique_ptr<GRBModel>
484  std::unique_ptr<GRBModel>
486  unsigned int nVarinEPEC{0};
490  unsigned int nCountr{0};
491 
492 protected: // Datafields
493  std::vector<std::shared_ptr<Game::NashGame>> countries_LL{};
494  std::vector<std::unique_ptr<Game::LCP>> countries_LCP{};
495 
496  std::vector<std::shared_ptr<Game::QP_Param>>
497  country_QP{};
498  std::vector<std::shared_ptr<Game::QP_objective>>
499  LeadObjec{};
500  std::vector<std::shared_ptr<Game::QP_objective>>
501  LeadObjec_ConvexHull{};
502 
504  std::unique_ptr<Game::NashGame> nashgame;
505 
506  std::vector<unsigned int> LeaderLocations{};
507  std::vector<const unsigned int *> LocEnds{};
512  std::vector<unsigned int> convexHullVariables{};
513  unsigned int n_MCVar{0};
514 
515  GRBEnv *env;
516  bool finalized{false};
517  bool nashEq{false};
518  std::chrono::high_resolution_clock::time_point initTime;
519  EPECStatistics Stats{};
520  arma::vec sol_z,
521  sol_x;
522  bool warmstart(const arma::vec x);
523 
524 private:
525  void
526  add_Dummy_Lead(const unsigned int i);
527  void make_country_QP(const unsigned int i);
528  void make_country_QP();
529  void make_country_LCP();
530  void resetLCP();
531  void iterativeNash();
532  void fullEnumerationNash();
533  void combinatorial_pure_NE(
534  const std::vector<long int> combination,
535  const std::vector<std::set<unsigned long int>> &excludeList);
536  void combinatorialPNE(
537  const std::vector<long int> combination = {},
538  const std::vector<std::set<unsigned long int>> &excludeList = {});
539  void make_pure_LCP(bool indicators = false);
540  void computeLeaderLocations(const unsigned int addSpaceForMC = 0);
541 
542  bool getAllDevns(std::vector<arma::vec> &devns, const arma::vec &guessSol,
543  const std::vector<arma::vec> &prevDev = {}) const;
544  unsigned int addDeviatedPolyhedron(const std::vector<arma::vec> &devns,
545  bool &infeasCheck) const;
546  void get_x_minus_i(const arma::vec &x, const unsigned int &i,
547  arma::vec &solOther) const;
548  bool computeNashEq(bool pureNE = false, double localTimeLimit = -1.0,
549  bool check = false);
550  bool addRandomPoly2All(unsigned int aggressiveLevel = 1,
551  bool stopOnSingleInfeasibility = false);
552 
553 protected: // functions
554  EPEC(GRBEnv *env)
555  : env{env} {};
556 
557  // virtual function to be implemented by the inheritor.
558  virtual void make_obj_leader(const unsigned int i,
559  Game::QP_objective &QP_obj) = 0;
560 
561  // virtual function to be optionally implemented by the inheritor.
562  virtual void prefinalize();
563  virtual void postfinalize();
564  virtual void
565  updateLocs() = 0; // If any location tracking system is implemented, that can
566  // be called from in here.
567  virtual void make_MC_cons(arma::sp_mat &MC, arma::vec &RHS) const {
568  MC.zeros();
569  RHS.zeros();
570  };
571  bool hasLCP() const {
572  if (this->lcp)
573  return true;
574  else
575  return false;
576  }
577 
578 public: // functions
579  EPEC() = delete; // No default constructor
580  EPEC(EPEC &) = delete; // Abstract class - no copy constructor
581  ~EPEC() {} // Destructor to free data
582 
583  void finalize();
584  void findNashEq();
585 
586  std::unique_ptr<GRBModel> Respond(const unsigned int i,
587  const arma::vec &x) const;
588  double RespondSol(arma::vec &sol, unsigned int player, const arma::vec &x,
589  const arma::vec &prevDev) const;
590  bool isSolved(unsigned int *countryNumber, arma::vec *ProfDevn,
591  double tol = 51e-4) const;
592 
593  bool isSolved(double tol = 51e-4) const;
594 
595  const arma::vec getx() const { return this->sol_x; }
596  void reset() { this->sol_x.ones(); }
597  const arma::vec getz() const { return this->sol_z; }
599  const EPECStatistics getStatistics() const { return this->Stats; }
600  void setAlgorithm(Game::EPECalgorithm algorithm);
602  return this->Stats.AlgorithmParam.algorithm;
603  }
604  void setRecoverStrategy(Game::EPECRecoverStrategy strategy);
606  return this->Stats.AlgorithmParam.recoverStrategy;
607  }
608  void setAggressiveness(unsigned int a) {
609  this->Stats.AlgorithmParam.aggressiveness = a;
610  }
611  unsigned int getAggressiveness() const {
612  return this->Stats.AlgorithmParam.aggressiveness;
613  }
614  void setNumThreads(unsigned int t) {
615  this->Stats.AlgorithmParam.threads = t;
616  this->env->set(GRB_IntParam_Threads, t);
617  }
618  unsigned int getNumThreads() const {
619  return this->Stats.AlgorithmParam.threads;
620  }
621  void setAddPolyMethodSeed(unsigned int t) {
622  this->Stats.AlgorithmParam.addPolyMethodSeed = t;
623  }
624  unsigned int getAddPolyMethodSeed() const {
625  return this->Stats.AlgorithmParam.addPolyMethodSeed;
626  }
627  void setIndicators(bool val) { this->Stats.AlgorithmParam.indicators = val; }
628  bool getIndicators() const { return this->Stats.AlgorithmParam.indicators; }
629  void setPureNE(bool val) { this->Stats.AlgorithmParam.pureNE = val; }
630  bool getPureNE() const { return this->Stats.AlgorithmParam.pureNE; }
631  void setBoundPrimals(bool val) {
632  this->Stats.AlgorithmParam.boundPrimals = val;
633  }
634  bool getBoundPrimals() const {
635  return this->Stats.AlgorithmParam.boundPrimals;
636  }
637  void setBoundBigM(double val) { this->Stats.AlgorithmParam.boundBigM = val; }
638  double getBoundBigM() const { return this->Stats.AlgorithmParam.boundBigM; }
639  void setTimeLimit(double val) { this->Stats.AlgorithmParam.timeLimit = val; }
640  double getTimeLimit() const { return this->Stats.AlgorithmParam.timeLimit; }
642  this->Stats.AlgorithmParam.addPolyMethod = add;
643  }
645  return this->Stats.AlgorithmParam.addPolyMethod;
646  }
647 
648  // Methods to get positions of variables
649  // The below are all const functions which return an unsigned int.
650  unsigned int getnVarinEPEC() const noexcept { return this->nVarinEPEC; }
651  unsigned int getNcountries() const noexcept {
652  return this->countries_LL.size();
653  }
654  unsigned int getPosition_LeadFoll(const unsigned int i,
655  const unsigned int j) const;
656  unsigned int getPosition_LeadLead(const unsigned int i,
657  const unsigned int j) const;
658  unsigned int getPosition_LeadFollPoly(const unsigned int i,
659  const unsigned int j,
660  const unsigned int k) const;
661  unsigned int getPosition_LeadLeadPoly(const unsigned int i,
662  const unsigned int j,
663  const unsigned int k) const;
664  unsigned int getNPoly_Lead(const unsigned int i) const;
665  unsigned int getPosition_Probab(const unsigned int i,
666  const unsigned int k) const;
667 
668  // The following obtain the variable values
669  double getVal_LeadFoll(const unsigned int i, const unsigned int j) const;
670  double getVal_LeadLead(const unsigned int i, const unsigned int j) const;
671  double getVal_LeadFollPoly(const unsigned int i, const unsigned int j,
672  const unsigned int k,
673  const double tol = 1e-5) const;
674  double getVal_LeadLeadPoly(const unsigned int i, const unsigned int j,
675  const unsigned int k,
676  const double tol = 1e-5) const;
677  double getVal_Probab(const unsigned int i, const unsigned int k) const;
678 
679  // The following checks if the returned strategy leader is a pure strategy
680  // for a leader or appropriately retrieve mixed-strategies
681  bool isPureStrategy(const unsigned int i, const double tol = 1e-5) const;
682  bool isPureStrategy(const double tol = 1e-5) const;
683  std::vector<unsigned int> mixedStratPoly(const unsigned int i,
684  const double tol = 1e-5) const;
685 
689  const LCP &getLcpDescr() const { return *this->lcp.get(); }
693  const GRBModel &getLcpModel() const { return *this->lcpmodel.get(); }
696  void writeLcpModel(std::string filename) const {
697  this->lcpmodel->write(filename);
698  }
699 };
700 } // namespace Game
701 
702 namespace std {
703 string to_string(const Game::EPECsolveStatus st);
704 string to_string(const Game::EPECalgorithm al);
705 string to_string(const Game::EPECRecoverStrategy st);
706 string to_string(const Game::EPECAlgorithmParams al);
707 string to_string(const Game::EPECAddPolyMethod add);
708 }; // namespace std
709 
710 /* Example for QP_Param */
711 
712 /* Example of NashGame */
arma::vec c
Definition: games.h:42
unsigned int getnVarinEPEC() const noexcept
Definition: games.h:650
std::ostream & operator<<(std::ostream &os, const QP_Param &Q)
arma::sp_mat MarketClearing
Market clearing constraints.
Definition: games.h:257
arma::vec sol_z
Solution equation values.
Definition: games.h:520
const GRBModel & getLcpModel() const
Definition: games.h:693
const arma::vec getz() const
Definition: games.h:597
bool hasLCP() const
Definition: games.h:571
Class to handle parameterized quadratic programs(QP)
Definition: games.h:146
void setAggressiveness(unsigned int a)
Definition: games.h:608
void reset()
Definition: games.h:596
EPEC(GRBEnv *env)
Definition: games.h:554
std::chrono::high_resolution_clock::time_point initTime
Definition: games.h:518
MP_Param & setA(const arma::sp_mat &A)
Set the private variable A.
Definition: games.h:107
EPECRecoverStrategy
Definition: games.h:418
const LCP & getLcpDescr() const
Definition: games.h:689
struct Game::QP_constraints QP_constraints
struct to handle the constraint params of MP_Param/QP_Param
arma::sp_mat getQ() const
Read-only access to the private variable Q.
Definition: games.h:74
arma::vec getc() const
Read-only access to the private variable c.
Definition: games.h:86
EPECalgorithm
Definition: games.h:408
std::vector< std::shared_ptr< QP_Param > > Players
The QP that each player solves.
Definition: games.h:256
void setBoundBigM(double val)
Definition: games.h:637
bool getBoundPrimals() const
Definition: games.h:634
unsigned int getPrimalLoc(unsigned int i=0) const
Gets the position of the primal variable of i th player.
Definition: games.h:344
class to handle parameterized mathematical programs(MP)
Definition: games.h:52
const arma::vec getx() const
Definition: games.h:595
string to_string(const Game::EPECAddPolyMethod add)
Definition: Games.cpp:2513
struct to handle the constraint params of MP_Param/QP_Param
Definition: games.h:46
NashGame(GRBEnv *e) noexcept
To be used only when NashGame is being loaded from a file.
Definition: games.h:278
void setIndicators(bool val)
Definition: games.h:627
unsigned int n_LeadVar
Definition: games.h:272
struct Game::QP_objective QP_objective
struct to handle the objective params of MP_Param/QP_Param
bool getIndicators() const
Definition: games.h:628
unsigned int Ny
Definition: games.h:58
bool getPureNE() const
Definition: games.h:630
Definition: games.h:702
unsigned int getNcountries() const noexcept
Definition: games.h:651
std::vector< unsigned int > dual_position
Definition: games.h:265
std::vector< std::pair< unsigned int, unsigned int > > perps
Definition: epecsolve.h:15
void setNumThreads(unsigned int t)
Definition: games.h:614
Stores statistics for a (solved) EPEC instance.
Definition: games.h:451
virtual void make_MC_cons(arma::sp_mat &MC, arma::vec &RHS) const
Definition: games.h:567
unsigned int MC_dual_position
Definition: games.h:267
void setTimeLimit(double val)
Definition: games.h:639
arma::sp_mat C
Definition: games.h:41
GRBEnv * env
Definition: games.h:515
bool made_yQy
Definition: games.h:163
unsigned int getNduals() const
Gets the number of dual variables in the problem.
Definition: games.h:331
Game::EPECalgorithm getAlgorithm() const
Definition: games.h:601
arma::vec MCRHS
RHS to the Market Clearing constraints.
Definition: games.h:258
QP_Param(arma::sp_mat Q, arma::sp_mat C, arma::sp_mat A, arma::sp_mat B, arma::vec c, arma::vec b, GRBEnv *env=nullptr)
Set data at construct time.
Definition: games.h:175
bool isZero(arma::mat M, double tol=1e-6) noexcept
Definition: Games.cpp:14
unsigned int getNx() const
Read-only access to the private variable Nx.
Definition: games.h:92
void setAddPolyMethod(Game::EPECAddPolyMethod add)
Definition: games.h:641
Class to handle a Nash game between leaders of Stackelberg games.
Definition: games.h:475
arma::sp_mat Q
Definition: games.h:40
~EPEC()
Definition: games.h:581
GRBEnv * env
Definition: games.h:161
Class to handle and solve linear complementarity problems.
Definition: lcptolp.h:41
Solution found for the instance.
arma::sp_mat getA() const
Read-only access to the private variable A.
Definition: games.h:80
Definition: epecsolve.h:26
unsigned int getAggressiveness() const
Definition: games.h:611
arma::sp_mat Q
Definition: games.h:55
double getBoundBigM() const
Definition: games.h:638
Game::EPECRecoverStrategy getRecoverStrategy() const
Definition: games.h:605
Adds polyhedra by selecting them in order.
MP_Param & setQ(const arma::sp_mat &Q)
Set the private variable Q.
Definition: games.h:99
unsigned int getNumThreads() const
Definition: games.h:618
arma::sp_mat getC() const
Read-only access to the private variable C.
Definition: games.h:77
EPECsolveStatus
Definition: games.h:397
void writeLcpModel(std::string filename) const
Definition: games.h:696
Instance proved to be infeasible.
Not started to solve the problem.
arma::vec b
Definition: games.h:48
MP_Param & setb(const arma::vec &b)
Set the private variable b.
Definition: games.h:119
unsigned int getAddPolyMethodSeed() const
Definition: games.h:624
QP_Param(GRBEnv *env=nullptr)
Initialize only the size. Everything else is empty (can be updated later)
Definition: games.h:169
unsigned int getNleaderVars() const
Gets the number of leader variables.
Definition: games.h:329
arma::vec LeaderConsRHS
Upper level leader constraints RHS.
Definition: games.h:253
arma::sp_mat getB() const
Read-only access to the private variable B.
Definition: games.h:83
double getTimeLimit() const
Definition: games.h:640
EPECAddPolyMethod
Definition: epecsolve.h:34
Time limit reached, nash equilibrium not found.
struct to handle the objective params of MP_Param/QP_Param
Definition: games.h:39
arma::vec getMCLeadRHS() const
Definition: games.h:363
GRBModel QuadModel
Definition: games.h:162
void setBoundPrimals(bool val)
Definition: games.h:631
Add random polyhedra in each iteration.
void setPureNE(bool val)
Definition: games.h:629
bool is_Playable(const QP_Param &P) const
Definition: games.h:215
void setAddPolyMethodSeed(unsigned int t)
Definition: games.h:621
unsigned int Leader_position
Definition: games.h:269
friend std::ostream & operator<<(std::ostream &os, const NashGame &N)
Definition: games.h:290
arma::vec getLeadRHS() const
Definition: games.h:362
arma::sp_mat LeaderConstraints
Upper level leader constraints LHS.
Definition: games.h:252
std::vector< unsigned int > primal_position
Definition: games.h:262
unsigned int getDualLoc(unsigned int i=0) const
Gets the location where the dual variables start.
Definition: games.h:352
virtual bool finalize()
Finalize the MP_Param object.
Definition: games.h:61
std::unique_ptr< GRBModel > lcpmodel
A Gurobi mode object of the LCP form of EPEC.
Definition: games.h:483
std::unique_ptr< Game::NashGame > nashgame
The EPEC nash game.
Definition: games.h:504
unsigned int getNy() const
Read-only access to the private variable Ny.
Definition: games.h:95
void print(const perps &C) noexcept
Definition: Games.cpp:39
unsigned int Nplayers
Number of players in the Nash Game.
Definition: games.h:254
MP_Param & setC(const arma::sp_mat &C)
Set the private variable C.
Definition: games.h:103
QP_Param(const QP_Param &Qu)
Copy constructor.
Definition: games.h:186
Game::EPECAddPolyMethod getAddPolyMethod() const
Definition: games.h:644
arma::sp_mat B
Definition: games.h:47
arma::vec c
Definition: games.h:56
Stores the configuration for EPEC algorithms.
Definition: games.h:425
Class to model Nash-cournot games with each player playing a QP.
Definition: games.h:249
std::unique_ptr< GRBModel > lcpmodel_base
Definition: games.h:485
arma::vec getb() const
Read-only access to the private variable b.
Definition: games.h:89
unsigned int getNshadow() const
Gets the number of Market clearing Shadow prices.
Definition: games.h:323
MP_Param & setB(const arma::sp_mat &B)
Set the private variable B.
Definition: games.h:111
unsigned int getLeaderLoc() const
Gets the positin where the Leader variables start.
Definition: games.h:350
unsigned int getNprimals() const
Return the number of primal variables.
Definition: games.h:311
unsigned int getMCdualLoc() const
Gets the positin where the Market-clearing dual variables start.
Definition: games.h:348
bool operator==(std::vector< short int > Fix1, std::vector< short int > Fix2)
const EPECStatistics getStatistics() const
Get the EPECStatistics object for the current instance.
Definition: games.h:599
MP_Param & setc(const arma::vec &c)
Set the private variable c.
Definition: games.h:115