coin-Bcp
CSP_colgen.hpp
Go to the documentation of this file.
1 // Copyright (C) 2005, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _CSP_COLGEN_H
4 #define _CSP_COLGEN_H
5 
7 
8 #include "CSP.hpp"
9 
10 class UserData;
11 
12 // CSP_subProblem was a private class of the CSP_colgen class
14 public:
15  // The csproblem for which we'll generate columns
18 
21 
22  // number of base rows
23  int nBaseRows;
24 
25  // array of the number of bits needed per item
26  // only the colgen class needs to know this data
27  // which is the same for every subproblem
28  // and calculated in setCsp method
29  int * numBits;
30 
31  // The largest entry in the numBits array
33 
34  // may want to have a pool of knapsack cover cuts in the future
35 
36  // Subproblem may only differ at this point by their bounds
37  // We may expand in the future
38  double* lowerBounds;
39  double* upperBounds;
40 
41  // number of cols in all the subproblems
42  int numCols;
43 
45 
46  // Default constructor
48 
49  // Destructor
51  delete [] lowerBounds;
52  delete [] upperBounds;
53  delete [] numBits;
54  }
55 
56  // Copy Constructor
57  // Declaring only effectively disables these methods so
58  // the code doesn't use the C++ default copy and assignment.
60 
61  // Assignment
63 };
64 
65 //#############################################################################
66 
67 class CSP_colgen {
68 private:
69 
70  //max number of columns in any of the subproblems
71  int maxCols_;
72 
73  // max number of bits for any item in any subproblem
75 
76  // to get the number use subProblems.size();
77  std::vector<CSP_subProblem*> subProblems;
78 
79 
80  // Whether the members set by the setXxx() methods will have to be deleted
81  // upon destructing the object
82  // hack to keep track of which objects need to get cleaned up on exit
83  // CSP doesn't need
84  const bool ownSetMembers;
85 
86  // The cutting stock problem instance for which we'll generate columns
88 
89  // private methods
90 private:
91  void resetColBounds(OsiSolverInterface& si, const int numCols,
92  const double* colLBs, const double* colUBs){
93  int i;
94  for (i=0; i<numCols; ++i){
95  si.setColLower(i,colLBs[i]);
96  si.setColUpper(i,colUBs[i]);
97  }
98  }
99 
101  if (ownSetMembers) {
102  delete csproblem_;
103  }
104  for(size_t i=0; i<subProblems.size(); ++i){
105  delete subProblems[i];
106  }
107  }
108 
109  // public methods
110 public:
111  // constructor.
112  // (Ask LL: The bool variable is to indicate whether to
113  // to delete pointers that are passed via a setXxx() method (?)
114  CSP_colgen(const bool own) : maxCols_(0),
115  maxNumBits_(0),
116  subProblems(),
117  ownSetMembers(own){}
118 
121  }
122 
123  // invoked once in the beginning of BCP
124  // sets up 1-row matrix (knapsack)
125  // binary expansion stuff
126  // has to set up mapping - these binvars correspon to which item
127  // setCSP - e.g., calculate space needed for binary expansions
128  void setCsp(const CSPROBLEM* a, double perturb_factor, int perturb_num);
129 
130  // this routine applies the exclusion contraints to the knapsack problem
131  // invoked exactly once for every searchtree node when we enter the node
132  // adds extra constraints for exclusions
133  void applyExclusions(const std::vector<const PATTERN*> &excl_patterns );
134 
135  // invoked every time you solve an lp relaxation
136  std::vector<PATTERN*>
137  generateColumns(const double* pi, const double detol, const bool feasible);
138 };
139 
140 #endif
virtual void setColLower(int elementIndex, double elementValue)=0
Set a single column lower bound.
double * upperBounds
Definition: CSP_colgen.hpp:39
void gutsOfDestructor()
Definition: CSP_colgen.hpp:100
const bool ownSetMembers
Definition: CSP_colgen.hpp:84
CSP_colgen(const bool own)
Definition: CSP_colgen.hpp:114
int maxNumBits_
Definition: CSP_colgen.hpp:74
double * lowerBounds
Definition: CSP_colgen.hpp:38
std::vector< CSP_subProblem * > subProblems
Definition: CSP_colgen.hpp:77
void resetColBounds(OsiSolverInterface &si, const int numCols, const double *colLBs, const double *colUBs)
Definition: CSP_colgen.hpp:91
virtual void setColUpper(int elementIndex, double elementValue)=0
Set a single column upper bound.
std::vector< PATTERN * > generateColumns(const double *pi, const double detol, const bool feasible)
UserData * user
Definition: CSP_colgen.hpp:17
const CSPROBLEM * csproblem
Definition: CSP_colgen.hpp:16
void applyExclusions(const std::vector< const PATTERN * > &excl_patterns)
Clp Solver Interface.
Abstract Base Class for describing an interface to a solver.
CSP_subProblem & operator=(const CSP_subProblem &)
const CSPROBLEM * csproblem_
Definition: CSP_colgen.hpp:87
double perturb_factor
Definition: CSP_colgen.hpp:19
void setCsp(const CSPROBLEM *a, double perturb_factor, int perturb_num)
OsiClpSolverInterface solver
Definition: CSP_colgen.hpp:44