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-2017 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 "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 #ifndef SOPLEX_LEGACY
66  bool passedValidation = true;
67  std::string reason = "";
68  Real objViolation = 0.0;
69  Real maxBoundViolation = 0.0;
70  Real maxRowViolation = 0.0;
71  Real maxRedCostViolation = 0.0;
72  Real maxDualViolation = 0.0;
73  Real sumBoundViolation = 0.0;
74  Real sumRowViolation = 0.0;
75  Real sumRedCostViolation = 0.0;
76  Real sumDualViolation = 0.0;
77  Real sol;
78 
79  std::ostream& os = soplex.spxout.getStream(SPxOut::INFO1);
80 
81  if( strncmp(validatesolution, "+infinity", 9 ) == 0 )
82  sol = soplex.realParam(SoPlex::INFTY);
83  else if ( strncmp(validatesolution, "-infinity", 9) == 0 )
84  sol = -soplex.realParam(SoPlex::INFTY);
85  else
86  {
87  sol = atof(validatesolution);
88  }
89 
90  objViolation = spxAbs(sol - soplex.objValueReal());
91  if( ! EQ(objViolation, 0.0, validatetolerance) )
92  {
93  passedValidation = false;
94  reason += "Objective Violation; ";
95  }
96  if( SPxSolver::OPTIMAL == soplex.status() )
97  {
98  soplex.getBoundViolationReal(maxBoundViolation, sumBoundViolation);
99  soplex.getRowViolationReal(maxRowViolation, sumRowViolation);
100  soplex.getRedCostViolationReal(maxRedCostViolation, sumRedCostViolation);
101  soplex.getDualViolationReal(maxDualViolation, sumDualViolation);
102  if( ! LE(maxBoundViolation, validatetolerance) )
103  {
104  passedValidation = false;
105  reason += "Bound Violation; ";
106  }
107  if( ! LE(maxRowViolation, validatetolerance) )
108  {
109  passedValidation = false;
110  reason += "Row Violation; ";
111  }
112  if( ! LE(maxRedCostViolation, validatetolerance) )
113  {
114  passedValidation = false;
115  reason += "Reduced Cost Violation; ";
116  }
117  if( ! LE(maxDualViolation, validatetolerance) )
118  {
119  passedValidation = false;
120  reason += "Dual Violation; ";
121  }
122  }
123 
124  os << "\n";
125  os << "Validation :";
126  if(passedValidation)
127  os << " Success\n";
128  else
129  {
130  reason[reason.length()-2] = ']';
131  os << " Fail [" + reason + "\n";
132  }
133  os << " Objective : " << std::scientific << std::setprecision(8) << objViolation << std::fixed << "\n";
134  os << " Bound : " << std::scientific << std::setprecision(8) << maxBoundViolation << std::fixed << "\n";
135  os << " Row : " << std::scientific << std::setprecision(8) << maxRowViolation << std::fixed << "\n";
136  os << " Reduced Cost : " << std::scientific << std::setprecision(8) << maxRedCostViolation << std::fixed << "\n";
137  os << " Dual : " << std::scientific << std::setprecision(8) << maxDualViolation << std::fixed << "\n";
138 #endif
139 }
140 
141 } /* namespace soplex */
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:3909
bool LE(Real a, Real b, Real eps=Param::epsilon())
returns true iff a <= b + eps
Definition: spxdefines.h:393
bool getRowViolationReal(Real &maxviol, Real &sumviol)
gets violation of constraints; returns true on success
Definition: soplex.cpp:3098
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
double Real
Definition: spxdefines.h:215
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:220
bool getDualViolationReal(Real &maxviol, Real &sumviol)
gets violation of dual multipliers; returns true on success
Definition: soplex.cpp:3194
Real realParam(const RealParam param) const
returns real parameter value
Definition: soplex.cpp:5544
SPxOut spxout
Definition: soplex.h:1441
infinity threshold
Definition: soplex.h:1289
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:375
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:90
bool getBoundViolationReal(Real &maxviol, Real &sumviol)
gets violation of bounds; returns true on success
Definition: soplex.cpp:3059
char * validatesolution
external solution used for validation
Definition: validation.h:35
SPxSolver::Status status() const
returns the current solver status
Definition: soplex.cpp:2892
Validation object for soplex solutions.
bool getRedCostViolationReal(Real &maxviol, Real &sumviol)
gets violation of reduced costs; returns true on success
Definition: soplex.cpp:3140
Real objValueReal()
returns the objective value if a primal solution is available
Definition: soplex.cpp:2948
bool updateValidationTolerance(char *tolerance)
updates the tolerance used for validation
Definition: validation.cpp:49