source: branches/sandbox/Cbc/src/CbcDynamicPseudoCostBranchingObject.cpp @ 1308

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

Broke up CbcBranchDynamic? and CbcBranchLotsize?.cpp.
Updated spreadsheets.

File size: 4.6 KB
Line 
1// Edwin 11/17/2009-- carved out of CbcBranchDynamic
2#if defined(_MSC_VER)
3// Turn off compiler warning about long names
4#  pragma warning(disable:4786)
5#endif
6#include <cassert>
7#include <cstdlib>
8#include <cmath>
9#include <cfloat>
10//#define CBC_DEBUG
11//#define TRACE_ONE 19
12#include "OsiSolverInterface.hpp"
13#include "OsiSolverBranch.hpp"
14#include "CbcModel.hpp"
15#include "CbcMessage.hpp"
16#include "CbcBranchDynamic.hpp"
17#include "CoinSort.hpp"
18#include "CoinError.hpp"
19
20// Default Constructor
21CbcDynamicPseudoCostBranchingObject::CbcDynamicPseudoCostBranchingObject()
22        : CbcIntegerBranchingObject()
23{
24    changeInGuessed_ = 1.0e-5;
25    object_ = NULL;
26}
27
28// Useful constructor
29CbcDynamicPseudoCostBranchingObject::CbcDynamicPseudoCostBranchingObject (CbcModel * model,
30        int variable,
31        int way , double value,
32        CbcSimpleIntegerDynamicPseudoCost * object)
33        : CbcIntegerBranchingObject(model, variable, way, value)
34{
35    changeInGuessed_ = 1.0e-5;
36    object_ = object;
37}
38// Does part of work for constructor
39void
40CbcDynamicPseudoCostBranchingObject::fillPart (int variable,
41        int way , double value,
42        CbcSimpleIntegerDynamicPseudoCost * object)
43{
44    CbcIntegerBranchingObject::fillPart(variable, way, value);
45    changeInGuessed_ = 1.0e-5;
46    object_ = object;
47}
48// Useful constructor for fixing
49CbcDynamicPseudoCostBranchingObject::CbcDynamicPseudoCostBranchingObject (CbcModel * model,
50        int variable, int way,
51        double lowerValue,
52        double /*upperValue*/)
53        : CbcIntegerBranchingObject(model, variable, way, lowerValue)
54{
55    changeInGuessed_ = 1.0e100;
56    object_ = NULL;
57}
58
59
60// Copy constructor
61CbcDynamicPseudoCostBranchingObject::CbcDynamicPseudoCostBranchingObject (
62    const CbcDynamicPseudoCostBranchingObject & rhs)
63        : CbcIntegerBranchingObject(rhs)
64{
65    changeInGuessed_ = rhs.changeInGuessed_;
66    object_ = rhs.object_;
67}
68
69// Assignment operator
70CbcDynamicPseudoCostBranchingObject &
71CbcDynamicPseudoCostBranchingObject::operator=( const CbcDynamicPseudoCostBranchingObject & rhs)
72{
73    if (this != &rhs) {
74        CbcIntegerBranchingObject::operator=(rhs);
75        changeInGuessed_ = rhs.changeInGuessed_;
76        object_ = rhs.object_;
77    }
78    return *this;
79}
80CbcBranchingObject *
81CbcDynamicPseudoCostBranchingObject::clone() const
82{
83    return (new CbcDynamicPseudoCostBranchingObject(*this));
84}
85
86// Destructor
87CbcDynamicPseudoCostBranchingObject::~CbcDynamicPseudoCostBranchingObject ()
88{
89}
90
91/*
92  Perform a branch by adjusting the bounds of the specified variable. Note
93  that each arm of the branch advances the object to the next arm by
94  advancing the value of way_.
95
96  Providing new values for the variable's lower and upper bounds for each
97  branching direction gives a little bit of additional flexibility and will
98  be easily extensible to multi-way branching.
99  Returns change in guessed objective on next branch
100*/
101double
102CbcDynamicPseudoCostBranchingObject::branch()
103{
104    CbcIntegerBranchingObject::branch();
105    return changeInGuessed_;
106}
107/* Some branchingObjects may claim to be able to skip
108   strong branching.  If so they have to fill in CbcStrongInfo.
109   The object mention in incoming CbcStrongInfo must match.
110   Returns nonzero if skip is wanted */
111int
112CbcDynamicPseudoCostBranchingObject::fillStrongInfo( CbcStrongInfo & info)
113{
114    assert (object_);
115    assert (info.possibleBranch == this);
116    info.upMovement = object_->upDynamicPseudoCost() * (ceil(value_) - value_);
117    info.downMovement = object_->downDynamicPseudoCost() * (value_ - floor(value_));
118    info.numIntInfeasUp  -= static_cast<int> (object_->sumUpDecrease() /
119                            (1.0e-12 + static_cast<double> (object_->numberTimesUp())));
120    info.numIntInfeasUp = CoinMax(info.numIntInfeasUp, 0);
121    info.numObjInfeasUp = 0;
122    info.finishedUp = false;
123    info.numItersUp = 0;
124    info.numIntInfeasDown  -= static_cast<int> (object_->sumDownDecrease() /
125                              (1.0e-12 + static_cast<double> (object_->numberTimesDown())));
126    info.numIntInfeasDown = CoinMax(info.numIntInfeasDown, 0);
127    info.numObjInfeasDown = 0;
128    info.finishedDown = false;
129    info.numItersDown = 0;
130    info.fix = 0;
131    if (object_->numberTimesUp() < object_->numberBeforeTrust() +
132            2*object_->numberTimesUpInfeasible() ||
133            object_->numberTimesDown() < object_->numberBeforeTrust() +
134            2*object_->numberTimesDownInfeasible()) {
135        return 0;
136    } else {
137        return 1;
138    }
139}
Note: See TracBrowser for help on using the repository browser.