source: branches/heur/Cbc/src/CbcStatistics.cpp @ 885

Last change on this file since 885 was 881, checked in by forrest, 11 years ago

try and get statistics working with osi objects

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
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"
12CbcStatistics &
13CbcStatistics::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
31CbcStatistics::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
46CbcStatistics::CbcStatistics(CbcNode * node, CbcModel * model)
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  const OsiTwoWayBranchingObject * branch2 = dynamic_cast <const OsiTwoWayBranchingObject *>(node->branchingObject());
56  startingObjective_=node->objectiveValue();
57  way_=node->way();
58  depth_=node->depth();
59  startingInfeasibility_ = node->numberUnsatisfied();
60  if (branch) {
61    sequence_=branch->variable();
62    value_ = branch->value();
63  } else {
64    const OsiSimpleInteger * obj = dynamic_cast<const OsiSimpleInteger *>(branch2->originalObject());
65    assert (obj);
66    sequence_=obj->columnNumber();
67    value_=branch2->value();
68  }
69  if (parent)
70    parentId_=parent->nodeNumber();
71  else
72    parentId_=-1;
73  if (numberBranches==2) {
74    id_=nodeInfo->nodeNumber();
75  } else {
76    way_ *= 10;
77    id_=model->getNodeCount2();
78  } 
79}
80
81CbcStatistics::CbcStatistics(const CbcStatistics & rhs) :
82  value_ ( rhs.value_),
83  startingObjective_(rhs.startingObjective_),
84  endingObjective_(rhs.endingObjective_),
85  id_(rhs.id_),
86  parentId_(rhs.parentId_),
87  way_ ( rhs.way_),
88  sequence_(rhs.sequence_),
89  depth_(rhs.depth_),
90  startingInfeasibility_(rhs.startingInfeasibility_),
91  endingInfeasibility_(rhs.endingInfeasibility_),
92  numberIterations_(rhs.numberIterations_)
93{
94}
95
96CbcStatistics::~CbcStatistics ()
97{
98}
99// Update at end of branch
100void 
101CbcStatistics::endOfBranch(int numberIterations, double objectiveValue)
102{
103  numberIterations_ = numberIterations;
104  endingObjective_=objectiveValue;
105}
106// Update number of infeasibilities
107void 
108CbcStatistics::updateInfeasibility(int numberInfeasibilities)
109{
110  endingInfeasibility_=numberInfeasibilities;
111}
112// Branch found to be infeasible by chooseBranch
113void 
114CbcStatistics::sayInfeasible()
115{
116  endingObjective_=COIN_DBL_MAX;
117}
118// Just prints
119void 
120CbcStatistics::print(const int * sequenceLookup) const
121{
122  int sequence=-1;
123  if (sequence_>=0)
124    sequence = sequenceLookup ? sequenceLookup[sequence_] : sequence_;
125  printf("%6d %6d %5d %6d %7.3f %s %s %13.7g (%5d) -> ",
126         id_,parentId_,depth_,sequence,value_,abs(way_)==1 ? " left" : "right",
127         way_<0 ? "down" : " up ",startingObjective_,startingInfeasibility_);
128  if (endingObjective_!=COIN_DBL_MAX)
129    if (endingInfeasibility_)
130      printf("%13.7g (%5d)\n",endingObjective_,endingInfeasibility_);
131    else
132      printf("%13.7g ** Solution\n",endingObjective_);
133  else
134    printf("cutoff\n");
135}
Note: See TracBrowser for help on using the repository browser.