source: branches/sandbox/Cbc/src/CbcFixingBranchingObject.cpp @ 1293

Last change on this file since 1293 was 1293, checked in by EdwinStraver, 10 years ago
File size: 5.3 KB
Line 
1// Edwin 11/10/2009-- carved out of CbcBranchActual
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
12#include "CoinTypes.hpp"
13#include "OsiSolverInterface.hpp"
14#include "OsiSolverBranch.hpp"
15#include "CbcModel.hpp"
16#include "CbcMessage.hpp"
17#include "CbcFixingBranchingObject.hpp"
18#include "CbcBranchActual.hpp"
19#include "CoinSort.hpp"
20#include "CoinError.hpp"
21
22//##############################################################################
23
24// Default Constructor
25CbcFixingBranchingObject::CbcFixingBranchingObject()
26        : CbcBranchingObject()
27{
28    numberDown_ = 0;
29    numberUp_ = 0;
30    downList_ = NULL;
31    upList_ = NULL;
32}
33
34// Useful constructor
35CbcFixingBranchingObject::CbcFixingBranchingObject (CbcModel * model,
36        int way ,
37        int numberOnDownSide, const int * down,
38        int numberOnUpSide, const int * up)
39        : CbcBranchingObject(model, 0, way, 0.5)
40{
41    numberDown_ = numberOnDownSide;
42    numberUp_ = numberOnUpSide;
43    downList_ = CoinCopyOfArray(down, numberDown_);
44    upList_ = CoinCopyOfArray(up, numberUp_);
45}
46
47// Copy constructor
48CbcFixingBranchingObject::CbcFixingBranchingObject ( const CbcFixingBranchingObject & rhs) : CbcBranchingObject(rhs)
49{
50    numberDown_ = rhs.numberDown_;
51    numberUp_ = rhs.numberUp_;
52    downList_ = CoinCopyOfArray(rhs.downList_, numberDown_);
53    upList_ = CoinCopyOfArray(rhs.upList_, numberUp_);
54}
55
56// Assignment operator
57CbcFixingBranchingObject &
58CbcFixingBranchingObject::operator=( const CbcFixingBranchingObject & rhs)
59{
60    if (this != &rhs) {
61        CbcBranchingObject::operator=(rhs);
62        delete [] downList_;
63        delete [] upList_;
64        numberDown_ = rhs.numberDown_;
65        numberUp_ = rhs.numberUp_;
66        downList_ = CoinCopyOfArray(rhs.downList_, numberDown_);
67        upList_ = CoinCopyOfArray(rhs.upList_, numberUp_);
68    }
69    return *this;
70}
71CbcBranchingObject *
72CbcFixingBranchingObject::clone() const
73{
74    return (new CbcFixingBranchingObject(*this));
75}
76
77
78// Destructor
79CbcFixingBranchingObject::~CbcFixingBranchingObject ()
80{
81    delete [] downList_;
82    delete [] upList_;
83}
84double
85CbcFixingBranchingObject::branch()
86{
87    decrementNumberBranchesLeft();
88    OsiSolverInterface * solver = model_->solver();
89    const double * columnLower = solver->getColLower();
90    int i;
91    // *** for way - up means fix all those in up section
92    if (way_ < 0) {
93#ifdef FULL_PRINT
94        printf("Down Fix ");
95#endif
96        //printf("Down Fix %d\n",numberDown_);
97        for (i = 0; i < numberDown_; i++) {
98            int iColumn = downList_[i];
99            model_->solver()->setColUpper(iColumn, columnLower[iColumn]);
100#ifdef FULL_PRINT
101            printf("Setting bound on %d to lower bound\n", iColumn);
102#endif
103        }
104        way_ = 1;         // Swap direction
105    } else {
106#ifdef FULL_PRINT
107        printf("Up Fix ");
108#endif
109        //printf("Up Fix %d\n",numberUp_);
110        for (i = 0; i < numberUp_; i++) {
111            int iColumn = upList_[i];
112            model_->solver()->setColUpper(iColumn, columnLower[iColumn]);
113#ifdef FULL_PRINT
114            printf("Setting bound on %d to lower bound\n", iColumn);
115#endif
116        }
117        way_ = -1;        // Swap direction
118    }
119#ifdef FULL_PRINT
120    printf("\n");
121#endif
122    return 0.0;
123}
124void
125CbcFixingBranchingObject::print()
126{
127    int i;
128    // *** for way - up means fix all those in up section
129    if (way_ < 0) {
130        printf("Down Fix ");
131        for (i = 0; i < numberDown_; i++) {
132            int iColumn = downList_[i];
133            printf("%d ", iColumn);
134        }
135    } else {
136        printf("Up Fix ");
137        for (i = 0; i < numberUp_; i++) {
138            int iColumn = upList_[i];
139            printf("%d ", iColumn);
140        }
141    }
142    printf("\n");
143}
144
145/** Compare the original object of \c this with the original object of \c
146    brObj. Assumes that there is an ordering of the original objects.
147    This method should be invoked only if \c this and brObj are of the same
148    type.
149    Return negative/0/positive depending on whether \c this is
150    smaller/same/larger than the argument.
151*/
152int
153CbcFixingBranchingObject::compareOriginalObject
154(const CbcBranchingObject* /*brObj*/) const
155{
156    throw("must implement");
157}
158
159/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
160    same type and must have the same original object, but they may have
161    different feasible regions.
162    Return the appropriate CbcRangeCompare value (first argument being the
163    sub/superset if that's the case). In case of overlap (and if \c
164    replaceIfOverlap is true) replace the current branching object with one
165    whose feasible region is the overlap.
166   */
167CbcRangeCompare
168CbcFixingBranchingObject::compareBranchingObject
169(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
170{
171#if 0 //ndef NDEBUG
172    const CbcFixingBranchingObject* br =
173        dynamic_cast<const CbcFixingBranchingObject*>(brObj);
174    assert(br);
175#endif
176    // If two FixingBranchingObject's have the same base object then it's pretty
177    // much guaranteed
178    throw("must implement");
179}
180
181//##############################################################################
Note: See TracBrowser for help on using the repository browser.