source: trunk/Cbc/src/CbcBranchingObject.hpp @ 1573

Last change on this file since 1573 was 1573, checked in by lou, 8 years ago

Change to EPL license notice.

File size: 7.6 KB
Line 
1// $Id$
2// Copyright (C) 2002, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6// Edwin 11/12/2009 carved from CbcBranchBase
7
8#ifndef CbcBranchingObject_H
9#define CbcBranchingObject_H
10
11#include <string>
12#include <vector>
13#include "CbcBranchBase.hpp"
14#include "OsiBranchingObject.hpp"
15
16
17// The types of objects that will be derived from this class.
18enum CbcBranchObjType
19  {
20    SimpleIntegerBranchObj = 100,
21    SimpleIntegerDynamicPseudoCostBranchObj = 101,
22    CliqueBranchObj = 102,
23    LongCliqueBranchObj = 103,
24    SoSBranchObj = 104,
25    NWayBranchObj = 105,
26    FollowOnBranchObj = 106,
27    DummyBranchObj = 107,
28    GeneralDepthBranchObj = 108,
29    OneGeneralBranchingObj = 110,
30    CutBranchingObj = 200,
31    LotsizeBranchObj = 300,
32    DynamicPseudoCostBranchObj = 400
33  };
34
35/** \brief Abstract branching object base class
36    Now just difference with OsiBranchingObject
37
38  In the abstract, an CbcBranchingObject contains instructions for how to
39  branch. We want an abstract class so that we can describe how to branch on
40  simple objects (<i>e.g.</i>, integers) and more exotic objects
41  (<i>e.g.</i>, cliques or hyperplanes).
42
43  The #branch() method is the crucial routine: it is expected to be able to
44  step through a set of branch arms, executing the actions required to create
45  each subproblem in turn. The base class is primarily virtual to allow for
46  a wide range of problem modifications.
47
48  See CbcObject for an overview of the three classes (CbcObject,
49  CbcBranchingObject, and CbcBranchDecision) which make up cbc's branching
50  model.
51*/
52
53class CbcBranchingObject : public OsiBranchingObject {
54
55public:
56
57    /// Default Constructor
58    CbcBranchingObject ();
59
60    /// Constructor
61    CbcBranchingObject (CbcModel * model, int variable, int way , double value);
62
63    /// Copy constructor
64    CbcBranchingObject ( const CbcBranchingObject &);
65
66    /// Assignment operator
67    CbcBranchingObject & operator=( const CbcBranchingObject& rhs);
68
69    /// Clone
70    virtual CbcBranchingObject * clone() const = 0;
71
72    /// Destructor
73    virtual ~CbcBranchingObject ();
74
75    /** Some branchingObjects may claim to be able to skip
76        strong branching.  If so they have to fill in CbcStrongInfo.
77        The object mention in incoming CbcStrongInfo must match.
78        Returns nonzero if skip is wanted */
79    virtual int fillStrongInfo( CbcStrongInfo & ) {
80        return 0;
81    }
82    /// Reset number of branches left to original
83    inline void resetNumberBranchesLeft() {
84        branchIndex_ = 0;
85    }
86    /// Set number of branches to do
87    inline void setNumberBranches(int value) {
88        branchIndex_ = 0;
89        numberBranches_ = value;
90    }
91
92    /** \brief Execute the actions required to branch, as specified by the
93           current state of the branching object, and advance the object's
94           state.  Mainly for diagnostics, whether it is true branch or
95           strong branching is also passed.
96           Returns change in guessed objective on next branch
97    */
98    virtual double branch() = 0;
99    /** \brief Execute the actions required to branch, as specified by the
100           current state of the branching object, and advance the object's
101           state.  Mainly for diagnostics, whether it is true branch or
102           strong branching is also passed.
103           Returns change in guessed objective on next branch
104    */
105    virtual double branch(OsiSolverInterface * ) {
106        return branch();
107    }
108    /** Update bounds in solver as in 'branch' and update given bounds.
109        branchState is -1 for 'down' +1 for 'up' */
110    virtual void fix(OsiSolverInterface * ,
111                     double * , double * ,
112                     int ) const {}
113
114    /** Reset every information so that the branching object appears to point to
115        the previous child. This method does not need to modify anything in any
116        solver. */
117    virtual void previousBranch() {
118        assert(branchIndex_ > 0);
119        branchIndex_--;
120        way_ = -way_;
121    }
122
123    using OsiBranchingObject::print ;
124    /** \brief Print something about branch - only if log level high
125    */
126    virtual void print() const {}
127
128    /** \brief Index identifying the associated CbcObject within its class.
129
130      The name is misleading, and typically the index will <i>not</i> refer
131      directly to a variable.
132      Rather, it identifies an CbcObject within the class of similar
133      CbcObjects
134
135      <i>E.g.</i>, for an CbcSimpleInteger, variable() is the index of the
136      integer variable in the set of integer variables (<i>not</i> the index of
137      the variable in the set of all variables).
138    */
139    inline int variable() const {
140        return variable_;
141    }
142
143    /** Get the state of the branching object
144
145      Returns a code indicating the active arm of the branching object.
146      The precise meaning is defined in the derived class.
147
148      \sa #way_
149    */
150    inline int way() const {
151        return way_;
152    }
153
154    /** Set the state of the branching object.
155
156      See #way()
157    */
158    inline void way(int way) {
159        way_ = way;
160    }
161
162    /// update model
163    inline void setModel(CbcModel * model) {
164        model_ = model;
165    }
166    /// Return model
167    inline CbcModel * model() const {
168        return  model_;
169    }
170
171    /// Return pointer back to object which created
172    inline CbcObject * object() const {
173        return  originalCbcObject_;
174    }
175    /// Set pointer back to object which created
176    inline void setOriginalObject(CbcObject * object) {
177        originalCbcObject_ = object;
178    }
179
180    // Methods used in heuristics
181
182    /** Return the type (an integer identifier) of \c this.
183        See definition of CbcBranchObjType above for possibilities
184    */
185   
186    virtual CbcBranchObjType type() const = 0;
187
188    /** Compare the original object of \c this with the original object of \c
189        brObj. Assumes that there is an ordering of the original objects.
190        This method should be invoked only if \c this and brObj are of the same
191        type.
192        Return negative/0/positive depending on whether \c this is
193        smaller/same/larger than the argument.
194    */
195    virtual int compareOriginalObject(const CbcBranchingObject* brObj) const {
196        const CbcBranchingObject* br = dynamic_cast<const CbcBranchingObject*>(brObj);
197        return variable() - br->variable();
198    }
199
200    /** Compare the \c this with \c brObj. \c this and \c brObj must be of the
201        same type and must have the same original object, but they may have
202        different feasible regions.
203        Return the appropriate CbcRangeCompare value (first argument being the
204        sub/superset if that's the case). In case of overlap (and if \c
205        replaceIfOverlap is true) replace the current branching object with one
206        whose feasible region is the overlap.
207     */
208    virtual CbcRangeCompare compareBranchingObject
209    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false) = 0;
210
211protected:
212
213    /// The model that owns this branching object
214    CbcModel * model_;
215    /// Pointer back to object which created
216    CbcObject * originalCbcObject_;
217
218    /// Branching variable (0 is first integer)
219    int variable_;
220    // was - Way to branch - -1 down (first), 1 up, -2 down (second), 2 up (second)
221    /** The state of the branching object.
222
223      Specifies the active arm of the branching object. Coded as -1 to take
224      the `down' arm, +1 for the `up' arm. `Down' and `up' are defined based on
225      the natural meaning (floor and ceiling, respectively) for a simple integer.
226      The precise meaning is defined in the derived class.
227    */
228    int way_;
229
230};
231#endif
232
Note: See TracBrowser for help on using the repository browser.