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-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 
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 
56  if(id.type() == SPxId::ROW_ID)
58  else
60  }
61 }
62 
63 void SPxWeightPR::computeRP(int start, int end)
64 {
65  for(int i = start; i < end; ++i)
66  {
67  /**@todo TK04NOV98 here is a bug.
68  * solver()->rowVector(i).length() could be zero, so
69  * solver()->rowVector(i).length2() is also zero and we
70  * get an arithmetic exception.
71  */
72  assert(solver()->rowVector(i).length() > 0);
73 
74  rPenalty[i] = (solver()->rowVector(i) * solver()->maxObj()) * objlength
75  / solver()->rowVector(i).length2();
76  ASSERT_WARN("WWGTPR01", rPenalty[i] > -1 - solver()->epsilon());
77  }
78 }
79 
80 void SPxWeightPR::computeCP(int start, int end)
81 {
82  for(int i = start; i < end; ++i)
83  {
84  cPenalty[i] = solver()->maxObj(i) * objlength;
85  ASSERT_WARN("WWGTPR02", cPenalty[i] > -1 - solver()->epsilon());
86  }
87 }
88 
90 {
91  thesolver = base;
92 
93  rPenalty.reDim(base->nRows());
94  cPenalty.reDim(base->nCols());
95 
96  objlength = 1 / solver()->maxObj().length();
97  computeCP(0, base->nCols());
98  computeRP(0, base->nRows());
99 }
100 
102 {
103  const Real* test = thesolver->fTest().get_const_ptr();
104  Real type = 1 - 2 * (thesolver->rep() == SPxSolver::COLUMN ? 1 : 0);
105  Real best = type * infinity;
106  int lastIdx = -1;
107  Real x;
108  int i;
109 
110  for(i = solver()->dim() - 1; i >= 0; --i)
111  {
112  x = test[i];
113 
114  if(x < -theeps)
115  {
116  x *= leavePenalty[i];
117 
118  if(type * (x - best) < 0.0)
119  {
120  best = x;
121  lastIdx = i;
122  }
123  }
124  }
125 
126  assert(isConsistent());
127  return lastIdx;
128 }
129 
131 {
132  const Vector& rTest = (solver()->rep() == SPxSolver::ROW)
133  ? solver()->test() : solver()->coTest();
134  const Vector& cTest = (solver()->rep() == SPxSolver::ROW)
135  ? solver()->coTest() : solver()->test();
136  const SPxBasis::Desc& ds = solver()->basis().desc();
137  Real best = infinity;
138  SPxId lastId;
139  Real x;
140  int i;
141 
142  for(i = solver()->nRows() - 1; i >= 0; --i)
143  {
144  x = rTest[i];
145 
146  if(x < -theeps)
147  {
148  x *= -x;
149 
150  switch(ds.rowStatus(i))
151  {
154  x *= 1 + rPenalty[i];
155  break;
156 
159  x *= 1 - rPenalty[i];
160  break;
161 
164  return SPxId(solver()->rId(i));
165 
167  if(solver()->pVec()[i] > solver()->upBound()[i])
168  x *= 1 + rPenalty[i];
169  else
170  x *= 1 - rPenalty[i];
171 
172  break;
173 
176  default:
177  throw SPxInternalCodeException("XWGTPR01 This should never happen.");
178  }
179 
180  if(x < best)
181  {
182  best = x;
183  lastId = solver()->rId(i);
184  }
185  }
186  }
187 
188  for(i = solver()->nCols() - 1; i >= 0; --i)
189  {
190  x = cTest[i];
191 
192  if(x < -theeps)
193  {
194  x *= -x;
195 
196  switch(ds.colStatus(i))
197  {
200  x *= 1 + cPenalty[i];
201  break;
202 
205  x *= 1 - cPenalty[i];
206  break;
207 
210  return SPxId(solver()->cId(i));
211 
213  if(solver()->coPvec()[i] > solver()->ucBound()[i])
214  x *= 1 + cPenalty[i];
215  else
216  x *= 1 - cPenalty[i];
217 
218  break;
219 
222  default:
223  throw SPxInternalCodeException("XWGTPR02 This should never happen.");
224  }
225 
226  if(x < best)
227  {
228  best = x;
229  lastId = solver()->cId(i);
230  }
231  }
232  }
233 
234  assert(isConsistent());
235  return lastId;
236 }
237 
239 {
240  if(solver()->rep() == SPxSolver::ROW)
241  {
242  int start = rPenalty.dim();
243  rPenalty.reDim(solver()->nRows());
244  computeRP(start, solver()->nRows());
245  }
246  else
247  {
248  int start = cPenalty.dim();
249  cPenalty.reDim(solver()->nCols());
250  computeCP(start, solver()->nCols());
251  }
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  if(solver()->rep() == SPxSolver::COLUMN)
264  {
265  int start = rPenalty.dim();
266  rPenalty.reDim(solver()->nRows());
267  computeRP(start, solver()->nRows());
268  }
269  else
270  {
271  int start = cPenalty.dim();
272  cPenalty.reDim(solver()->nCols());
273  computeCP(start, solver()->nCols());
274  }
275 
276  if(solver()->type() == SPxSolver::LEAVE)
277  {
278  int start = leavePenalty.dim();
279  leavePenalty.reDim(solver()->dim());
280  computeLeavePenalty(start, solver()->dim());
281  }
282 }
283 
285 {
286  assert(solver() != 0);
287 
288  if(solver()->rep() == SPxSolver::ROW)
289  {
290  rPenalty[i] = rPenalty[rPenalty.dim()];
291  rPenalty.reDim(solver()->nRows());
292  }
293  else
294  {
295  cPenalty[i] = cPenalty[cPenalty.dim()];
296  cPenalty.reDim(solver()->nCols());
297  }
298 }
299 
300 void SPxWeightPR::removedVecs(const int perm[])
301 {
302  assert(solver() != 0);
303 
304  if(solver()->rep() == SPxSolver::ROW)
305  {
306  int j = rPenalty.dim();
307 
308  for(int i = 0; i < j; ++i)
309  {
310  if(perm[i] >= 0)
311  rPenalty[perm[i]] = rPenalty[i];
312  }
313 
314  rPenalty.reDim(solver()->nRows());
315  }
316  else
317  {
318  int j = cPenalty.dim();
319 
320  for(int i = 0; i < j; ++i)
321  {
322  if(perm[i] >= 0)
323  cPenalty[perm[i]] = cPenalty[i];
324  }
325 
326  cPenalty.reDim(solver()->nCols());
327  }
328 }
329 
331 {
332  assert(solver() != 0);
333 
334  if(solver()->rep() == SPxSolver::COLUMN)
335  {
336  rPenalty[i] = rPenalty[rPenalty.dim()];
337  rPenalty.reDim(solver()->nRows());
338  }
339  else
340  {
341  cPenalty[i] = cPenalty[cPenalty.dim()];
342  cPenalty.reDim(solver()->nCols());
343  }
344 }
345 
346 void SPxWeightPR::removedCoVecs(const int perm[])
347 {
348  assert(solver() != 0);
349 
350  if(solver()->rep() == SPxSolver::COLUMN)
351  {
352  int j = rPenalty.dim();
353 
354  for(int i = 0; i < j; ++i)
355  {
356  if(perm[i] >= 0)
357  rPenalty[perm[i]] = rPenalty[i];
358  }
359 
360  rPenalty.reDim(solver()->nRows());
361  }
362  else
363  {
364  int j = cPenalty.dim();
365 
366  for(int i = 0; i < j; ++i)
367  {
368  if(perm[i] >= 0)
369  cPenalty[perm[i]] = cPenalty[i];
370  }
371 
372  cPenalty.reDim(solver()->nCols());
373  }
374 }
375 
377 {
378 #ifdef ENABLE_CONSISTENCY_CHECKS
379 
380  if(solver() != 0)
381  {
382  if(rPenalty.dim() != solver()->nRows())
383  return MSGinconsistent("SPxWeightPR");
384 
385  if(cPenalty.dim() != solver()->nCols())
386  return MSGinconsistent("SPxWeightPR");
387  }
388 
389 #endif
390 
391  return true;
392 }
393 } // 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:567
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase&#39;s dimension to newdim.
Definition: dvectorbase.h:253
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:1385
THREADLOCAL const Real infinity
Definition: spxdefines.cpp:26
Type
Algorithmic type.
Definition: spxsolver.h:124
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:105
int number(const SPxRowId &id) const
Returns the row number of the row with identifier id.
Definition: spxlpbase.h:527
int dim() const
dimension of basis matrix.
Definition: spxsolver.h:1075
#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:80
rowwise representation.
Definition: spxsolver.h:107
SPxColId cId(int n) const
Returns the column identifier for column n.
Definition: spxlpbase.h:573
const R * get_const_ptr() const
Conversion to C-style pointer.
Definition: vectorbase.h:455
dual variable is left free, but unset
Definition: spxbasis.h:191
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:152
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:143
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:1531
Status & colStatus(int i)
Definition: spxbasis.h:254
SPxId & baseId(int i)
Definition: spxbasis.h:504
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:85
int dim() const
Dimension of vector.
Definition: vectorbase.h:217
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:434
const SVectorBase< R > & rowVector(int i) const
Gets row vector of row i.
Definition: spxlpbase.h:206
Real theeps
violation bound
Definition: spxpricer.h:58
const Vector & coTest() const
violations of coPvec.
Definition: spxsolver.h:1465
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:63
virtual SPxSolver * solver() const
returns loaded SPxSolver object.
Definition: spxpricer.h:124
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:158
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:89
DVector rPenalty
row penalties
Definition: spxweightpr.h:51
const SPxBasis & basis() const
Return current basis.
Definition: spxsolver.h:1761
const Desc & desc() const
Definition: spxbasis.h:464
Representation rep() const
return the current basis representation.
Definition: spxsolver.h:506
Weighted pricing.
columnwise representation.
Definition: spxsolver.h:108