File: CbcStatistics.cpp

package info (click to toggle)
coinor-cbc 2.9.9+repack1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,848 kB
  • ctags: 5,787
  • sloc: cpp: 104,337; sh: 8,921; xml: 2,950; makefile: 520; ansic: 491; awk: 197
file content (139 lines) | stat: -rw-r--r-- 4,319 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* $Id: CbcStatistics.cpp 1573 2011-01-05 01:12:36Z lou $ */
// Copyright (C) 2005, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

#if defined(_MSC_VER)
// Turn off compiler warning about long names
#  pragma warning(disable:4786)
#endif

#include <cassert>
#include <cstdio>

#include "CbcStatistics.hpp"
CbcStatistics &
CbcStatistics::operator=(const CbcStatistics & rhs)
{
    if (this != &rhs) {
        value_ = rhs.value_;
        startingObjective_ = rhs.startingObjective_;
        endingObjective_ = rhs.endingObjective_;
        id_ = rhs.id_;
        parentId_ = rhs.parentId_;
        way_ = rhs.way_;
        sequence_ = rhs.sequence_;
        depth_ = rhs.depth_;
        startingInfeasibility_ = rhs.startingInfeasibility_;
        endingInfeasibility_ = rhs.endingInfeasibility_;
        numberIterations_ = rhs.numberIterations_;
    }
    return *this;
}

CbcStatistics::CbcStatistics () :
        value_ ( 0.0),
        startingObjective_(0.0),
        endingObjective_(COIN_DBL_MAX),
        id_(-1),
        parentId_(-1),
        way_ ( 0),
        sequence_(-1),
        depth_(0),
        startingInfeasibility_(-1),
        endingInfeasibility_(0),
        numberIterations_(0)
{
}
// First or second branch
CbcStatistics::CbcStatistics(CbcNode * node, CbcModel * model)
        :  endingObjective_(COIN_DBL_MAX),
        endingInfeasibility_(0),
        numberIterations_(0)
{
    CbcNodeInfo * nodeInfo = node->nodeInfo();
    CbcNodeInfo * parent = nodeInfo->parent();
    int numberBranches = nodeInfo->numberBranchesLeft();
    const CbcBranchingObject * branch = dynamic_cast <const CbcBranchingObject *>(node->branchingObject());
    const OsiTwoWayBranchingObject * branch2 = dynamic_cast <const OsiTwoWayBranchingObject *>(node->branchingObject());
    startingObjective_ = node->objectiveValue();
    way_ = node->way();
    depth_ = node->depth();
    startingInfeasibility_ = node->numberUnsatisfied();
    if (branch) {
        sequence_ = branch->variable();
        value_ = branch->value();
    } else {
        const OsiSimpleInteger * obj = dynamic_cast<const OsiSimpleInteger *>(branch2->originalObject());
        assert (obj);
        sequence_ = obj->columnNumber();
        value_ = branch2->value();
    }
    if (parent)
        parentId_ = parent->nodeNumber();
    else
        parentId_ = -1;
    if (numberBranches == 2) {
        id_ = nodeInfo->nodeNumber();
    } else {
        way_ *= 10;
        id_ = model->getNodeCount2();
    }
}

CbcStatistics::CbcStatistics(const CbcStatistics & rhs) :
        value_ ( rhs.value_),
        startingObjective_(rhs.startingObjective_),
        endingObjective_(rhs.endingObjective_),
        id_(rhs.id_),
        parentId_(rhs.parentId_),
        way_ ( rhs.way_),
        sequence_(rhs.sequence_),
        depth_(rhs.depth_),
        startingInfeasibility_(rhs.startingInfeasibility_),
        endingInfeasibility_(rhs.endingInfeasibility_),
        numberIterations_(rhs.numberIterations_)
{
}

CbcStatistics::~CbcStatistics ()
{
}
// Update at end of branch
void
CbcStatistics::endOfBranch(int numberIterations, double objectiveValue)
{
    numberIterations_ = numberIterations;
    endingObjective_ = objectiveValue;
}
// Update number of infeasibilities
void
CbcStatistics::updateInfeasibility(int numberInfeasibilities)
{
    endingInfeasibility_ = numberInfeasibilities;
}
// Branch found to be infeasible by chooseBranch
void
CbcStatistics::sayInfeasible()
{
    endingObjective_ = COIN_DBL_MAX;
}
// Just prints
void
CbcStatistics::print(const int * sequenceLookup) const
{
    int sequence = -1;
    if (sequence_ >= 0)
        sequence = sequenceLookup ? sequenceLookup[sequence_] : sequence_;
    printf("%6d %6d %5d %6d %7.3f %s %s %13.7g (%5d) -> ",
           id_, parentId_, depth_, sequence, value_, abs(way_) == 1 ? " left" : "right",
           way_ < 0 ? "down" : " up ", startingObjective_, startingInfeasibility_);
    if (endingObjective_ != COIN_DBL_MAX)
        if (endingInfeasibility_)
            printf("%13.7g (%5d)\n", endingObjective_, endingInfeasibility_);
        else
            printf("%13.7g ** Solution\n", endingObjective_);
    else
        printf("cutoff\n");
}