/home/coin/SVN-release/Bcp-1.2.1/Applications/Csp/include/CSP_colgen.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2005, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef _CSP_COLGEN_H
00004 #define _CSP_COLGEN_H
00005 
00006 #include <OsiClpSolverInterface.hpp>
00007 
00008 #include "CSP.hpp"
00009 
00010 class UserData;
00011 
00012 // CSP_subProblem was a private class of the CSP_colgen class
00013 class CSP_subProblem {
00014 public:
00015    // The csproblem for which we'll generate columns
00016    const CSPROBLEM* csproblem;
00017    UserData* user;
00018 
00019    double perturb_factor;
00020    int perturb_num;
00021    
00022    // number of base rows
00023    int nBaseRows;
00024    
00025    // array of the number of bits needed per item 
00026    // only the colgen class needs to know this data
00027    // which is the same for every subproblem
00028    // and calculated in setCsp method
00029    int * numBits;
00030    
00031    // The largest entry in the numBits array
00032    int maxNumBits;
00033    
00034    // may want to have a pool of knapsack cover cuts in the future
00035    
00036    // Subproblem may only differ at this point by their bounds
00037    // We may expand in the future
00038    double* lowerBounds;
00039    double* upperBounds;
00040    
00041    // number of cols in all the subproblems
00042    int numCols;
00043    
00044    OsiClpSolverInterface solver;
00045    
00046    // Default constructor
00047    CSP_subProblem(){}
00048    
00049    // Destructor 
00050    ~CSP_subProblem(){
00051       delete [] lowerBounds;
00052       delete [] upperBounds;
00053       delete [] numBits;
00054    }
00055    
00056    // Copy Constructor
00057    // Declaring only effectively disables these methods so 
00058    // the code doesn't use the C++ default copy and assignment.
00059    CSP_subProblem(const CSP_subProblem&);
00060    
00061    // Assignment
00062    CSP_subProblem& operator=(const CSP_subProblem&);
00063 };
00064 
00065 //#############################################################################
00066 
00067 class CSP_colgen {
00068 private:
00069 
00070   //max number of columns in any of the subproblems
00071   int maxCols_;
00072 
00073   // max number of bits for any item in any subproblem
00074   int maxNumBits_;
00075 
00076   // to get the number use subProblems.size();
00077   std::vector<CSP_subProblem*> subProblems;
00078   
00079 
00080   // Whether the members set by the setXxx() methods will have to be deleted
00081   // upon destructing the object
00082   // hack to keep track of which objects need to get cleaned up on exit
00083   // CSP doesn't need  
00084   const bool ownSetMembers;
00085 
00086   // The cutting stock problem instance for which we'll generate columns
00087   const CSPROBLEM* csproblem_;
00088   
00089   // private methods
00090 private:
00091   void resetColBounds(OsiSolverInterface& si, const int numCols, 
00092                       const double* colLBs, const double* colUBs){
00093     int i;
00094     for (i=0; i<numCols; ++i){
00095       si.setColLower(i,colLBs[i]);
00096       si.setColUpper(i,colUBs[i]);
00097     }
00098   }
00099   
00100   void gutsOfDestructor() {
00101     if (ownSetMembers) {
00102       delete csproblem_;
00103     }
00104     for(size_t i=0; i<subProblems.size(); ++i){
00105       delete subProblems[i];
00106     }
00107   }
00108 
00109   // public methods  
00110 public:
00111   // constructor. 
00112   // (Ask LL: The bool variable is to indicate whether to 
00113   //  to delete pointers that are passed via a setXxx() method (?)
00114   CSP_colgen(const bool own) : maxCols_(0),
00115                                maxNumBits_(0),
00116                                subProblems(),
00117                                ownSetMembers(own){}
00118 
00119   ~CSP_colgen() {
00120     gutsOfDestructor();
00121   }
00122   
00123   // invoked once in the beginning of BCP
00124   // sets up 1-row matrix (knapsack)
00125   // binary expansion stuff
00126   // has to set up mapping - these binvars correspon to which item
00127   // setCSP - e.g., calculate space needed for binary expansions
00128   void setCsp(const CSPROBLEM* a, double perturb_factor, int perturb_num);
00129   
00130   // this routine applies the exclusion contraints to the knapsack problem
00131   // invoked exactly once for every searchtree node when we enter the node
00132   // adds extra constraints for exclusions
00133   void applyExclusions(const std::vector<const PATTERN*> &excl_patterns );
00134   
00135   // invoked every time you solve an lp relaxation
00136   std::vector<PATTERN*>
00137   generateColumns(const double* pi, const double detol, const bool feasible);
00138 };
00139 
00140 #endif

Generated on Thu Jan 15 03:00:58 2009 for coin-Bcp by  doxygen 1.4.7