Dip 0.95.0
Loading...
Searching...
No Matches
DippyDecompApp.h
Go to the documentation of this file.
1#ifndef DIPPY_DECOMPAPP_INCLUDED
2#define DIPPY_DECOMPAPP_INCLUDED
3
4//===========================================================================//
5#include "Decomp.h"
6#include "DecompApp.h"
7#include "UtilParameters.h"
8
9#include "Python.h"
10
11#include <map>
12#include <vector>
13using namespace std;
14
15//===========================================================================//
23
24//===========================================================================//
25class DippyDecompApp : public DecompApp {
26private:
28 const string m_classTag;
29
31
32 PyObject* m_pProb;
33
34 int m_numCols;
35
37 bool m_pySolveRelaxed;
38 bool m_pyIsUserFeasible;
39 bool m_pyGenerateCuts;
40 bool m_pyHeuristics;
41 bool m_pyInitVars;
42
43public:
45
46 /* Add PuLP problem. */
47
48 void addPuLPProb(PyObject* p) {
49 Py_XINCREF(p); /* Add a reference to new problem */
50 Py_XDECREF(m_pProb); /* Dispose of previous problem */
51 m_pProb = p;
52 };
53
54 /* Create models. */
56
57 virtual DecompSolverStatus solveRelaxed(const int whichBlock,
58 const double* redCostX,
59 const double convexDual,
60 DecompVarList& varList);
61
62 bool APPisUserFeasible(const double* x, const int n_cols, const double tolZero);
63
64 virtual int generateCuts(const double* x, DecompCutList& newCuts);
65
66 int APPheuristics(const double* xhat, const double* origCost, vector<DecompSolution*>& xhatIPFeas);
67
69
70 PyObject* m_rowList;
71 map<PyObject*, int> m_rowIndices;
72 PyObject* m_colList;
73 map<PyObject*, int> m_colIndices;
74
75 PyObject* m_relaxedKeys;
76 map<PyObject*, int> m_relaxIndices;
77
78public:
79 DippyDecompApp(UtilParameters& utilParam, PyObject* p) :
80 DecompApp (utilParam),
81 m_classTag ("SMALL-APP"),
82 m_pProb(NULL) {
83 addPuLPProb(p);
85 m_pySolveRelaxed = utilParam.GetSetting("pyRelaxedSolver", true);
86 m_pyIsUserFeasible = utilParam.GetSetting("pyIsSolutionFeasible", true);
87 m_pyGenerateCuts = utilParam.GetSetting("pyGenerateCuts", true);
88 m_pyHeuristics = utilParam.GetSetting("pyHeuristics", true);
89 m_pyInitVars = utilParam.GetSetting("pyInitVars", true);
90 }
91
92 virtual ~DippyDecompApp() {
93 // Remove references to Python objects/lists
94 Py_XDECREF(m_pProb);
95 Py_XDECREF(m_rowList);
96 Py_XDECREF(m_colList);
97 Py_XDECREF(m_relaxedKeys);
98 delete [] m_objective;
99 m_objective = NULL;
100 delete m_modelCore.getModel();
101 m_modelCore.setModel(NULL);
102 map<int, DecompModel >::iterator mit;
103
104 for (mit = m_modelRelax.begin(); mit != m_modelRelax.end(); mit++) {
105 DecompModel & modelRelax = (*mit).second;
106 delete modelRelax.getModel();
107 modelRelax.setModel(NULL);
108 }
109 };
110};
111
112#endif
DecompSolverStatus
Definition Decomp.h:208
std::list< DecompVar * > DecompVarList
Definition Decomp.h:92
std::list< DecompCut * > DecompCutList
Definition Decomp.h:93
const double * m_objective
Model data: objective function.
Definition DecompApp.h:85
std::map< int, DecompModel > m_modelRelax
Model data: the relaxed model(s) (A')
Definition DecompApp.h:95
DecompApp(UtilParameters &utilParam)
Constructor for base DecompApp class.
Definition DecompApp.h:442
DecompModel m_modelCore
Model data: the core model (A'')
Definition DecompApp.h:90
void setModel(DecompConstraintSet *model)
Definition DecompModel.h:46
DecompConstraintSet * getModel() const
Definition DecompModel.h:35
map< PyObject *, int > m_rowIndices
virtual int generateCuts(const double *x, DecompCutList &newCuts)
PyObject * m_rowList
int generateInitVars(DecompVarList &initVars)
map< PyObject *, int > m_relaxIndices
bool APPisUserFeasible(const double *x, const int n_cols, const double tolZero)
Method to determine if the solution (x) is feasible to the original model.
map< PyObject *, int > m_colIndices
virtual DecompSolverStatus solveRelaxed(const int whichBlock, const double *redCostX, const double convexDual, DecompVarList &varList)
int APPheuristics(const double *xhat, const double *origCost, vector< DecompSolution * > &xhatIPFeas)
virtual ~DippyDecompApp()
void createModels()
PyObject * m_relaxedKeys
DippyDecompApp(UtilParameters &utilParam, PyObject *p)
void addPuLPProb(PyObject *p)
PyObject * m_colList
std::string GetSetting(const char *name, const char *defaultValue, const char *section=NULL)