Scippy

SoPlex

Sequential object-oriented simPlex

spxsumst.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 #include <iostream>
17 
18 #include "spxdefines.h"
19 #include "spxsumst.h"
20 #include "vector.h"
21 
22 namespace soplex
23 {
24 
26 {
27  int count;
28  int i;
29  Real x;
30  DVector work, delta, rowLen;
31 
32  assert(base.nRows() > 0);
33  assert(base.nCols() > 0);
34 
35  rowLen.reDim(base.nRows(), true);
36  work.reDim(base.nCols(), true);
37  delta.reDim(base.nCols(), true);
38 
39  Real* wrk = work.get_ptr();
40  const Real* lhs = base.lhs().get_const_ptr();
41  const Real* rhs = base.rhs().get_const_ptr();
42  const Real* up = base.upper().get_const_ptr();
43  const Real* low = base.lower().get_const_ptr();
44 
45  for (i = base.nRows(); --i >= 0;)
46  {
47  rowLen[i] = base.rowVector(i).length2();
48  if (lhs[i] > 0)
49  delta.multAdd(lhs[i] / rowLen[i], base.rowVector(i));
50  else if (rhs[i] < 0)
51  delta.multAdd(rhs[i] / rowLen[i], base.rowVector(i));
52  }
53 
54  for (count = 0;; count++)
55  {
56  work += delta;
57  for (i = base.nCols(); --i >= 0;)
58  {
59  if (wrk[i] > up[i])
60  wrk[i] = up[i];
61  if (wrk[i] < low[i])
62  wrk[i] = low[i];
63  }
64 
65  // std::cout << -(work * base.maxObj()) << std::endl;
66  if (count >= 12)
67  break;
68 
69  delta.clear();
70  for (i = base.nRows(); --i >= 0;)
71  {
72  x = base.rowVector(i) * work;
73  if (lhs[i] > x)
74  delta.multAdd((lhs[i] - x) / rowLen[i], base.rowVector(i));
75  else if (rhs[i] < x)
76  delta.multAdd((rhs[i] - x) / rowLen[i], base.rowVector(i));
77  }
78  }
79 
80  primal(work);
82 }
83 } // namespace soplex
const VectorBase< R > & rhs() const
Returns right hand side vector.
Definition: spxlpbase.h:219
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase&#39;s dimension to newdim.
Definition: dvectorbase.h:249
const VectorBase< R > & upper() const
Returns upper bound vector.
Definition: spxlpbase.h:456
Dense vector for linear algebra.
const R * get_const_ptr() const
Conversion to C-style pointer.
Definition: vectorbase.h:453
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:151
R * get_ptr()
Conversion to C-style pointer.
Definition: vectorbase.h:444
double Real
Definition: spxdefines.h:218
void setupWeights(SPxSolver &base)
sets up variable weights.
Definition: spxsumst.cpp:25
void setupWeights(SPxSolver &base)
sets up variable weights.
Definition: spxvectorst.cpp:25
const VectorBase< R > & lhs() const
Returns left hand side vector.
Definition: spxlpbase.h:253
Simple heuristic SPxStarter.
Debugging, floating point type and parameter definitions.
Sequential object-oriented SimPlex.SPxSolver is an LP solver class using the revised Simplex algorith...
Definition: spxsolver.h:84
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition: vectorbase.h:410
Everything should be within this namespace.
const SVectorBase< R > & rowVector(int i) const
Gets row vector of row i.
Definition: spxlpbase.h:204
void primal(const Vector &v)
sets up primal solution vector.
Definition: spxvectorst.h:118
void clear()
Set vector to 0.
Definition: vectorbase.h:260
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:157
const VectorBase< R > & lower() const
Returns (internal and possibly scaled) lower bound vector.
Definition: spxlpbase.h:483
R length2() const
Squared norm.
Definition: svectorbase.h:503