1 | // Copyright (C) 2005, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #if defined(_MSC_VER) |
---|
4 | // Turn off compiler warning about long names |
---|
5 | # pragma warning(disable:4786) |
---|
6 | #endif |
---|
7 | |
---|
8 | #include <cassert> |
---|
9 | #include <cstdio> |
---|
10 | |
---|
11 | #include "CbcStatistics.hpp" |
---|
12 | CbcStatistics & |
---|
13 | CbcStatistics::operator=(const CbcStatistics & rhs) |
---|
14 | { |
---|
15 | if (this != &rhs) { |
---|
16 | value_ = rhs.value_; |
---|
17 | startingObjective_=rhs.startingObjective_; |
---|
18 | endingObjective_=rhs.endingObjective_; |
---|
19 | id_=rhs.id_; |
---|
20 | parentId_=rhs.parentId_; |
---|
21 | way_ = rhs.way_; |
---|
22 | sequence_=rhs.sequence_; |
---|
23 | depth_=rhs.depth_; |
---|
24 | startingInfeasibility_=rhs.startingInfeasibility_; |
---|
25 | endingInfeasibility_=rhs.endingInfeasibility_; |
---|
26 | numberIterations_=rhs.numberIterations_; |
---|
27 | } |
---|
28 | return *this; |
---|
29 | } |
---|
30 | |
---|
31 | CbcStatistics::CbcStatistics () : |
---|
32 | value_ ( 0.0), |
---|
33 | startingObjective_(0.0), |
---|
34 | endingObjective_(COIN_DBL_MAX), |
---|
35 | id_(-1), |
---|
36 | parentId_(-1), |
---|
37 | way_ ( 0), |
---|
38 | sequence_(-1), |
---|
39 | depth_(0), |
---|
40 | startingInfeasibility_(-1), |
---|
41 | endingInfeasibility_(0), |
---|
42 | numberIterations_(0) |
---|
43 | { |
---|
44 | } |
---|
45 | // First or second branch |
---|
46 | CbcStatistics::CbcStatistics(CbcNode * node) |
---|
47 | : endingObjective_(COIN_DBL_MAX), |
---|
48 | endingInfeasibility_(0), |
---|
49 | numberIterations_(0) |
---|
50 | { |
---|
51 | CbcNodeInfo * nodeInfo = node->nodeInfo(); |
---|
52 | CbcNodeInfo * parent = nodeInfo->parent(); |
---|
53 | int numberBranches = nodeInfo->numberBranchesLeft(); |
---|
54 | const CbcBranchingObject * branch = dynamic_cast <const CbcBranchingObject *>(node->branchingObject()); |
---|
55 | startingObjective_=node->objectiveValue(); |
---|
56 | way_=node->way(); |
---|
57 | depth_=node->depth(); |
---|
58 | startingInfeasibility_ = node->numberUnsatisfied(); |
---|
59 | if (branch) { |
---|
60 | sequence_=branch->variable(); |
---|
61 | value_ = branch->value(); |
---|
62 | } else { |
---|
63 | sequence_=-1; |
---|
64 | value_=0.0; |
---|
65 | } |
---|
66 | if (parent) |
---|
67 | parentId_=parent->nodeNumber(); |
---|
68 | else |
---|
69 | parentId_=-1; |
---|
70 | if (numberBranches==2) { |
---|
71 | id_=nodeInfo->nodeNumber(); |
---|
72 | } else { |
---|
73 | way_ *= 10; |
---|
74 | assert (branch); |
---|
75 | CbcModel * model = branch->model(); |
---|
76 | id_=model->getNodeCount2(); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | CbcStatistics::CbcStatistics(const CbcStatistics & rhs) : |
---|
81 | value_ ( rhs.value_), |
---|
82 | startingObjective_(rhs.startingObjective_), |
---|
83 | endingObjective_(rhs.endingObjective_), |
---|
84 | id_(rhs.id_), |
---|
85 | parentId_(rhs.parentId_), |
---|
86 | way_ ( rhs.way_), |
---|
87 | sequence_(rhs.sequence_), |
---|
88 | depth_(rhs.depth_), |
---|
89 | startingInfeasibility_(rhs.startingInfeasibility_), |
---|
90 | endingInfeasibility_(rhs.endingInfeasibility_), |
---|
91 | numberIterations_(rhs.numberIterations_) |
---|
92 | { |
---|
93 | } |
---|
94 | |
---|
95 | CbcStatistics::~CbcStatistics () |
---|
96 | { |
---|
97 | } |
---|
98 | // Update at end of branch |
---|
99 | void |
---|
100 | CbcStatistics::endOfBranch(int numberIterations, double objectiveValue) |
---|
101 | { |
---|
102 | numberIterations_ = numberIterations; |
---|
103 | endingObjective_=objectiveValue; |
---|
104 | } |
---|
105 | // Update number of infeasibilities |
---|
106 | void |
---|
107 | CbcStatistics::updateInfeasibility(int numberInfeasibilities) |
---|
108 | { |
---|
109 | endingInfeasibility_=numberInfeasibilities; |
---|
110 | } |
---|
111 | // Branch found to be infeasible by chooseBranch |
---|
112 | void |
---|
113 | CbcStatistics::sayInfeasible() |
---|
114 | { |
---|
115 | endingObjective_=COIN_DBL_MAX; |
---|
116 | } |
---|
117 | // Just prints |
---|
118 | void |
---|
119 | CbcStatistics::print(const int * sequenceLookup) const |
---|
120 | { |
---|
121 | int sequence=-1; |
---|
122 | if (sequence_>=0) |
---|
123 | sequence = sequenceLookup ? sequenceLookup[sequence_] : sequence_; |
---|
124 | printf("%6d %6d %5d %6d %7.3f %s %s %13.7g (%5d) -> ", |
---|
125 | id_,parentId_,depth_,sequence,value_,abs(way_)==1 ? " left" : "right", |
---|
126 | way_<0 ? "down" : " up ",startingObjective_,startingInfeasibility_); |
---|
127 | if (endingObjective_!=COIN_DBL_MAX) |
---|
128 | if (endingInfeasibility_) |
---|
129 | printf("%13.7g (%5d)\n",endingObjective_,endingInfeasibility_); |
---|
130 | else |
---|
131 | printf("%13.7g ** Solution\n",endingObjective_); |
---|
132 | else |
---|
133 | printf("cutoff\n"); |
---|
134 | } |
---|