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

Last change on this file since 2128 was 1573, checked in by lou, 9 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
RevLine 
[1271]1/* $Id: CbcStatistics.cpp 1573 2011-01-05 01:12:36Z forrest $ */
[150]2// Copyright (C) 2005, International Business Machines
3// Corporation and others.  All Rights Reserved.
[1573]4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
[150]6#if defined(_MSC_VER)
7// Turn off compiler warning about long names
8#  pragma warning(disable:4786)
9#endif
[1286]10
[150]11#include <cassert>
12#include <cstdio>
13
14#include "CbcStatistics.hpp"
15CbcStatistics &
16CbcStatistics::operator=(const CbcStatistics & rhs)
17{
[1286]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;
[150]32}
33
34CbcStatistics::CbcStatistics () :
[1286]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)
[150]46{
47}
[1286]48// First or second branch
[881]49CbcStatistics::CbcStatistics(CbcNode * node, CbcModel * model)
[1286]50        :  endingObjective_(COIN_DBL_MAX),
51        endingInfeasibility_(0),
52        numberIterations_(0)
[150]53{
[1286]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    }
[150]82}
83
84CbcStatistics::CbcStatistics(const CbcStatistics & rhs) :
[1286]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_)
[150]96{
97}
98
99CbcStatistics::~CbcStatistics ()
100{
101}
102// Update at end of branch
[1286]103void
[150]104CbcStatistics::endOfBranch(int numberIterations, double objectiveValue)
105{
[1286]106    numberIterations_ = numberIterations;
107    endingObjective_ = objectiveValue;
[150]108}
109// Update number of infeasibilities
[1286]110void
[150]111CbcStatistics::updateInfeasibility(int numberInfeasibilities)
112{
[1286]113    endingInfeasibility_ = numberInfeasibilities;
[150]114}
115// Branch found to be infeasible by chooseBranch
[1286]116void
[150]117CbcStatistics::sayInfeasible()
118{
[1286]119    endingObjective_ = COIN_DBL_MAX;
[150]120}
121// Just prints
[1286]122void
[150]123CbcStatistics::print(const int * sequenceLookup) const
124{
[1286]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_);
[150]136    else
[1286]137        printf("cutoff\n");
[150]138}
[1432]139
Note: See TracBrowser for help on using the repository browser.