CYCLUS
Loading...
Searching...
No Matches
coin_helpers.cc
Go to the documentation of this file.
1
// Copyright (C) 2000, International Business Machines
2
// Corporation and others. All Rights Reserved.
3
// This code is licensed under the terms of the Eclipse Public License (EPL).
4
5
#include "
coin_helpers.h
"
6
7
#include "CoinPackedMatrix.hpp"
8
#include "CoinFloatEqual.hpp"
9
10
/// taken directly from OsiSolverInterface.cpp on 2/17/14 from
11
/// https://projects.coin-or.org/Osi/browser/trunk. Thanks to John Forrest for
12
/// his assistance! Some small changes have been made to the original file.
13
14
namespace
cyclus
{
15
16
// Check two agents against each other. Return nonzero if different.
17
// Ignore names if that set.
18
// May modify both agents by cleaning up
19
20
int
21
differentAgent
(OsiSolverInterface &
lhs
, OsiSolverInterface &
rhs
,
22
bool
/*ignoreNames*/
) {
23
// set reasonable defaults
24
bool
takeHint
;
25
OsiHintStrength
strength
;
26
// Switch off printing if asked to
27
bool
gotHint
= (
lhs
.getHintParam(
OsiDoReducePrint
,
takeHint
,
strength
));
28
assert
(
gotHint
);
29
bool
printStuff
=
true
;
30
// if (strength!=OsiHintIgnore&&takeHint) // always printStuff
31
// printStuff=false;
32
int
returnCode
= 0;
33
int
numberRows
=
lhs
.getNumRows();
34
int
numberColumns
=
lhs
.getNumCols();
35
int
numberIntegers
=
lhs
.getNumIntegers();
36
if
(
numberRows
!=
rhs
.getNumRows() ||
numberColumns
!=
rhs
.getNumCols()) {
37
if
(
printStuff
)
38
printf
(
"** Mismatch on size, this has %d rows, %d columns - rhs has %d rows, %d columns\n"
,
39
numberRows
,
numberColumns
,
rhs
.getNumRows(),
rhs
.getNumCols());
40
return
1000;
41
}
42
if
(
numberIntegers
!=
rhs
.getNumIntegers()) {
43
if
(
printStuff
)
44
printf
(
"** Mismatch on number of integers, this has %d - rhs has %d\n"
,
45
numberIntegers
,
rhs
.getNumIntegers());
46
return
1001;
47
}
48
int
numberErrors1
= 0;
49
int
numberErrors2
= 0;
50
for
(
int
i = 0; i <
numberColumns
; i++) {
51
if
(
lhs
.isInteger(i)) {
52
if
(!
rhs
.isInteger(i))
53
numberErrors1
++;
54
}
else
{
55
if
(
rhs
.isInteger(i))
56
numberErrors2
++;
57
}
58
}
59
if
(
numberErrors1
||
numberErrors2
) {
60
if
(
printStuff
)
61
printf
(
"** Mismatch on integers, %d (this int, rhs not), %d (this not rhs int)\n"
,
62
numberErrors1
,
numberErrors2
);
63
return
1002;
64
}
65
// Arrays
66
const
double
*
rowLower
=
lhs
.getRowLower();
67
const
double
*
rowUpper
=
lhs
.getRowUpper();
68
const
double
*
columnLower
=
lhs
.getColLower();
69
const
double
*
columnUpper
=
lhs
.getColUpper();
70
const
double
*
objective
=
lhs
.getObjCoefficients();
71
const
double
*
rowLower2
=
rhs
.getRowLower();
72
const
double
*
rowUpper2
=
rhs
.getRowUpper();
73
const
double
*
columnLower2
=
rhs
.getColLower();
74
const
double
*
columnUpper2
=
rhs
.getColUpper();
75
const
double
*
objective2
=
rhs
.getObjCoefficients();
76
const
CoinPackedMatrix
*
matrix
=
lhs
.getMatrixByCol();
77
const
CoinPackedMatrix
*
matrix2
=
rhs
.getMatrixByCol();
78
CoinRelFltEq
tolerance
;
79
int
numberDifferentL
= 0;
80
int
numberDifferentU
= 0;
81
for
(
int
i = 0; i <
numberRows
; i++) {
82
if
(!
tolerance
(
rowLower
[i],
rowLower2
[i]))
83
numberDifferentL
++;
84
if
(!
tolerance
(
rowUpper
[i],
rowUpper2
[i]))
85
numberDifferentU
++;
86
}
87
int
n =
numberDifferentL
+
numberDifferentU
;
88
returnCode
+= n;
89
if
(n&&
printStuff
)
90
printf
(
"Row differences , %d lower, %d upper\n"
,
91
numberDifferentL
,
numberDifferentU
);
92
numberDifferentL
= 0;
93
numberDifferentU
= 0;
94
int
numberDifferentO
= 0;
95
for
(
int
i = 0; i <
numberColumns
; i++) {
96
if
(!
tolerance
(
columnLower
[i],
columnLower2
[i]))
97
numberDifferentL
++;
98
if
(!
tolerance
(
columnUpper
[i],
columnUpper2
[i]))
99
numberDifferentU
++;
100
if
(!
tolerance
(
objective
[i],
objective2
[i]))
101
numberDifferentO
++;
102
}
103
n =
numberDifferentL
+
numberDifferentU
+
numberDifferentO
;
104
returnCode
+= n;
105
if
(n&&
printStuff
)
106
printf
(
"Column differences , %d lower, %d upper, %d objective\n"
,
107
numberDifferentL
,
numberDifferentU
,
numberDifferentO
);
108
if
(
matrix
->getNumElements() ==
rhs
.getNumElements()) {
109
if
(!
matrix
->isEquivalent(*
matrix2
,
tolerance
)) {
110
returnCode
+= 100;
111
if
(
printStuff
)
112
printf
(
"Two matrices are not same\n"
);
113
}
114
}
else
{
115
returnCode
+= 200;
116
if
(
printStuff
)
117
printf
(
"Two matrices are not same - %d elements and %d elements\n"
,
118
matrix
->getNumElements(),
matrix2
->getNumElements());
119
}
120
return
returnCode
;
121
}
122
123
}
// namespace cyclus
coin_helpers.h
cyclus
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition
agent.cc:14
cyclus::differentAgent
int differentAgent(OsiSolverInterface &lhs, OsiSolverInterface &rhs, bool)
Definition
coin_helpers.cc:21
cyclus::OptionalQuery
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
Definition
infile_tree.h:121
src
coin_helpers.cc
Generated by
1.10.0