CbcObject.hpp
Go to the documentation of this file.
1 // Edwin 11/12/2009 carved from CbcBranchBase
2 #ifndef CbcObject_H
3 #define CbcObject_H
4 
5 #include <string>
6 #include <vector>
7 #include "OsiBranchingObject.hpp"
8 class OsiSolverInterface;
9 class OsiSolverBranch;
10 
11 class CbcModel;
12 class CbcNode;
13 class CbcNodeInfo;
14 class CbcBranchingObject;
15 class OsiChooseVariable;
17 //#############################################################################
18 
44 // This can be used if object wants to skip strong branching
45 typedef struct {
46  CbcBranchingObject * possibleBranch; // what a branch would do
47  double upMovement; // cost going up (and initial away from feasible)
48  double downMovement; // cost going down
49  int numIntInfeasUp ; // without odd ones
50  int numObjInfeasUp ; // just odd ones
51  bool finishedUp; // true if solver finished
52  int numItersUp ; // number of iterations in solver
53  int numIntInfeasDown ; // without odd ones
54  int numObjInfeasDown ; // just odd ones
55  bool finishedDown; // true if solver finished
56  int numItersDown; // number of iterations in solver
57  int objectNumber; // Which object it is
58  int fix; // 0 if no fix, 1 if we can fix up, -1 if we can fix down
60 
61 class CbcObject : public OsiObject {
62 
63 public:
64 
65  // Default Constructor
66  CbcObject ();
67 
68  // Useful constructor
70 
71  // Copy constructor
72  CbcObject ( const CbcObject &);
73 
74  // Assignment operator
75  CbcObject & operator=( const CbcObject& rhs);
76 
78  virtual CbcObject * clone() const = 0;
79 
81  virtual ~CbcObject ();
82 
97 #ifdef CBC_NEW_STYLE_BRANCH
98  virtual double infeasibility(const OsiBranchingInformation * info,
99  int &preferredWay) const = 0;
100 #else
101  virtual double infeasibility(const OsiBranchingInformation * /*info*/,
102  int &preferredWay) const {
103  return infeasibility(preferredWay);
104  }
105  virtual double infeasibility(int &/*preferredWay*/) const {
106  throw CoinError("Need code", "infeasibility", "CbcBranchBase");
107  }
108 #endif
109 
113  virtual void feasibleRegion() = 0;
115  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
116 
121  virtual double feasibleRegion(OsiSolverInterface * solver) const ;
122 
128 #ifdef CBC_NEW_STYLE_BRANCH
129  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) = 0;
130 #else
131  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) {
132  return createBranch(solver, info, way);
133  }
134  virtual CbcBranchingObject * createBranch(OsiSolverInterface * /*solver*/,
135  const OsiBranchingInformation * /*info*/, int /*way*/) {
136  throw CoinError("Need code", "createBranch", "CbcBranchBase");
137  }
138 #endif
139 
144  virtual OsiBranchingObject * createOsiBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
149  virtual OsiSolverBranch * solverBranch() const;
150 
160  return NULL;
161  }
162 
172  return NULL;
173  }
174 
179  virtual void resetBounds(const OsiSolverInterface * ) {}
180 
183  virtual void floorCeiling(double & floorValue, double & ceilingValue, double value,
184  double tolerance) const;
185 
189  virtual CbcObjectUpdateData createUpdateInformation(const OsiSolverInterface * solver,
190  const CbcNode * node,
191  const CbcBranchingObject * branchingObject);
192 
194  virtual void updateInformation(const CbcObjectUpdateData & ) {}
195 
197  inline int id() const {
198  return id_;
199  }
200 
204  inline void setId(int value) {
205  id_ = value;
206  }
207 
210  inline bool optionalObject() const {
211  return (id_ >= 1000000000 && id_ < 1100000000);
212  }
213 
215  inline int position() const {
216  return position_;
217  }
218 
220  inline void setPosition(int position) {
222  }
223 
225  inline void setModel(CbcModel * model) {
226  model_ = model;
227  }
228 
230  inline CbcModel * model() const {
231  return model_;
232  }
233 
235  inline int preferredWay() const {
236  return preferredWay_;
237  }
239  inline void setPreferredWay(int value) {
240  preferredWay_ = value;
241  }
243  virtual void redoSequenceEtc(CbcModel * , int , const int * ) {}
244 
245 protected:
247 
249  CbcModel * model_;
251  int id_;
253  int position_;
255  int preferredWay_;
256 
257 };
258 
259 #endif
260 
virtual ~CbcObject()
Destructor.
void setModel(CbcModel *model)
update model
Definition: CbcObject.hpp:225
CbcModel * model_
data
Definition: CbcObject.hpp:249
Abstract branching object base class Now just difference with OsiBranchingObject. ...
int preferredWay_
If -1 down always chosen first, +1 up always, 0 normal.
Definition: CbcObject.hpp:255
virtual double infeasibility(const OsiBranchingInformation *, int &preferredWay) const
Infeasibility of the object.
Definition: CbcObject.hpp:101
virtual CbcObject * clone() const =0
Clone.
virtual CbcBranchingObject * createBranch(OsiSolverInterface *, const OsiBranchingInformation *, int)
Definition: CbcObject.hpp:134
virtual void redoSequenceEtc(CbcModel *, int, const int *)
Redoes data when sequence numbers change.
Definition: CbcObject.hpp:243
virtual OsiBranchingObject * createOsiBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way) const
Create an Osibranching object and indicate which way to branch first.
int position_
Position in object list.
Definition: CbcObject.hpp:253
virtual double infeasibility(int &) const
Definition: CbcObject.hpp:105
Information required to recreate the subproblem at this node.
Definition: CbcNodeInfo.hpp:62
void setId(int value)
Set identifier (normally column number in matrix) but 1000000000 to 1100000000 means optional branchi...
Definition: CbcObject.hpp:204
virtual void resetBounds(const OsiSolverInterface *)
Reset variable bounds to their original values.
Definition: CbcObject.hpp:179
CbcObject & operator=(const CbcObject &rhs)
virtual void updateInformation(const CbcObjectUpdateData &)
Update object by CbcObjectUpdateData.
Definition: CbcObject.hpp:194
virtual CbcBranchingObject * preferredNewFeasible() const
Given a valid solution (with reduced costs, etc.), return a branching object which would give a new f...
Definition: CbcObject.hpp:159
virtual void feasibleRegion()=0
For the variable(s) referenced by the object, look at the current solution and set bounds to match th...
int preferredWay() const
If -1 down always chosen first, +1 up always, 0 normal.
Definition: CbcObject.hpp:235
int id_
Identifier (normally column number in matrix)
Definition: CbcObject.hpp:251
virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way)
Create a branching object and indicate which way to branch first.
Definition: CbcObject.hpp:131
bool optionalObject() const
Return true if optional branching object i.e.
Definition: CbcObject.hpp:210
void setPreferredWay(int value)
Set -1 down always chosen first, +1 up always, 0 normal.
Definition: CbcObject.hpp:239
void setPosition(int position)
Set position in object_ list.
Definition: CbcObject.hpp:220
CbcModel * model() const
Return model.
Definition: CbcObject.hpp:230
virtual CbcBranchingObject * notPreferredNewFeasible() const
Given a valid solution (with reduced costs, etc.), return a branching object which would give a new f...
Definition: CbcObject.hpp:171
int position() const
Get position in object_ list.
Definition: CbcObject.hpp:215
virtual void floorCeiling(double &floorValue, double &ceilingValue, double value, double tolerance) const
Returns floor and ceiling i.e.
virtual CbcObjectUpdateData createUpdateInformation(const OsiSolverInterface *solver, const CbcNode *node, const CbcBranchingObject *branchingObject)
Pass in information on branch just done and create CbcObjectUpdateData instance.
Information required while the node is live.
Definition: CbcNode.hpp:47
Abstract base class for `objects'.
Definition: CbcObject.hpp:45
int id() const
Identifier (normally column number in matrix)
Definition: CbcObject.hpp:197
virtual OsiSolverBranch * solverBranch() const
Create an OsiSolverBranch object.
Simple Branch and bound class.
Definition: CbcModel.hpp:98