PIPS-NLP
stochasticInput.hpp
Go to the documentation of this file.
1 #ifndef STOCHASTICINPUTHPP
2 #define STOCHASTICINPUTHPP
3 
4 #include <vector>
5 #include <string>
6 #include "CoinPackedMatrix.hpp"
7 
8 // Stochastic (MI)LP readers will implement this virtual class
9 // Assume 2-stage stochastic (MI)LP with recourse, with a discrete distribution
10 
11 /*
12 constraints are of form:
13 A x
14 T_1x + W_1y1
15 T_2x + W_2y_2
16 ...
17 T_Nx + W_Ny_N
18 
19 where x are first-stage variables, and y second-stage variables
20 each row (constraint) and column (variable) can have an upper and lower bound
21 if these are equal for a row, then you have an equality constraint
22 if these are equal for a column, then you have a fixed variable
23 */
24 
25 
26 // Meant to be a "nice" interface that can be used from other languages,
27 // e.g. with SWIG, so no pointers involved.
28 // If worried about copying objects on return, use move semantics in
29 // the implementation.
30 // Accessors not marked const because implementing class may need to
31 // change internal data structures when called, e.g. for caching the answer.
33 public:
34  virtual ~stochasticInput() {}
35  virtual int nScenarios() = 0;
36  virtual int nFirstStageVars() = 0;
37  virtual int nFirstStageCons() = 0;
38  virtual int nSecondStageVars(int scen) = 0;
39  virtual int nSecondStageCons(int scen) = 0;
40 
41  virtual std::vector<double> getFirstStageColLB() = 0;
42  virtual std::vector<double> getFirstStageColUB() = 0;
43  virtual std::vector<double> getFirstStageObj() = 0;
44  virtual std::vector<std::string> getFirstStageColNames() = 0;
45  virtual std::vector<double> getFirstStageRowLB() = 0;
46  virtual std::vector<double> getFirstStageRowUB() = 0;
47  virtual std::vector<double> getLinkRowLB(){ return std::vector<double>(); }
48  virtual std::vector<double> getLinkRowUB(){ return std::vector<double>(); }
49  virtual std::vector<std::string> getFirstStageRowNames() = 0;
50  virtual bool isFirstStageColInteger(int col) = 0;
51 
52  virtual std::vector<double> getSecondStageColLB(int scen) = 0;
53  virtual std::vector<double> getSecondStageColUB(int scen) = 0;
54  // objective vector, already multiplied by probability
55  virtual std::vector<double> getSecondStageObj(int scen) = 0;
56  virtual std::vector<std::string> getSecondStageColNames(int scen) = 0;
57  virtual std::vector<double> getSecondStageRowUB(int scen) = 0;
58  virtual std::vector<double> getSecondStageRowLB(int scen) = 0;
59  virtual std::vector<std::string> getSecondStageRowNames(int scen) = 0;
60  virtual double scenarioProbability(int scen) = 0;
61  virtual bool isSecondStageColInteger(int scen, int col) = 0;
62 
63  // returns the column-oriented first-stage constraint matrix (A matrix)
64  virtual CoinPackedMatrix getFirstStageConstraints() = 0;
65  // returns the column-oriented second-stage constraint matrix (W matrix)
66  virtual CoinPackedMatrix getSecondStageConstraints(int scen) = 0;
67  // returns the column-oriented matrix linking the first-stage to the second (T matrix)
68  virtual CoinPackedMatrix getLinkingConstraints(int scen) = 0;
69 
70 
71 
72  // some problem characteristics that could be helpful to know
73 
74  // all scenarios have the same number of variables and constraints
75  virtual bool scenarioDimensionsEqual() = 0;
76  // constraint (and hessian) matrices are identical for each scenario,
77  // column and row bounds and objective are allowed to vary
78  virtual bool onlyBoundsVary() = 0;
79  // all scenarios equally likely
80  virtual bool allProbabilitiesEqual() = 0;
81  // all second-stage variables continuous
82  virtual bool continuousRecourse() = 0;
83 
84  /* Quadratic terms:
85  We allow the input to specify quadratic objective in the form of:
86  (1/2)x^TQx + c^T + \sum_{i=1}^N p_i ((1/2)y_i^TQ_iy_i + x_i^T{\hat Q_i^T}y_i + c_i^Ty)
87 
88  Q is the first-stage hessian
89  Q_i is the second-stage hessian
90  \hat Q_i is the second-stage cross hessian
91 
92  Default implementations are provided so that these do not need to be implemented if not used
93  */
94 
95  // column-oriented *lower triangle only*
96  // Q
97  virtual CoinPackedMatrix getFirstStageHessian();
98  // Q_i
99  virtual CoinPackedMatrix getSecondStageHessian(int scen);
100  // column-oriented, \hat Q_i
101  // Note: this has the second-stage variables on the rows and first-stage on the columns
102  virtual CoinPackedMatrix getSecondStageCrossHessian(int scen);
103 
104 
105  virtual int nLinkCons(){ return 0; }
106  virtual int nLinkECons(){ return 0; }
107  virtual int nLinkICons(){ return 0; }
108  virtual CoinPackedMatrix getLinkMatrix(int nodeid){ return CoinPackedMatrix(); }
109  std::string datarootname;
111 
112 };
113 
114 
115 
116 #endif
117 
virtual CoinPackedMatrix getFirstStageHessian()
Definition: stochasticInput.cpp:5
virtual std::vector< double > getLinkRowUB()
Definition: stochasticInput.hpp:48
virtual std::vector< double > getFirstStageObj()=0
virtual CoinPackedMatrix getSecondStageCrossHessian(int scen)
Definition: stochasticInput.cpp:17
virtual int nScenarios()=0
virtual std::vector< double > getSecondStageColUB(int scen)=0
virtual double scenarioProbability(int scen)=0
Definition: stochasticInput.hpp:32
virtual std::vector< double > getSecondStageRowLB(int scen)=0
virtual int nFirstStageCons()=0
virtual std::vector< std::string > getFirstStageRowNames()=0
virtual int nLinkCons()
Definition: stochasticInput.hpp:105
virtual bool allProbabilitiesEqual()=0
std::string datarootname
Definition: stochasticInput.hpp:109
virtual std::vector< double > getFirstStageColLB()=0
int useInputDate
Definition: stochasticInput.hpp:110
virtual int nFirstStageVars()=0
virtual bool onlyBoundsVary()=0
virtual CoinPackedMatrix getLinkMatrix(int nodeid)
Definition: stochasticInput.hpp:108
virtual CoinPackedMatrix getSecondStageConstraints(int scen)=0
virtual std::vector< std::string > getFirstStageColNames()=0
virtual CoinPackedMatrix getSecondStageHessian(int scen)
Definition: stochasticInput.cpp:11
virtual std::vector< double > getSecondStageColLB(int scen)=0
virtual std::vector< double > getFirstStageColUB()=0
virtual std::vector< double > getSecondStageRowUB(int scen)=0
virtual int nLinkECons()
Definition: stochasticInput.hpp:106
virtual CoinPackedMatrix getLinkingConstraints(int scen)=0
virtual std::vector< double > getFirstStageRowLB()=0
virtual CoinPackedMatrix getFirstStageConstraints()=0
virtual std::vector< double > getSecondStageObj(int scen)=0
virtual bool continuousRecourse()=0
virtual int nLinkICons()
Definition: stochasticInput.hpp:107
virtual bool isFirstStageColInteger(int col)=0
virtual int nSecondStageVars(int scen)=0
virtual bool scenarioDimensionsEqual()=0
virtual std::vector< double > getFirstStageRowUB()=0
virtual std::vector< std::string > getSecondStageRowNames(int scen)=0
virtual bool isSecondStageColInteger(int scen, int col)=0
virtual std::vector< std::string > getSecondStageColNames(int scen)=0
virtual ~stochasticInput()
Definition: stochasticInput.hpp:34
virtual int nSecondStageCons(int scen)=0
virtual std::vector< double > getLinkRowLB()
Definition: stochasticInput.hpp:47