1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15
16 /**@file validation.hpp
17 * @brief Validation object for soplex solutions
18 */
19
(1) Event include_recursion: |
#include file "/sapmnt/home1/d029903/my_work/SCIPSoPlex_coverity/scipoptsuite-8.0.1/soplex/src/soplex/validation.h" includes itself: validation.h -> validation.hpp -> validation.h |
(2) Event caretline: |
^ |
20 #include "soplex/validation.h"
21
22 namespace soplex
23 {
24
25 template <class R>
26 bool Validation<R>::updateExternalSolution(const std::string& solution)
27 {
28 validate = true;
29 validatesolution = solution;
30
31 if(solution == "+infinity")
32 {
33 return true;
34 }
35 else if(solution == "-infinity")
36 {
37 return true;
38 }
39 else
40 {
41 char* tailptr;
42 strtod(solution.c_str(), &tailptr);
43
44 if(*tailptr)
45 {
46 //conversion failed because the input wasn't a number
47 return false;
48 }
49 }
50
51 return true;
52 }
53
54
55 /// updates the tolerance used for validation
56 template <class R>
57 bool Validation<R>::updateValidationTolerance(const std::string& tolerance)
58 {
59 char* tailptr;
60 validatetolerance = strtod(tolerance.c_str(), &tailptr);
61
62 if(*tailptr)
63 {
64 //conversion failed because the input wasn't a number
65 return false;
66 }
67
68 return true;
69 }
70
71 template <class R>
72 void Validation<R>::validateSolveReal(SoPlexBase<R>& soplex)
73 {
74 bool passedValidation = true;
75 std::string reason = "";
76 R objViolation = 0.0;
77 R maxBoundViolation = 0.0;
78 R maxRowViolation = 0.0;
79 R maxRedCostViolation = 0.0;
80 R maxDualViolation = 0.0;
81 R sumBoundViolation = 0.0;
82 R sumRowViolation = 0.0;
83 R sumRedCostViolation = 0.0;
84 R sumDualViolation = 0.0;
85 R sol;
86
87 std::ostream& os = soplex.spxout.getStream(SPxOut::INFO1);
88
89 if(validatesolution == "+infinity")
90 {
91 sol = soplex.realParam(SoPlexBase<R>::INFTY);
92 }
93 else if(validatesolution == "-infinity")
94 {
95 sol = -soplex.realParam(SoPlexBase<R>::INFTY);
96 }
97 else
98 {
99 sol = atof(validatesolution.c_str());
100 }
101
102 objViolation = spxAbs(sol - soplex.objValueReal());
103
104 // skip check in case presolving detected infeasibility/unboundedness
105 if(SPxSolverBase<R>::INForUNBD == soplex.status() &&
106 (sol == soplex.realParam(SoPlexBase<R>::INFTY)
107 || sol == -soplex.realParam(SoPlexBase<R>::INFTY)))
108 objViolation = 0.0;
109
110 if(! EQ(objViolation, R(0.0), validatetolerance))
111 {
112 passedValidation = false;
113 reason += "Objective Violation; ";
114 }
115
116 if(SPxSolverBase<R>::OPTIMAL == soplex.status())
117 {
118 soplex.getBoundViolation(maxBoundViolation, sumBoundViolation);
119 soplex.getRowViolation(maxRowViolation, sumRowViolation);
120 soplex.getRedCostViolation(maxRedCostViolation, sumRedCostViolation);
121 soplex.getDualViolation(maxDualViolation, sumDualViolation);
122
123 if(! LE(maxBoundViolation, validatetolerance))
124 {
125 passedValidation = false;
126 reason += "Bound Violation; ";
127 }
128
129 if(! LE(maxRowViolation, validatetolerance))
130 {
131 passedValidation = false;
132 reason += "Row Violation; ";
133 }
134
135 if(! LE(maxRedCostViolation, validatetolerance))
136 {
137 passedValidation = false;
138 reason += "Reduced Cost Violation; ";
139 }
140
141 if(! LE(maxDualViolation, validatetolerance))
142 {
143 passedValidation = false;
144 reason += "Dual Violation; ";
145 }
146 }
147
148 os << "\n";
149 os << "Validation :";
150
151 if(passedValidation)
152 os << " Success\n";
153 else
154 {
155 reason[reason.length() - 2] = ']';
156 os << " Fail [" + reason + "\n";
157 }
158
159 os << " Objective : " << std::scientific << std::setprecision(
160 8) << objViolation << std::fixed << "\n";
161 os << " Bound : " << std::scientific << std::setprecision(
162 8) << maxBoundViolation << std::fixed << "\n";
163 os << " Row : " << std::scientific << std::setprecision(
164 8) << maxRowViolation << std::fixed << "\n";
165 os << " Reduced Cost : " << std::scientific << std::setprecision(
166 8) << maxRedCostViolation << std::fixed << "\n";
167 os << " Dual : " << std::scientific << std::setprecision(
168 8) << maxDualViolation << std::fixed << "\n";
169 }
170
171 } // namespace soplex
172