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
14namespace 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
20int differentAgent(OsiSolverInterface& lhs, OsiSolverInterface& rhs,
21 bool /*ignoreNames*/) {
22 // set reasonable defaults
23 bool takeHint;
24 OsiHintStrength strength;
25 // Switch off printing if asked to
26 bool gotHint = (lhs.getHintParam(OsiDoReducePrint, takeHint, strength));
27 assert(gotHint);
28 bool printStuff = true;
29 // if (strength!=OsiHintIgnore&&takeHint) // always printStuff
30 // printStuff=false;
31 int returnCode = 0;
32 int numberRows = lhs.getNumRows();
33 int numberColumns = lhs.getNumCols();
34 int numberIntegers = lhs.getNumIntegers();
35 if (numberRows != rhs.getNumRows() || numberColumns != rhs.getNumCols()) {
36 if (printStuff)
37 printf(
38 "** Mismatch on size, this has %d rows, %d columns - rhs has %d "
39 "rows, %d columns\n",
40 numberRows, numberColumns, rhs.getNumRows(), rhs.getNumCols());
41 return 1000;
42 }
43 if (numberIntegers != rhs.getNumIntegers()) {
44 if (printStuff)
45 printf("** Mismatch on number of integers, this has %d - rhs has %d\n",
46 numberIntegers, rhs.getNumIntegers());
47 return 1001;
48 }
49 int numberErrors1 = 0;
50 int numberErrors2 = 0;
51 for (int i = 0; i < numberColumns; i++) {
52 if (lhs.isInteger(i)) {
53 if (!rhs.isInteger(i)) numberErrors1++;
54 } else {
55 if (rhs.isInteger(i)) numberErrors2++;
56 }
57 }
58 if (numberErrors1 || numberErrors2) {
59 if (printStuff)
60 printf(
61 "** Mismatch on integers, %d (this int, rhs not), %d (this not rhs "
62 "int)\n",
63 numberErrors1, numberErrors2);
64 return 1002;
65 }
66 // Arrays
67 const double* rowLower = lhs.getRowLower();
68 const double* rowUpper = lhs.getRowUpper();
69 const double* columnLower = lhs.getColLower();
70 const double* columnUpper = lhs.getColUpper();
71 const double* objective = lhs.getObjCoefficients();
72 const double* rowLower2 = rhs.getRowLower();
73 const double* rowUpper2 = rhs.getRowUpper();
74 const double* columnLower2 = rhs.getColLower();
75 const double* columnUpper2 = rhs.getColUpper();
76 const double* objective2 = rhs.getObjCoefficients();
77 const CoinPackedMatrix* matrix = lhs.getMatrixByCol();
78 const CoinPackedMatrix* matrix2 = rhs.getMatrixByCol();
79 CoinRelFltEq tolerance;
80 int numberDifferentL = 0;
81 int numberDifferentU = 0;
82 for (int i = 0; i < numberRows; i++) {
83 if (!tolerance(rowLower[i], rowLower2[i])) numberDifferentL++;
84 if (!tolerance(rowUpper[i], rowUpper2[i])) numberDifferentU++;
85 }
86 int n = numberDifferentL + numberDifferentU;
87 returnCode += n;
88 if (n && printStuff)
89 printf("Row differences , %d lower, %d upper\n", numberDifferentL,
90 numberDifferentU);
91 numberDifferentL = 0;
92 numberDifferentU = 0;
93 int numberDifferentO = 0;
94 for (int i = 0; i < numberColumns; i++) {
95 if (!tolerance(columnLower[i], columnLower2[i])) numberDifferentL++;
96 if (!tolerance(columnUpper[i], columnUpper2[i])) numberDifferentU++;
97 if (!tolerance(objective[i], objective2[i])) numberDifferentO++;
98 }
99 n = numberDifferentL + numberDifferentU + numberDifferentO;
100 returnCode += n;
101 if (n && printStuff)
102 printf("Column differences , %d lower, %d upper, %d objective\n",
103 numberDifferentL, numberDifferentU, numberDifferentO);
104 if (matrix->getNumElements() == rhs.getNumElements()) {
105 if (!matrix->isEquivalent(*matrix2, tolerance)) {
106 returnCode += 100;
107 if (printStuff) printf("Two matrices are not same\n");
108 }
109 } else {
110 returnCode += 200;
111 if (printStuff)
112 printf("Two matrices are not same - %d elements and %d elements\n",
113 matrix->getNumElements(), matrix2->getNumElements());
114 }
115 return returnCode;
116}
117
118} // namespace cyclus
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
int differentAgent(OsiSolverInterface &lhs, OsiSolverInterface &rhs, bool)