Scippy

SoPlex

Sequential object-oriented simPlex

spxquality.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 #include <assert.h>
17 #include <iostream>
18 
19 #include "soplex/spxdefines.h"
20 #include "soplex/spxsolver.h"
21 
22 namespace soplex
23 {
24 
25 void SPxSolver::qualConstraintViolation(Real& maxviol, Real& sumviol) const
26 {
27  maxviol = 0.0;
28  sumviol = 0.0;
29 
30  DVector solu(nCols());
31 
32  getPrimal(solu);
33 
34  for(int row = 0; row < nRows(); ++row)
35  {
36  const SVector& rowvec = rowVector(row);
37 
38  Real val = 0.0;
39 
40  for(int col = 0; col < rowvec.size(); ++col)
41  val += rowvec.value(col) * solu[rowvec.index(col)];
42 
43  Real viol = 0.0;
44 
45  assert(lhs(row) <= rhs(row) + (100 * epsilon()));
46 
47  if(val < lhs(row))
48  viol = spxAbs(val - lhs(row));
49  else if(val > rhs(row))
50  viol = spxAbs(val - rhs(row));
51 
52  if(viol > maxviol)
53  maxviol = viol;
54 
55  sumviol += viol;
56  }
57 }
58 
60  Real& maxviol, Real& sumviol) const
61 {
62  maxviol = 0.0;
63  sumviol = 0.0;
64 
65  DVector solu(nCols());
66 
67  getPrimal(solu);
68 
69  for(int col = 0; col < nCols(); ++col)
70  {
71  assert(lower(col) <= upper(col) + (100 * epsilon()));
72 
73  Real viol = 0.0;
74 
75  if(solu[col] < lower(col))
76  viol = spxAbs(solu[col] - lower(col));
77  else if(solu[col] > upper(col))
78  viol = spxAbs(solu[col] - upper(col));
79 
80  if(viol > maxviol)
81  maxviol = viol;
82 
83  sumviol += viol;
84  }
85 }
86 
87 void SPxSolver::qualSlackViolation(Real& maxviol, Real& sumviol) const
88 {
89  maxviol = 0.0;
90  sumviol = 0.0;
91 
92  DVector solu(nCols());
93  DVector slacks(nRows());
94 
95  getPrimal(solu);
96  getSlacks(slacks);
97 
98  for(int row = 0; row < nRows(); ++row)
99  {
100  const SVector& rowvec = rowVector(row);
101 
102  Real val = 0.0;
103 
104  for(int col = 0; col < rowvec.size(); ++col)
105  val += rowvec.value(col) * solu[rowvec.index(col)];
106 
107  Real viol = spxAbs(val - slacks[row]);
108 
109  if(viol > maxviol)
110  maxviol = viol;
111 
112  sumviol += viol;
113  }
114 }
115 
116 void SPxSolver::qualRedCostViolation(Real& maxviol, Real& sumviol) const
117 {
118  maxviol = 0.0;
119  sumviol = 0.0;
120 
121  int i;
122 
123  // TODO: y = c_B * B^-1 => coSolve(y, c_B)
124  // redcost = c_N - yA_N
125  // solve system "x = e_i^T * B^-1" to get i'th row of B^-1
126  // DVector y( nRows() );
127  // basis().coSolve( x, spx->unitVector( i ) );
128  // DVector rdcost( nCols() );
129  if(type() == ENTER)
130  {
131  for(i = 0; i < dim(); ++i)
132  {
133  Real x = coTest()[i];
134 
135  if(x < 0.0)
136  {
137  sumviol -= x;
138 
139  if(x < maxviol)
140  maxviol = x;
141  }
142  }
143 
144  for(i = 0; i < coDim(); ++i)
145  {
146  Real x = test()[i];
147 
148  if(x < 0.0)
149  {
150  sumviol -= x;
151 
152  if(x < maxviol)
153  maxviol = x;
154  }
155  }
156  }
157  else
158  {
159  assert(type() == LEAVE);
160 
161  for(i = 0; i < dim(); ++i)
162  {
163  Real x = fTest()[i];
164 
165  if(x < 0.0)
166  {
167  sumviol -= x;
168 
169  if(x < maxviol)
170  maxviol = x;
171  }
172  }
173  }
174 
175  maxviol *= -1;
176 }
177 
178 } // namespace soplex
const VectorBase< R > & rhs() const
Returns right hand side vector.
Definition: spxlpbase.h:221
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:4102
const VectorBase< R > & upper() const
Returns upper bound vector.
Definition: spxlpbase.h:461
const Vector & fTest() const
Violations of fVec.
Definition: spxsolver.h:1385
virtual Status getPrimal(Vector &vector) const
get solution vector for primal variables.
Definition: spxsolve.cpp:1842
virtual void qualRedCostViolation(Real &maxviol, Real &sumviol) const
get violation of optimality criterion.
Definition: spxquality.cpp:116
int size() const
Number of used indices.
Definition: svectorbase.h:153
virtual void qualBoundViolation(Real &maxviol, Real &sumviol) const
get violations of bounds.
Definition: spxquality.cpp:59
int dim() const
dimension of basis matrix.
Definition: spxsolver.h:1075
R & value(int n)
Reference to value of n &#39;th nonzero.
Definition: svectorbase.h:253
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:152
Entering Simplex.
Definition: spxsolver.h:134
Leaving Simplex.
Definition: spxsolver.h:143
double Real
Definition: spxdefines.h:218
int & index(int n)
Reference to index of n &#39;th nonzero.
Definition: svectorbase.h:235
main LP solver class
virtual void qualSlackViolation(Real &maxviol, Real &sumviol) const
get the residuum |Ax-b|.
Definition: spxquality.cpp:87
const VectorBase< R > & lhs() const
Returns left hand side vector.
Definition: spxlpbase.h:255
const Vector & test() const
Violations of pVec.
Definition: spxsolver.h:1531
Real epsilon() const
values are considered to be 0.
Definition: spxsolver.h:784
Debugging, floating point type and parameter definitions.
Everything should be within this namespace.
const SVectorBase< R > & rowVector(int i) const
Gets row vector of row i.
Definition: spxlpbase.h:206
const Vector & coTest() const
violations of coPvec.
Definition: spxsolver.h:1465
Type type() const
return current Type.
Definition: spxsolver.h:512
int coDim() const
codimension.
Definition: spxsolver.h:1080
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:158
virtual void qualConstraintViolation(Real &maxviol, Real &sumviol) const
get violation of constraints.
Definition: spxquality.cpp:25
const VectorBase< R > & lower() const
Returns (internal and possibly scaled) lower bound vector.
Definition: spxlpbase.h:488
virtual Status getSlacks(Vector &vector) const
get vector of slack variables.
Definition: spxsolve.cpp:2048