Scippy

SoPlex

Sequential object-oriented simPlex

validation.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2019 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.cpp
17  * @brief Validation object for soplex solutions
18  */
19 
20 #include "soplex/validation.h"
21 
22 namespace soplex
23 {
24 
25 /// updates the external solution used for validation
27 {
28  validate = true;
29  validatesolution = solution;
30 
31  if(strncmp(solution, "+infinity", 9) == 0)
32  return true;
33  else if(strncmp(solution, "-infinity", 9) == 0)
34  return true;
35  else
36  {
37  char* tailptr;
38  strtod(solution, &tailptr);
39 
40  if(*tailptr)
41  {
42  //conversion failed because the input wasn't a number
43  return false;
44  }
45  }
46 
47  return true;
48 }
49 
50 
51 
52 /// updates the tolerance used for validation
54 {
55  char* tailptr;
56  validatetolerance = strtod(tolerance, &tailptr);
57 
58  if(*tailptr)
59  {
60  //conversion failed because the input wasn't a number
61  return false;
62  }
63 
64  return true;
65 }
66 
67 
68 
69 /// validates the soplex solution using the external solution
71 {
72  bool passedValidation = true;
73  std::string reason = "";
74  Real objViolation = 0.0;
75  Real maxBoundViolation = 0.0;
76  Real maxRowViolation = 0.0;
77  Real maxRedCostViolation = 0.0;
78  Real maxDualViolation = 0.0;
79  Real sumBoundViolation = 0.0;
80  Real sumRowViolation = 0.0;
81  Real sumRedCostViolation = 0.0;
82  Real sumDualViolation = 0.0;
83  Real sol;
84 
85  std::ostream& os = soplex.spxout.getStream(SPxOut::INFO1);
86 
87  if(strncmp(validatesolution, "+infinity", 9) == 0)
88  sol = soplex.realParam(SoPlex::INFTY);
89  else if(strncmp(validatesolution, "-infinity", 9) == 0)
90  sol = -soplex.realParam(SoPlex::INFTY);
91  else
92  {
93  sol = atof(validatesolution);
94  }
95 
96  objViolation = spxAbs(sol - soplex.objValueReal());
97 
98  // skip check in case presolving detected infeasibility/unboundedness
99  if(SPxSolver::INForUNBD == soplex.status() &&
100  (sol == soplex.realParam(SoPlex::INFTY) || sol == -soplex.realParam(SoPlex::INFTY)))
101  objViolation = 0.0;
102 
103  if(! EQ(objViolation, 0.0, validatetolerance))
104  {
105  passedValidation = false;
106  reason += "Objective Violation; ";
107  }
108 
109  if(SPxSolver::OPTIMAL == soplex.status())
110  {
111  soplex.getBoundViolationReal(maxBoundViolation, sumBoundViolation);
112  soplex.getRowViolationReal(maxRowViolation, sumRowViolation);
113  soplex.getRedCostViolationReal(maxRedCostViolation, sumRedCostViolation);
114  soplex.getDualViolationReal(maxDualViolation, sumDualViolation);
115 
116  if(! LE(maxBoundViolation, validatetolerance))
117  {
118  passedValidation = false;
119  reason += "Bound Violation; ";
120  }
121 
122  if(! LE(maxRowViolation, validatetolerance))
123  {
124  passedValidation = false;
125  reason += "Row Violation; ";
126  }
127 
128  if(! LE(maxRedCostViolation, validatetolerance))
129  {
130  passedValidation = false;
131  reason += "Reduced Cost Violation; ";
132  }
133 
134  if(! LE(maxDualViolation, validatetolerance))
135  {
136  passedValidation = false;
137  reason += "Dual Violation; ";
138  }
139  }
140 
141  os << "\n";
142  os << "Validation :";
143 
144  if(passedValidation)
145  os << " Success\n";
146  else
147  {
148  reason[reason.length() - 2] = ']';
149  os << " Fail [" + reason + "\n";
150  }
151 
152  os << " Objective : " << std::scientific << std::setprecision(
153  8) << objViolation << std::fixed << "\n";
154  os << " Bound : " << std::scientific << std::setprecision(
155  8) << maxBoundViolation << std::fixed << "\n";
156  os << " Row : " << std::scientific << std::setprecision(
157  8) << maxRowViolation << std::fixed << "\n";
158  os << " Reduced Cost : " << std::scientific << std::setprecision(
159  8) << maxRedCostViolation << std::fixed << "\n";
160  os << " Dual : " << std::scientific << std::setprecision(
161  8) << maxDualViolation << std::fixed << "\n";
162 }
163 
164 } /* namespace soplex */
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:4102
bool LE(Real a, Real b, Real eps=Param::epsilon())
returns true iff a <= b + eps
Definition: spxdefines.h:394
bool getRowViolationReal(Real &maxviol, Real &sumviol)
gets violation of constraints; returns true on success
Definition: soplex.cpp:3211
bool updateExternalSolution(char *solution)
updates the external solution used for validation
Definition: validation.cpp:26
std::ostream & getStream(const Verbosity &verbosity) const
Returns the stream for the specified verbosity level.
Definition: spxout.h:157
LP is primal infeasible or unbounded.
Definition: spxsolver.h:223
double Real
Definition: spxdefines.h:218
void validateSolveReal(SoPlex &soplex)
validates the soplex solution using the external solution
Definition: validation.cpp:70
LP has been solved to optimality.
Definition: spxsolver.h:220
bool getDualViolationReal(Real &maxviol, Real &sumviol)
gets violation of dual multipliers; returns true on success
Definition: soplex.cpp:3317
Real realParam(const RealParam param) const
returns real parameter value
Definition: soplex.cpp:5785
SPxOut spxout
Definition: soplex.h:1476
infinity threshold
Definition: soplex.h:1320
double validatetolerance
tolerance used for validation
Definition: validation.h:39
bool EQ(Real a, Real b, Real eps=Param::epsilon())
returns true iff |a-b| <= eps
Definition: spxdefines.h:376
bool validate
should the soplex solution be validated?
Definition: validation.h:33
Everything should be within this namespace.
Preconfigured SoPlex LP-solver.
Definition: soplex.h:89
bool getBoundViolationReal(Real &maxviol, Real &sumviol)
gets violation of bounds; returns true on success
Definition: soplex.cpp:3168
char * validatesolution
external solution used for validation
Definition: validation.h:36
SPxSolver::Status status() const
returns the current solver status
Definition: soplex.cpp:2998
Validation object for soplex solutions.
bool getRedCostViolationReal(Real &maxviol, Real &sumviol)
gets violation of reduced costs; returns true on success
Definition: soplex.cpp:3257
Real objValueReal()
returns the objective value if a primal solution is available
Definition: soplex.cpp:3057
bool updateValidationTolerance(char *tolerance)
updates the tolerance used for validation
Definition: validation.cpp:53