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-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 #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
50  if (val > rhs( row ))
51  viol = spxAbs(val - rhs( row ));
52 
53  if (viol > maxviol)
54  maxviol = viol;
55 
56  sumviol += viol;
57  }
58 }
59 
61  Real& maxviol, Real& sumviol) const
62 {
63  maxviol = 0.0;
64  sumviol = 0.0;
65 
66  DVector solu( nCols() );
67 
68  getPrimal( solu );
69 
70  for( int col = 0; col < nCols(); ++col )
71  {
72  assert(lower( col ) <= upper( col ) + (100 * epsilon()));
73 
74  Real viol = 0.0;
75 
76  if (solu[col] < lower( col ))
77  viol = spxAbs( solu[col] - lower( col ));
78  else
79  if (solu[col] > upper( col ))
80  viol = spxAbs( solu[col] - upper( col ));
81 
82  if (viol > maxviol)
83  maxviol = viol;
84 
85  sumviol += viol;
86  }
87 }
88 
89 void SPxSolver::qualSlackViolation(Real& maxviol, Real& sumviol) const
90 {
91  maxviol = 0.0;
92  sumviol = 0.0;
93 
94  DVector solu( nCols() );
95  DVector slacks( nRows() );
96 
97  getPrimal( solu );
98  getSlacks( slacks );
99 
100  for( int row = 0; row < nRows(); ++row )
101  {
102  const SVector& rowvec = rowVector( row );
103 
104  Real val = 0.0;
105 
106  for( int col = 0; col < rowvec.size(); ++col )
107  val += rowvec.value( col ) * solu[rowvec.index( col )];
108 
109  Real viol = spxAbs(val - slacks[row]);
110 
111  if (viol > maxviol)
112  maxviol = viol;
113 
114  sumviol += viol;
115  }
116 }
117 
118 void SPxSolver::qualRedCostViolation(Real& maxviol, Real& sumviol) const
119 {
120  maxviol = 0.0;
121  sumviol = 0.0;
122 
123  int i;
124  // TODO: y = c_B * B^-1 => coSolve(y, c_B)
125  // redcost = c_N - yA_N
126  // solve system "x = e_i^T * B^-1" to get i'th row of B^-1
127  // DVector y( nRows() );
128  // basis().coSolve( x, spx->unitVector( i ) );
129  // DVector rdcost( nCols() );
130  if (type() == ENTER)
131  {
132  for(i = 0; i < dim(); ++i)
133  {
134  Real x = coTest()[i];
135 
136  if (x < 0.0)
137  {
138  sumviol -= x;
139 
140  if (x < maxviol)
141  maxviol = x;
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  maxviol *= -1;
175 }
176 
177 } // namespace soplex
const VectorBase< R > & rhs() const
Returns right hand side vector.
Definition: spxlpbase.h:219
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:3908
const VectorBase< R > & upper() const
Returns upper bound vector.
Definition: spxlpbase.h:456
const Vector & fTest() const
Violations of fVec.
Definition: spxsolver.h:1364
virtual Status getPrimal(Vector &vector) const
get solution vector for primal variables.
Definition: spxsolve.cpp:1729
virtual void qualRedCostViolation(Real &maxviol, Real &sumviol) const
get violation of optimality criterion.
Definition: spxquality.cpp:118
int size() const
Number of used indices.
Definition: svectorbase.h:152
virtual void qualBoundViolation(Real &maxviol, Real &sumviol) const
get violations of bounds.
Definition: spxquality.cpp:60
int dim() const
dimension of basis matrix.
Definition: spxsolver.h:1054
R & value(int n)
Reference to value of n &#39;th nonzero.
Definition: svectorbase.h:252
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:151
Entering Simplex.
Definition: spxsolver.h:133
Leaving Simplex.
Definition: spxsolver.h:142
double Real
Definition: spxdefines.h:218
int & index(int n)
Reference to index of n &#39;th nonzero.
Definition: svectorbase.h:234
main LP solver class
virtual void qualSlackViolation(Real &maxviol, Real &sumviol) const
get the residuum |Ax-b|.
Definition: spxquality.cpp:89
const VectorBase< R > & lhs() const
Returns left hand side vector.
Definition: spxlpbase.h:253
const Vector & test() const
Violations of pVec.
Definition: spxsolver.h:1510
Real epsilon() const
values are considered to be 0.
Definition: spxsolver.h:765
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:204
const Vector & coTest() const
violations of coPvec.
Definition: spxsolver.h:1444
Type type() const
return current Type.
Definition: spxsolver.h:493
int coDim() const
codimension.
Definition: spxsolver.h:1059
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:157
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:483
virtual Status getSlacks(Vector &vector) const
get vector of slack variables.
Definition: spxsolve.cpp:1888