1 | // $Id: CbcObject.cpp 1899 2013-04-09 18:12:08Z tkr $ |
---|
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 | #if defined(_MSC_VER) |
---|
9 | // Turn off compiler warning about long names |
---|
10 | # pragma warning(disable:4786) |
---|
11 | #endif |
---|
12 | #include <cassert> |
---|
13 | #include <cstdlib> |
---|
14 | #include <cmath> |
---|
15 | #include <cfloat> |
---|
16 | |
---|
17 | #include "OsiSolverInterface.hpp" |
---|
18 | #include "OsiSolverBranch.hpp" |
---|
19 | #include "OsiChooseVariable.hpp" |
---|
20 | #include "CbcModel.hpp" |
---|
21 | #include "CbcMessage.hpp" |
---|
22 | #include "CbcBranchBase.hpp" |
---|
23 | |
---|
24 | |
---|
25 | // Default Constructor |
---|
26 | CbcObject::CbcObject() |
---|
27 | : OsiObject(), |
---|
28 | model_(NULL), |
---|
29 | id_(-1), |
---|
30 | position_(-1), |
---|
31 | preferredWay_(0) |
---|
32 | { |
---|
33 | } |
---|
34 | |
---|
35 | // Constructor from model |
---|
36 | CbcObject::CbcObject(CbcModel * model) |
---|
37 | : OsiObject(), |
---|
38 | model_(model), |
---|
39 | id_(-1), |
---|
40 | position_(-1), |
---|
41 | preferredWay_(0) |
---|
42 | { |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | // Destructor |
---|
47 | CbcObject::~CbcObject () |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | // Copy constructor |
---|
52 | CbcObject::CbcObject ( const CbcObject & rhs) |
---|
53 | : OsiObject(rhs) |
---|
54 | { |
---|
55 | model_ = rhs.model_; |
---|
56 | id_ = rhs.id_; |
---|
57 | position_ = rhs.position_; |
---|
58 | preferredWay_ = rhs.preferredWay_; |
---|
59 | } |
---|
60 | |
---|
61 | // Assignment operator |
---|
62 | CbcObject & |
---|
63 | CbcObject::operator=( const CbcObject & rhs) |
---|
64 | { |
---|
65 | if (this != &rhs) { |
---|
66 | OsiObject::operator=(rhs); |
---|
67 | model_ = rhs.model_; |
---|
68 | id_ = rhs.id_; |
---|
69 | position_ = rhs.position_; |
---|
70 | preferredWay_ = rhs.preferredWay_; |
---|
71 | } |
---|
72 | return *this; |
---|
73 | } |
---|
74 | |
---|
75 | /* Returns floor and ceiling i.e. closest valid points |
---|
76 | */ |
---|
77 | void |
---|
78 | CbcObject::floorCeiling(double & floorValue, double & ceilingValue, double value, |
---|
79 | double tolerance) const |
---|
80 | { |
---|
81 | if (fabs(floor(value + 0.5) - value) > tolerance) { |
---|
82 | floorValue = floor(value); |
---|
83 | } else { |
---|
84 | floorValue = floor(value + 0.5); |
---|
85 | } |
---|
86 | ceilingValue = floorValue + 1.0; |
---|
87 | } |
---|
88 | /* For the variable(s) referenced by the object, |
---|
89 | look at the current solution and set bounds to match the solution. |
---|
90 | Returns measure of how much it had to move solution to make feasible |
---|
91 | */ |
---|
92 | double |
---|
93 | CbcObject::feasibleRegion(OsiSolverInterface * /*solver*/) const |
---|
94 | { |
---|
95 | //assert (solver==model_->solver()); |
---|
96 | CbcObject * fudge = const_cast<CbcObject *>(this); |
---|
97 | fudge->feasibleRegion(); |
---|
98 | return 0.0; |
---|
99 | } |
---|
100 | |
---|
101 | /* For the variable(s) referenced by the object, |
---|
102 | look at the current solution and set bounds to match the solution. |
---|
103 | Returns measure of how much it had to move solution to make feasible |
---|
104 | */ |
---|
105 | double |
---|
106 | CbcObject::feasibleRegion(OsiSolverInterface * /*solver*/, |
---|
107 | const OsiBranchingInformation * /*info*/) const |
---|
108 | { |
---|
109 | //assert (solver==model_->solver()); |
---|
110 | CbcObject * fudge = const_cast<CbcObject *>(this); |
---|
111 | fudge->feasibleRegion(); |
---|
112 | return 0.0; |
---|
113 | } |
---|
114 | /* Create a branching object and indicate which way to branch first. |
---|
115 | |
---|
116 | The branching object has to know how to create branches (fix |
---|
117 | variables, etc.) |
---|
118 | */ |
---|
119 | OsiBranchingObject * |
---|
120 | CbcObject::createOsiBranch(OsiSolverInterface * solver, |
---|
121 | const OsiBranchingInformation * info, |
---|
122 | int way) const |
---|
123 | { |
---|
124 | //assert (solver==model_->solver()); |
---|
125 | CbcObject * fudge = const_cast<CbcObject *>(this); |
---|
126 | return fudge->createBranch(solver, info, way); |
---|
127 | } |
---|
128 | /* Create an OsiSolverBranch object |
---|
129 | |
---|
130 | This returns NULL if branch not represented by bound changes |
---|
131 | */ |
---|
132 | OsiSolverBranch * |
---|
133 | CbcObject::solverBranch() const |
---|
134 | { |
---|
135 | return NULL; |
---|
136 | } |
---|
137 | /* Pass in information on branch just done and create CbcObjectUpdateData instance. |
---|
138 | If object does not need data then backward pointer will be NULL. |
---|
139 | Assumes can get information from solver */ |
---|
140 | CbcObjectUpdateData |
---|
141 | CbcObject::createUpdateInformation(const OsiSolverInterface * /*solver*/, |
---|
142 | const CbcNode * /*node*/, |
---|
143 | const CbcBranchingObject * /*branchingObject*/) |
---|
144 | { |
---|
145 | return CbcObjectUpdateData(); |
---|
146 | } |
---|
147 | |
---|