Scippy

SoPlex

Sequential object-oriented simPlex

spxvectorst.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/spxvectorst.h"
21 
22 namespace soplex
23 {
24 
26 {
27  if(state == PVEC)
28  {
29  if(vec.dim() != base.nCols())
30  {
32  return;
33  }
34 
35  const Vector& obj = base.maxObj();
36  Real eps = base.epsilon();
37  Real bias = 10000 * eps;
38  Real x, y;
39  int i;
40 
41  MSG_DEBUG(std::cout << "DVECST01 colWeight[]: ";)
42 
43  for(i = base.nCols(); i--;)
44  {
45  x = vec[i] - base.SPxLP::lower(i);
46  y = base.SPxLP::upper(i) - vec[i];
47 
48  if(x < y)
49  {
50  colWeight[i] = -x - bias * obj[i];
51  colUp[i] = 0;
52  }
53  else
54  {
55  colWeight[i] = -y + bias * obj[i];
56  colUp[i] = 1;
57  }
58 
59  MSG_DEBUG(std::cout << colWeight[i] << " ";)
60  }
61 
62  MSG_DEBUG(std::cout << std::endl << std::endl;)
63 
64  MSG_DEBUG(std::cout << "DVECST02 rowWeight[]: ";)
65 
66  for(i = base.nRows(); i--;)
67  {
68  const SVector& row = base.rowVector(i);
69  y = vec * row;
70  x = (y - base.lhs(i));
71  y = (base.rhs(i) - y);
72 
73  if(x < y)
74  {
75  rowWeight[i] = -x - eps * row.size() - bias * (obj * row);
76  rowRight[i] = 0;
77  }
78  else
79  {
80  rowWeight[i] = -y - eps * row.size() + bias * (obj * row);
81  rowRight[i] = 1;
82  }
83 
84  MSG_DEBUG(std::cout << rowWeight[i] << " ";)
85  }
86 
87  MSG_DEBUG(std::cout << std::endl;)
88  }
89 
90  else if(state == DVEC)
91  {
92  if(vec.dim() != base.nRows())
93  {
95  return;
96  }
97 
98  Real x, y, len;
99  int i, j;
100 
101  for(i = base.nRows(); i--;)
102  rowWeight[i] += spxAbs(vec[i]);
103 
104  for(i = base.nCols(); i--;)
105  {
106  const SVector& col = base.colVector(i);
107 
108  for(y = len = 0, j = col.size(); j--;)
109  {
110  x = col.value(j);
111  y += vec[col.index(j)] * x;
112  len += x * x;
113  }
114 
115  if(len > 0)
116  colWeight[i] += spxAbs(y / len - base.maxObj(i));
117  }
118  }
119  else
121 }
122 } // 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
int size() const
Number of used indices.
Definition: svectorbase.h:153
Solution vector based start basis.
R & value(int n)
Reference to value of n &#39;th nonzero.
Definition: svectorbase.h:253
DataArray< Real > rowWeight
weight value for LP rows.
Definition: spxweightst.h:84
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:152
virtual void setupWeights(SPxSolver &base)
sets up variable weights.
double Real
Definition: spxdefines.h:218
#define MSG_DEBUG(x)
Definition: spxdefines.h:132
int & index(int n)
Reference to index of n &#39;th nonzero.
Definition: svectorbase.h:235
void setupWeights(SPxSolver &base)
sets up variable weights.
Definition: spxvectorst.cpp:25
DVector vec
the current (approximate) primal or dual vector
Definition: spxvectorst.h:59
const VectorBase< R > & lhs() const
Returns left hand side vector.
Definition: spxlpbase.h:255
Real epsilon() const
values are considered to be 0.
Definition: spxsolver.h:784
Debugging, floating point type and parameter definitions.
enum soplex::SPxVectorST::@1 state
specifies whether to work on the primal, the dual, or not at all.
Sequential object-oriented SimPlex.SPxSolver is an LP solver class using the revised Simplex algorith...
Definition: spxsolver.h:85
int dim() const
Dimension of vector.
Definition: vectorbase.h:217
Everything should be within this namespace.
const VectorBase< R > & maxObj() const
Returns objective vector for maximization problem.
Definition: spxlpbase.h:434
const SVectorBase< R > & rowVector(int i) const
Gets row vector of row i.
Definition: spxlpbase.h:206
int size() const
return nr. of elements.
Definition: dataarray.h:214
const SVectorBase< R > & colVector(int i) const
Returns column vector of column i.
Definition: spxlpbase.h:377
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:158
DataArray< Real > colWeight
weight value for LP columns.
Definition: spxweightst.h:86
DataArray< bool > colUp
set primal variable to upper bound.
Definition: spxweightst.h:90
DataArray< bool > rowRight
set variable to rhs?.
Definition: spxweightst.h:88