9 #include <gurobi_c++.h> 18 arma::vec
LPSolve(
const arma::sp_mat &A,
const arma::vec &b,
const arma::vec &c,
19 int &status,
bool Positivity =
false);
21 unsigned int ConvexHull(
const std::vector<arma::sp_mat *> *Ai,
22 const std::vector<arma::vec *> *bi, arma::sp_mat &A,
23 arma::vec &b,
const arma::sp_mat Acom = {},
24 const arma::vec bcom = {});
26 void compConvSize(arma::sp_mat &A,
const unsigned int nFinCons,
27 const unsigned int nFinVar,
28 const std::vector<arma::sp_mat *> *Ai,
29 const std::vector<arma::vec *> *bi,
const arma::sp_mat &Acom,
30 const arma::vec &bcom);
42 using spmat_Vec = std::vector<std::unique_ptr<arma::sp_mat>>;
43 using vec_Vec = std::vector<std::unique_ptr<arma::vec>>;
72 std::unique_ptr<spmat_Vec>
74 std::unique_ptr<vec_Vec>
83 const unsigned int nCompl = this->Compl.size();
90 std::unique_ptr<GRBModel>
LCPasMIP(std::vector<unsigned int> FixEq = {},
91 std::vector<unsigned int> FixVar = {},
93 std::unique_ptr<GRBModel>
LCPasMIP(std::vector<short int> Fixes,
bool solve);
94 std::unique_ptr<GRBModel>
96 std::vector<unsigned int> FixVar = {});
98 arma::Col<int> FixVar);
99 template <
class T>
inline bool isZero(
const T val)
const {
100 return (val >= -
eps && val <=
eps);
102 inline std::vector<short int>
solEncode(GRBModel *model)
const;
103 std::vector<short int>
solEncode(
const arma::vec &x)
const;
104 std::vector<short int>
solEncode(
const arma::vec &z,
105 const arma::vec &x)
const;
106 bool FixToPoly(
const std::vector<short int> Fix,
bool checkFeas =
false,
107 bool custom =
false,
spmat_Vec *custAi = {},
109 LCP &
FixToPolies(
const std::vector<short int> Fix,
bool checkFeas =
false,
110 bool custom =
false,
spmat_Vec *custAi = {},
136 LCP(GRBEnv *env, arma::sp_mat M, arma::vec q,
unsigned int LeadStart,
137 unsigned LeadEnd, arma::sp_mat A = {},
139 LCP(GRBEnv *env, arma::sp_mat M, arma::vec q,
perps Compl,
150 inline arma::sp_mat
getM() {
return this->
M; }
154 inline arma::vec
getq() {
return this->
q; }
167 void print(std::string end =
"\n");
168 inline unsigned int getNcol() {
return this->M.n_cols; };
170 inline unsigned int getNrow() {
return this->M.n_rows; };
172 bool extractSols(GRBModel *model, arma::vec &z, arma::vec &x,
173 bool extractZ =
false)
const;
176 std::unique_ptr<GRBModel>
LCPasQP(
bool solve =
false);
177 std::unique_ptr<GRBModel>
LCPasMIP(
bool solve =
false);
178 std::unique_ptr<GRBModel>
MPECasMILP(
const arma::sp_mat &C,
180 const arma::vec &x_minus_i,
182 std::unique_ptr<GRBModel>
183 MPECasMIQP(
const arma::sp_mat &Q,
const arma::sp_mat &C,
const arma::vec &c,
184 const arma::vec &x_minus_i,
bool solve =
false);
186 unsigned int ConvexHull(arma::sp_mat &A, arma::vec &b);
189 unsigned int conv_PolyWt(
const unsigned long int i)
const;
200 std::set<std::vector<short int>>
201 addAPoly(
unsigned long int nPoly = 1,
203 std::set<std::vector<short int>> Polys = {});
204 bool addThePoly(
const unsigned long int &decimalEncoding);
205 bool checkPolyFeas(
const unsigned long int &decimalEncoding);
210 this->AllPolyhedra.clear();
216 void write(std::string filename,
bool append =
true)
const;
217 void save(std::string filename,
bool erase =
true)
const;
218 long int load(std::string filename,
long int pos = 0);
std::set< unsigned long int > AllPolyhedra
Decimal encoding of polyhedra that have been enumerated.
std::set< unsigned long int > knownInfeas
Decimal encoding of polyhedra known to be infeasible.
unsigned int getFeasiblePolyhedra() const
unsigned int conv_PolyWt(const unsigned long int i) const
Class to handle parameterized quadratic programs(QP)
unsigned int getLStart()
Read-only access to LCP::LeadStart.
std::set< unsigned long int > feasiblePoly
Decimal encoding of polyhedra that have been enumerated.
LCP & EnumerateAll(bool solveLP=true)
Brute force computation of LCP feasible region.
bool checkPolyFeas(const unsigned long int &decimalEncoding)
bool FixToPoly(const std::vector< short int > Fix, bool checkFeas=false, bool custom=false, spmat_Vec *custAi={}, vec_Vec *custbi={})
Computes the equation of the feasibility polyhedron corresponding to the given Fix.
void defConst(GRBEnv *env)
Assign default values to LCP attributes.
arma::vec LPSolve(const arma::sp_mat &A, const arma::vec &b, const arma::vec &c, int &status, bool Positivity=false)
unsigned long int maxTheoreticalPoly
LCP & makeQP(Game::QP_objective &QP_obj, Game::QP_Param &QP)
void write(std::string filename, bool append=true) const
arma::sp_mat M
M in that defines the LCP.
void compConvSize(arma::sp_mat &A, const unsigned int nFinCons, const unsigned int nFinVar, const std::vector< arma::sp_mat *> *Ai, const std::vector< arma::vec *> *bi, const arma::sp_mat &Acom, const arma::vec &bcom)
bool errorCheck(bool throwErr=true) const
unsigned long int getNumTheoreticalPoly() const noexcept
long double eps
The threshold for optimality and feasability tollerances.
std::unique_ptr< GRBModel > MPECasMILP(const arma::sp_mat &C, const arma::vec &c, const arma::vec &x_minus_i, bool solve=false)
Helps solving an LCP as an MIP.
std::vector< std::pair< unsigned int, unsigned int > > perps
std::vector< std::unique_ptr< arma::sp_mat > > spmat_Vec
std::set< unsigned long int > getAllPolyhedra() const
arma::sp_mat * getMstar()
Reference access to LCP::M.
arma::vec q
q in that defines the LCP
unsigned int ConvexHull(const std::vector< arma::sp_mat *> *Ai, const std::vector< arma::vec *> *bi, arma::sp_mat &A, arma::vec &b, const arma::sp_mat Acom={}, const arma::vec bcom={})
int reverseSequentialPolyCounter
arma::vec getq()
Read-only access to LCP::q.
std::unique_ptr< GRBModel > LCPasQP(bool solve=false)
Solves the LCP as a QP using Gurobi.
long int addPolyMethodSeed
std::unique_ptr< vec_Vec > bi
Vector to contain the RHS of inner approx polyhedra.
bool madeRlxdModel
Keep track if LCP::RlxdModel is made.
perps Compl
Compl stores data in <Eqn, Var> form.
bool isZero(const T val) const
Class to handle and solve linear complementarity problems.
unsigned int conv_PolyPosition(const unsigned long int i) const
std::unique_ptr< GRBModel > LCPasMIP(std::vector< unsigned int > FixEq={}, std::vector< unsigned int > FixVar={}, bool solve=false)
bool useIndicators
constraints. BigM formulation otherwise
std::string feas_detail_str() const
bool extractSols(GRBModel *model, arma::vec &z, arma::vec &x, bool extractZ=false) const
Extracts variable and equation values from a solved Gurobi model for LCP.
std::vector< short int > solEncode(GRBModel *model) const
Given a Gurobi model, extracts variable values and equation values, encodes it in 0/+1/-1 format and ...
Adds polyhedra by selecting them in order.
perps getCompl()
Read-only access to LCP::Compl.
std::unique_ptr< spmat_Vec > Ai
Vector to contain the LHS of inner approx polyhedra.
LCP()=delete
Class has no default constructors.
LCP & FixToPolies(const std::vector< short int > Fix, bool checkFeas=false, bool custom=false, spmat_Vec *custAi={}, vec_Vec *custbi={})
Computes the equation of the feasibility polyhedron corresponding to the given Fix.
long int load(std::string filename, long int pos=0)
arma::sp_mat getM()
Read-only access to LCP::M.
unsigned int conv_Npoly() const
unsigned int sequentialPolyCounter
unsigned int getLEnd()
Read-only access to LCP::LeadEnd.
void print(std::string end="\)
Print a summary of the LCP.
unsigned int ConvexHull(arma::sp_mat &A, arma::vec &b)
struct to handle the objective params of MP_Param/QP_Param
void makeRelaxed()
Makes a Gurobi object that relaxes complementarity constraints in an LCP.
arma::vec * getqstar()
Reference access to LCP::q.
bool addThePoly(const unsigned long int &decimalEncoding)
std::unique_ptr< GRBModel > MPECasMIQP(const arma::sp_mat &Q, const arma::sp_mat &C, const arma::vec &c, const arma::vec &x_minus_i, bool solve=false)
Helps solving an LCP as an MIQPs.
std::vector< std::unique_ptr< arma::vec > > vec_Vec
long double bigM
bigM used to rewrite the LCP as MIP
unsigned long int getNextPoly(Game::EPECAddPolyMethod method)
std::unique_ptr< GRBModel > LCP_Polyhed_fixed(std::vector< unsigned int > FixEq={}, std::vector< unsigned int > FixVar={})
void save(std::string filename, bool erase=true) const
std::set< std::vector< short int > > addAPoly(unsigned long int nPoly=1, Game::EPECAddPolyMethod method=Game::EPECAddPolyMethod::sequential, std::set< std::vector< short int >> Polys={})
Class to model Nash-cournot games with each player playing a QP.
unsigned int feasiblePolyhedra
void initializeNotProcessed()
LCP & addPolyFromX(const arma::vec &x, bool &ret)