source: trunk/Cbc/src/CbcStatistics.cpp @ 2464

Last change on this file since 2464 was 2464, checked in by unxusr, 6 months ago

.clang-format with proposal for formatting code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: CbcStatistics.cpp 2464 2019-01-03 19:03:23Z unxusr $ */
2// Copyright (C) 2005, 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#if defined(_MSC_VER)
7// Turn off compiler warning about long names
8#pragma warning(disable : 4786)
9#endif
10
11#include <cassert>
12#include <cstdio>
13
14#include "CbcStatistics.hpp"
15CbcStatistics &
16CbcStatistics::operator=(const CbcStatistics &rhs)
17{
18  if (this != &rhs) {
19    value_ = rhs.value_;
20    startingObjective_ = rhs.startingObjective_;
21    endingObjective_ = rhs.endingObjective_;
22    id_ = rhs.id_;
23    parentId_ = rhs.parentId_;
24    way_ = rhs.way_;
25    sequence_ = rhs.sequence_;
26    depth_ = rhs.depth_;
27    startingInfeasibility_ = rhs.startingInfeasibility_;
28    endingInfeasibility_ = rhs.endingInfeasibility_;
29    numberIterations_ = rhs.numberIterations_;
30  }
31  return *this;
32}
33
34CbcStatistics::CbcStatistics()
35  : value_(0.0)
36  , startingObjective_(0.0)
37  , endingObjective_(COIN_DBL_MAX)
38  , id_(-1)
39  , parentId_(-1)
40  , way_(0)
41  , sequence_(-1)
42  , depth_(0)
43  , startingInfeasibility_(-1)
44  , endingInfeasibility_(0)
45  , numberIterations_(0)
46{
47}
48// First or second branch
49CbcStatistics::CbcStatistics(CbcNode *node, CbcModel *model)
50  : endingObjective_(COIN_DBL_MAX)
51  , endingInfeasibility_(0)
52  , numberIterations_(0)
53{
54  CbcNodeInfo *nodeInfo = node->nodeInfo();
55  CbcNodeInfo *parent = nodeInfo->parent();
56  int numberBranches = nodeInfo->numberBranchesLeft();
57  const CbcBranchingObject *branch = dynamic_cast<const CbcBranchingObject *>(node->branchingObject());
58  const OsiTwoWayBranchingObject *branch2 = dynamic_cast<const OsiTwoWayBranchingObject *>(node->branchingObject());
59  startingObjective_ = node->objectiveValue();
60  way_ = node->way();
61  depth_ = node->depth();
62  startingInfeasibility_ = node->numberUnsatisfied();
63  if (branch) {
64    sequence_ = branch->variable();
65    value_ = branch->value();
66  } else {
67    const OsiSimpleInteger *obj = dynamic_cast<const OsiSimpleInteger *>(branch2->originalObject());
68    assert(obj);
69    sequence_ = obj->columnNumber();
70    value_ = branch2->value();
71  }
72  if (parent)
73    parentId_ = parent->nodeNumber();
74  else
75    parentId_ = -1;
76  if (numberBranches == 2) {
77    id_ = nodeInfo->nodeNumber();
78  } else {
79    way_ *= 10;
80    id_ = model->getNodeCount2();
81  }
82}
83
84CbcStatistics::CbcStatistics(const CbcStatistics &rhs)
85  : value_(rhs.value_)
86  , startingObjective_(rhs.startingObjective_)
87  , endingObjective_(rhs.endingObjective_)
88  , id_(rhs.id_)
89  , parentId_(rhs.parentId_)
90  , way_(rhs.way_)
91  , sequence_(rhs.sequence_)
92  , depth_(rhs.depth_)
93  , startingInfeasibility_(rhs.startingInfeasibility_)
94  , endingInfeasibility_(rhs.endingInfeasibility_)
95  , numberIterations_(rhs.numberIterations_)
96{
97}
98
99CbcStatistics::~CbcStatistics()
100{
101}
102// Update at end of branch
103void CbcStatistics::endOfBranch(int numberIterations, double objectiveValue)
104{
105  numberIterations_ = numberIterations;
106  endingObjective_ = objectiveValue;
107}
108// Update number of infeasibilities
109void CbcStatistics::updateInfeasibility(int numberInfeasibilities)
110{
111  endingInfeasibility_ = numberInfeasibilities;
112}
113// Branch found to be infeasible by chooseBranch
114void CbcStatistics::sayInfeasible()
115{
116  endingObjective_ = COIN_DBL_MAX;
117}
118// Just prints
119void 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}
Note: See TracBrowser for help on using the repository browser.