Scippy

SoPlex

Sequential object-oriented simPlex

spxweightpr.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 
18 #include "soplex/spxdefines.h"
19 #include "soplex/spxweightpr.h"
20 #include "soplex/exceptions.h"
21 
22 namespace soplex
23 {
24 
26 {
27  if (rep == SPxSolver::ROW)
28  {
31  }
32  else
33  {
36  }
37 }
38 
40 {
41  if (thesolver && tp == SPxSolver::LEAVE)
42  {
45  }
46 }
47 
48 void SPxWeightPR::computeLeavePenalty(int start, int end)
49 {
50  const SPxBasis& basis = solver()->basis();
51 
52  for (int i = start; i < end; ++i)
53  {
54  SPxId id = basis.baseId(i);
55  if (id.type() == SPxId::ROW_ID)
57  else
59  }
60 }
61 
62 void SPxWeightPR::computeRP(int start, int end)
63 {
64  for (int i = start; i < end; ++i)
65  {
66  /**@todo TK04NOV98 here is a bug.
67  * solver()->rowVector(i).length() could be zero, so
68  * solver()->rowVector(i).length2() is also zero and we
69  * get an arithmetic exception.
70  */
71  assert(solver()->rowVector(i).length() > 0);
72 
73  rPenalty[i] = (solver()->rowVector(i) * solver()->maxObj()) * objlength
74  / solver()->rowVector(i).length2();
75  ASSERT_WARN( "WWGTPR01", rPenalty[i] > -1 - solver()->epsilon() );
76  }
77 }
78 
79 void SPxWeightPR::computeCP(int start, int end)
80 {
81  for (int i = start; i < end; ++i)
82  {
83  cPenalty[i] = solver()->maxObj(i) * objlength;
84  ASSERT_WARN( "WWGTPR02", cPenalty[i] > -1 - solver()->epsilon() );
85  }
86 }
87 
89 {
90  thesolver = base;
91 
92  rPenalty.reDim(base->nRows());
93  cPenalty.reDim(base->nCols());
94 
95  objlength = 1 / solver()->maxObj().length();
96  computeCP(0, base->nCols());
97  computeRP(0, base->nRows());
98 }
99 
101 {
102  const Real* test = thesolver->fTest().get_const_ptr();
103  Real type = 1 - 2 * (thesolver->rep() == SPxSolver::COLUMN ? 1 : 0);
104  Real best = type * infinity;
105  int lastIdx = -1;
106  Real x;
107  int i;
108 
109  for (i = solver()->dim() - 1; i >= 0; --i)
110  {
111  x = test[i];
112  if (x < -theeps)
113  {
114  x *= leavePenalty[i];
115  if (type * (x-best) < 0.0)
116  {
117  best = x;
118  lastIdx = i;
119  }
120  }
121  }
122  assert(isConsistent());
123  return lastIdx;
124 }
125 
127 {
128  const Vector& rTest = (solver()->rep() == SPxSolver::ROW)
129  ? solver()->test() : solver()->coTest();
130  const Vector& cTest = (solver()->rep() == SPxSolver::ROW)
131  ? solver()->coTest() : solver()->test();
132  const SPxBasis::Desc& ds = solver()->basis().desc();
133  Real best = infinity;
134  SPxId lastId;
135  Real x;
136  int i;
137 
138  for (i = solver()->nRows() - 1; i >= 0; --i)
139  {
140  x = rTest[i];
141  if (x < -theeps)
142  {
143  x *= -x;
144  switch (ds.rowStatus(i))
145  {
148  x *= 1 + rPenalty[i];
149  break;
152  x *= 1 - rPenalty[i];
153  break;
156  return SPxId(solver()->rId(i));
158  if (solver()->pVec()[i] > solver()->upBound()[i])
159  x *= 1 + rPenalty[i];
160  else
161  x *= 1 - rPenalty[i];
162  break;
165  default:
166  throw SPxInternalCodeException("XWGTPR01 This should never happen.");
167  }
168  if (x < best)
169  {
170  best = x;
171  lastId = solver()->rId(i);
172  }
173  }
174  }
175 
176  for (i = solver()->nCols() - 1; i >= 0; --i)
177  {
178  x = cTest[i];
179  if (x < -theeps)
180  {
181  x *= -x;
182  switch (ds.colStatus(i))
183  {
186  x *= 1 + cPenalty[i];
187  break;
190  x *= 1 - cPenalty[i];
191  break;
194  return SPxId(solver()->cId(i));
196  if (solver()->coPvec()[i] > solver()->ucBound()[i])
197  x *= 1 + cPenalty[i];
198  else
199  x *= 1 - cPenalty[i];
200  break;
203  default:
204  throw SPxInternalCodeException("XWGTPR02 This should never happen.");
205  }
206  if (x < best)
207  {
208  best = x;
209  lastId = solver()->cId(i);
210  }
211  }
212  }
213  assert(isConsistent());
214  return lastId;
215 }
216 
218 {
219  if (solver()->rep() == SPxSolver::ROW)
220  {
221  int start = rPenalty.dim();
222  rPenalty.reDim(solver()->nRows());
223  computeRP(start, solver()->nRows());
224  }
225  else
226  {
227  int start = cPenalty.dim();
228  cPenalty.reDim(solver()->nCols());
229  computeCP(start, solver()->nCols());
230  }
231  if (solver()->type() == SPxSolver::LEAVE)
232  {
233  int start = leavePenalty.dim();
234  leavePenalty.reDim( solver()->dim() );
235  computeLeavePenalty( start, solver()->dim() );
236  }
237 }
238 
240 {
241  if (solver()->rep() == SPxSolver::COLUMN)
242  {
243  int start = rPenalty.dim();
244  rPenalty.reDim(solver()->nRows());
245  computeRP(start, solver()->nRows());
246  }
247  else
248  {
249  int start = cPenalty.dim();
250  cPenalty.reDim(solver()->nCols());
251  computeCP(start, solver()->nCols());
252  }
253  if (solver()->type() == SPxSolver::LEAVE)
254  {
255  int start = leavePenalty.dim();
256  leavePenalty.reDim( solver()->dim() );
257  computeLeavePenalty( start, solver()->dim() );
258  }
259 }
260 
262 {
263  assert(solver() != 0);
264 
265  if (solver()->rep() == SPxSolver::ROW)
266  {
267  rPenalty[i] = rPenalty[rPenalty.dim()];
268  rPenalty.reDim(solver()->nRows());
269  }
270  else
271  {
272  cPenalty[i] = cPenalty[cPenalty.dim()];
273  cPenalty.reDim(solver()->nCols());
274  }
275 }
276 
277 void SPxWeightPR::removedVecs(const int perm[])
278 {
279  assert(solver() != 0);
280 
281  if (solver()->rep() == SPxSolver::ROW)
282  {
283  int j = rPenalty.dim();
284  for (int i = 0; i < j; ++i)
285  {
286  if (perm[i] >= 0)
287  rPenalty[perm[i]] = rPenalty[i];
288  }
289  rPenalty.reDim(solver()->nRows());
290  }
291  else
292  {
293  int j = cPenalty.dim();
294  for (int i = 0; i < j; ++i)
295  {
296  if (perm[i] >= 0)
297  cPenalty[perm[i]] = cPenalty[i];
298  }
299  cPenalty.reDim(solver()->nCols());
300  }
301 }
302 
304 {
305  assert(solver() != 0);
306 
307  if (solver()->rep() == SPxSolver::COLUMN)
308  {
309  rPenalty[i] = rPenalty[rPenalty.dim()];
310  rPenalty.reDim(solver()->nRows());
311  }
312  else
313  {
314  cPenalty[i] = cPenalty[cPenalty.dim()];
315  cPenalty.reDim(solver()->nCols());
316  }
317 }
318 
319 void SPxWeightPR::removedCoVecs(const int perm[])
320 {
321  assert(solver() != 0);
322 
323  if (solver()->rep() == SPxSolver::COLUMN)
324  {
325  int j = rPenalty.dim();
326  for (int i = 0; i < j; ++i)
327  {
328  if (perm[i] >= 0)
329  rPenalty[perm[i]] = rPenalty[i];
330  }
331  rPenalty.reDim(solver()->nRows());
332  }
333  else
334  {
335  int j = cPenalty.dim();
336  for (int i = 0; i < j; ++i)
337  {
338  if (perm[i] >= 0)
339  cPenalty[perm[i]] = cPenalty[i];
340  }
341  cPenalty.reDim(solver()->nCols());
342  }
343 }
344 
346 {
347 #ifdef ENABLE_CONSISTENCY_CHECKS
348  if (solver() != 0)
349  {
350  if (rPenalty.dim() != solver()->nRows())
351  return MSGinconsistent("SPxWeightPR");
352  if (cPenalty.dim() != solver()->nCols())
353  return MSGinconsistent("SPxWeightPR");
354  }
355 #endif
356 
357  return true;
358 }
359 } // namespace soplex
Exception class for things that should NEVER happen.This class is derived from the SoPlex exception b...
Definition: exceptions.h:109
SPxRowId rId(int n) const
Returns the row identifier for row n.
Definition: spxlpbase.h:562
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase&#39;s dimension to newdim.
Definition: dvectorbase.h:249
primal variable is fixed to both bounds
Definition: spxbasis.h:190
primal or dual variable is undefined
Definition: spxbasis.h:195
const Vector & fTest() const
Violations of fVec.
Definition: spxsolver.h:1364
THREADLOCAL const Real infinity
Definition: spxdefines.cpp:26
Type
Algorithmic type.
Definition: spxsolver.h:123
const Real * penalty
Definition: spxweightpr.h:55
void setType(SPxSolver::Type tp)
set entering/leaving algorithm
Definition: spxweightpr.cpp:39
Exception classes for SoPlex.
Status & rowStatus(int i)
Definition: spxbasis.h:239
Representation
LP basis representation.
Definition: spxsolver.h:104
int number(const SPxRowId &id) const
Returns the row number of the row with identifier id.
Definition: spxlpbase.h:522
int dim() const
dimension of basis matrix.
Definition: spxsolver.h:1054
#define ASSERT_WARN(prefix, expr)
Macro to turn some assertions into warnings.
Definition: spxdefines.h:77
void computeCP(int start, int end)
compute weights for columns.
Definition: spxweightpr.cpp:79
rowwise representation.
Definition: spxsolver.h:106
SPxColId cId(int n) const
Returns the column identifier for column n.
Definition: spxlpbase.h:568
const R * get_const_ptr() const
Conversion to C-style pointer.
Definition: vectorbase.h:453
dual variable is left free, but unset
Definition: spxbasis.h:191
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:151
const Real * coPenalty
Definition: spxweightpr.h:57
primal variable is set to its upper bound
Definition: spxbasis.h:188
Generic Ids for LP rows or columns.Both SPxColIds and SPxRowIds may be treated uniformly as SPxIds: ...
Definition: spxid.h:85
Leaving Simplex.
Definition: spxsolver.h:142
double Real
Definition: spxdefines.h:218
virtual void removedVecs(const int perm[])
n vectors have been removed from the loaded LP.
DVector cPenalty
column penalties
Definition: spxweightpr.h:49
dual variable is set to its upper bound
Definition: spxbasis.h:192
virtual void addedVecs(int n)
n vectors have been added to the loaded LP.
primal variable is left free, but unset
Definition: spxbasis.h:189
SPxSolver * thesolver
the solver
Definition: spxpricer.h:56
virtual void removedCoVecs(const int perm[])
n covectors have been removed from the loaded LP.
Basis descriptor.
Definition: spxbasis.h:104
virtual void removedCoVec(int i)
the i&#39;th covector has been removed from the loaded LP.
virtual SPxId selectEnter()
virtual void removedVec(int i)
the i&#39;th vector has been removed from the loaded LP.
row identifier.
Definition: spxid.h:97
DVector leavePenalty
penalties for leaving alg
Definition: spxweightpr.h:53
const Vector & test() const
Violations of pVec.
Definition: spxsolver.h:1510
Status & colStatus(int i)
Definition: spxbasis.h:254
SPxId & baseId(int i)
Definition: spxbasis.h:503
Debugging, floating point type and parameter definitions.
virtual bool isConsistent() const
checks for consistency
Simplex basis.Consider the linear program as provided from class SPxLP: where , and ...
Definition: spxbasis.h:82
Sequential object-oriented SimPlex.SPxSolver is an LP solver class using the revised Simplex algorith...
Definition: spxsolver.h:84
int dim() const
Dimension of vector.
Definition: vectorbase.h:215
Everything should be within this namespace.
virtual void addedCoVecs(int n)
n covectors have been added to the loaded LP.
void computeLeavePenalty(int start, int end)
compute leave penalties.
Definition: spxweightpr.cpp:48
primal variable is set to its lower bound
Definition: spxbasis.h:187
const VectorBase< R > & maxObj() const
Returns objective vector for maximization problem.
Definition: spxlpbase.h:429
const SVectorBase< R > & rowVector(int i) const
Gets row vector of row i.
Definition: spxlpbase.h:204
Real theeps
violation bound
Definition: spxpricer.h:58
const Vector & coTest() const
violations of coPvec.
Definition: spxsolver.h:1444
Real objlength
length of objective vector.
Definition: spxweightpr.h:59
virtual Real epsilon() const
returns violation bound theeps.
Definition: spxpricer.h:130
dual variable is set to its lower bound
Definition: spxbasis.h:193
void computeRP(int start, int end)
compute weights for rows.
Definition: spxweightpr.cpp:62
virtual SPxSolver * solver() const
returns loaded SPxSolver object.
Definition: spxpricer.h:124
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:157
dual variable has two bounds
Definition: spxbasis.h:194
virtual int selectLeave()
#define MSGinconsistent(name)
Definition: spxdefines.h:126
void setRep(SPxSolver::Representation rep)
set row/column representation
Definition: spxweightpr.cpp:25
virtual void load(SPxSolver *base)
sets the solver
Definition: spxweightpr.cpp:88
DVector rPenalty
row penalties
Definition: spxweightpr.h:51
const SPxBasis & basis() const
Return current basis.
Definition: spxsolver.h:1740
const Desc & desc() const
Definition: spxbasis.h:463
Representation rep() const
return the current basis representation.
Definition: spxsolver.h:487
Weighted pricing.
columnwise representation.
Definition: spxsolver.h:107