Cbc trunk
|
00001 // $Id$ 00002 // Copyright (C) 2002, International Business Machines 00003 // Corporation and others. All Rights Reserved. 00004 // This code is licensed under the terms of the Eclipse Public License (EPL). 00005 00006 // Edwin 11/12/2009 carved from CbcBranchBase 00007 00008 #ifndef CbcObject_H 00009 #define CbcObject_H 00010 00011 #include <string> 00012 #include <vector> 00013 #include "OsiBranchingObject.hpp" 00014 class OsiSolverInterface; 00015 class OsiSolverBranch; 00016 00017 class CbcModel; 00018 class CbcNode; 00019 class CbcNodeInfo; 00020 class CbcBranchingObject; 00021 class OsiChooseVariable; 00022 class CbcObjectUpdateData; 00023 //############################################################################# 00024 00050 // This can be used if object wants to skip strong branching 00051 typedef struct { 00052 CbcBranchingObject * possibleBranch; // what a branch would do 00053 double upMovement; // cost going up (and initial away from feasible) 00054 double downMovement; // cost going down 00055 int numIntInfeasUp ; // without odd ones 00056 int numObjInfeasUp ; // just odd ones 00057 bool finishedUp; // true if solver finished 00058 int numItersUp ; // number of iterations in solver 00059 int numIntInfeasDown ; // without odd ones 00060 int numObjInfeasDown ; // just odd ones 00061 bool finishedDown; // true if solver finished 00062 int numItersDown; // number of iterations in solver 00063 int objectNumber; // Which object it is 00064 int fix; // 0 if no fix, 1 if we can fix up, -1 if we can fix down 00065 } CbcStrongInfo; 00066 00067 class CbcObject : public OsiObject { 00068 00069 public: 00070 00071 // Default Constructor 00072 CbcObject (); 00073 00074 // Useful constructor 00075 CbcObject (CbcModel * model); 00076 00077 // Copy constructor 00078 CbcObject ( const CbcObject &); 00079 00080 // Assignment operator 00081 CbcObject & operator=( const CbcObject& rhs); 00082 00084 virtual CbcObject * clone() const = 0; 00085 00087 virtual ~CbcObject (); 00088 00103 #ifdef CBC_NEW_STYLE_BRANCH 00104 virtual double infeasibility(const OsiBranchingInformation * info, 00105 int &preferredWay) const = 0; 00106 #else 00107 virtual double infeasibility(const OsiBranchingInformation * /*info*/, 00108 int &preferredWay) const { 00109 return infeasibility(preferredWay); 00110 } 00111 virtual double infeasibility(int &/*preferredWay*/) const { 00112 throw CoinError("Need code", "infeasibility", "CbcBranchBase"); 00113 } 00114 #endif 00115 00119 virtual void feasibleRegion() = 0; 00121 virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const; 00122 00127 virtual double feasibleRegion(OsiSolverInterface * solver) const ; 00128 00134 #ifdef CBC_NEW_STYLE_BRANCH 00135 virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) = 0; 00136 #else 00137 virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) { 00138 return createBranch(solver, info, way); 00139 } 00140 virtual CbcBranchingObject * createBranch(OsiSolverInterface * /*solver*/, 00141 const OsiBranchingInformation * /*info*/, int /*way*/) { 00142 throw CoinError("Need code", "createBranch", "CbcBranchBase"); 00143 } 00144 #endif 00145 00150 virtual OsiBranchingObject * createOsiBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const; 00155 virtual OsiSolverBranch * solverBranch() const; 00156 00165 virtual CbcBranchingObject * preferredNewFeasible() const { 00166 return NULL; 00167 } 00168 00177 virtual CbcBranchingObject * notPreferredNewFeasible() const { 00178 return NULL; 00179 } 00180 00185 virtual void resetBounds(const OsiSolverInterface * ) {} 00186 00189 virtual void floorCeiling(double & floorValue, double & ceilingValue, double value, 00190 double tolerance) const; 00191 00195 virtual CbcObjectUpdateData createUpdateInformation(const OsiSolverInterface * solver, 00196 const CbcNode * node, 00197 const CbcBranchingObject * branchingObject); 00198 00200 virtual void updateInformation(const CbcObjectUpdateData & ) {} 00201 00203 inline int id() const { 00204 return id_; 00205 } 00206 00210 inline void setId(int value) { 00211 id_ = value; 00212 } 00213 00216 inline bool optionalObject() const { 00217 return (id_ >= 1000000000 && id_ < 1100000000); 00218 } 00219 00221 inline int position() const { 00222 return position_; 00223 } 00224 00226 inline void setPosition(int position) { 00227 position_ = position; 00228 } 00229 00231 inline void setModel(CbcModel * model) { 00232 model_ = model; 00233 } 00234 00236 inline CbcModel * model() const { 00237 return model_; 00238 } 00239 00241 inline int preferredWay() const { 00242 return preferredWay_; 00243 } 00245 inline void setPreferredWay(int value) { 00246 preferredWay_ = value; 00247 } 00249 virtual void redoSequenceEtc(CbcModel * , int , const int * ) {} 00250 00251 protected: 00253 00255 CbcModel * model_; 00257 int id_; 00259 int position_; 00261 int preferredWay_; 00262 00263 }; 00264 00265 #endif 00266