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-2018 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 /// updates the external solution used for validation
26 {
27  validate = true;
28  validatesolution = solution;
29 
30  if( strncmp(solution, "+infinity", 9 ) == 0 )
31  return true;
32  else if ( strncmp(solution, "-infinity", 9) == 0 )
33  return true;
34  else
35  {
36  char* tailptr;
37  strtod(solution, &tailptr);
38  if (*tailptr) {
39  //conversion failed because the input wasn't a number
40  return false;
41  }
42  }
43  return true;
44 }
45 
46 
47 
48 /// updates the tolerance used for validation
50 {
51  char* tailptr;
52  validatetolerance = strtod(tolerance, &tailptr);
53  if (*tailptr) {
54  //conversion failed because the input wasn't a number
55  return false;
56  }
57  return true;
58 }
59 
60 
61 
62 /// validates the soplex solution using the external solution
64 {
65  bool passedValidation = true;
66  std::string reason = "";
67  Real objViolation = 0.0;
68  Real maxBoundViolation = 0.0;
69  Real maxRowViolation = 0.0;
70  Real maxRedCostViolation = 0.0;
71  Real maxDualViolation = 0.0;
72  Real sumBoundViolation = 0.0;
73  Real sumRowViolation = 0.0;
74  Real sumRedCostViolation = 0.0;
75  Real sumDualViolation = 0.0;
76  Real sol;
77 
78  std::ostream& os = soplex.spxout.getStream(SPxOut::INFO1);
79 
80  if( strncmp(validatesolution, "+infinity", 9 ) == 0 )
81  sol = soplex.realParam(SoPlex::INFTY);
82  else if ( strncmp(validatesolution, "-infinity", 9) == 0 )
83  sol = -soplex.realParam(SoPlex::INFTY);
84  else
85  {
86  sol = atof(validatesolution);
87  }
88 
89  objViolation = spxAbs(sol - soplex.objValueReal());
90  // skip check in case presolving detected infeasibility/unboundedness
91  if( SPxSolver::INForUNBD == soplex.status() &&
92  (sol == soplex.realParam(SoPlex::INFTY) || sol == -soplex.realParam(SoPlex::INFTY)) )
93  objViolation = 0.0;
94  if( ! EQ(objViolation, 0.0, validatetolerance) )
95  {
96  passedValidation = false;
97  reason += "Objective Violation; ";
98  }
99  if( SPxSolver::OPTIMAL == soplex.status() )
100  {
101  soplex.getBoundViolationReal(maxBoundViolation, sumBoundViolation);
102  soplex.getRowViolationReal(maxRowViolation, sumRowViolation);
103  soplex.getRedCostViolationReal(maxRedCostViolation, sumRedCostViolation);
104  soplex.getDualViolationReal(maxDualViolation, sumDualViolation);
105  if( ! LE(maxBoundViolation, validatetolerance) )
106  {
107  passedValidation = false;
108  reason += "Bound Violation; ";
109  }
110  if( ! LE(maxRowViolation, validatetolerance) )
111  {
112  passedValidation = false;
113  reason += "Row Violation; ";
114  }
115  if( ! LE(maxRedCostViolation, validatetolerance) )
116  {
117  passedValidation = false;
118  reason += "Reduced Cost Violation; ";
119  }
120  if( ! LE(maxDualViolation, validatetolerance) )
121  {
122  passedValidation = false;
123  reason += "Dual Violation; ";
124  }
125  }
126 
127  os << "\n";
128  os << "Validation :";
129  if(passedValidation)
130  os << " Success\n";
131  else
132  {
133  reason[reason.length()-2] = ']';
134  os << " Fail [" + reason + "\n";
135  }
136  os << " Objective : " << std::scientific << std::setprecision(8) << objViolation << std::fixed << "\n";
137  os << " Bound : " << std::scientific << std::setprecision(8) << maxBoundViolation << std::fixed << "\n";
138  os << " Row : " << std::scientific << std::setprecision(8) << maxRowViolation << std::fixed << "\n";
139  os << " Reduced Cost : " << std::scientific << std::setprecision(8) << maxRedCostViolation << std::fixed << "\n";
140  os << " Dual : " << std::scientific << std::setprecision(8) << maxDualViolation << std::fixed << "\n";
141 }
142 
143 } /* namespace soplex */
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:3908
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:3105
bool updateExternalSolution(char *solution)
updates the external solution used for validation
Definition: validation.cpp:25
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:222
double Real
Definition: spxdefines.h:218
void validateSolveReal(SoPlex &soplex)
validates the soplex solution using the external solution
Definition: validation.cpp:63
LP has been solved to optimality.
Definition: spxsolver.h:219
bool getDualViolationReal(Real &maxviol, Real &sumviol)
gets violation of dual multipliers; returns true on success
Definition: soplex.cpp:3201
Real realParam(const RealParam param) const
returns real parameter value
Definition: soplex.cpp:5551
SPxOut spxout
Definition: soplex.h:1457
infinity threshold
Definition: soplex.h:1305
double validatetolerance
tolerance used for validation
Definition: validation.h:38
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:32
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:3066
char * validatesolution
external solution used for validation
Definition: validation.h:35
SPxSolver::Status status() const
returns the current solver status
Definition: soplex.cpp:2899
Validation object for soplex solutions.
bool getRedCostViolationReal(Real &maxviol, Real &sumviol)
gets violation of reduced costs; returns true on success
Definition: soplex.cpp:3147
Real objValueReal()
returns the objective value if a primal solution is available
Definition: soplex.cpp:2955
bool updateValidationTolerance(char *tolerance)
updates the tolerance used for validation
Definition: validation.cpp:49