1 #ifndef IClpSimplex_H
2 #define IClpSimplex_H
3 
4 //#define NPY_NO_DEPRECATED_API
5 //#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
6 
7 //#include "ClpModel.hpp"
8 #include "ClpSimplex.hpp"
9 #include "ClpPresolve.hpp"
10 #include "ClpLinearObjective.hpp"
11 #include "CoinIndexedVector.hpp"
12 #include "ClpFactorization.hpp"
13 #include "Python.h"
14 #include <numpy/arrayobject.h>
15 #include "ICbcModel.hpp"
16 #include "ClpParameters.hpp"
17 
18 #include "ICoinPackedMatrix.hpp"
19 
20 
21 //#include "ClpSimplexPrimal.hpp"
22 
23 typedef int (*runIsPivotAcceptable_t)(void *instance);
24 typedef int (*varSelCriteria_t)(void *instance, int varInd);
25 
26 
27 class IClpSimplex : public ClpSimplex{
28 public:
29     ClpPresolve pinfo;
30     IClpSimplex(const ClpSimplex &rhs,PyObject *obj,
31                             runIsPivotAcceptable_t runPivotRow,
32                             varSelCriteria_t RunVarSelCriteria,
33                             int useCustomPrimal, int scalingMode=-1 );
34 	IClpSimplex(PyObject *obj, runIsPivotAcceptable_t runPivotRow,
35                 varSelCriteria_t RunVarSelCriteria );
36     int initialSolve(int preSolveType=ClpSolve::presolveOn);
37 	// For initializing instances that are build using ClpSimplex consructor (NOT IClpSimplex)
38     void setCriteria(varSelCriteria_t vsc);
39 
40     int argWeightedMax(PyObject* arr, PyObject* whr, double weight);
41     int argWeightedMax(PyObject* arr, PyObject* arr_ind, PyObject* w, PyObject* w_ind);
42 
43     PyObject *obj;
44   	runIsPivotAcceptable_t runIsPivotAcceptable;
45 	int isPivotAcceptable();
46 
47     varSelCriteria_t varSelCriteria;
48     int checkVar(int varInd);
49     PyObject* filterVars(PyObject* inds);
50     int* tempIntArray;
51     bool tempArrayExists;
52     void createTempArray(void);
53 
54     int* QP_ComplementarityList;
55 	int* QP_BanList;
56 	int QP_ExistsBannedVariable;
57 
58 	void setComplementarityList(int *);
59 	int* ComplementarityList();
60 
61     bool varIsFree(int ind);
62     bool varBasic(int ind);
63     bool varAtUpperBound(int ind);
64     bool varAtLowerBound(int ind);
65     bool varSuperBasic(int ind);
66     bool varIsFixed(int ind);
67 	PyObject * getReducedCosts();
68 	void setReducedCosts(double*);
69     PyObject * getStatusArray();
70 	PyObject * getComplementarityList();
71 	PyObject * getPivotVariable();
72 	PyObject * getPrimalRowSolution();
73 	PyObject * getPrimalColumnSolution();
74     PyObject * getPrimalColumnSolutionAll();
75     PyObject * getSolutionRegion();
76     PyObject * getCostRegion();
77 	PyObject * getDualRowSolution();
78 	PyObject * getDualColumnSolution();
79 	PyObject * getObjective();
80 	PyObject * getRowLower();
81 	PyObject * getRowUpper();
82 	PyObject * getColLower();
83     PyObject * getColUpper();
84     PyObject * getColumnScale();
85     PyObject * getRowScale();
86 
87 
88     PyObject* getLower();
89     PyObject* getUpper();
90 
91     PyObject* getIntegerInformation();
92 
93 
94 
95 
96 	void getBInvACol(int col, double* vec);
97 	void getACol(int ncol, CoinIndexedVector * colArray);
updateColumnFT(CoinIndexedVector * spare,CoinIndexedVector * updatedColumn)98   int updateColumnFT(CoinIndexedVector * spare,
99                           CoinIndexedVector * updatedColumn)
100       {
101       return this->factorization()->updateColumnFT(spare, updatedColumn);
102       }
103 
updateColumnTranspose(CoinIndexedVector * regionSparse,CoinIndexedVector * regionSparse2)104   int updateColumnTranspose (CoinIndexedVector * regionSparse,
105                                  CoinIndexedVector * regionSparse2){
106       return this->factorization()->updateColumnTranspose(regionSparse, regionSparse2);
107       }
108 
109 	int customPrimal;
110 	void useCustomPrimal(int);
111 	int getUseCustomPrimal();
112 
113 
setPrimalColumnPivotAlgorithm(ClpPrimalColumnPivot * choice)114 	void setPrimalColumnPivotAlgorithm(ClpPrimalColumnPivot *choice){ClpSimplex::setPrimalColumnPivotAlgorithm(*choice);}
setDualRowPivotAlgorithm(ClpDualRowPivot * choice)115   void setDualRowPivotAlgorithm(ClpDualRowPivot *choice){ClpSimplex::setDualRowPivotAlgorithm(*choice);}
116 
loadQuadraticObjective(const CoinPackedMatrix * matrix)117     void loadQuadraticObjective(const CoinPackedMatrix* matrix){ClpModel::loadQuadraticObjective(*matrix);}
getMatrix()118     ICoinPackedMatrix* getMatrix(){return static_cast<ICoinPackedMatrix*>(ClpModel::matrix());}
119 
loadProblem(CoinModel * modelObject,bool tryPlusMinusOne=false)120 	int loadProblem (CoinModel * modelObject,bool tryPlusMinusOne=false){return ClpSimplex::loadProblem(*modelObject, tryPlusMinusOne);}
121 	//double* infeasibilityRay();
loadProblem(const CoinPackedMatrix * matrix,const double * collb,const double * colub,const double * obj,const double * rowlb,const double * rowub,const double * rowObjective=NULL)122     void loadProblem (const CoinPackedMatrix* matrix,
123 		     const double* collb, const double* colub,
124 		     const double* obj,
125 		     const double* rowlb, const double* rowub,
126 		     const double * rowObjective=NULL){
127                    ClpSimplex::loadProblem(*matrix, collb, colub, obj, rowlb, rowub, rowObjective);}
128 
129 	int primal(int ifValuesPass=0, int startFinishOptions=0);
130 
131 	IClpSimplex (ClpSimplex * wholeModel,
132 	      int numberColumns, const int * whichColumns);
133 
134 	~IClpSimplex();
135 
136 	void dualExpanded(ClpSimplex * model,CoinIndexedVector * array, double * other,int mode);
137 
138 
139 	void convertBoundToSense(const double lower, const double upper,
140 						 double& right);
141 	void extractSenseRhsRange(double* rhs_);
142 	void getRightHandSide(double* righthandside);
143 
144 
145 	double* tempRow;
146 	CoinIndexedVector* tempRow_vector;
147 
148 	void vectorTimesB_1(CoinIndexedVector*);
149     void transposeTimesSubsetAll(int number, long long int* which, double* pi, double* y);
150     void transposeTimesSubset(int number, int* which, double* pi, double* y);
151     void transposeTimes(const ClpSimplex * model, double scalar,
152                                  const CoinIndexedVector * x,
153                                  CoinIndexedVector * y,
154                                  CoinIndexedVector * z);
155 
156     IClpSimplex*	preSolve(IClpSimplex* si,
157                               double feasibilityTolerance=0.0,
158                               bool keepIntegers=true,
159                               int numberPasses=5,
160                               bool dropNames=false,
161                               bool doRowObjective=false);
162     void postSolve(bool updateStatus=true);
163 
164     int dualWithPresolve(IClpSimplex* si,
165                               double feasibilityTolerance=0.0,
166                               bool keepIntegers=true,
167                               int numberPasses=5,
168                               bool dropNames=false,
169                               bool doRowObjective=false);
170 
171     int primalWithPresolve(IClpSimplex* si,
172                               double feasibilityTolerance=0.0,
173                               bool keepIntegers=true,
174                               int numberPasses=5,
175                               bool dropNames=false,
176                               bool doRowObjective=false);
177 
setComplement(int var1,int var2)178     void setComplement(int var1, int var2){QP_ComplementarityList[var1] = var2; QP_ComplementarityList[var2] = var1;}
179 
180 
getCoinInfinity()181     inline double getCoinInfinity(){return COIN_DBL_MAX;}
182 
setColumnUpperArray(double * cu)183     inline void setColumnUpperArray(double *cu){columnUpper_ = cu;}
setColumnLowerArray(double * cl)184     inline void setColumnLowerArray(double *cl){columnLower_ = cl;}
setRowUpperArray(double * ru)185     inline void setRowUpperArray(double *ru){rowUpper_ = ru;}
setRowLowerArray(double * rl)186     inline void setRowLowerArray(double *rl){rowLower_ = rl;}
187 
setColumnUpperSubset(int n,int * indicesOfIndices,int * indices,double * values)188     inline void setColumnUpperSubset(int n, int *indicesOfIndices, int *indices, double* values){
189         for (int i = 0 ; i < n ; i++)
190             setColumnUpper(indices[indicesOfIndices[i]], values[indicesOfIndices[i]]);
191     }
setColumnLowerSubset(int n,int * indicesOfIndices,int * indices,double * values)192     inline void setColumnLowerSubset(int n, int *indicesOfIndices, int *indices, double* values){
193         for (int i = 0 ; i < n ; i++)
194             setColumnLower(indices[indicesOfIndices[i]], values[indicesOfIndices[i]]);
195     }
196 
setColumnUpperFirstElements(int n,double * values)197     inline void setColumnUpperFirstElements(int n, double* values){
198         for (int i = 0 ; i < n ; i++)
199             setColumnUpper(i, values[i]);
200     }
setColumnLowerFirstElements(int n,double * values)201     inline void setColumnLowerFirstElements(int n, double* values){
202         for (int i = 0 ; i < n ; i++)
203             setColumnLower(i, values[i]);
204     }
205 
setObjectiveArray(double * o,int numberColumns)206     inline void setObjectiveArray(double *o, int numberColumns)
207     {
208     if (objective_)
209     	delete objective_;
210     objective_ = new ClpLinearObjective(o, numberColumns);
211     }
212 
213 	void setVariableName(int varInd,  char* name);
214     void setConstraintName(int constInd,  char* name);
215     std::vector<std::string> getVariableNames();
216 
217     /// Partial pricing
partialPrice(int start,int end,int * numberWanted)218     int partialPrice(int start, int end, int* numberWanted)
219       {
220        int bestVarInd;
221        this->clpMatrix()->partialPricing(this,
222                                           static_cast<double>(start),
223                                           static_cast<double>(end),
224                                           bestVarInd,
225                                           *numberWanted);
226         return bestVarInd;
227         }
228 
229     ICbcModel* getICbcModel();
230     void writeLp(const char *filename,
231                        const char *extension = "lp",
232                        double epsilon = 1e-5,
233                        int numberAcross = 10,
234                        int decimals = 5,
235                        double objSense = 0.0,
236                        bool useRowNames = true);
237 
238     void setBasisStatus(const int* cstat, const int* rstat);
239     void getBasisStatus(int* cstat, int* rstat);
240 
241     void setMaxNumIteration(int m);
242 
243 };
244 
245 double cdot(CoinIndexedVector* v1, CoinIndexedVector* v2);
246 
247 
248 #endif
249