Scippy

SoPlex

Sequential object-oriented simPlex

spxsteeppr.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 //TODO may be faster to have a greater zero tolerance for sparse pricing vectors
17 // to reduce the number of nonzero entries, e.g. for workVec
18 
19 #include <assert.h>
20 #include <iostream>
21 
22 #include "soplex/spxdefines.h"
23 #include "soplex/spxsteeppr.h"
24 #include "soplex/random.h"
25 
26 #define STEEP_REFINETOL 2.0
27 
28 namespace soplex
29 {
30 
31 // #define EQ_PREF 1000
32 
34 {
35  thesolver = 0;
36 }
37 
39 {
40  thesolver = base;
41 
42  if(base)
43  {
44  workVec.clear();
45  workVec.reDim(base->dim());
46  workRhs.clear();
47  workRhs.reDim(base->dim());
48  }
49 }
50 
52 {
54 
55  setupWeights(type);
56  workVec.clear();
57  workRhs.clear();
58  refined = false;
59 
60  bestPrices.clear();
63 
64  if(type == SPxSolver::ENTER)
65  {
69  }
70 }
71 
73 {
74  int i;
75  int endDim = 0;
76  int endCoDim = 0;
77  DVector& weights = thesolver->weights;
78  DVector& coWeights = thesolver->coWeights;
79 
80  if(setup == DEFAULT)
81  {
82  if(type == SPxSolver::ENTER)
83  {
85  {
86  // check for added/removed rows and adapt norms accordingly
87  if(coWeights.dim() < thesolver->dim())
88  endDim = coWeights.dim();
89  else
90  endDim = thesolver->dim();
91 
92  if(weights.dim() < thesolver->coDim())
93  endCoDim = weights.dim();
94  else
95  endCoDim = thesolver->coDim();
96  }
97 
98  coWeights.reDim(thesolver->dim(), false);
99 
100  for(i = thesolver->dim() - 1; i >= endDim; --i)
101  coWeights[i] = 2.0;
102 
103  weights.reDim(thesolver->coDim(), false);
104 
105  for(i = thesolver->coDim() - 1; i >= endCoDim; --i)
106  weights[i] = 1.0;
107  }
108  else
109  {
110  assert(type == SPxSolver::LEAVE);
111 
113  {
114  // check for added/removed rows and adapt norms accordingly
115  if(coWeights.dim() < thesolver->dim())
116  endDim = coWeights.dim();
117  else
118  endDim = thesolver->dim();
119  }
120 
121  coWeights.reDim(thesolver->dim(), false);
122 
123  for(i = thesolver->dim() - 1; i >= endDim; --i)
124  coWeights[i] = 1.0;
125  }
126  }
127  else
128  {
130  (*thesolver->spxout) << " --- initializing steepest edge multipliers" << std::endl;)
131 
132  if(type == SPxSolver::ENTER)
133  {
134  coWeights.reDim(thesolver->dim(), false);
135 
136  for(i = thesolver->dim() - 1; i >= endDim; --i)
137  coWeights[i] = 1.0;
138 
139  weights.reDim(thesolver->coDim(), false);
140 
141  for(i = thesolver->coDim() - 1; i >= endCoDim; --i)
142  weights[i] = 1.0 + thesolver->vector(i).length2();
143  }
144  else
145  {
146  assert(type == SPxSolver::LEAVE);
147  coWeights.reDim(thesolver->dim(), false);
148  SSVector tmp(thesolver->dim(), thesolver->epsilon());
149 
150  for(i = thesolver->dim() - 1; i >= endDim && !thesolver->isTimeLimitReached(); --i)
151  {
153  coWeights[i] = tmp.length2();
154  }
155  }
156  }
157 
158  thesolver->weightsAreSetup = true;
159 }
160 
162 {
163  if(workVec.dim() != thesolver->dim())
164  {
165  DVector tmp = thesolver->weights;
167  thesolver->coWeights = tmp;
168 
169  workVec.clear();
171  }
172 }
173 
174 void SPxSteepPR::left4(int n, SPxId id)
175 {
176  assert(thesolver->type() == SPxSolver::LEAVE);
177 
178  if(id.isValid())
179  {
180  Real delta = 0.1 + 1.0 / thesolver->basis().iteration();
181  Real* coWeights_ptr = thesolver->coWeights.get_ptr();
182  const Real* workVec_ptr = workVec.get_const_ptr();
183  const Real* rhoVec = thesolver->fVec().delta().values();
184  Real rhov_1 = 1.0 / rhoVec[n];
185  Real beta_q = thesolver->coPvec().delta().length2() * rhov_1 * rhov_1;
186 
187 #ifndef NDEBUG
188 
189  if(spxAbs(rhoVec[n]) < theeps * 0.5)
190  {
191  MSG_INFO3((*thesolver->spxout), (*thesolver->spxout) << "WSTEEP04: rhoVec = "
192  << rhoVec[n] << " with smaller absolute value than 0.5*theeps = " << 0.5 * theeps << std::endl;)
193  }
194 
195 #endif
196 
197  const IdxSet& rhoIdx = thesolver->fVec().idx();
198  int len = thesolver->fVec().idx().size();
199 
200  for(int i = 0; i < len; ++i)
201  {
202  int j = rhoIdx.index(i);
203  coWeights_ptr[j] += rhoVec[j] * (beta_q * rhoVec[j] - 2.0 * rhov_1 * workVec_ptr[j]);
204 
205  if(coWeights_ptr[j] < delta)
206  coWeights_ptr[j] = delta; // coWeights_ptr[j] = delta / (1+delta-x);
207  else if(coWeights_ptr[j] >= infinity)
208  coWeights_ptr[j] = 1.0 / theeps;
209  }
210 
211  coWeights_ptr[n] = beta_q;
212  }
213 }
214 
215 Real inline computePrice(Real viol, Real weight, Real tol)
216 {
217  if(weight < tol)
218  return viol * viol / tol;
219  else
220  return viol * viol / weight;
221 }
222 
224 {
225  int idx;
226  int nsorted;
227  Real x;
228  const Real* fTest = thesolver->fTest().get_const_ptr();
229  const Real* cpen = thesolver->coWeights.get_const_ptr();
230  IdxElement price;
231  prices.clear();
232  bestPrices.clear();
233 
234  // construct vector of all prices
235  for(int i = thesolver->infeasibilities.size() - 1; i >= 0; --i)
236  {
237  idx = thesolver->infeasibilities.index(i);
238  x = fTest[idx];
239 
240  if(x < -feastol)
241  {
242  // it might happen that we call the pricer with a tighter tolerance than what was used when computing the violations
244  price.val = computePrice(x, cpen[idx], feastol);
245  price.idx = idx;
246  prices.append(price);
247  }
248  }
249 
250  // set up structures for the quicksort implementation
252  // do a partial sort to move the best ones to the front
253  // TODO this can be done more efficiently, since we only need the indices
255 
256  // copy indices of best values to bestPrices
257  for(int i = 0; i < nsorted; ++i)
258  {
259  bestPrices.addIdx(prices[i].idx);
261  }
262 
263  if(nsorted > 0)
264  return prices[0].idx;
265  else
266  return -1;
267 }
268 
269 
271 {
272  assert(isConsistent());
273 
274  int retid;
275 
277  {
278  if(bestPrices.size() < 2 || thesolver->basis().lastUpdate() == 0)
279  {
280  // call init method to build up price-vector and return index of largest price
282  }
283  else
284  retid = selectLeaveHyper(theeps);
285  }
286  else if(thesolver->sparsePricingLeave)
287  retid = selectLeaveSparse(theeps);
288  else
289  retid = selectLeaveX(theeps);
290 
291  if(retid < 0 && !refined)
292  {
293  refined = true;
294  MSG_INFO3((*thesolver->spxout), (*thesolver->spxout) << "WSTEEP03 trying refinement step..\n";)
296  }
297 
298  if(retid >= 0)
299  {
300  assert(thesolver->coPvec().delta().isConsistent());
301  // coPvec().delta() might be not setup after the solve when it contains too many nonzeros.
302  // This is intended and forcing to keep the sparsity information leads to a slowdown
303  // TODO implement a dedicated solve method for unitvectors
305  thesolver->unitVector(retid));
306  assert(thesolver->coPvec().delta().isConsistent());
309  }
310 
311  return retid;
312 }
313 
315 {
316  const Real* coWeights_ptr = thesolver->coWeights.get_const_ptr();
317  const Real* fTest = thesolver->fTest().get_const_ptr();
318  Real best = -infinity;
319  Real x;
320  int lastIdx = -1;
321 
322  for(int i = thesolver->dim() - 1; i >= 0; --i)
323  {
324  x = fTest[i];
325 
326  if(x < -tol)
327  {
328  x = computePrice(x, coWeights_ptr[i], tol);
329 
330  if(x > best)
331  {
332  best = x;
333  lastIdx = i;
334  }
335  }
336  }
337 
338  return lastIdx;
339 }
340 
342 {
343  const Real* coWeights_ptr = thesolver->coWeights.get_const_ptr();
344  const Real* fTest = thesolver->fTest().get_const_ptr();
345  Real best = -infinity;
346  Real x;
347  int lastIdx = -1;
348  int idx;
349 
350  for(int i = thesolver->infeasibilities.size() - 1; i >= 0; --i)
351  {
352  idx = thesolver->infeasibilities.index(i);
353  x = fTest[idx];
354 
355  if(x < -tol)
356  {
357  x = computePrice(x, coWeights_ptr[idx], tol);
358 
359  if(x > best)
360  {
361  best = x;
362  lastIdx = idx;
363  }
364  }
365  else
366  {
368  assert(thesolver->isInfeasible[idx] == VIOLATED
371  }
372  }
373 
374  return lastIdx;
375 }
376 
378 {
379  const Real* coPen = thesolver->coWeights.get_const_ptr();
380  const Real* fTest = thesolver->fTest().get_const_ptr();
381  Real leastBest = infinity;
382  Real best = -infinity;
383  Real x;
384  int bestIdx = -1;
385  int idx = 0;
386 
387  // find the best price from the short candidate list
388  for(int i = bestPrices.size() - 1; i >= 0; --i)
389  {
390  idx = bestPrices.index(i);
391  x = fTest[idx];
392 
393  if(x < -tol)
394  {
395  assert(thesolver->isInfeasible[idx] == VIOLATED
397  x = computePrice(x, coPen[idx], tol);
398 
399  if(x > best)
400  {
401  best = x;
402  bestIdx = idx;
403  }
404 
405  if(x < leastBest)
406  leastBest = x;
407  }
408  else
409  {
410  bestPrices.remove(i);
412  }
413  }
414 
415  // make sure we do not skip potential candidates due to a high leastBest value
416  if(leastBest == infinity)
417  {
418  assert(bestPrices.size() == 0);
419  leastBest = 0;
420  }
421 
422  // scan the updated indices for a better price
423  for(int i = thesolver->updateViols.size() - 1; i >= 0; --i)
424  {
425  idx = thesolver->updateViols.index(i);
426 
427  // is this index a candidate for bestPrices?
428  if(thesolver->isInfeasible[idx] == VIOLATED)
429  {
430  x = fTest[idx];
431  assert(x < -tol);
432  x = computePrice(x, coPen[idx], tol);
433 
434  if(x > leastBest)
435  {
436  if(x > best)
437  {
438  best = x;
439  bestIdx = idx;
440  }
441 
443  bestPrices.addIdx(idx);
444  }
445  }
446  }
447 
448  return bestIdx;
449 }
450 
451 /* Entering Simplex
452  */
453 void SPxSteepPR::entered4(SPxId /* id */, int n)
454 {
455  assert(thesolver->type() == SPxSolver::ENTER);
456 
457  if(n >= 0 && n < thesolver->dim())
458  {
459  Real delta = 2 + 1.0 / thesolver->basis().iteration();
460  Real* coWeights_ptr = thesolver->coWeights.get_ptr();
461  Real* weights_ptr = thesolver->weights.get_ptr();
462  const Real* workVec_ptr = workVec.get_const_ptr();
463  const Real* pVec = thesolver->pVec().delta().values();
464  const IdxSet& pIdx = thesolver->pVec().idx();
465  const Real* coPvec = thesolver->coPvec().delta().values();
466  const IdxSet& coPidx = thesolver->coPvec().idx();
467  Real xi_p = 1 / thesolver->fVec().delta()[n];
468  int i, j;
469  Real xi_ip;
470 
471  assert(thesolver->fVec().delta()[n] > thesolver->epsilon()
472  || thesolver->fVec().delta()[n] < -thesolver->epsilon());
473 
474  for(j = coPidx.size() - 1; j >= 0; --j)
475  {
476  i = coPidx.index(j);
477  xi_ip = xi_p * coPvec[i];
478  coWeights_ptr[i] += xi_ip * (xi_ip * pi_p - 2.0 * workVec_ptr[i]);
479 
480  /*
481  if(coWeights_ptr[i] < 1)
482  coWeights_ptr[i] = 1 / (2-x);
483  */
484  if(coWeights_ptr[i] < delta)
485  coWeights_ptr[i] = delta;
486  // coWeights_ptr[i] = 1;
487  else if(coWeights_ptr[i] > infinity)
488  coWeights_ptr[i] = 1 / thesolver->epsilon();
489  }
490 
491  for(j = pIdx.size() - 1; j >= 0; --j)
492  {
493  i = pIdx.index(j);
494  xi_ip = xi_p * pVec[i];
495  weights_ptr[i] += xi_ip * (xi_ip * pi_p - 2.0 * (thesolver->vector(i) * workVec));
496 
497  /*
498  if(weights_ptr[i] < 1)
499  weights_ptr[i] = 1 / (2-x);
500  */
501  if(weights_ptr[i] < delta)
502  weights_ptr[i] = delta;
503  // weights_ptr[i] = 1;
504  else if(weights_ptr[i] > infinity)
505  weights_ptr[i] = 1.0 / thesolver->epsilon();
506  }
507  }
508 
509  /*@
510  if(thesolver->isId(id))
511  weights[ thesolver->number(id) ] *= 1.0001;
512  else if(thesolver->isCoId(id))
513  coWeights[ thesolver->number(id) ] *= 1.0001;
514  */
515 
516 }
517 
518 
520 {
521  const Real* coTest = thesolver->coTest().get_const_ptr();
522  const Real* coWeights_ptr = thesolver->coWeights.get_const_ptr();
523  int idx;
524  int nsorted;
525  Real x;
526  IdxElement price;
527 
528  prices.clear();
529  bestPrices.clear();
530 
531  // construct vector of all prices
532  for(int i = thesolver->infeasibilities.size() - 1; i >= 0; --i)
533  {
534  idx = thesolver->infeasibilities.index(i);
535  x = coTest[idx];
536 
537  if(x < -feastol)
538  {
539  // it might happen that we call the pricer with a tighter tolerance than what was used when computing the violations
541  price.val = computePrice(x, coWeights_ptr[idx], feastol);
542  price.idx = idx;
543  prices.append(price);
544  }
545  else
546  {
549  }
550  }
551 
552  // set up structures for the quicksort implementation
554  // do a partial sort to move the best ones to the front
555  // TODO this can be done more efficiently, since we only need the indices
557 
558  // copy indices of best values to bestPrices
559  for(int i = 0; i < nsorted; ++i)
560  {
561  bestPrices.addIdx(prices[i].idx);
563  }
564 
565  if(nsorted > 0)
566  {
567  best = prices[0].val;
568  return thesolver->coId(prices[0].idx);
569  }
570  else
571  return SPxId();
572 }
573 
574 
576 {
577  const Real* test = thesolver->test().get_const_ptr();
578  const Real* weights_ptr = thesolver->weights.get_const_ptr();
579  int idx;
580  int nsorted;
581  Real x;
582  IdxElement price;
583 
584  pricesCo.clear();
586 
587  // construct vector of all prices
588  for(int i = thesolver->infeasibilitiesCo.size() - 1; i >= 0; --i)
589  {
591  x = test[idx];
592 
593  if(x < -feastol)
594  {
595  // it might happen that we call the pricer with a tighter tolerance than what was used when computing the violations
597  price.val = computePrice(x, weights_ptr[idx], feastol);
598  price.idx = idx;
599  pricesCo.append(price);
600  }
601  else
602  {
605  }
606  }
607 
608  // set up structures for the quicksort implementation
610  // do a partial sort to move the best ones to the front
611  // TODO this can be done more efficiently, since we only need the indices
613 
614  // copy indices of best values to bestPrices
615  for(int i = 0; i < nsorted; ++i)
616  {
617  bestPricesCo.addIdx(pricesCo[i].idx);
619  }
620 
621  if(nsorted > 0)
622  {
623  best = pricesCo[0].val;
624  return thesolver->id(pricesCo[0].idx);
625  }
626  else
627  return SPxId();
628 }
629 
630 
632 {
633  assert(thesolver != 0);
634  SPxId enterId;
635 
636  enterId = selectEnterX(theeps);
637 
638  if(!enterId.isValid() && !refined)
639  {
640  refined = true;
641  MSG_INFO3((*thesolver->spxout), (*thesolver->spxout) << "WSTEEP05 trying refinement step..\n";)
642  enterId = selectEnterX(theeps / STEEP_REFINETOL);
643  }
644 
645  assert(isConsistent());
646 
647  if(enterId.isValid())
648  {
649  SSVector& delta = thesolver->fVec().delta();
650 
651  thesolver->basis().solve4update(delta, thesolver->vector(enterId));
652 
653  workRhs.setup_and_assign(delta);
654  pi_p = 1 + delta.length2();
655 
657  }
658 
659  return enterId;
660 }
661 
663 {
664  SPxId enterId;
665  SPxId enterCoId;
666  Real best;
667  Real bestCo;
668 
669  best = -infinity;
670  bestCo = -infinity;
671 
673  {
674  if(bestPrices.size() < 2 || thesolver->basis().lastUpdate() == 0)
676  tol) : selectEnterDenseDim(best, tol);
677  else
678  enterCoId = (thesolver->sparsePricingEnter) ? selectEnterHyperDim(best,
679  tol) : selectEnterDenseDim(best, tol);
680 
681  if(bestPricesCo.size() < 2 || thesolver->basis().lastUpdate() == 0)
683  tol) : selectEnterDenseCoDim(bestCo, tol);
684  else
686  tol) : selectEnterDenseCoDim(bestCo, tol);
687  }
688  else
689  {
690  enterCoId = (thesolver->sparsePricingEnter
691  && !refined) ? selectEnterSparseDim(best, tol) : selectEnterDenseDim(best, tol);
692  enterId = (thesolver->sparsePricingEnterCo
693  && !refined) ? selectEnterSparseCoDim(bestCo, tol) : selectEnterDenseCoDim(bestCo, tol);
694  }
695 
696  // prefer slack indices to reduce nonzeros in basis matrix
697  if(enterCoId.isValid() && (best > SPARSITY_TRADEOFF * bestCo || !enterId.isValid()))
698  return enterCoId;
699  else
700  return enterId;
701 }
702 
703 
705 {
706  const Real* coTest = thesolver->coTest().get_const_ptr();
707  const Real* coWeights_ptr = thesolver->coWeights.get_const_ptr();
708 
709  Real leastBest = infinity;
710  Real x;
711  int enterIdx = -1;
712  int idx;
713 
714  // find the best price from short candidate list
715  for(int i = bestPrices.size() - 1; i >= 0; --i)
716  {
717  idx = bestPrices.index(i);
718  x = coTest[idx];
719 
720  if(x < -tol)
721  {
722  x = computePrice(x, coWeights_ptr[idx], tol);
723 
724  if(x > best)
725  {
726  best = x;
727  enterIdx = idx;
728  }
729 
730  if(x < leastBest)
731  leastBest = x;
732  }
733  else
734  {
735  bestPrices.remove(i);
737  }
738  }
739 
740  // make sure we do not skip potential candidates due to a high leastBest value
741  if(leastBest == infinity)
742  {
743  assert(bestPrices.size() == 0);
744  leastBest = 0;
745  }
746 
747  // scan the updated indices for a better price
748  for(int i = thesolver->updateViols.size() - 1; i >= 0; --i)
749  {
750  idx = thesolver->updateViols.index(i);
751 
752  // only look at indices that were not checked already
753  if(thesolver->isInfeasible[idx] == VIOLATED)
754  {
755  x = coTest[idx];
756 
757  if(x < -tol)
758  {
759  x = computePrice(x, coWeights_ptr[idx], tol);
760 
761  if(x > leastBest)
762  {
763  if(x > best)
764  {
765  best = x;
766  enterIdx = idx;
767  }
768 
769  // put index into candidate list
771  bestPrices.addIdx(idx);
772  }
773  }
774  else
775  {
777  }
778  }
779  }
780 
781  if(enterIdx >= 0)
782  return thesolver->coId(enterIdx);
783  else
784  return SPxId();
785 }
786 
787 
789 {
790  const Real* test = thesolver->test().get_const_ptr();
791  const Real* weights_ptr = thesolver->weights.get_const_ptr();
792 
793  Real leastBest = infinity;
794  Real x;
795  int enterIdx = -1;
796  int idx;
797 
798  // find the best price from short candidate list
799  for(int i = bestPricesCo.size() - 1; i >= 0; --i)
800  {
801  idx = bestPricesCo.index(i);
802  x = test[idx];
803 
804  if(x < -tol)
805  {
806  x = computePrice(x, weights_ptr[idx], tol);
807 
808  if(x > best)
809  {
810  best = x;
811  enterIdx = idx;
812  }
813 
814  if(x < leastBest)
815  leastBest = x;
816  }
817  else
818  {
819  bestPricesCo.remove(i);
821  }
822  }
823 
824  // make sure we do not skip potential candidates due to a high leastBest value
825  if(leastBest == infinity)
826  {
827  assert(bestPricesCo.size() == 0);
828  leastBest = 0;
829  }
830 
831  // scan the updated indices for a better price
832  for(int i = thesolver->updateViolsCo.size() - 1; i >= 0; --i)
833  {
834  idx = thesolver->updateViolsCo.index(i);
835 
836  // only look at indices that were not checked already
837  if(thesolver->isInfeasibleCo[idx] == VIOLATED)
838  {
839  x = test[idx];
840 
841  if(x < -tol)
842  {
843  x = computePrice(x, weights_ptr[idx], tol);
844 
845  if(x > leastBest)
846  {
847  if(x > best)
848  {
849  best = x;
850  enterIdx = idx;
851  }
852 
853  // put index into candidate list
855  bestPricesCo.addIdx(idx);
856  }
857  }
858  else
859  {
861  }
862  }
863  }
864 
865  if(enterIdx >= 0)
866  return thesolver->id(enterIdx);
867  else
868  return SPxId();
869 }
870 
871 
873 {
874  SPxId enterId;
875  const Real* coTest = thesolver->coTest().get_const_ptr();
876  const Real* coWeights_ptr = thesolver->coWeights.get_const_ptr();
877 
878  int idx;
879  Real x;
880 
881  for(int i = thesolver->infeasibilities.size() - 1; i >= 0; --i)
882  {
883  idx = thesolver->infeasibilities.index(i);
884  x = coTest[idx];
885 
886  if(x < -tol)
887  {
888  x = computePrice(x, coWeights_ptr[idx], tol);
889 
890  if(x > best)
891  {
892  best = x;
893  enterId = thesolver->coId(idx);
894  }
895  }
896  else
897  {
900  }
901  }
902 
903  return enterId;
904 }
905 
907 {
908  SPxId enterId;
909  const Real* test = thesolver->test().get_const_ptr();
910  const Real* weights_ptr = thesolver->weights.get_const_ptr();
911 
912  int idx;
913  Real x;
914 
915  for(int i = thesolver->infeasibilitiesCo.size() - 1; i >= 0; --i)
916  {
918  x = test[idx];
919 
920  if(x < -tol)
921  {
922  x = computePrice(x, weights_ptr[idx], tol);
923 
924  if(x > best)
925  {
926  best = x;
927  enterId = thesolver->id(idx);
928  }
929  }
930  else
931  {
934  }
935  }
936 
937  return enterId;
938 }
939 
941 {
942  SPxId enterId;
943  const Real* coTest = thesolver->coTest().get_const_ptr();
944  const Real* coWeights_ptr = thesolver->coWeights.get_const_ptr();
945 
946  Real x;
947 
948  for(int i = 0, end = thesolver->dim(); i < end; ++i)
949  {
950  x = coTest[i];
951 
952  if(x < -tol)
953  {
954  x = computePrice(x, coWeights_ptr[i], tol);
955 
956  if(x > best)
957  {
958  best = x;
959  enterId = thesolver->coId(i);
960  }
961  }
962  }
963 
964  return enterId;
965 }
966 
968 {
969  SPxId enterId;
970  const Real* test = thesolver->test().get_const_ptr();
971  const Real* weights_ptr = thesolver->weights.get_const_ptr();
972 
973  Real x;
974 
975  for(int i = 0, end = thesolver->coDim(); i < end; ++i)
976  {
977  x = test[i];
978 
979  if(x < -tol)
980  {
981  x = computePrice(x, weights_ptr[i], tol);
982 
983  if(x > best)
984  {
985  best = x;
986  enterId = thesolver->id(i);
987  }
988  }
989  }
990 
991  return enterId;
992 }
993 
994 
996 {
997  DVector& weights = thesolver->weights;
998  n = weights.dim();
999  weights.reDim(thesolver->coDim());
1000 
1001  if(thesolver->type() == SPxSolver::ENTER)
1002  {
1003  for(; n < weights.dim(); ++n)
1004  weights[n] = 2;
1005  }
1006 }
1007 
1009 {
1010  DVector& coWeights = thesolver->coWeights;
1011  n = coWeights.dim();
1012  workVec.reDim(thesolver->dim());
1013  coWeights.reDim(thesolver->dim());
1014 
1015  for(; n < coWeights.dim(); ++n)
1016  coWeights[n] = 1;
1017 }
1018 
1020 {
1021  assert(thesolver != 0);
1022  DVector& weights = thesolver->weights;
1023  weights[i] = weights[weights.dim()];
1024  weights.reDim(thesolver->coDim());
1025 }
1026 
1027 void SPxSteepPR::removedVecs(const int perm[])
1028 {
1029  assert(thesolver != 0);
1030  DVector& weights = thesolver->weights;
1031 
1032  if(thesolver->type() == SPxSolver::ENTER)
1033  {
1034  int i;
1035  int j = weights.dim();
1036 
1037  for(i = 0; i < j; ++i)
1038  {
1039  if(perm[i] >= 0)
1040  weights[perm[i]] = weights[i];
1041  }
1042  }
1043 
1044  weights.reDim(thesolver->coDim());
1045 }
1046 
1048 {
1049  assert(thesolver != 0);
1050  DVector& coWeights = thesolver->coWeights;
1051  coWeights[i] = coWeights[coWeights.dim()];
1052  coWeights.reDim(thesolver->dim());
1053 }
1054 
1055 void SPxSteepPR::removedCoVecs(const int perm[])
1056 {
1057  assert(thesolver != 0);
1058  DVector& coWeights = thesolver->coWeights;
1059  int i;
1060  int j = coWeights.dim();
1061 
1062  for(i = 0; i < j; ++i)
1063  {
1064  if(perm[i] >= 0)
1065  coWeights[perm[i]] = coWeights[i];
1066  }
1067 
1068  coWeights.reDim(thesolver->dim());
1069 }
1070 
1072 {
1073 #ifdef ENABLE_CONSISTENCY_CHECKS
1074  DVector& w = thesolver->weights;
1075  DVector& coW = thesolver->coWeights;
1076 
1077  if(thesolver != 0 && thesolver->type() == SPxSolver::LEAVE && setup == EXACT)
1078  {
1079  int i;
1080  SSVector tmp(thesolver->dim(), thesolver->epsilon());
1081  Real x;
1082 
1083  for(i = thesolver->dim() - 1; i >= 0; --i)
1084  {
1086  x = coW[i] - tmp.length2();
1087 
1088  if(x > thesolver->leavetol() || -x > thesolver->leavetol())
1089  {
1090  MSG_ERROR(std::cerr << "ESTEEP03 x[" << i << "] = " << x << std::endl;)
1091  }
1092  }
1093  }
1094 
1095  if(thesolver != 0 && thesolver->type() == SPxSolver::ENTER)
1096  {
1097  int i;
1098 
1099  for(i = thesolver->dim() - 1; i >= 0; --i)
1100  {
1101  if(coW[i] < thesolver->epsilon())
1102  return MSGinconsistent("SPxSteepPR");
1103  }
1104 
1105  for(i = thesolver->coDim() - 1; i >= 0; --i)
1106  {
1107  if(w[i] < thesolver->epsilon())
1108  return MSGinconsistent("SPxSteepPR");
1109  }
1110  }
1111 
1112 #endif
1113 
1114  return true;
1115 }
1116 } // namespace soplex
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:4102
Random numbers.
SPxId coId(int i) const
id of i &#39;th covector.
Definition: spxsolver.h:1117
int iteration() const
returns number of basis changes since last load().
Definition: spxbasis.h:546
virtual SPxId selectEnter()
Definition: spxsteeppr.cpp:631
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase&#39;s dimension to newdim.
Definition: dvectorbase.h:253
int selectLeaveX(Real tol)
implementation of full pricing
Definition: spxsteeppr.cpp:314
void coSolve(Vector &x, const Vector &rhs)
Cosolves linear system with basis matrix.
Definition: spxbasis.h:730
SPxId selectEnterHyperCoDim(Real &best, Real feastol)
implementation of hyper sparse pricing in the entering Simplex
Definition: spxsteeppr.cpp:788
int buildBestPriceVectorLeave(Real feastol)
prepare data structures for hyper sparse pricing
Definition: spxsteeppr.cpp:223
const Vector & fTest() const
Violations of fVec.
Definition: spxsolver.h:1385
virtual void setType(SPxSolver::Type)
set entering/leaving algorithm
Definition: spxsteeppr.cpp:51
DIdxSet updateViols
store indices that were changed in the previous iteration and must be checked in hyper pricing ...
Definition: spxsolver.h:435
SPxOut * spxout
message handler
Definition: spxsolver.h:463
bool sparsePricingLeave
These values enable or disable sparse pricing.
Definition: spxsolver.h:448
THREADLOCAL const Real infinity
Definition: spxdefines.cpp:26
#define STEEP_REFINETOL
Definition: spxsteeppr.cpp:26
Type
Algorithmic type.
Definition: spxsolver.h:124
R length2() const
Squared norm.
Definition: vectorbase.h:405
DIdxSet bestPrices
array of best pricing candidates
Definition: spxsteeppr.h:76
T * get_ptr()
get a C pointer to the data.
Definition: dataarray.h:110
virtual void load(SPxSolver *base)
sets the solver
Definition: spxsteeppr.cpp:38
Real leavetol() const
feasibility tolerance maintained by ratio test during LEAVE algorithm.
Definition: spxsolver.h:796
Representation
LP basis representation.
Definition: spxsolver.h:105
bool sparsePricingEnterCo
true if sparsePricing is turned on in the entering Simplex
Definition: spxsolver.h:450
Real computePrice(Real viol, Real weight, Real tol)
Definition: spxdevexpr.cpp:110
DataArray< int > isInfeasible
0: index not violated, 1: index violated, 2: index violated and among candidate list ...
Definition: spxsolver.h:443
DataArray< IdxElement > prices
temporary array of precomputed pricing values
Definition: spxsteeppr.h:72
starting with multipliers set to 1
Definition: spxsteeppr.h:56
void clear()
removes all indices.
Definition: idxset.h:184
int lastUpdate() const
returns number of basis changes since last refactorization.
Definition: spxbasis.h:540
int dim() const
dimension of basis matrix.
Definition: spxsolver.h:1075
void setup4solve(SSVector *p_y, SSVector *p_rhs)
Setup vectors to be solved within Simplex loop.
Definition: spxsolver.h:1694
void clear()
remove all elements.
Definition: dataarray.h:208
virtual int selectLeave()
Definition: spxsteeppr.cpp:270
virtual void addedCoVecs(int n)
n covectors have been added to loaded LP.
SSVector workVec
working vector
Definition: spxsteeppr.h:68
bool isTimeLimitReached(const bool forceCheck=false)
returns whether current time limit is reached; call to time() may be skipped unless forceCheck is tru...
Definition: spxsolver.cpp:1657
const R * get_const_ptr() const
Conversion to C-style pointer.
Definition: vectorbase.h:455
Steepest edge pricer.
int dim() const
Dimension of VectorBase.
Definition: ssvectorbase.h:563
Entering Simplex.
Definition: spxsolver.h:134
Generic Ids for LP rows or columns.Both SPxColIds and SPxRowIds may be treated uniformly as SPxIds: ...
Definition: spxid.h:85
UpdateVector & coPvec() const
copricing vector.
Definition: spxsolver.h:1398
void remove(int n, int m)
removes indices at position numbers n through m.
Definition: idxset.cpp:51
R * get_ptr()
Conversion to C-style pointer.
Definition: vectorbase.h:446
Leaving Simplex.
Definition: spxsolver.h:143
double Real
Definition: spxdefines.h:218
SPxId selectEnterX(Real tol)
choose the best entering index among columns and rows but prefer sparsity
Definition: spxsteeppr.cpp:662
const R * values() const
Returns array values.
Definition: ssvectorbase.h:300
bool refined
has a refinement step already been tried?
Definition: spxsteeppr.h:84
#define HYPERPRICINGSIZE
Definition: spxsolver.h:39
virtual void setRep(SPxSolver::Representation rep)
set row/column representation
Definition: spxsteeppr.cpp:161
virtual void entered4(SPxId id, int n)
Definition: spxsteeppr.cpp:453
virtual bool isConsistent() const
int size() const
returns the number of used indices.
Definition: idxset.h:124
virtual void left4(int n, SPxId id)
Definition: spxsteeppr.cpp:174
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:114
void append(const T &t)
append element t.
Definition: dataarray.h:121
SPxId id(int i) const
id of i &#39;th vector.
Definition: spxsolver.h:1098
UpdateVector & fVec() const
feasibility vector.
Definition: spxsolver.h:1323
void addIdx(int i)
adds index i to the index set
Definition: didxset.h:79
const T * get_const_ptr() const
get a const C pointer to the data.
Definition: dataarray.h:115
DVector coWeights
store dual norms
Definition: spxsolver.h:460
virtual void addedVecs(int n)
n vectors have been added to loaded LP.
Definition: spxsteeppr.cpp:995
SPxSolver * thesolver
the solver
Definition: spxpricer.h:56
void clear()
Clears vector.
Definition: ssvectorbase.h:603
starting with exactly computed values
Definition: spxsteeppr.h:55
DataArray< IdxElement > pricesCo
temporary array of precomputed pricing values
Definition: spxsteeppr.h:74
void setEpsilon(R eps)
Changes the non-zero epsilon, invalidating the setup. */.
Definition: ssvectorbase.h:111
bool isConsistent() const
consistency check.
Definition: ssvectorbase.h:620
bool sparsePricingEnter
true if sparsePricing is turned on in the entering Simplex for slack variables
Definition: spxsolver.h:449
DIdxSet bestPricesCo
array of best pricing candidates
Definition: spxsteeppr.h:78
void setup4coSolve(SSVector *p_y, SSVector *p_rhs)
Setup vectors to be cosolved within Simplex loop.
Definition: spxsolver.h:1722
SPxId selectEnterSparseCoDim(Real &best, Real tol)
implementation of sparse pricing for the entering Simplex
Definition: spxsteeppr.cpp:906
const Vector & test() const
Violations of pVec.
Definition: spxsolver.h:1531
#define MSG_INFO3(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO3.
Definition: spxdefines.h:122
Real epsilon() const
values are considered to be 0.
Definition: spxsolver.h:784
SPxId selectEnterHyperDim(Real &best, Real feastol)
implementation of hyper sparse pricing in the entering Simplex
Definition: spxsteeppr.cpp:704
void reDim(int newdim)
Resets dimension to newdim.
Definition: ssvectorbase.h:569
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:85
UpdateVector & pVec() const
pricing vector.
Definition: spxsolver.h:1478
int selectLeaveHyper(Real tol)
implementation of hyper sparse pricing in the leaving Simplex
Definition: spxsteeppr.cpp:377
DIdxSet infeasibilities
Definition: spxsolver.h:429
R length2() const
Squared euclidian norm.
Definition: ssvectorbase.h:535
int dim() const
Dimension of vector.
Definition: vectorbase.h:217
void setup_and_assign(SSVectorBase< S > &rhs)
Sets up rhs vector, and assigns it.
Definition: ssvectorbase.h:722
Everything should be within this namespace.
void setupWeights(SPxSolver::Type type)
setup steepest edge weights
Definition: spxsteeppr.cpp:72
const IdxSet & idx() const
nonzero indices of update vector
Definition: updatevector.h:133
IdxCompare compare
Definition: spxpricer.h:88
void solve4update(SSVector &x, const SVector &rhs)
solves linear system with basis matrix.
Definition: spxbasis.h:669
int selectLeaveSparse(Real tol)
implementation of sparse pricing in the leaving Simplex
Definition: spxsteeppr.cpp:341
SPxId buildBestPriceVectorEnterDim(Real &best, Real feastol)
build up vector of pricing values for later use
Definition: spxsteeppr.cpp:519
#define SPARSITY_TRADEOFF
Definition: spxsolver.h:42
int SPxQuicksortPart(T *keys, COMPARATOR &compare, int start, int end, int size, int start2=0, int end2=0, bool type=true)
Generic implementation of Partial QuickSort.
Definition: sorter.h:227
Real theeps
violation bound
Definition: spxpricer.h:58
const Vector & coTest() const
violations of coPvec.
Definition: spxsolver.h:1465
virtual void clear()
clear solver and preferences
Definition: spxsteeppr.cpp:33
bool isValid() const
returns TRUE iff the id is a valid column or row identifier.
Definition: spxid.h:151
int size() const
return nr. of elements.
Definition: dataarray.h:214
Type type() const
return current Type.
Definition: spxsolver.h:512
DataArray< int > isInfeasibleCo
0: index not violated, 1: index violated, 2: index violated and among candidate list ...
Definition: spxsolver.h:445
virtual void removedVec(int i)
the i&#39;th vector has been removed from the loaded LP.
int coDim() const
codimension.
Definition: spxsolver.h:1080
bool hyperPricingEnter
true if hyper sparse pricing is turned on in the entering Simplex
Definition: spxsolver.h:452
#define MSG_INFO1(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO1.
Definition: spxdefines.h:118
virtual void removedCoVec(int i)
the i&#39;th covector has been removed from the loaded LP.
DVector weights
dual pricing norms
Definition: spxsolver.h:459
Setup setup
setup type.
Definition: spxsteeppr.h:82
#define MSGinconsistent(name)
Definition: spxdefines.h:126
bool weightsAreSetup
are the dual norms already set up?
Definition: spxsolver.h:461
const SVector & vector(int i) const
i &#39;th vector.
Definition: spxsolver.h:1157
SSVector & delta()
update vector , writeable
Definition: updatevector.h:122
DIdxSet updateViolsCo
Definition: spxsolver.h:436
SPxId selectEnterDenseCoDim(Real &best, Real tol)
implementation of selectEnter() in dense case
Definition: spxsteeppr.cpp:967
void reMax(int newMax=1, int newSize=-1)
reset maximum number of elements.
Definition: dataarray.h:258
SSVector workRhs
working vector
Definition: spxsteeppr.h:70
int index(int n) const
access n &#39;th index.
Definition: idxset.h:118
void setMax(int newmax=1)
sets the maximum number of indices.
Definition: didxset.cpp:22
SPxId buildBestPriceVectorEnterCoDim(Real &best, Real feastol)
Definition: spxsteeppr.cpp:575
const SPxBasis & basis() const
Return current basis.
Definition: spxsolver.h:1761
virtual void removedCoVecs(const int perm[])
n covectors have been removed from loaded LP.
DIdxSet infeasibilitiesCo
Definition: spxsolver.h:432
bool hyperPricingLeave
true if hyper sparse pricing is turned on in the leaving Simplex
Definition: spxsolver.h:451
const IdxElement * elements
Definition: spxpricer.h:77
SPxId selectEnterDenseDim(Real &best, Real tol)
implementation of selectEnter() in dense case (slack variables)
Definition: spxsteeppr.cpp:940
Set of indices.Class IdxSet provides a set of indices. At construction it must be given an array of i...
Definition: idxset.h:56
R length2() const
Squared norm.
Definition: svectorbase.h:513
const SVector & unitVector(int i) const
return i &#39;th unit vector.
Definition: spxsolver.h:1236
SPxId selectEnterSparseDim(Real &best, Real tol)
implementation of sparse pricing for the entering Simplex (slack variables)
Definition: spxsteeppr.cpp:872
virtual void removedVecs(const int perm[])
n vectors have been removed from loaded LP.