source: branches/sandbox/Cbc/src/CbcBranchDynamic.hpp @ 1351

Last change on this file since 1351 was 1351, checked in by EdwinStraver, 10 years ago

Combined CbcBranchDynamic?.cpp with CbcDynamicPseudoCostBranchingObject?
Combined CbcBranchCut? with CbcCutBranchingObject?
Combined CbcLotsize? with CbcBranchLotsize?.cpp

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