Dip  0.92.4
DecompAlgo.old.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the Decomp Solver Framework. //
3 // //
4 // Decomp is distributed under the Common Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Author: Matthew Galati, Lehigh University //
8 // //
9 // Copyright (C) 2002-2007, Lehigh University, Matthew Galati, and Ted Ralphs//
10 // All Rights Reserved. //
11 //===========================================================================//
12 
13 #ifndef DECOMP_ALGO_INCLUDED
14 #define DECOMP_ALGO_INCLUDED
15 
16 #define EXPLICIT_BOUNDS
17 
18 #include "DecompConstraintSet.h"
19 #include "DecompSolution.h"
20 #include "DecompMemPool.h"
21 #include "DecompVarPool.h"
22 #include "DecompCutPool.h"
23 #include "DecompStats.h"
24 //class DecompStats;
25 class DecompApp;
26 class ClpModel;
27 
28 
29 #include "OsiSolverInterface.hpp"
30 
31 
32 
33 // --------------------------------------------------------------------- //
34 class DecompAlgo{
35  private:
36  DecompAlgo(const DecompAlgo &);
37  DecompAlgo & operator=(const DecompAlgo &);
38 
39  private:
40  static const char * m_classTag;
41  static const char * versionTag;
42  DecompAlgoType m_algo; //"who am i"
43 
44  protected:
46  DecompApp * m_app;
47 
48  int m_nodeIndex;
49  int m_whichModel;
50  int m_whichCoreModel;
53  int m_cutCallsRound;
54  int m_cutCallsTotal;
55  int m_varsThisRound;
56  int m_cutsThisRound;
57  int m_varsThisCall;
58  int m_cutsThisCall;
59 
60  int m_isTightenAlgo;
61 
62  ostream * m_osLog;
63 
64  //THINK: naming outer, inner?? - will work across all?
65 
66  //solver interface for subproblem (P')
67  map<int, OsiSolverInterface*> m_subprobSI;
68 
69  //solver interface for master (Q")
71 
72 #ifdef __DECOMP_LP_CLP__
73  //THINK: so we don't freecached when getModelPtr - do once...
74  //makes it so that we are stuck with CLP - also need to support CPX
75  ClpModel * m_masterCLP;
76 #endif
77 
78 
79  //m_vars and m_cuts have no destructor, but they are list of ptrs
80  //the memory they point to needs to be deleted.
81 
82  //member of app or member of algo?
83  DecompVarList m_vars; //list of vars added to master
88 
89  double m_tlb;
90  double m_tub;
91  double m_bestUpperBound;//known opt
92 
93  double * m_xhat;
94 
95  //think about do we want a solution pool?
96  //for now, just keep the best and toss the rest
97  vector<DecompSolution*> m_xhatIPFeas;
99 
100  int m_numOrigCols; //DECOMP
101 
102  vector< vector<double> > m_optPoint;
103 
104  //stabilization techniques
105  double * m_piEstimate;
106  vector<bool> isStab;
107 
108  public:
109  //these are just pointers into app
112 
114 
115  public:
116  //helper functions
118 
119  //TODO: functions in alphabetical order??
120  void startupLog();
121  void initSetup(int whichModel = 1);
122 
123  void tighten(int whichModel);
124  inline double getTrueLowerBound(){
125  return m_tlb;
126  }
127  inline double getTrueUpperBound(){
128  return m_tub;
129  }
130 
131  //TODO: should not call these LB UB
132  void setTrueLowerBound(const double mostNegReducedCost);
133  void setTrueUpperBound(const double ub){
134  m_tub = ub;
135  };
136  double calcConstant(const int m,
137  const double * u);
138 
139  //helper functions - DecompDebug.cpp
140  bool isDualRayInfProof(const double * dualRay,
141  const CoinPackedMatrix * rowMatrix,
142  const double * colLB,
143  const double * colUB,
144  const double * rowRhs,
145  ostream * os = 0);
147  ostream * os);
148  void printCurrentProblem(const OsiSolverInterface * si,
149  const string baseName,
150  const int nodeIndex,
151  const int cutPass,
152  const int pricePass,
153  const bool printMps = true,
154  const bool printLp = true);
155  void printCurrentProblem(const OsiSolverInterface * si,
156  const string fileName,
157  const bool printMps = true,
158  const bool printLp = true);
159 
160  void printVars(ostream * os = &cout);
161  void printCuts(ostream * os = &cout);
162 
163  void solveBruteForce();
164  void createFullMps(const string filename);
165  vector<double*> getDualRays(int maxNumRays);
166 
167  inline void setApp(DecompApp * app){
168  m_app = app;
169  }
170 
171 
172  inline void setBestUpperBound(const double bestUpperBound){
173  m_bestUpperBound = bestUpperBound;
174  }
175 
176  DecompStat solveRelaxed(const int whichModel,
177  const double * redCostX,
178  const double * origCost,
179  const double alpha,
180  const int n_origCols,
181  const bool checkRC,
182  const bool checkDup,
184  list<DecompVar*> & vars);
185 
186  public:
187  //pure virtual methods
188 
189 
190 
191 
192  virtual void createMasterProblem(DecompVarList & initVars) = 0;
193 
194  //possible base is enough here too... think at least for PC and C
195  //seem to be ok
196 
197  //just base is enough for PC and C here
198  virtual DecompStat solutionUpdate(const DecompPhase phase,
199  const int maxInnerIter,
200  const int maxOuterIter);
201 
202  //just base is enough?
203  virtual DecompPhase phaseUpdate(const DecompPhase phase,
204  const DecompStat stat);
205 
206  public:
207  //virtual methods
208  //all this mess, just so that we don't use m_masterSI for RC??
209  //doesn't make alot of sense to me... THINK
210 
211  //just feed u vector in rowPrice in OSI???
212 
213  virtual void setMasterBounds(const double * lbs,
214  const double * ubs);
215 
217  return m_masterSI;
218  }
219 
220  virtual const double * getRowPrice() const {
221  return m_masterSI->getRowPrice();
222  }
223 
224  inline const double * getX(){
225  return m_xhat;
226  }
227 
228  inline DecompApp * getApp(){
229  return m_app;
230  }
231 
232  inline const DecompSolution * getXhatIPBest(){
233  return m_xhatIPBest;
234  }
235 
236 #if 1
237  virtual const double * getRightHandSide() const {
238  return &m_modelCore->rowRhs[0];//THINK
239  //return m_masterSI->getRightHandSide();
240  }
241  virtual const char * getRowSense() const {
242  return &m_modelCore->rowSense[0];//THINK - should be SI?
243  //return m_masterSI->getRowSense();
244  }
245 #endif
246 
247  int heuristics(const double * xhat,
248  vector<DecompSolution*> & xhatIPFeas);
249 
250  virtual int generateVars(const DecompStat stat,
251  DecompVarList & newVars,
252  double & mostNegReducedCost);
253  virtual int generateCuts(DecompCutList & newCuts);
254 
255  //different name? set x vector? and maybe base just memcpy
256  //while PC does recompose then copies in?
257  virtual void recomposeSolution(const double * solution,
258  double * rsolution){
259  printf("\nbase recomposeSolution does nothing.");
260  };
261 
262  virtual int generateInitVars(DecompVarList & initVars);
263  virtual bool isDone() { return false; };
264 
265 
266  //will never get called in C, yet PC specific, do nothing in base
267  //and move to PC?
268  void addVarsToPool(DecompVarList & newVars);
269  void addVarsFromPool();
270 
271 
272  bool isIPFeasible(const double * x,
273  const double feasTol = 1.0e-4,
274  const double intTol = 1.0e-4);
275  bool isLPFeasible(const double * x,
276  const double feasTol = 1.0e-4);
277 
278 
279  //different for C and PC, pure virtual for now
280  virtual void addCutsToPool(const double * x,
281  DecompCutList & newCuts,
282  int & n_newCuts);
283  virtual int addCutsFromPool();
284 
285  //DecompBranch.cpp
286  int chooseBranchVar(int & branchedOnIndex,
287  double & branchedOnValue);
288  virtual int branch(int branchedOnIndex,
289  double branchedOnValue);
290  DecompStat processNode(const int nodeIndex = 0,
291  const double globalLB = -DecompInf,
292  const double globalUB = DecompInf);
293  //process node? or just process?
294 
295 
296  /*helper functions*/
297  inline void appendVars(DecompVar * var){
298  m_vars.push_back(var);
299  }
300  inline void appendVars(DecompVarList & varList){
301  copy(varList.begin(), varList.end(), back_inserter(m_vars));
302 #if 0
303  if(m_vars.empty()){
304  m_vars = varList;
305  }
306  else
307  m_vars.insert(m_vars.end(), varList.begin(), varList.end());
308 #endif
309  }
310 
311 
312 
313  public:
315  DecompApp * app) :
316  m_algo(algo),
317  m_auxMemPool(),
318  m_app(app),
319  m_whichModel(-1),
320  m_whichCoreModel(-1),
321  m_nodeIndex(0),
324  m_cutCallsRound(0),
325  m_cutCallsTotal(0),
326  m_varsThisRound(0),
327  m_cutsThisRound(0),
328  m_varsThisCall(0),
329  m_cutsThisCall(0),
330  m_isTightenAlgo(0),
331  m_osLog(&cout),//TODO
332  m_masterSI(0),
333  m_vars(),
334  m_initVars(),
335  m_cuts(),
336  m_varpool(),
337  m_cutpool(),
338  m_tlb(-DecompInf),
339  m_tub( DecompInf),
340  m_bestUpperBound(DecompInf),
341  m_xhat(0),
342  m_xhatIPBest(0),
343  m_piEstimate(0)
344  {
345  (*m_osLog).setf(ios::fixed);
346  };
347 
348  virtual ~DecompAlgo(){
349  map<int, OsiSolverInterface*>::iterator it;
350  for(it = m_subprobSI.begin();
351  it != m_subprobSI.end(); it++){
352  if(it->second)
353  UTIL_DELPTR(it->second);
354  }
358 
359  //THINK - if was class, the std::list<T*> would be cleaner?
360  //let T's destructor do the work? the way cutpool manages that?
361  //should m_cuts and m_vars be pools anyway? vector to waiting row
362  //or list of waiting row pts?
365 
366  //THINK - m_initVars always (?) gets pushed into m_vars -
367  //so if we free here we'll double free?
368  //UtilDeleteListPtr(m_initVars);
369 
370 
371 
372  //?? who deletes m_var, m_cuts????
373  };
374 };
375 
376 #endif
377 
int m_isTightenAlgo
Definition: DecompAlgo.h:66
std::list< DecompCut * > DecompCutList
Definition: Decomp.h:93
virtual void createMasterProblem(DecompVarList &initVars)
Create the master problem (all algorithms must define this function).
void startupLog()
virtual void addVarsFromPool()
void UtilDeleteVectorPtr(vector< T * > &vectorPtr, typename vector< T * >::iterator first, typename vector< T * >::iterator last)
Definition: UtilMacros.h:288
vector< bool > isStab
Definition: DecompAlgo.h:112
DecompAlgo & operator=(const DecompAlgo &)
DecompStats m_stats
Storage of statistics for run and node.
Definition: DecompAlgo.h:113
int m_nodeIndex
Definition: DecompAlgo.h:54
int heuristics(const double *xhat, vector< DecompSolution * > &xhatIPFeas)
virtual DecompStatus processNode(const AlpsDecompTreeNode *node, const double globalLB, const double globalUB)
The main DECOMP process loop for a node.
map< int, OsiSolverInterface * > m_subprobSI
Definition: DecompAlgo.h:73
void solveBruteForce()
void printCurrentProblem(const OsiSolverInterface *si, const std::string baseName, const int nodeIndex, const int cutPass, const int pricePass, const int blockId=-1, const bool printMps=true, const bool printLp=true)
Initial setup of algorithm structures and solver interfaces.
int chooseBranchVar(int &branchedOnIndex, double &branchedOnValue)
void setBestUpperBound(const double bestUpperBound)
virtual void recomposeSolution(const double *solution, double *rsolution)
DecompMemPool m_auxMemPool
Definition: DecompAlgo.h:51
int m_priceCallsRound
Definition: DecompAlgo.h:57
virtual int generateVars(DecompVarList &newVars, double &mostNegReducedCost)
DecompStatus solveRelaxed(const double *redCostX, const double *origCost, const double alpha, const int n_origCols, const bool isNested, DecompSubModel &subModel, DecompSolverResult *solveResult, std::list< DecompVar * > &vars, double timeLimit)
DecompAlgo(const DecompAlgoType algo, DecompApp *app)
DecompCutList m_cuts
Containers for cuts (current and pool).
Definition: DecompAlgo.h:175
#define UTIL_DELARR(x)
Definition: UtilMacros.h:29
DecompSubModel m_modelCore
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
Definition: DecompAlgo.h:161
Sparse Matrix Base Class.
DecompVarList m_vars
Containers for variables (current and pool).
Definition: DecompAlgo.h:169
int m_cutCallsRound
Definition: DecompAlgo.h:59
virtual const double * getRowPrice() const
std::vector< double * > getDualRays(int maxNumRays)
const double * getX()
int m_cutsThisRound
Definition: DecompAlgo.h:62
std::vector< DecompSolution * > m_xhatIPFeas
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
Definition: DecompAlgo.h:189
double getTrueUpperBound()
virtual void addCutsToPool(const double *x, DecompCutList &newCuts, int &m_cutsThisCall)
double calcConstant(const int m, const double *u)
void appendVars(DecompVarList &varList)
void setTrueUpperBound(const double ub)
virtual bool isDone()
DecompVarList m_initVars
Definition: DecompAlgo.h:90
OsiSolverInterface * initSolverInterface()
void tighten(int whichModel)
void UtilDeleteListPtr(list< T * > &listPtr, typename list< T * >::iterator first, typename list< T * >::iterator last)
Definition: UtilMacros.h:308
int m_whichCoreModel
Definition: DecompAlgo.h:56
DecompApp * getApp()
DecompAlgo(const DecompAlgoType algo, DecompApp *app, UtilParameters &utilParam, bool doSetup=true)
Default constructors.
Definition: DecompAlgo.h:979
DecompVarPool m_varpool
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
Definition: DecompAlgo.h:170
void printVars(std::ostream *os)
Initial setup of algorithm structures and solver interfaces.
std::map< int, DecompSubModel > m_modelRelax
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
Definition: DecompAlgo.h:162
int m_priceCallsTotal
Definition: DecompAlgo.h:58
void printBasisInfo(OsiSolverInterface *si, std::ostream *os)
Initial setup of algorithm structures and solver interfaces.
int m_cutCallsTotal
Definition: DecompAlgo.h:60
static const char * versionTag
Definition: DecompAlgo.h:47
virtual DecompStatus solutionUpdate(const DecompPhase phase, const bool resolve=true, const int maxInnerIter=COIN_INT_MAX, const int maxOuterIter=COIN_INT_MAX)
Update of the solution vectors (primal and/or dual).
virtual void addVarsToPool(DecompVarList &newVars)
double * m_xhat
Storage for current solution (in x-space).
Definition: DecompAlgo.h:181
double getTrueLowerBound()
const DecompSolution * getXhatIPBest()
virtual const char * getRowSense() const
double m_tub
Definition: DecompAlgo.h:96
DecompAlgoType
Definition: Decomp.h:123
int m_varsThisRound
Definition: DecompAlgo.h:61
Abstract Base Class for describing an interface to a solver.
int m_varsThisCall
Definition: DecompAlgo.h:63
virtual void setMasterBounds(const double *lbs, const double *ubs)
void printCuts(std::ostream *os)
Initial setup of algorithm structures and solver interfaces.
DecompAlgoType m_algo
Type of algorithm for this instance.
Definition: DecompAlgo.h:86
bool isLPFeasible(const double *x, const bool isXSparse=false, const double feasVarTol=1.0e-6, const double feasConTol=1.0e-5)
int m_numOrigCols
Definition: DecompAlgo.h:106
DecompApp * m_app
Pointer to current active DECOMP application.
Definition: DecompAlgo.h:108
virtual int addCutsFromPool()
#define UTIL_DELPTR(x)
Definition: UtilMacros.h:28
void appendVars(DecompVar *var)
std::string m_classTag
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
Definition: DecompAlgo.h:75
void setApp(DecompApp *app)
virtual ~DecompAlgo()
bool isIPFeasible(const double *x, const bool isXSparse=false, const double feasVarTol=1.0e-6, const double feasConTol=1.0e-5, const double intTol=1.0e-5)
OsiSolverInterface * m_masterSI
Solver interface(s) for subproblems (P&#39;).
Definition: DecompAlgo.h:147
double m_bestUpperBound
Definition: DecompAlgo.h:97
DecompSolution * m_xhatIPBest
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
Definition: DecompAlgo.h:190
virtual int generateCuts(double *xhat, DecompCutList &newCuts)
virtual const double * getRowPrice() const =0
Get pointer to array[getNumRows()] of dual variable values.
double * m_piEstimate
Definition: DecompAlgo.h:111
virtual const double * getRightHandSide() const
OsiSolverInterface * getMasterSolverInterface()
DecompCutPool m_cutpool
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
Definition: DecompAlgo.h:176
Base class for DECOMP algorithms.
Definition: DecompAlgo.h:62
double m_tlb
Definition: DecompAlgo.h:95
bool isDualRayInfProof(const double *dualRay, const CoinPackedMatrix *rowMatrix, const double *colLB, const double *colUB, const double *rowRhs, std::ostream *os)
Initial setup of algorithm structures and solver interfaces.
virtual void phaseUpdate(DecompPhase &phase, DecompStatus &status)
Update of the phase for process loop.
std::ostream * m_osLog
Stream for log file (default to stdout).
Definition: DecompAlgo.h:124
void setTrueLowerBound(const double mostNegReducedCost)
int m_whichModel
Definition: DecompAlgo.h:55
virtual int generateInitVars(DecompVarList &initVars)
Generate initial variables for master problem (PC/DC/RC).
std::list< DecompVar * > DecompVarList
Definition: Decomp.h:91
DecompPhase
Definition: Decomp.h:165
The main application class.
Definition: DecompApp.h:48
int m_cutsThisCall
Definition: DecompAlgo.h:64
void createFullMps(const std::string fileName)
Initial setup of algorithm structures and solver interfaces.
virtual int branch(int branchedOnIndex, double branchedOnValue)
void initSetup()
Initial setup of algorithm structures and solver interfaces.
vector< vector< double > > m_optPoint
Definition: DecompAlgo.h:108