source: stable/2.8/Cbc/src/CbcBranchDynamic.hpp @ 1902

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

Change to EPL license notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: CbcBranchDynamic.hpp 1573 2011-01-05 01:12:36Z stefan $ */
2// Copyright (C) 2005, 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#ifndef CbcBranchDynamic_H
7#define CbcBranchDynamic_H
8
9#include "CoinPackedMatrix.hpp"
10#include "CbcSimpleIntegerDynamicPseudoCost.hpp"
11#include "CbcBranchActual.hpp"
12
13/** Branching decision dynamic class
14
15  This class implements a simple algorithm
16  (betterBranch()) for choosing a branching variable when dynamic pseudo costs.
17*/
18
19class CbcBranchDynamicDecision : public CbcBranchDecision {
20public:
21    // Default Constructor
22    CbcBranchDynamicDecision ();
23
24    // Copy constructor
25    CbcBranchDynamicDecision ( const CbcBranchDynamicDecision &);
26
27    virtual ~CbcBranchDynamicDecision();
28
29    /// Clone
30    virtual CbcBranchDecision * clone() const;
31
32    /// Initialize, <i>e.g.</i> before the start of branch selection at a node
33    virtual void initialize(CbcModel * model);
34
35    /** \brief Compare two branching objects. Return nonzero if \p thisOne is
36           better than \p bestSoFar.
37
38      The routine compares branches using the values supplied in \p numInfUp and
39      \p numInfDn until a solution is found by search, after which it uses the
40      values supplied in \p changeUp and \p changeDn. The best branching object
41      seen so far and the associated parameter values are remembered in the
42      \c CbcBranchDynamicDecision object. The nonzero return value is +1 if the
43      up branch is preferred, -1 if the down branch is preferred.
44
45      As the names imply, the assumption is that the values supplied for
46      \p numInfUp and \p numInfDn will be the number of infeasibilities reported
47      by the branching object, and \p changeUp and \p changeDn will be the
48      estimated change in objective. Other measures can be used if desired.
49
50      Because an \c CbcBranchDynamicDecision object remembers the current best
51      branching candidate (#bestObject_) as well as the values used in the
52      comparison, the parameter \p bestSoFar is redundant, hence unused.
53    */
54    virtual int betterBranch(CbcBranchingObject * thisOne,
55                             CbcBranchingObject * bestSoFar,
56                             double changeUp, int numInfUp,
57                             double changeDn, int numInfDn);
58    /** Sets or gets best criterion so far */
59    virtual void setBestCriterion(double value);
60    virtual double getBestCriterion() const;
61    /** Says whether this method can handle both methods -
62        1 better, 2 best, 3 both */
63    virtual int whichMethod() {
64        return 3;
65    }
66
67    /** Saves a clone of current branching object.  Can be used to update
68        information on object causing branch - after branch */
69    virtual void saveBranchingObject(OsiBranchingObject * object) ;
70    /** Pass in information on branch just done.
71        assumes object can get information from solver */
72    virtual void updateInformation(OsiSolverInterface * solver,
73                                   const CbcNode * node);
74
75
76private:
77
78    /// Illegal Assignment operator
79    CbcBranchDynamicDecision & operator=(const CbcBranchDynamicDecision& rhs);
80
81    /// data
82
83    /// "best" so far
84    double bestCriterion_;
85
86    /// Change up for best
87    double bestChangeUp_;
88
89    /// Number of infeasibilities for up
90    int bestNumberUp_;
91
92    /// Change down for best
93    double bestChangeDown_;
94
95    /// Number of infeasibilities for down
96    int bestNumberDown_;
97
98    /// Pointer to best branching object
99    CbcBranchingObject * bestObject_;
100};
101/** Simple branching object for an integer variable with pseudo costs
102
103  This object can specify a two-way branch on an integer variable. For each
104  arm of the branch, the upper and lower bounds on the variable can be
105  independently specified.
106
107  Variable_ holds the index of the integer variable in the integerVariable_
108  array of the model.
109*/
110
111class CbcDynamicPseudoCostBranchingObject : public CbcIntegerBranchingObject {
112
113public:
114
115    /// Default constructor
116    CbcDynamicPseudoCostBranchingObject ();
117
118    /** Create a standard floor/ceiling branch object
119
120      Specifies a simple two-way branch. Let \p value = x*. One arm of the
121      branch will be is lb <= x <= floor(x*), the other ceil(x*) <= x <= ub.
122      Specify way = -1 to set the object state to perform the down arm first,
123      way = 1 for the up arm.
124    */
125    CbcDynamicPseudoCostBranchingObject (CbcModel *model, int variable,
126                                         int way , double value,
127                                         CbcSimpleIntegerDynamicPseudoCost * object) ;
128
129    /** Create a degenerate branch object
130
131      Specifies a `one-way branch'. Calling branch() for this object will
132      always result in lowerValue <= x <= upperValue. Used to fix a variable
133      when lowerValue = upperValue.
134    */
135
136    CbcDynamicPseudoCostBranchingObject (CbcModel *model, int variable, int way,
137                                         double lowerValue, double upperValue) ;
138
139    /// Copy constructor
140    CbcDynamicPseudoCostBranchingObject ( const CbcDynamicPseudoCostBranchingObject &);
141
142    /// Assignment operator
143    CbcDynamicPseudoCostBranchingObject & operator= (const CbcDynamicPseudoCostBranchingObject& rhs);
144
145    /// Clone
146    virtual CbcBranchingObject * clone() const;
147
148    /// Destructor
149    virtual ~CbcDynamicPseudoCostBranchingObject ();
150
151    /// Does part of constructor
152    void fillPart (int variable,
153                   int way , double value,
154                   CbcSimpleIntegerDynamicPseudoCost * object) ;
155
156    using CbcBranchingObject::branch ;
157    /** \brief Sets the bounds for the variable according to the current arm
158           of the branch and advances the object state to the next arm.
159           This version also changes guessed objective value
160    */
161    virtual double branch();
162
163    /** Some branchingObjects may claim to be able to skip
164        strong branching.  If so they have to fill in CbcStrongInfo.
165        The object mention in incoming CbcStrongInfo must match.
166        Returns nonzero if skip is wanted */
167    virtual int fillStrongInfo( CbcStrongInfo & info);
168
169    /// Change in guessed
170    inline double changeInGuessed() const {
171        return changeInGuessed_;
172    }
173    /// Set change in guessed
174    inline void setChangeInGuessed(double value) {
175        changeInGuessed_ = value;
176    }
177    /// Return object
178    inline CbcSimpleIntegerDynamicPseudoCost * object() const {
179        return object_;
180    }
181    /// Set object
182    inline void setObject(CbcSimpleIntegerDynamicPseudoCost * object) {
183        object_ = object;
184    }
185
186    /** Return the type (an integer identifier) of \c this */
187    virtual CbcBranchObjType type() const {
188        return DynamicPseudoCostBranchObj;
189    }
190
191    // LL: compareOriginalObject and compareBranchingObject are inherited from
192    // CbcIntegerBranchingObject thus need not be declared/defined here. After
193    // all, this kind of branching object is simply using pseudocosts to make
194    // decisions, but once the decisions are made they are the same kind as in
195    // the underlying class.
196
197protected:
198    /// Change in guessed objective value for next branch
199    double changeInGuessed_;
200    /// Pointer back to object
201    CbcSimpleIntegerDynamicPseudoCost * object_;
202
203};
204
205#endif
206
Note: See TracBrowser for help on using the repository browser.