DippyDecompApp.h
Go to the documentation of this file.00001 #ifndef DIPPY_DECOMPAPP_INCLUDED
00002 #define DIPPY_DECOMPAPP_INCLUDED
00003
00004
00005 #include "Decomp.h"
00006 #include "DecompApp.h"
00007 #include "UtilParameters.h"
00008
00009 #include "Python.h"
00010
00011 #include <map>
00012 #include <vector>
00013 using namespace std;
00014
00015
00024
00025 class DippyDecompApp : public DecompApp {
00026 private:
00028 const string m_classTag;
00029
00032 PyObject* m_pProb;
00033
00034 int m_numCols;
00035
00037 bool m_pySolveRelaxed;
00038 bool m_pyIsUserFeasible;
00039 bool m_pyGenerateCuts;
00040 bool m_pyHeuristics;
00041 bool m_pyInitVars;
00042
00043 public:
00046
00047
00048 void addPuLPProb(PyObject* p) {
00049 Py_XINCREF(p);
00050 Py_XDECREF(m_pProb);
00051 m_pProb = p;
00052 };
00053
00054
00055 void createModels();
00056
00057 virtual DecompSolverStatus solveRelaxed(const int whichBlock,
00058 const double* redCostX,
00059 const double convexDual,
00060 DecompVarList& varList);
00061
00062 bool APPisUserFeasible(const double* x, const int n_cols, const double tolZero);
00063
00064 virtual int generateCuts(const double* x, DecompCutList& newCuts);
00065
00066 int APPheuristics(const double* xhat, const double* origCost, vector<DecompSolution*>& xhatIPFeas);
00067
00068 int generateInitVars(DecompVarList& initVars);
00069
00070 PyObject* m_rowList;
00071 map<PyObject*, int> m_rowIndices;
00072 PyObject* m_colList;
00073 map<PyObject*, int> m_colIndices;
00074
00075 PyObject* m_relaxedKeys;
00076 map<PyObject*, int> m_relaxIndices;
00077
00078 public:
00079 DippyDecompApp(UtilParameters& utilParam, PyObject* p) :
00080 DecompApp (),
00081 m_classTag ("SMALL-APP"),
00082 m_pProb(NULL) {
00083 addPuLPProb(p);
00084 createModels();
00085 m_pySolveRelaxed = utilParam.GetSetting("pyRelaxedSolver", true);
00086 m_pyIsUserFeasible = utilParam.GetSetting("pyIsSolutionFeasible", true);
00087 m_pyGenerateCuts = utilParam.GetSetting("pyGenerateCuts", true);
00088 m_pyHeuristics = utilParam.GetSetting("pyHeuristics", true);
00089 m_pyInitVars = utilParam.GetSetting("pyInitVars", true);
00090 }
00091
00092 virtual ~DippyDecompApp() {
00093
00094 Py_XDECREF(m_pProb);
00095 Py_XDECREF(m_rowList);
00096 Py_XDECREF(m_colList);
00097 Py_XDECREF(m_relaxedKeys);
00098 delete [] m_objective;
00099 m_objective = NULL;
00100 delete m_modelCore.getModel();
00101 m_modelCore.setModel(NULL);
00102 map<int, DecompAppModel>::iterator mit;
00103
00104 for (mit = m_modelRelax.begin(); mit != m_modelRelax.end(); mit++) {
00105 DecompAppModel& modelRelax = (*mit).second;
00106 delete modelRelax.getModel();
00107 modelRelax.setModel(NULL);
00108 }
00109 };
00110 };
00111
00112 #endif