source: branches/sandbox/Cbc/src/CbcObject.cpp @ 1302

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

Added new files for breakup of CbcBranchBase?

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