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

Last change on this file since 2128 was 1573, checked in by lou, 8 years ago

Change to EPL license notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: CbcStatistics.cpp 1573 2011-01-05 01:12:36Z forrest $ */
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
104CbcStatistics::endOfBranch(int numberIterations, double objectiveValue)
105{
106    numberIterations_ = numberIterations;
107    endingObjective_ = objectiveValue;
108}
109// Update number of infeasibilities
110void
111CbcStatistics::updateInfeasibility(int numberInfeasibilities)
112{
113    endingInfeasibility_ = numberInfeasibilities;
114}
115// Branch found to be infeasible by chooseBranch
116void
117CbcStatistics::sayInfeasible()
118{
119    endingObjective_ = COIN_DBL_MAX;
120}
121// Just prints
122void
123CbcStatistics::print(const int * sequenceLookup) const
124{
125    int sequence = -1;
126    if (sequence_ >= 0)
127        sequence = sequenceLookup ? sequenceLookup[sequence_] : sequence_;
128    printf("%6d %6d %5d %6d %7.3f %s %s %13.7g (%5d) -> ",
129           id_, parentId_, depth_, sequence, value_, abs(way_) == 1 ? " left" : "right",
130           way_ < 0 ? "down" : " up ", startingObjective_, startingInfeasibility_);
131    if (endingObjective_ != COIN_DBL_MAX)
132        if (endingInfeasibility_)
133            printf("%13.7g (%5d)\n", endingObjective_, endingInfeasibility_);
134        else
135            printf("%13.7g ** Solution\n", endingObjective_);
136    else
137        printf("cutoff\n");
138}
139
Note: See TracBrowser for help on using the repository browser.