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

Last change on this file since 1432 was 1432, checked in by bjarni, 9 years ago

Added extra return at end of each source file where needed, to remove possible linefeed conflicts (NightlyBuild? errors)

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