Dip  0.92.4
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>
13 using namespace std;
14 
15 //===========================================================================//
24 //===========================================================================//
25 class DippyDecompApp : public DecompApp {
26 private:
28  const string m_classTag;
29 
32  PyObject* m_pProb;
33 
34  int m_numCols;
35 
42 
43 public:
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. */
55  void createModels();
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 
68  int generateInitVars(DecompVarList& initVars);
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 
78 public:
79  DippyDecompApp(UtilParameters& utilParam, PyObject* p) :
80  DecompApp (utilParam),
81  m_classTag ("SMALL-APP"),
82  m_pProb(NULL) {
83  addPuLPProb(p);
84  createModels();
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
std::list< DecompCut * > DecompCutList
Definition: Decomp.h:93
DecompConstraintSet * getModel() const
Definition: DecompModel.h:35
map< PyObject *, int > m_colIndices
string GetSetting(const char *name, const char *defaultValue, const char *section=NULL)
PyObject * m_pProb
The various model constraint systems used for different algos.
PyObject * m_colList
bool m_pySolveRelaxed
Flags for Python callbacks.
DippyDecompApp(UtilParameters &utilParam, PyObject *p)
map< PyObject *, int > m_relaxIndices
PyObject * m_relaxedKeys
map< PyObject *, int > m_rowIndices
void setModel(DecompConstraintSet *model)
Definition: DecompModel.h:46
void addPuLPProb(PyObject *p)
const string m_classTag
Class id tag (for log / debugging).
DecompSolverStatus
Definition: Decomp.h:208
PyObject * m_rowList
virtual ~DippyDecompApp()
std::list< DecompVar * > DecompVarList
Definition: Decomp.h:91
The main application class.
Definition: DecompApp.h:48