Scippy

SoPlex

Sequential object-oriented simPlex

spxsolver.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 #include <iostream>
18 #include <sstream>
19 
20 #include "spxdefines.h"
21 #include "soplex.h"
22 #include "spxpricer.h"
23 #include "spxratiotester.h"
24 #include "spxstarter.h"
25 #include "spxout.h"
26 #include "timerfactory.h"
27 
28 namespace soplex
29 {
30 
31 bool SPxSolver::read(std::istream& in, NameSet* rowNames,
32  NameSet* colNames, DIdxSet* intVars)
33 {
34  if( initialized )
35  {
36  clear();
37  unInit();
38 
39  if (thepricer)
40  thepricer->clear();
41 
42  if (theratiotester)
44  }
45 
46  unLoad();
47  if (!SPxLP::read(in, rowNames, colNames, intVars))
48  return false;
49 
50  theLP = this;
51 
52  return true;
53 }
54 
56 {
58  unInit();
59  unLoad();
60  theLP = this;
62  if (thepricer)
63  thepricer->clear();
64  if (theratiotester)
66 }
67 
68 void SPxSolver::loadLP(const SPxLP& lp, bool initSlackBasis)
69 {
70  clear();
71  unInit();
72  unLoad();
74  if (thepricer)
75  thepricer->clear();
76  if (theratiotester)
78  SPxLP::operator=(lp);
79  reDim();
80  SPxBasis::load(this, initSlackBasis);
81 }
82 
83 void SPxSolver::setBasisSolver(SLinSolver* slu, const bool destroy)
84 {
85  // we need to set the outstream before we load the solver to ensure that the basis
86  // can be initialized with this pointer in loadSolver()
87  assert(spxout != 0);
88  slu->spxout = spxout;
89  SPxBasis::loadBasisSolver(slu, destroy);
90 }
91 
93 {
94  unInit();
96  {
97  SPxBasis::load(this, false);
98  }
100  SPxBasis::loadDesc(p_desc);
101 }
102 
103 void SPxSolver::setPricer(SPxPricer* x, const bool destroy)
104 {
105 
106  assert(!freePricer || thepricer != 0);
107 
108  if(freePricer)
109  {
110  delete thepricer;
111  thepricer = 0;
112  }
113 
114  if (x != 0 && x != thepricer)
115  {
116  setPricing(FULL);
117  if (isInitialized())
118  x->load(this);
119  else
120  x->clear();
121  }
122 
123  if (thepricer && thepricer != x)
124  thepricer->clear();
125  thepricer = x;
126 
127  freePricer = destroy;
128 }
129 
130 void SPxSolver::setTester(SPxRatioTester* x, const bool destroy)
131 {
132  assert(!freeRatioTester || theratiotester != 0);
133 
134  if(freeRatioTester)
135  {
136  delete theratiotester;
137  theratiotester = 0;
138  }
139 
140  theratiotester = x;
141 
142  // set the solver pointer inside the ratiotester
143  if( theratiotester != 0 )
144  {
145  if( isInitialized() )
146  theratiotester->load(this);
147  else
149  }
150 
151  freeRatioTester = destroy;
152 }
153 
154 void SPxSolver::setStarter(SPxStarter* x, const bool destroy)
155 {
156 
157  assert(!freeStarter || thestarter != 0);
158 
159  if(freeStarter)
160  {
161  delete thestarter;
162  thestarter = 0;
163  }
164  thestarter = x;
165 
166  freeStarter = destroy;
167 }
168 
170 {
171 
172  if (theType != tp)
173  {
174  theType = tp;
175 
177 
178  unInit();
179 #if 0
180  else
181  {
182  if (!matrixIsSetup)
183  {
184  SPxBasis::load(this);
185  // SPxBasis::load(desc());
186  // not needed, because load(this) allready loads descriptor
187  }
188  factorized = false;
189  m_numCycle = 0;
190 #endif
191  MSG_INFO3( (*spxout), (*spxout) << "Switching to "
192  << static_cast<const char*>((tp == LEAVE)
193  ? "leaving" : "entering")
194  << " algorithm" << std::endl; )
195  }
196 }
197 
199 {
200 
201  Real tmpfeastol = feastol();
202  Real tmpopttol = opttol();
203 
204  theRep = p_rep;
205 
206  if (theRep == COLUMN)
207  {
208  thevectors = colSet();
209  thecovectors = rowSet();
210  theFrhs = &primRhs;
211  theFvec = &primVec;
212  theCoPrhs = &dualRhs;
213  theCoPvec = &dualVec;
214  thePvec = &addVec;
216  theCPvec = thePvec;
221  }
222  else
223  {
224  assert(theRep == ROW);
225 
226  thevectors = rowSet();
227  thecovectors = colSet();
228  theFrhs = &dualRhs;
229  theFvec = &dualVec;
230  theCoPrhs = &primRhs;
231  theCoPvec = &primVec;
232  thePvec = &addVec;
233  theRPvec = thePvec;
239  }
240  unInit();
241  reDim();
242 
244 
245  setFeastol(tmpfeastol);
246  setOpttol(tmpopttol);
247 
251 
252  if (thepricer && thepricer->solver() == this)
253  thepricer->setRep(p_rep);
254 }
255 
257 {
258 
259  if (p_rep != theRep)
260  initRep(p_rep);
261 }
262 
263 // needed for strongbranching. use carefully
265 {
266 
267  initialized = true;
268 
269  if (type() == ENTER)
270  {
271  if (rep() == COLUMN)
272  setPrimalBounds();
273  else
275 
276  setEnterBounds();
278  }
279  else
280  {
281  if (rep() == ROW)
282  setPrimalBounds();
283  else
285 
286  setLeaveBounds();
288  }
289 
291  computePvec();
292  computeFrhs();
294 
295  theShift = 0.0;
296  lastShift = 0.0;
297 
298  if (type() == ENTER)
299  {
300  computeCoTest();
301  computeTest();
302  }
303  else
304  {
305  computeFtest();
306  }
307  assert((testBounds(), 1));
308 }
309 
311 {
312  nClckSkipsLeft = 0;
313  nCallsToTimelim = 0;
314  theCumulativeTime = 0.0;
315 }
316 
318 {
319 
320  assert(thepricer != 0);
321  assert(theratiotester != 0);
322 
323  if (!initialized)
324  {
325  initialized = true;
326  clearUpdateVecs();
327  reDim();
328  if (SPxBasis::status() <= SPxBasis::NO_PROBLEM || solver() != this)
329  SPxBasis::load(this);
330  initialized = false;
331  }
332  if (!matrixIsSetup)
334 
335  // Inna/Tobi: don't "upgrade" a singular basis to a regular one
337  return;
338 
339  // catch pathological case for LPs with zero constraints
340  if( dim() == 0 )
341  {
342  factorized = true;
343  }
344 
345  // we better factorize explicitly before solving
346  if( !factorized )
347  {
348  try
349  {
351  }
352  catch( const SPxException& )
353  {
354  // reload inital slack basis in case the factorization failed
358  assert(factorized);
359  }
360  }
361 
362  m_numCycle = 0;
363 
364  if (type() == ENTER)
365  {
366  if (rep() == COLUMN)
367  {
368  setPrimalBounds();
370  }
371  else
372  {
375  }
376  setEnterBounds();
378  // prepare support vectors for sparse pricing
384  }
385  else
386  {
387  if (rep() == ROW)
388  {
389  setPrimalBounds();
391  }
392  else
393  {
396  }
397  setLeaveBounds();
399  // prepare support vectors for sparse pricing
403  }
404 
406  computePvec();
407  computeFrhs();
409 
410  theShift = 0.0;
411 
412  if (type() == ENTER)
413  {
414  shiftFvec();
416 
417  computeCoTest();
418  computeTest();
419  }
420  else
421  {
422  shiftPvec();
424 
425  computeFtest();
426  }
427 
428  if (!initialized)
429  {
430  // if(thepricer->solver() != this)
431  thepricer->load(this);
432  // if(theratiotester->solver() != this)
433  theratiotester->load(this);
434  initialized = true;
435  }
436 }
437 
439 {
440  thePricing = pr;
441  if (initialized && type() == ENTER)
442  {
443  computePvec();
444  computeCoTest();
445  computeTest();
446  }
447 }
448 
450 {
451  if( decomp_stat == FINDSTARTBASIS )
452  getStartingDecompBasis = true;
453  else
454  getStartingDecompBasis = false;
455 }
456 
457 /*
458  The following method resizes all vectors and arrays of |SoPlex|
459  (excluding inherited vectors).
460  */
462 {
463 
464  int newsize = SPxLP::nCols() > SPxLP::nRows() ? SPxLP::nCols() : SPxLP::nRows();
465 
466  if (newsize > unitVecs.size())
467  {
468  unitVecs.reSize(newsize);
469 
470  while (newsize-- > 0)
471  unitVecs[newsize] = UnitVector(newsize);
472  }
473 
474  if (isInitialized())
475  {
476  theFrhs->reDim(dim());
477  theFvec->reDim(dim());
478  thePvec->reDim(coDim());
479 
480  theCoPrhs->reDim(dim());
481  theCoPvec->reDim(dim());
482 
483  theTest.reDim(coDim());
484  theCoTest.reDim(dim());
485 
490  theUBbound.reDim(dim());
491  theLBbound.reDim(dim());
492  }
493 }
494 
496 {
497  unitVecs.reSize(0);
498 
499  dualRhs.clear();
500  dualVec.clear();
501  primRhs.clear();
502  primVec.clear();
503  addVec.clear();
504  theURbound.clear();
505  theLRbound.clear();
506  theUCbound.clear();
507  theLCbound.clear();
508  theTest.clear();
509  theCoTest.clear();
510 
512  unInit();
513  SPxLP::clear();
515  // clear the basis only when theLP is present, because LP data (nrows, ncols) is used in reDim()
516  if( theLP != 0 )
517  SPxBasis::reDim();
518 
523 }
524 
526 {
529  unInit();
530  init();
531 }
532 
534 {
535  theFvec->clearUpdate();
536  thePvec->clearUpdate();
538  solveVector2 = 0;
539  solveVector3 = 0;
540  coSolveVector2 = 0;
541  coSolveVector3 = 0;
542 }
543 
544 /*
545  When the basis matrix factorization is recomputed from scratch,
546  we also recompute the vectors.
547  */
549 {
550 
551  MSG_INFO3( (*spxout), (*spxout) << " --- refactorizing basis matrix" << std::endl; )
552 
553  try
554  {
556  }
557  catch( const SPxStatusException& )
558  {
560  m_status = SINGULAR;
561  std::stringstream s;
562  s << "Basis is singular (numerical troubles, feastol = " << feastol() << ", opttol = " << opttol() << ")";
563  throw SPxStatusException(s.str());
564  }
565 
566  if( !initialized )
567  {
568  init(); // not sure if init() is neccessary here
569  // we must not go on here because not all vectors (e.g. fVec) may be set up correctly
570  return;
571  }
572 
574  {
575 #ifndef NDEBUG
576  DVector ftmp(fVec());
577  DVector ptmp(pVec());
578  DVector ctmp(coPvec());
579 #endif // NDEBUG
580 
581  if (type() == LEAVE)
582  {
583  /* we have to recompute theFrhs, because roundoff errors can occur during updating, especially when
584  * columns/rows with large bounds are present
585  */
586  computeFrhs();
589 
590 #ifndef NDEBUG
591  ftmp -= fVec();
592  ptmp -= pVec();
593  ctmp -= coPvec();
594  if (ftmp.length() > DEFAULT_BND_VIOL)
595  {
596  MSG_DEBUG( std::cout << "DSOLVE21 fVec: " << ftmp.length() << std::endl; )
597  ftmp = fVec();
598  multBaseWith(ftmp);
599  ftmp -= fRhs();
600  if (ftmp.length() > DEFAULT_BND_VIOL)
601  MSG_INFO1( (*spxout), (*spxout) << "ESOLVE29 " << iteration() << ": fVec error = "
602  << ftmp.length() << " exceeding DEFAULT_BND_VIOL = " << DEFAULT_BND_VIOL << std::endl; )
603  }
604  if (ctmp.length() > DEFAULT_BND_VIOL)
605  {
606  MSG_DEBUG( std::cout << "DSOLVE23 coPvec: " << ctmp.length() << std::endl; )
607  ctmp = coPvec();
608  multWithBase(ctmp);
609  ctmp -= coPrhs();
610  if (ctmp.length() > DEFAULT_BND_VIOL)
611  MSG_INFO1( (*spxout), (*spxout) << "ESOLVE30 " << iteration() << ": coPvec error = "
612  << ctmp.length() << " exceeding DEFAULT_BND_VIOL = " << DEFAULT_BND_VIOL << std::endl; )
613  }
614  if (ptmp.length() > DEFAULT_BND_VIOL)
615  {
616  MSG_DEBUG( std::cout << "DSOLVE24 pVec: " << ptmp.length() << std::endl; )
617  }
618 #endif // NDEBUG
619 
620  computeFtest();
621  }
622  else
623  {
624  assert(type() == ENTER);
625 
627  computeCoTest();
628 
629  if (pricing() == FULL)
630  {
631  /* to save time only recompute the row activities (in row rep) when we are already nearly optimal to
632  * avoid missing any violations from previous updates */
633  if( rep() == ROW && m_pricingViolCo < entertol() && m_pricingViol < entertol() )
634  computePvec();
635 
636  /* was deactivated, but this leads to warnings in testVecs() */
637  computeTest();
638  }
639  }
640  }
641 
642 #ifdef ENABLE_ADDITIONAL_CHECKS
643  /* moved this test after the computation of fTest and coTest below, since these vectors might not be set up at top, e.g. for an initial basis */
645  testVecs();
646 #endif
647 }
648 
649 /* We compute how much the current solution violates (primal or dual) feasibility. In the
650  row/enter or column/leave algorithm the maximum violation of dual feasibility is
651  computed. In the row/leave or column/enter algorithm the primal feasibility is checked.
652  Additionally, the violation from pricing is taken into account. */
654 {
655  Real inf = 0.0;
656 
657  if (type() == ENTER)
658  {
661 
662  for (int i = 0; i < dim(); i++)
663  {
664  if ((*theFvec)[i] > theUBbound[i])
665  inf = MAXIMUM(inf, (*theFvec)[i] - theUBbound[i]);
666  else if ((*theFvec)[i] < theLBbound[i])
667  inf = MAXIMUM(inf, theLBbound[i] - (*theFvec)[i]);
668  }
669  }
670  else
671  {
672  assert(type() == LEAVE);
673 
675  inf = m_pricingViol;
676 
677  for (int i = 0; i < dim(); i++)
678  {
679  if ((*theCoPvec)[i] > (*theCoUbound)[i])
680  inf = MAXIMUM(inf, (*theCoPvec)[i] - (*theCoUbound)[i]);
681  else if ((*theCoPvec)[i] < (*theCoLbound)[i])
682  inf = MAXIMUM(inf, (*theCoLbound)[i] - (*theCoPvec)[i]);
683  }
684  for (int i = 0; i < coDim(); i++)
685  {
686  if ((*thePvec)[i] > (*theUbound)[i])
687  inf = MAXIMUM(inf, (*thePvec)[i] - (*theUbound)[i]);
688  else if ((*thePvec)[i] < (*theLbound)[i])
689  inf = MAXIMUM(inf, (*theLbound)[i] - (*thePvec)[i]);
690  }
691  }
692 
693  return inf;
694 }
695 
696 /* check for (dual) violations above tol and immediately return false w/o checking the remaining values
697  This method is useful for verifying whether an objective limit can be used as termination criterion */
698 bool SPxSolver::noViols(Real tol) const
699 {
700  assert(tol >= 0.0);
701 
702  if( type() == ENTER )
703  {
704  for( int i = 0; i < dim(); i++ )
705  {
706  if( (*theFvec)[i] - theUBbound[i] > tol )
707  return false;
708  if( theLBbound[i] - (*theFvec)[i] > tol )
709  return false;
710  }
711  }
712  else
713  {
714  assert(type() == LEAVE);
715 
716  for( int i = 0; i < dim(); i++ )
717  {
718  if( (*theCoPvec)[i] - (*theCoUbound)[i] > tol )
719  return false;
720  if( (*theCoLbound)[i] - (*theCoPvec)[i] > tol )
721  return false;
722  }
723  for (int i = 0; i < coDim(); i++)
724  {
725  if( (*thePvec)[i] - (*theUbound)[i] > tol )
726  return false;
727  if( (*theLbound)[i] - (*thePvec)[i] > tol )
728  return false;
729  }
730  }
731  return true;
732 }
733 
735 {
736  int i;
737  Real val = 0;
738  const SPxBasis::Desc& ds = desc();
739 
740 #ifndef ENABLE_ADDITIONAL_CHECKS
741  // if the value is available we don't need to recompute it
743  return m_nonbasicValue;
744 #endif
745 
746  if (rep() == COLUMN)
747  {
748  if (type() == LEAVE)
749  {
750  for (i = nCols() - 1; i >= 0; --i)
751  {
752  switch (ds.colStatus(i))
753  {
755  val += theUCbound[i] * SPxLP::upper(i);
756  //@ val += maxObj(i) * SPxLP::upper(i);
757  break;
759  val += theLCbound[i] * SPxLP::lower(i);
760  //@ val += maxObj(i) * SPxLP::lower(i);
761  break;
763  val += maxObj(i) * SPxLP::lower(i);
764  break;
765  default:
766  break;
767  }
768  }
769  for (i = nRows() - 1; i >= 0; --i)
770  {
771  switch (ds.rowStatus(i))
772  {
774  val += theLRbound[i] * SPxLP::rhs(i);
775  break;
777  val += theURbound[i] * SPxLP::lhs(i);
778  break;
780  val += maxRowObj(i) * SPxLP::lhs(i);
781  break;
782  default:
783  break;
784  }
785  }
786  }
787  else
788  {
789  assert(type() == ENTER);
790  for (i = nCols() - 1; i >= 0; --i)
791  {
792  switch (ds.colStatus(i))
793  {
795  val += maxObj(i) * theUCbound[i];
796  break;
798  val += maxObj(i) * theLCbound[i];
799  break;
801  assert(theLCbound[i] == theUCbound[i]);
802  val += maxObj(i) * theLCbound[i];
803  break;
804  default:
805  break;
806  }
807  }
808  for (i = nRows() - 1; i >= 0; --i)
809  {
810  switch (ds.rowStatus(i))
811  {
813  val += maxRowObj(i) * theLRbound[i];
814  break;
816  val += maxRowObj(i) * theURbound[i];
817  break;
819  val += maxRowObj(i) * theURbound[i];
820  break;
821  default:
822  break;
823  }
824  }
825  }
826  }
827  else
828  {
829  assert(rep() == ROW);
830  assert(type() == ENTER);
831  for (i = nCols() - 1; i >= 0; --i)
832  {
833  switch (ds.colStatus(i))
834  {
836  val += theUCbound[i] * lower(i);
837  break;
839  val += theLCbound[i] * upper(i);
840  break;
842  val += theLCbound[i] * upper(i);
843  val += theUCbound[i] * lower(i);
844  break;
845  default:
846  break;
847  }
848  }
849  for (i = nRows() - 1; i >= 0; --i)
850  {
851  switch (ds.rowStatus(i))
852  {
854  val += theURbound[i] * lhs(i);
855  break;
857  val += theLRbound[i] * rhs(i);
858  break;
860  val += theLRbound[i] * rhs(i);
861  val += theURbound[i] * lhs(i);
862  break;
863  default:
864  break;
865  }
866  }
867  }
868 
869 #ifdef ENABLE_ADDITIONAL_CHECKS
871  {
872  MSG_ERROR( std::cerr << "stored nonbasic value: " << m_nonbasicValue
873  << ", correct nonbasic value: " << val
874  << ", violation: " << val - m_nonbasicValue << std::endl; )
875  assert(EQrel(m_nonbasicValue, val, 1e-12));
876  }
877 #endif
878 
880  {
881  m_nonbasicValue = val;
883  }
884 
885  return val;
886 }
887 
889 {
890  assert(isInitialized());
891 
892  Real x;
893 
894  // calling value() without having a suitable status is an error.
895  if (!isInitialized())
896  return infinity;
897 
898  if (rep() == ROW)
899  {
900  if (type() == LEAVE)
901  x = SPxLP::spxSense() * (coPvec() * fRhs()); // the contribution of maxRowObj() is missing
902  else
903  x = SPxLP::spxSense() * (nonbasicValue() + (coPvec() * fRhs()));
904  }
905  else
906  x = SPxLP::spxSense() * (nonbasicValue() + fVec() * coPrhs());
907 
908  return x + objOffset();
909 }
910 
912 {
914  m_nonbasicValue += objChange;
915 
916  MSG_DEBUG( std::cout
917  << "Iteration: " << iteration()
918  << ": updated objValue: " << objChange
919  << ", new value: " << m_nonbasicValue
920  << ", correct value: " << nonbasicValue()
921  << std::endl;
922  )
923 
925 }
926 
927 
928 
930 {
931 
932  if( d <= 0.0 )
933  throw SPxInterfaceException("XSOLVE30 Cannot set feastol less than or equal to zero.");
934 
935  if( theRep == COLUMN )
936  m_entertol = d;
937  else
938  m_leavetol = d;
939 }
940 
942 {
943 
944  if( d <= 0.0 )
945  throw SPxInterfaceException("XSOLVE31 Cannot set opttol less than or equal to zero.");
946 
947  if( theRep == COLUMN )
948  m_leavetol = d;
949  else
950  m_entertol = d;
951 }
952 
954 {
955 
956  if( d <= 0.0 )
957  throw SPxInterfaceException("XSOLVE32 Cannot set delta less than or equal to zero.");
958 
959  m_entertol = d;
960  m_leavetol = d;
961 }
962 
964 {
965  hyperPricingEnter = h;
966  hyperPricingLeave = h;
967  if( h )
968  {
971  }
972 }
973 
975  Type p_type,
976  Representation p_rep,
977  Timer::TYPE ttype)
978  : theType (p_type)
979  , thePricing(FULL)
980  , theRep(p_rep)
982  , theTime(0)
983  , timerType(ttype)
984  , theCumulativeTime(0.0)
985  , maxIters (-1)
986  , maxTime (infinity)
987  , nClckSkipsLeft(0)
988  , nCallsToTimelim(0)
989  , objLimit(infinity)
990  , m_status(UNKNOWN)
991  , m_nonbasicValue(0.0)
992  , m_nonbasicValueUpToDate(false)
993  , m_pricingViol(0.0)
994  , m_pricingViolUpToDate(false)
995  , m_pricingViolCo(0.0)
996  , m_pricingViolCoUpToDate(false)
997  , theShift (0)
998  , m_maxCycle(100)
999  , m_numCycle(0)
1000  , initialized (false)
1001  , solveVector2 (0)
1002  , solveVector3 (0)
1003  , coSolveVector2(0)
1004  , coSolveVector3(0)
1005  , freePricer (false)
1006  , freeRatioTester (false)
1007  , freeStarter (false)
1008  , displayLine (0)
1009  , displayFreq (200)
1011  , getStartingDecompBasis(false)
1012  , computeDegeneracy(false)
1013  , degenCompIterOffset(0)
1014  , fullPerturbation(false)
1015  , printCondition(0)
1016  , unitVecs (0)
1017  , primVec (0, Param::epsilon())
1018  , dualVec (0, Param::epsilon())
1019  , addVec (0, Param::epsilon())
1020  , thepricer (0)
1021  , theratiotester (0)
1022  , thestarter (0)
1023  , boundrange(0.0)
1024  , siderange(0.0)
1025  , objrange(0.0)
1026  , infeasibilities(0)
1027  , infeasibilitiesCo(0)
1028  , isInfeasible(0)
1029  , isInfeasibleCo(0)
1030  , sparsePricingLeave(false)
1031  , sparsePricingEnter(false)
1032  , sparsePricingEnterCo(false)
1033  , hyperPricingLeave(true)
1034  , hyperPricingEnter(true)
1038  , weights(0)
1039  , coWeights(0)
1040  , weightsAreSetup(false)
1041  , integerVariables(0)
1042 {
1044 
1046 
1047  theLP = this;
1048  initRep(p_rep);
1049 
1050  // info: SPxBasis is not consistent in this moment.
1051  //assert(SPxSolver::isConsistent());
1052 }
1053 
1055 {
1056  assert(!freePricer || thepricer != 0);
1057  assert(!freeRatioTester || theratiotester != 0);
1058  assert(!freeStarter || thestarter != 0);
1059 
1060  if(freePricer)
1061  {
1062  delete thepricer;
1063  thepricer = 0;
1064  }
1065 
1066  if(freeRatioTester)
1067  {
1068  delete theratiotester;
1069  theratiotester = 0;
1070  }
1071 
1072  if(freeStarter)
1073  {
1074  delete thestarter;
1075  thestarter = 0;
1076  }
1077 
1078  // free timer
1079  assert(theTime);
1080  theTime->~Timer();
1081  spx_free(theTime);
1082 }
1083 
1084 
1086 {
1087  if(this != &base)
1088  {
1089  SPxLP::operator=(base);
1090  SPxBasis::operator=(base);
1091  theType = base.theType;
1092  thePricing = base.thePricing;
1093  theRep = base.theRep;
1094  polishObj = base.polishObj;
1095  timerType = base.timerType;
1096  maxIters = base.maxIters;
1097  maxTime = base.maxTime;
1098  objLimit = base.objLimit;
1099  m_status = base.m_status;
1106  m_entertol = base.m_entertol;
1107  m_leavetol = base.m_leavetol;
1108  theShift = base.theShift;
1109  lastShift = base.lastShift;
1110  m_maxCycle = base.m_maxCycle;
1111  m_numCycle = base.m_numCycle;
1112  initialized = base.initialized;
1119  displayLine = base.displayLine;
1120  displayFreq = base.displayFreq;
1128  unitVecs = base.unitVecs;
1129  primRhs = base.primRhs;
1130  primVec = base.primVec;
1131  dualRhs = base.dualRhs;
1132  dualVec = base.dualVec;
1133  addVec = base.addVec;
1134  theURbound = base.theURbound;
1135  theLRbound = base.theLRbound;
1136  theUCbound = base.theUCbound;
1137  theLCbound = base.theLCbound;
1138  theUBbound = base.theUBbound;
1139  theLBbound = base.theLBbound;
1140  theCoTest = base.theCoTest;
1141  theTest = base.theTest;
1142  primalRay = base.primalRay;
1143  dualFarkas = base.dualFarkas;
1144  leaveCount = base.leaveCount;
1145  enterCount = base.enterCount;
1147  primalCount = base.primalCount;
1148  polishCount = base.polishCount;
1149  boundflips = base.boundflips;
1151  enterCycles = base.enterCycles;
1152  leaveCycles = base.leaveCycles;
1156  boundrange = base.boundrange;
1157  siderange = base.siderange;
1158  objrange = base.objrange;
1161  isInfeasible = base.isInfeasible;
1172  weights = base.weights;
1173  coWeights = base.coWeights;
1175  spxout = base.spxout;
1177 
1178  if (base.theRep == COLUMN)
1179  {
1180  thevectors = colSet();
1181  thecovectors = rowSet();
1182  theFrhs = &primRhs;
1183  theFvec = &primVec;
1184  theCoPrhs = &dualRhs;
1185  theCoPvec = &dualVec;
1186  thePvec = &addVec;
1187  theRPvec = theCoPvec;
1188  theCPvec = thePvec;
1189  theUbound = &theUCbound;
1190  theLbound = &theLCbound;
1193  }
1194  else
1195  {
1196  assert(base.theRep == ROW);
1197 
1198  thevectors = rowSet();
1199  thecovectors = colSet();
1200  theFrhs = &dualRhs;
1201  theFvec = &dualVec;
1202  theCoPrhs = &primRhs;
1203  theCoPvec = &primVec;
1204  thePvec = &addVec;
1205  theRPvec = thePvec;
1206  theCPvec = theCoPvec;
1207  theUbound = &theURbound;
1208  theLbound = &theLRbound;
1211  }
1212 
1213  SPxBasis::theLP = this;
1214 
1215  assert(!freePricer || thepricer != 0);
1216  assert(!freeRatioTester || theratiotester != 0);
1217  assert(!freeStarter || thestarter != 0);
1218 
1219  // thepricer
1220  if(freePricer)
1221  {
1222  delete thepricer;
1223  thepricer = 0;
1224  }
1225  if(base.thepricer == 0)
1226  {
1227  thepricer = 0;
1228  freePricer = false;
1229  }
1230  else
1231  {
1232  thepricer = base.thepricer->clone();
1233  freePricer = true;
1234  thepricer->load(this);
1235  }
1236 
1237  // theratiotester
1238  if(freeRatioTester)
1239  {
1240  delete theratiotester;
1241  theratiotester = 0;
1242  }
1243  if(base.theratiotester == 0)
1244  {
1245  theratiotester = 0;
1246  freeRatioTester = false;
1247  }
1248  else
1249  {
1251  freeRatioTester = true;
1252  theratiotester->load(this);
1253  }
1254 
1255  // thestarter
1256  if(freeStarter)
1257  {
1258  delete thestarter;
1259  thestarter = 0;
1260  }
1261  if(base.thestarter == 0)
1262  {
1263  thestarter = 0;
1264  freeStarter = false;
1265  }
1266  else
1267  {
1268  thestarter = base.thestarter->clone();
1269  freeStarter = true;
1270  }
1271 
1272  assert(SPxSolver::isConsistent());
1273  }
1274 
1275  return *this;
1276 }
1277 
1278 
1280  : SPxLP (base)
1281  , SPxBasis(base)
1282  , theType(base.theType)
1283  , thePricing(base.thePricing)
1284  , theRep(base.theRep)
1285  , polishObj(base.polishObj)
1286  , timerType(base.timerType)
1288  , maxIters(base.maxIters)
1289  , maxTime(base.maxTime)
1292  , objLimit(base.objLimit)
1293  , m_status(base.m_status)
1300  , m_entertol(base.m_entertol)
1301  , m_leavetol(base.m_leavetol)
1302  , theShift(base.theShift)
1303  , lastShift(base.lastShift)
1304  , m_maxCycle(base.m_maxCycle)
1305  , m_numCycle(base.m_numCycle)
1306  , initialized(base.initialized)
1307  , solveVector2 (0)
1309  , solveVector3 (0)
1311  , coSolveVector2(0)
1313  , coSolveVector3(0)
1321  , displayLine(base.displayLine)
1322  , displayFreq(base.displayFreq)
1330  , unitVecs(base.unitVecs)
1331  , primRhs(base.primRhs)
1332  , primVec(base.primVec)
1333  , dualRhs(base.dualRhs)
1334  , dualVec(base.dualVec)
1335  , addVec(base.addVec)
1336  , theURbound(base.theURbound)
1337  , theLRbound(base.theLRbound)
1338  , theUCbound(base.theUCbound)
1339  , theLCbound(base.theLCbound)
1340  , theUBbound(base.theUBbound)
1341  , theLBbound(base.theLBbound)
1342  , theCoTest(base.theCoTest)
1343  , theTest(base.theTest)
1344  , primalRay(base.primalRay)
1345  , dualFarkas(base.dualFarkas)
1346  , leaveCount(base.leaveCount)
1347  , enterCount(base.enterCount)
1348  , primalCount(base.primalCount)
1349  , polishCount(base.polishCount)
1350  , boundflips(base.boundflips)
1352  , enterCycles(base.enterCycles)
1353  , leaveCycles(base.leaveCycles)
1357  , dualDegenSum(base.dualDegenSum)
1358  , boundrange(base.boundrange)
1359  , siderange(base.siderange)
1360  , objrange(base.objrange)
1363  , isInfeasible(base.isInfeasible)
1373  , weights(base.weights)
1374  , coWeights(base.coWeights)
1376  , spxout(base.spxout)
1378 {
1380 
1381  if (base.theRep == COLUMN)
1382  {
1383  thevectors = colSet();
1384  thecovectors = rowSet();
1385  theFrhs = &primRhs;
1386  theFvec = &primVec;
1387  theCoPrhs = &dualRhs;
1388  theCoPvec = &dualVec;
1389  thePvec = &addVec;
1390  theRPvec = theCoPvec;
1391  theCPvec = thePvec;
1392  theUbound = &theUCbound;
1393  theLbound = &theLCbound;
1396  }
1397  else
1398  {
1399  assert(base.theRep == ROW);
1400 
1401  thevectors = rowSet();
1402  thecovectors = colSet();
1403  theFrhs = &dualRhs;
1404  theFvec = &dualVec;
1405  theCoPrhs = &primRhs;
1406  theCoPvec = &primVec;
1407  thePvec = &addVec;
1408  theRPvec = thePvec;
1409  theCPvec = theCoPvec;
1410  theUbound = &theURbound;
1411  theLbound = &theLRbound;
1414  }
1415 
1416  SPxBasis::theLP = this;
1417 
1418  if(base.thepricer == 0)
1419  {
1420  thepricer = 0;
1421  freePricer = false;
1422  }
1423  else
1424  {
1425  thepricer = base.thepricer->clone();
1426  freePricer = true;
1427  thepricer->clear();
1428  thepricer->load(this);
1429  }
1430 
1431  if(base.theratiotester == 0)
1432  {
1433  theratiotester = 0;
1434  freeRatioTester = false;
1435  }
1436  else
1437  {
1439  freeRatioTester = true;
1440  theratiotester->clear();
1441  theratiotester->load(this);
1442  }
1443 
1444  if(base.thestarter == 0)
1445  {
1446  thestarter = 0;
1447  freeStarter = false;
1448  }
1449  else
1450  {
1451  thestarter = base.thestarter->clone();
1452  freeStarter = true;
1453  }
1454 
1455  assert(SPxSolver::isConsistent());
1456 }
1457 
1459 {
1460 #ifdef ENABLE_CONSISTENCY_CHECKS
1461  if (epsilon() < 0)
1462  return MSGinconsistent("SPxSolver");
1463 
1465  return MSGinconsistent("SPxSolver");
1466 
1467  if (dualVec.delta().getEpsilon() != addVec.delta().getEpsilon())
1468  return MSGinconsistent("SPxSolver");
1469 
1470  if (unitVecs.size() < SPxLP::nCols() || unitVecs.size() < SPxLP::nRows())
1471  return MSGinconsistent("SPxSolver");
1472 
1473  if (initialized)
1474  {
1475  if (theFrhs->dim() != dim())
1476  return MSGinconsistent("SPxSolver");
1477  if (theFvec->dim() != dim())
1478  return MSGinconsistent("SPxSolver");
1479 
1480  if (theCoPrhs->dim() != dim())
1481  return MSGinconsistent("SPxSolver");
1482  if (thePvec->dim() != coDim())
1483  return MSGinconsistent("SPxSolver");
1484  if (theCoPvec->dim() != dim())
1485  return MSGinconsistent("SPxSolver");
1486 
1487  if (theTest.dim() != coDim())
1488  return MSGinconsistent("SPxSolver");
1489  if (theCoTest.dim() != dim())
1490  return MSGinconsistent("SPxSolver");
1491 
1492  if (theURbound.dim() != SPxLP::nRows())
1493  return MSGinconsistent("SPxSolver");
1494  if (theLRbound.dim() != SPxLP::nRows())
1495  return MSGinconsistent("SPxSolver");
1496  if (theUCbound.dim() != SPxLP::nCols())
1497  return MSGinconsistent("SPxSolver");
1498  if (theLCbound.dim() != SPxLP::nCols())
1499  return MSGinconsistent("SPxSolver");
1500  if (theUBbound.dim() != dim())
1501  return MSGinconsistent("SPxSolver");
1502  if (theLBbound.dim() != dim())
1503  return MSGinconsistent("SPxSolver");
1504  }
1505 
1506  if (rep() == COLUMN)
1507  {
1508  if(thecovectors !=
1509  reinterpret_cast<const SVSet*>(static_cast<const LPRowSet*>(this))
1510  || thevectors !=
1511  reinterpret_cast<const SVSet*>(static_cast<const LPColSet*>(this))
1512  || theFrhs != &primRhs ||
1513  theFvec != &primVec ||
1514  theCoPrhs != &dualRhs ||
1515  theCoPvec != &dualVec ||
1516  thePvec != &addVec ||
1517  theRPvec != theCoPvec ||
1518  theCPvec != thePvec ||
1519  theUbound != &theUCbound ||
1520  theLbound != &theLCbound ||
1521  theCoUbound != &theURbound ||
1522  theCoLbound != &theLRbound)
1523  return MSGinconsistent("SPxSolver");
1524  }
1525  else
1526  {
1527  if (thecovectors
1528  != reinterpret_cast<const SVSet*>(static_cast<const LPColSet*>(this))
1529  || thevectors
1530  != reinterpret_cast<const SVSet*>(static_cast<const LPRowSet*>(this))
1531  || theFrhs != &dualRhs ||
1532  theFvec != &dualVec ||
1533  theCoPrhs != &primRhs ||
1534  theCoPvec != &primVec ||
1535  thePvec != &addVec ||
1536  theRPvec != thePvec ||
1537  theCPvec != theCoPvec ||
1538  theUbound != &theURbound ||
1539  theLbound != &theLRbound ||
1540  theCoUbound != &theUCbound ||
1541  theCoLbound != &theLCbound)
1542  return MSGinconsistent("SPxSolver");
1543  }
1544 
1545  return SPxLP::isConsistent()
1546  && primRhs.isConsistent()
1547  && primVec.isConsistent()
1548  && dualRhs.isConsistent()
1549  && dualVec.isConsistent()
1550  && addVec.isConsistent()
1551  && theTest.isConsistent()
1552  && theCoTest.isConsistent()
1558  ;
1559 #else
1560  return true;
1561 #endif
1562 }
1563 
1564 
1566 {
1567  if( p_time < 0.0 )
1568  p_time = 0.0;
1569  maxTime = p_time;
1570 }
1571 
1573 {
1574  return maxTime;
1575 }
1576 
1577 void SPxSolver::setTerminationIter(int p_iteration)
1578 {
1579  if( p_iteration < 0 )
1580  p_iteration = -1;
1581  maxIters = p_iteration;
1582 }
1583 
1585 {
1586  return maxIters;
1587 }
1588 
1589 // returns whether current time limit is reached; call to time() may be skipped unless \p forceCheck is true
1590 bool SPxSolver::isTimeLimitReached(const bool forceCheck)
1591 {
1592  // always update the number of calls, since the user might set a time limit later in the solving process
1593  ++nCallsToTimelim;
1594 
1595  // check if a time limit is actually set
1596  if( maxTime >= infinity )
1597  return false;
1598 
1599  // check if the expensive system call to update the time should be skipped again
1600  if( forceCheck || nCallsToTimelim < NINITCALLS || nClckSkipsLeft <= 0 )
1601  {
1602  Real currtime = time();
1603 
1604  if( currtime >= maxTime )
1605  return true;
1606 
1607  // determine the number of times the clock can be skipped again.
1608  int nClckSkips = MAXNCLCKSKIPS;
1609  Real avgtimeinterval = (currtime + cumulativeTime()) / (Real)(nCallsToTimelim);
1610 
1611  // it would not be safe to skip the clock so many times since we are approaching the time limit
1612  if( SAFETYFACTOR * (maxTime - currtime) / (avgtimeinterval + 1e-6) < nClckSkips )
1613  nClckSkips = 0;
1614  nClckSkipsLeft = nClckSkips;
1615  }
1616  else
1617  --nClckSkipsLeft;
1618 
1619  return false;
1620 }
1621 
1622 
1623 /**@todo A first version for the termination value is
1624  * implemented. Currently we check if no bound violations (shifting)
1625  * is present. It might be even possible to use this termination
1626  * value in case of bound violations (shifting) but in this case it
1627  * is quite difficult to determine if we already reached the limit.
1628  */
1630 {
1631  objLimit = p_value;
1632 }
1633 
1635 {
1636  return objLimit;
1637 }
1638 
1641 {
1642  VarStatus vstat;
1643 
1644  switch( stat )
1645  {
1647  vstat = ON_LOWER;
1648  break;
1650  vstat = ON_UPPER;
1651  break;
1653  vstat = FIXED;
1654  break;
1656  vstat = ZERO;
1657  break;
1663  vstat = BASIC;
1664  break;
1665  default:
1666  MSG_ERROR( std::cerr << "ESOLVE26 ERROR: unknown basis status (" << stat << ")"
1667  << std::endl; )
1668  throw SPxInternalCodeException("XSOLVE22 This should never happen.");
1669  }
1670  return vstat;
1671 }
1672 
1675 {
1676  SPxBasis::Desc::Status rstat;
1677 
1678  switch( stat )
1679  {
1680  case FIXED :
1681  assert(rhs(row) == lhs(row));
1682  rstat = SPxBasis::Desc::P_FIXED;
1683  break;
1684  case ON_UPPER :
1685  assert(rhs(row) < infinity);
1686  rstat = lhs(row) < rhs(row)
1689  break;
1690  case ON_LOWER :
1691  assert(lhs(row) > -infinity);
1692  rstat = lhs(row) < rhs(row)
1695  break;
1696  case ZERO :
1697  /* A 'free' row (i.e., infinite lower & upper bounds) does not really make sense. The user
1698  * might (think to) know better, e.g., when temporarily turning off a row. We therefore apply
1699  * the same adjustment as in the column case in varStatusToBasisStatusCol(). */
1700  if (lhs(row) <= -infinity && rhs(row) >= infinity)
1701  rstat = SPxBasis::Desc::P_FREE;
1702  else
1703  {
1704  if ( lhs(row) == rhs(row) )
1705  {
1706  assert( rhs(row) < infinity );
1707  rstat = SPxBasis::Desc::P_FIXED;
1708  }
1709  else
1710  {
1711  if ( lhs(row) > -infinity )
1713  else
1714  {
1715  assert( rhs(row) < infinity );
1717  }
1718  }
1719  }
1720  break;
1721  case BASIC :
1722  rstat = dualRowStatus(row);
1723  break;
1724  default:
1725  MSG_ERROR( std::cerr << "ESOLVE27 ERROR: unknown VarStatus (" << int(stat) << ")"
1726  << std::endl; )
1727  throw SPxInternalCodeException("XSOLVE23 This should never happen.");
1728  }
1729  return rstat;
1730 }
1731 
1734 {
1735  SPxBasis::Desc::Status cstat;
1736 
1737  switch( stat )
1738  {
1739  case FIXED :
1740  if (upper(col) == lower(col))
1741  cstat = SPxBasis::Desc::P_FIXED;
1742  else if (maxObj(col) > 0.0)
1744  else
1746  break;
1747  case ON_UPPER :
1748  assert(upper(col) < infinity);
1749  cstat = lower(col) < upper(col)
1752  break;
1753  case ON_LOWER :
1754  assert(lower(col) > -infinity);
1755  cstat = lower(col) < upper(col)
1758  break;
1759  case ZERO :
1760  /* In this case the upper and lower bounds on the variable should be infinite. The bounds
1761  * might, however, have changed and we try to recover from this by changing the status to
1762  * 'resonable' settings. A solve has to find the correct values afterwards. Note that the
1763  * approach below is consistent with changesoplex.cpp (e.g., changeUpperStatus() and
1764  * changeLowerStatus() ). */
1765  if (lower(col) <= -infinity && upper(col) >= infinity)
1766  cstat = SPxBasis::Desc::P_FREE;
1767  else
1768  {
1769  if ( lower(col) == upper(col) )
1770  {
1771  assert( upper(col) < infinity );
1772  cstat = SPxBasis::Desc::P_FIXED;
1773  }
1774  else
1775  {
1776  if ( lower(col) > -infinity )
1778  else
1779  {
1780  assert( upper(col) < infinity );
1782  }
1783  }
1784  }
1785  break;
1786  case BASIC :
1787  cstat = dualColStatus(col);
1788  break;
1789  default:
1790  MSG_ERROR( std::cerr << "ESOLVE28 ERROR: unknown VarStatus (" << int(stat) << ")"
1791  << std::endl; )
1792  throw SPxInternalCodeException("XSOLVE24 This should never happen.");
1793  }
1794  return cstat;
1795 }
1796 
1798 {
1799  assert( 0 <= row && row < nRows() );
1800  return basisStatusToVarStatus( desc().rowStatus( row ) );
1801 }
1802 
1804 {
1805  assert( 0 <= col && col < nCols() );
1806  return basisStatusToVarStatus( desc().colStatus( col ) );
1807 }
1808 
1809 SPxSolver::Status SPxSolver::getBasis(VarStatus row[], VarStatus col[], const int rowsSize, const int colsSize) const
1810 {
1811  const SPxBasis::Desc& d = desc();
1812  int i;
1813 
1814  assert(rowsSize < 0 || rowsSize >= nRows());
1815  assert(colsSize < 0 || colsSize >= nCols());
1816 
1817  if (col)
1818  for (i = nCols() - 1; i >= 0; --i)
1819  col[i] = basisStatusToVarStatus( d.colStatus(i) );
1820 
1821  if (row)
1822  for (i = nRows() - 1; i >= 0; --i)
1823  row[i] = basisStatusToVarStatus( d.rowStatus(i) );
1824 
1825  return status();
1826 }
1827 
1829 {
1830 
1831  int basisdim;
1832 
1833  if ( p_rows.size() != nRows() || p_cols.size() != nCols() )
1834  return false;
1835 
1836  basisdim = 0;
1837  for ( int row = nRows()-1; row >= 0; --row )
1838  {
1839  if ( p_rows[row] == UNDEFINED )
1840  return false;
1841  // row is basic
1842  else if ( p_rows[row] == BASIC )
1843  {
1844  basisdim++;
1845  }
1846  // row is nonbasic
1847  else
1848  {
1849  if ( (p_rows[row] == FIXED && lhs(row) != rhs(row))
1850  || (p_rows[row] == ON_UPPER && rhs(row) >= infinity)
1851  || (p_rows[row] == ON_LOWER && lhs(row) <= -infinity) )
1852  return false;
1853  }
1854  }
1855 
1856  for ( int col = nCols()-1; col >= 0; --col )
1857  {
1858  if ( p_cols[col] == UNDEFINED )
1859  return false;
1860  // col is basic
1861  else if ( p_cols[col] == BASIC )
1862  {
1863  basisdim++;
1864  }
1865  // col is nonbasic
1866  else
1867  {
1868  if ( (p_cols[col] == FIXED && lower(col) != upper(col))
1869  || (p_cols[col] == ON_UPPER && upper(col) >= infinity)
1870  || (p_cols[col] == ON_LOWER && lower(col) <= -infinity) )
1871  return false;
1872  }
1873  }
1874 
1875  if ( basisdim != dim() )
1876  return false;
1877 
1878  // basis valid
1879  return true;
1880 }
1881 
1882 void SPxSolver::setBasis(const VarStatus p_rows[], const VarStatus p_cols[])
1883 {
1885  SPxBasis::load(this, false);
1886 
1887  SPxBasis::Desc ds = desc();
1888  int i;
1889 
1890  for(i = 0; i < nRows(); i++)
1891  ds.rowStatus(i) = varStatusToBasisStatusRow( i, p_rows[i] );
1892 
1893  for(i = 0; i < nCols(); i++)
1894  ds.colStatus(i) = varStatusToBasisStatusCol( i, p_cols[i] );
1895 
1896  loadBasis(ds);
1898 }
1899 
1900 // NOTE: This only works for the row representation. Need to update to account for column representation.
1901 // The degenvec differs relative to the algorithm being used.
1902 // For the primal simplex, degenvec is the primal solution values.
1903 // For the dual simplex, the degenvec is the feasvec (ROW) and pVec (COLUMN).
1905 {
1906  int numDegenerate = 0;
1907  Real degeneracyLevel = 0;
1908 
1909  // iterating over all columns in the basis matrix
1910  // this identifies the basis indices and those that have a zero dual multiplier (rows) or zero reduced cost (cols).
1911  if( rep() == ROW )
1912  {
1913  for( int i = 0; i < nCols(); ++i ) // @todo Check the use of numColsReal for the reduced problem.
1914  {
1915  // degeneracy in the dual simplex exists if there are rows with a zero dual multiplier or columns with a zero
1916  // reduced costs. This requirement is regardless of the objective sense.
1917  if( isZero(degenvec[i], feastol()) )
1918  numDegenerate++;
1919  }
1920 
1921  if( type() == ENTER ) // dual simplex
1922  degeneracyLevel = Real(numDegenerate)/nCols();
1923  else // primal simplex
1924  {
1925  assert(type() == LEAVE);
1926  Real degenVars = (numDegenerate > (nCols() - nRows())) ? Real(numDegenerate - (nCols() - nRows())) : 0.0;
1927  degeneracyLevel = degenVars/nRows();
1928  }
1929  }
1930  else
1931  {
1932  assert(rep() == COLUMN);
1933 
1934  for( int i = 0; i < nCols(); i++ )
1935  {
1936  if( type() == LEAVE ) // dual simplex
1937  {
1938  if( isZero(maxObj()[i] - degenvec[i], feastol()) )
1939  numDegenerate++;
1940  }
1941  else // primal simplex
1942  {
1943  assert( type() == ENTER );
1944  if( isZero(degenvec[i], feastol()) )
1945  numDegenerate++;
1946  }
1947  }
1948 
1949 
1950  if( type() == LEAVE ) // dual simplex
1951  {
1952  Real degenVars = nRows() > numDegenerate ? Real(nRows() - numDegenerate) : 0.0;
1953  degeneracyLevel = degenVars/nCols();
1954  }
1955  else // primal simplex
1956  {
1957  assert(type() == ENTER);
1958  Real degenVars = (numDegenerate > (nCols() - nRows())) ? Real(numDegenerate - (nCols() - nRows())) : 0.0;
1959  degeneracyLevel = degenVars/nRows();
1960  }
1961  }
1962 
1963  return degeneracyLevel;
1964 }
1965 
1966 void SPxSolver::getNdualNorms(int& nnormsRow, int& nnormsCol) const
1967 {
1968  nnormsRow = 0;
1969  nnormsCol = 0;
1970 
1971  if( weightsAreSetup )
1972  {
1973  if( type() == SPxSolver::LEAVE && rep() == SPxSolver::COLUMN )
1974  {
1975  nnormsRow = coWeights.dim();
1976  nnormsCol = 0;
1977 
1978  assert(nnormsRow == dim());
1979  }
1980  else if( type() == SPxSolver::ENTER && rep() == SPxSolver::ROW )
1981  {
1982  nnormsRow = weights.dim();
1983  nnormsCol = coWeights.dim();
1984 
1985  assert(nnormsRow == coDim());
1986  assert(nnormsCol == dim());
1987  }
1988  }
1989 }
1990 
1991 bool SPxSolver::getDualNorms(int& nnormsRow, int& nnormsCol, Real* norms) const
1992 {
1993  nnormsRow = 0;
1994  nnormsCol = 0;
1995 
1996  if( !weightsAreSetup )
1997  return false;
1998 
1999  if( type() == SPxSolver::LEAVE && rep() == SPxSolver::COLUMN )
2000  {
2001  nnormsCol = 0;
2002  nnormsRow = coWeights.dim();
2003 
2004  assert(nnormsRow == dim());
2005 
2006  for( int i = 0; i < nnormsRow; ++i)
2007  norms[i] = coWeights[i];
2008  }
2009  else if( type() == SPxSolver::ENTER && rep() == SPxSolver::ROW )
2010  {
2011  nnormsRow = weights.dim();
2012  nnormsCol = coWeights.dim();
2013 
2014  assert(nnormsCol == dim());
2015  assert(nnormsRow == coDim());
2016 
2017  for( int i = 0; i < nnormsRow; ++i )
2018  norms[i] = weights[i];
2019 
2020  for( int i = 0; i < nnormsCol; ++i )
2021  norms[nnormsRow + i] = coWeights[i];
2022  }
2023  else
2024  return false;
2025 
2026  return true;
2027 }
2028 
2029 bool SPxSolver::setDualNorms(int nnormsRow, int nnormsCol, Real* norms)
2030 {
2031  weightsAreSetup = false;
2032 
2033  if( type() == SPxSolver::LEAVE && rep() == SPxSolver::COLUMN)
2034  {
2035  coWeights.reDim(dim(), false);
2036  assert(coWeights.dim() >= nnormsRow);
2037  for( int i = 0; i < nnormsRow; ++i )
2038  coWeights[i] = norms[i];
2039  weightsAreSetup = true;
2040  }
2041  else if( type() == SPxSolver::ENTER && rep() == SPxSolver::ROW)
2042  {
2043  weights.reDim(coDim(), false);
2044  coWeights.reDim(dim(), false);
2045  assert(weights.dim() >= nnormsRow);
2046  assert(coWeights.dim() >= nnormsCol);
2047  for( int i = 0; i < nnormsRow; ++i )
2048  weights[i] = norms[i];
2049  for( int i = 0; i < nnormsCol; ++i )
2050  coWeights[i] = norms[nnormsRow + i];
2051  weightsAreSetup = true;
2052  }
2053  else
2054  return false;
2055  return true;
2056 }
2057 
2058 void SPxSolver::setIntegralityInformation(int ncols, int* intInfo)
2059 {
2060  assert(ncols == nCols() || (ncols == 0 && intInfo == NULL));
2061 
2062  integerVariables.reSize(ncols);
2063  for( int i = 0; i < ncols; ++i )
2064  {
2065  integerVariables[i] = intInfo[i];
2066  }
2067 }
2068 
2069 
2070 
2071 //
2072 // Auxiliary functions.
2073 //
2074 
2075 // Pretty-printing of variable status.
2076 std::ostream& operator<<( std::ostream& os,
2077  const SPxSolver::VarStatus& status )
2078 {
2079  switch( status )
2080  {
2081  case SPxSolver::BASIC:
2082  os << "BASIC";
2083  break;
2084  case SPxSolver::FIXED:
2085  os << "FIXED";
2086  break;
2087  case SPxSolver::ON_LOWER:
2088  os << "ON_LOWER";
2089  break;
2090  case SPxSolver::ON_UPPER:
2091  os << "ON_UPPER";
2092  break;
2093  case SPxSolver::ZERO:
2094  os << "ZERO";
2095  break;
2096  case SPxSolver::UNDEFINED:
2097  os << "UNDEFINED";
2098  break;
2099  default:
2100  os << "?invalid?";
2101  break;
2102  }
2103  return os;
2104 }
2105 
2106 // Pretty-printing of solver status.
2107 std::ostream& operator<<( std::ostream& os,
2108  const SPxSolver::Status& status )
2109 {
2110  switch ( status )
2111  {
2112  case SPxSolver::ERROR:
2113  os << "ERROR";
2114  break;
2116  os << "NO_RATIOTESTER";
2117  break;
2118  case SPxSolver::NO_PRICER:
2119  os << "NO_PRICER";
2120  break;
2121  case SPxSolver::NO_SOLVER:
2122  os << "NO_SOLVER";
2123  break;
2124  case SPxSolver::NOT_INIT:
2125  os << "NOT_INIT";
2126  break;
2128  os << "ABORT_CYCLING";
2129  break;
2130  case SPxSolver::ABORT_TIME:
2131  os << "ABORT_TIME";
2132  break;
2133  case SPxSolver::ABORT_ITER:
2134  os << "ABORT_ITER";
2135  break;
2137  os << "ABORT_VALUE";
2138  break;
2139  case SPxSolver::SINGULAR:
2140  os << "SINGULAR";
2141  break;
2142  case SPxSolver::NO_PROBLEM:
2143  os << "NO_PROBLEM";
2144  break;
2145  case SPxSolver::REGULAR:
2146  os << "REGULAR";
2147  break;
2148  case SPxSolver::RUNNING:
2149  os << "RUNNING";
2150  break;
2151  case SPxSolver::UNKNOWN:
2152  os << "UNKNOWN";
2153  break;
2154  case SPxSolver::OPTIMAL:
2155  os << "OPTIMAL";
2156  break;
2157  case SPxSolver::UNBOUNDED:
2158  os << "UNBOUNDED";
2159  break;
2160  case SPxSolver::INFEASIBLE:
2161  os << "INFEASIBLE";
2162  break;
2163  default:
2164  os << "?other?";
2165  break;
2166  }
2167  return os;
2168 }
2169 
2170 // Pretty-printing of algorithm.
2171 std::ostream& operator<<( std::ostream& os,
2172  const SPxSolver::Type& status )
2173 {
2174  switch ( status )
2175  {
2176  case SPxSolver::ENTER:
2177  os << "ENTER";
2178  break;
2179  case SPxSolver::LEAVE:
2180  os << "LEAVE";
2181  break;
2182  default:
2183  os << "?other?";
2184  break;
2185  }
2186  return os;
2187 }
2188 
2189 // Pretty-printing of representation.
2190 std::ostream& operator<<( std::ostream& os,
2192 {
2193  switch ( status )
2194  {
2195  case SPxSolver::ROW:
2196  os << "ROW";
2197  break;
2198  case SPxSolver::COLUMN:
2199  os << "COLUMN";
2200  break;
2201  default:
2202  os << "?other?";
2203  break;
2204  }
2205  return os;
2206 }
2207 
2208 
2209 } // namespace soplex
const VectorBase< Real > & rhs() const
Returns right hand side vector.
Definition: spxlpbase.h:219
void computeFtest()
compute basis feasibility test vector.
Definition: leave.cpp:38
Real boundrange
absolute range of all bounds in the problem
Definition: spxsolver.h:388
void clearUpdate()
clear ,
Definition: updatevector.h:160
virtual ~SPxSolver()
Definition: spxsolver.cpp:1054
int iteration() const
returns number of basis changes since last load().
Definition: spxbasis.h:545
Exception class for things that should NEVER happen.This class is derived from the SoPlex exception b...
Definition: exceptions.h:109
Vector & multWithBase(Vector &x) const
Vector-basis product.
Definition: spxbasis.cpp:940
SoPlex start basis generation base class.
Basis is dual feasible.
Definition: spxbasis.h:95
free variable fixed to zero.
Definition: spxsolver.h:194
Safe arrays of data objects.Class DataArray provides safe arrays of Data Objects. For general C++ obj...
Definition: dataarray.h:63
not initialised error
Definition: spxsolver.h:208
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase&#39;s dimension to newdim.
Definition: dvectorbase.h:249
Basis is not known to be dual nor primal feasible.
Definition: spxbasis.h:94
void coSolve(Vector &x, const Vector &rhs)
Cosolves linear system with basis matrix.
Definition: spxbasis.h:719
UnitVectorBase< Real > UnitVector
Definition: unitvector.h:29
int enterDegenCand
the number of degenerate candidates in the entering algorithm
Definition: spxsolver.h:379
primal variable is fixed to both bounds
Definition: spxbasis.h:190
int nClckSkipsLeft
remaining number of times the clock can be safely skipped
Definition: spxsolver.h:251
UpdateVector primVec
primal vector
Definition: spxsolver.h:323
const Real & objOffset() const
Returns the objective function value offset.
Definition: spxlpbase.h:516
SPxOut * spxout
message handler
Definition: slinsolver.h:214
bool isConsistent() const
Consistency check.
Definition: dvectorbase.h:302
int boundflips
number of performed bound flips
Definition: spxsolver.h:374
bool getDualNorms(int &nnormsRow, int &nnormsCol, Real *norms) const
get dual norms
Definition: spxsolver.cpp:1991
primal or dual variable is undefined
Definition: spxbasis.h:195
void invalidate()
invalidates actual basis.
const VectorBase< Real > & upper() const
Returns upper bound vector.
Definition: spxlpbase.h:456
Desc::Status dualColStatus(int i) const
dual Status for the i&#39;th column variable of the loaded LP.
Definition: spxbasis.cpp:69
#define DEFAULT_BND_VIOL
default allowed bound violation
Definition: spxdefines.h:226
void getNdualNorms(int &nnormsRow, int &nnormsCol) const
get number of dual norms
Definition: spxsolver.cpp:1966
DIdxSet updateViols
store indices that were changed in the previous iteration and must be checked in hyper pricing ...
Definition: spxsolver.h:417
SPxOut * spxout
message handler
Definition: spxsolver.h:443
bool sparsePricingLeave
These values enable or disable sparse pricing.
Definition: spxsolver.h:428
THREADLOCAL const Real infinity
Definition: spxdefines.cpp:26
Type
Algorithmic type.
Definition: spxsolver.h:124
DVector * theUbound
Upper bound for vars.
Definition: spxsolver.h:357
Pricing pricing() const
return current Pricing.
Definition: spxsolver.h:497
Real objrange
absolute range of all objective coefficients in the problem
Definition: spxsolver.h:390
void setBasis(const VarStatus rows[], const VarStatus cols[])
set the lp solver&#39;s basis.
Definition: spxsolver.cpp:1882
void testBounds() const
Definition: spxbounds.cpp:311
UpdateVector addVec
storage for thePvec = &addVec
Definition: spxsolver.h:326
DVector theCoTest
Definition: spxsolver.h:363
Abstract pricer base class.
Real leavetol() const
feasibility tolerance maintained by ratio test during LEAVE algorithm.
Definition: spxsolver.h:786
DVector * theCoUbound
Upper bound for covars.
Definition: spxsolver.h:359
SSVector * solveVector3
when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic so...
Definition: spxsolver.h:274
void computeTest()
compute test vector in ENTERing Simplex.
Definition: enter.cpp:102
Status getBasis(VarStatus rows[], VarStatus cols[], const int rowsSize=-1, const int colsSize=-1) const
get current basis, and return solver status.
Definition: spxsolver.cpp:1809
virtual void setStarter(SPxStarter *starter, const bool destroy=false)
setup starting basis generator to use. If destroy is true, starter will be freed in destructor...
Definition: spxsolver.cpp:154
int degenCompIterOffset
the number of iterations performed before the degeneracy level is computed
Definition: spxsolver.h:305
virtual void reDim()
reset dimensions of vectors according to loaded LP.
Definition: spxsolver.cpp:461
Real feastol() const
allowed primal feasibility tolerance.
Definition: spxsolver.h:793
UpdateVector dualVec
dual vector
Definition: spxsolver.h:325
void unscaleLPandReloadBasis()
unscales the LP and reloads the basis
Definition: spxsolver.cpp:525
virtual void setBasisSolver(SLinSolver *slu, const bool destroy=false)
setup linear solver to use. If destroy is true, slusolver will be freed in destructor.
Definition: spxsolver.cpp:83
Type theType
entering or leaving algortihm.
Definition: spxsolver.h:242
Status & rowStatus(int i)
Definition: spxbasis.h:239
Representation
LP basis representation.
Definition: spxsolver.h:105
bool sparsePricingEnterCo
true if sparsePricing is turned on in the entering Simplex
Definition: spxsolver.h:430
virtual void clear()
clear all data in solver.
Definition: spxsolver.cpp:495
virtual void setRep(SPxSolver::Representation)
sets basis representation.
Definition: spxpricer.h:160
void setType(Type tp)
set LEAVE or ENTER algorithm.
Definition: spxsolver.cpp:169
void clear()
clear vector and update vector
Definition: updatevector.h:153
virtual ~Timer()
Definition: timer.h:124
VarStatus basisStatusToVarStatus(SPxBasis::Desc::Status stat) const
converts basis status to VarStatus
Definition: spxsolver.cpp:1640
Abstract ratio test base class.
solve() aborted due to iteration limit.
Definition: spxsolver.h:213
int leaveDegenCand
the number of degenerate candidates in the leaving algorithm
Definition: spxsolver.h:380
DecompStatus
Improved dual simplex status.
Definition: spxsolver.h:181
virtual int terminationIter() const
return iteration limit.
Definition: spxsolver.cpp:1584
virtual SPxStarter * clone() const =0
clone function for polymorphism
int m_maxCycle
maximum steps before cycling is detected.
Definition: spxsolver.h:268
DataArray< int > isInfeasible
0: index not violated, 1: index violated, 2: index violated and among candidate list ...
Definition: spxsolver.h:424
No Problem has been loaded.
Definition: spxsolver.h:216
bool NE(Real a, Real b, Real eps=Param::epsilon())
returns true iff |a-b| > eps
Definition: spxdefines.h:386
Real length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
Definition: vectorbase.h:397
Pricing thePricing
full or partial pricing.
Definition: spxsolver.h:243
void clear()
removes all indices.
Definition: idxset.h:184
virtual bool noViols(Real tol) const
check for violations above tol and immediately return false w/o checking the remaining values ...
Definition: spxsolver.cpp:698
Abstract ratio test base class.Class SPxRatioTester is the virtual base class for computing the ratio...
#define SPARSITYFACTOR
Definition: spxsolver.h:39
DVector primRhs
rhs vector for computing the primal vector
Definition: spxsolver.h:322
SPxLPBase< Real > & operator=(const SPxLPBase< Real > &old)
Assignment operator.
Definition: spxlpbase.h:2642
int dim() const
dimension of basis matrix.
Definition: spxsolver.h:1063
Vector & multBaseWith(Vector &x) const
Basis-vector product.
Definition: spxbasis.cpp:979
SoPlex start basis generation base class.SPxStarter is the virtual base class for classes generating ...
Definition: spxstarter.h:41
virtual bool read(std::istream &in, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
Reads LP in LP or MPS format from input stream in.
Definition: spxlpbase.h:1134
void clear()
remove all elements.
Definition: dataarray.h:205
void reDim(int newdim)
reset dimension
Definition: updatevector.h:167
variable fixed to identical bounds.
Definition: spxsolver.h:193
Real sparsePricingFactor
enable sparse pricing when viols < factor * dim()
Definition: spxsolver.h:301
virtual SPxRatioTester * clone() const =0
clone function for polymorphism
LP has been proven to be primal infeasible.
Definition: spxsolver.h:222
void setPrimalBounds()
setup feasibility bounds for entering algorithm
Definition: spxbounds.cpp:32
SSVector * solveVector2rhs
when 2 systems are to be solved at a time; typically for speepest edge weights
Definition: spxsolver.h:273
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:1590
void setOpttol(Real d)
set parameter opttol.
Definition: spxsolver.cpp:941
Real time() const
time spent in last call to method solve().
Definition: spxsolver.h:2129
bool factorized
true iff factor = matrix .
Definition: spxbasis.h:357
bool freeRatioTester
true iff theratiotester should be freed inside of object
Definition: spxsolver.h:282
void setRep()
sets descriptor representation according to loaded LP.
Definition: spxbasis.cpp:307
Sparse Linear Solver virtual base class.Class SLinSolver provides a class for solving sparse linear s...
Definition: slinsolver.h:43
#define NINITCALLS
Definition: spxsolver.h:48
Real m_nonbasicValue
nonbasic part of current objective value
Definition: spxsolver.h:256
virtual Real value()
current objective value.
Definition: spxsolver.cpp:888
rowwise representation.
Definition: spxsolver.h:107
bool setDualNorms(int nnormsRow, int nnormsCol, Real *norms)
set dual norms
Definition: spxsolver.cpp:2029
Real lastShift
for forcing feasibility.
Definition: spxsolver.h:267
virtual void computeLeaveCoPrhs()
compute theCoPrhs for leaving Simplex.
Definition: spxvecs.cpp:478
TimerFactory class.
SPxSolver(Type type=LEAVE, Representation rep=ROW, Timer::TYPE ttype=Timer::USER_TIME)
default constructor.
Definition: spxsolver.cpp:974
virtual void setTerminationTime(Real time=infinity)
set time limit.
Definition: spxsolver.cpp:1565
Basis is singular.
Definition: spxbasis.h:93
Desc::Status dualRowStatus(int i) const
dual Status for the i&#39;th row variable of the loaded LP.
Definition: spxbasis.cpp:46
#define SAFETYFACTOR
Definition: spxsolver.h:47
bool freePricer
true iff thepricer should be freed inside of object
Definition: spxsolver.h:281
Representation theRep
row or column representation.
Definition: spxsolver.h:244
dual variable is left free, but unset
Definition: spxbasis.h:191
Real getDegeneracyLevel(Vector degenvec)
get level of dual degeneracy
Definition: spxsolver.cpp:1904
Wrapper for different output streams and verbosity levels.
int nRows() const
Returns number of rows in LP.
Definition: spxlpbase.h:151
virtual SPxPricer * clone() const =0
clone function for polymorphism
No ratiotester loaded.
Definition: spxsolver.h:205
No pricer loaded.
Definition: spxsolver.h:206
Entering Simplex.
Definition: spxsolver.h:134
const Vector & fRhs() const
right-hand side vector for fVec
Definition: spxsolver.h:1324
primal variable is set to its upper bound
Definition: spxbasis.h:188
UpdateVector & coPvec() const
copricing vector.
Definition: spxsolver.h:1386
int remainingRoundsLeave
number of dense rounds/refactorizations until sparsePricing is enabled again
Definition: spxsolver.h:434
int m_numCycle
actual number of degenerate steps so far.
Definition: spxsolver.h:269
int maxIters
maximum allowed iterations.
Definition: spxsolver.h:249
Leaving Simplex.
Definition: spxsolver.h:143
Real m_entertol
feasibility tolerance maintained during entering algorithm
Definition: spxsolver.h:264
nothing known about basis status (possibly due to a singular basis in transformed problem) ...
Definition: spxsolver.h:196
SPxStatus status() const
returns current SPxStatus.
Definition: spxbasis.h:425
SPxStarter * thestarter
Definition: spxsolver.h:386
SSVector * solveVector3rhs
when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic so...
Definition: spxsolver.h:275
UpdateVector * theRPvec
row pricing vector
Definition: spxsolver.h:352
bool m_pricingViolCoUpToDate
true, if the stored violation in coDim is up to date
Definition: spxsolver.h:262
void reDim()
resizes internal arrays.
double Real
Definition: spxdefines.h:218
SSVector * coSolveVector3
when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic so...
Definition: spxsolver.h:278
#define MAXNCLCKSKIPS
Definition: spxsolver.h:46
#define MAXIMUM(x, y)
Definition: spxdefines.h:246
Pricing
Pricing type.
Definition: spxsolver.h:152
DVector * theFrhs
Definition: spxsolver.h:342
#define MSG_DEBUG(x)
Definition: spxdefines.h:132
Status status() const
Status of solution process.
Definition: spxsolve.cpp:2043
DVector * theLbound
Lower bound for vars.
Definition: spxsolver.h:358
SPxSense spxSense() const
Returns the optimization sense.
Definition: spxlpbase.h:510
virtual void clear()
unloads LP.
Definition: spxpricer.h:118
Real m_pricingViol
maximal feasibility violation of current solution
Definition: spxsolver.h:259
virtual void unInit()
uninitialize data structures.
Definition: spxsolver.h:1847
std::ostream & operator<<(std::ostream &s, const VectorBase< R > &vec)
Output operator.
Definition: basevectors.h:1159
Real entertol() const
feasibility tolerance maintained by ratio test during ENTER algorithm.
Definition: spxsolver.h:779
UpdateVector * thePvec
Definition: spxsolver.h:350
SPxBasis::Desc::Status varStatusToBasisStatusRow(int row, VarStatus stat) const
converts VarStatus to basis status for rows
Definition: spxsolver.cpp:1674
LP has been solved to optimality.
Definition: spxsolver.h:220
bool computeDegeneracy
Definition: spxsolver.h:304
virtual void setPricer(SPxPricer *pricer, const bool destroy=false)
setup pricer to use. If destroy is true, pricer will be freed in destructor.
Definition: spxsolver.cpp:103
Real cumulativeTime() const
cumulative time spent in all calls to method solve().
Definition: spxsolver.h:2145
virtual void setLeaveBounds()
Definition: spxbounds.cpp:297
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:114
SPxPricer * thepricer
Definition: spxsolver.h:384
const SVSet * thecovectors
the LP coVectors according to representation
Definition: spxsolver.h:320
virtual Real terminationTime() const
return time limit.
Definition: spxsolver.cpp:1572
UpdateVector & fVec() const
feasibility vector.
Definition: spxsolver.h:1311
virtual void reinitializeVecs()
setup all vecs fresh
Definition: spxsolver.cpp:264
SPxId instableEnterId
Definition: spxsolver.h:295
dual variable is set to its upper bound
Definition: spxbasis.h:192
solve() aborted due to time limit.
Definition: spxsolver.h:212
DVector theLBbound
Lower Basic Feasibility bound.
Definition: spxsolver.h:339
an error occured.
Definition: spxsolver.h:204
DVector coWeights
store dual norms
Definition: spxsolver.h:440
primal variable is left free, but unset
Definition: spxbasis.h:189
Real siderange
absolute range of all side in the problem
Definition: spxsolver.h:389
const VectorBase< Real > & lhs() const
Returns left hand side vector.
Definition: spxlpbase.h:253
SPxSolver & operator=(const SPxSolver &base)
assignment operator
Definition: spxsolver.cpp:1085
int primalCount
number of primal iterations
Definition: spxsolver.h:371
Abstract pricer base class.Class SPxPricer is a pure virtual class defining the interface for pricer ...
Definition: spxpricer.h:46
void shiftPvec()
Perform initial shifting to optain an feasible or pricable basis.
Definition: spxshift.cpp:79
SSVector * coSolveVector3rhs
when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic so...
Definition: spxsolver.h:279
variable set to its upper bound.
Definition: spxsolver.h:191
bool updateNonbasicValue(Real objChange)
Definition: spxsolver.cpp:911
Basis descriptor.
Definition: spxbasis.h:104
virtual void loadBasisSolver(SLinSolver *solver, const bool destroy=false)
sets up linear solver to use.
Definition: spxbasis.cpp:342
Dynamic index set.Class DIdxSet provides dynamic IdxSet in the sense, that no restrictions are posed ...
Definition: didxset.h:42
DVector theURbound
Upper Row Feasibility bound.
Definition: spxsolver.h:328
bool freeStarter
true iff thestarter should be freed inside of object
Definition: spxsolver.h:283
bool sparsePricingEnter
true if sparsePricing is turned on in the entering Simplex for slack variables
Definition: spxsolver.h:429
int remainingRoundsEnterCo
Definition: spxsolver.h:436
virtual void load(SPxSolver *p_solver)
loads LP.
int leaveCycles
the number of degenerate steps during the leaving algorithm
Definition: spxsolver.h:378
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
Definition: timerfactory.h:43
algorithm is running
Definition: spxsolver.h:218
const VectorBase< Real > & maxRowObj() const
Definition: spxlpbase.h:297
Timer * theTime
time spent in last call to method solve()
Definition: spxsolver.h:246
virtual void setDelta(Real newDelta)
set allowed bound violation
Status & colStatus(int i)
Definition: spxbasis.h:254
Real m_leavetol
feasibility tolerance maintained during leaving algorithm
Definition: spxsolver.h:265
virtual void loadLP(const SPxLP &LP, bool initSlackBasis=true)
copy LP.
Definition: spxsolver.cpp:68
variable set to its lower bound.
Definition: spxsolver.h:192
DVector theUBbound
Upper Basic Feasibility bound.
Definition: spxsolver.h:338
Preconfigured SoPlex LP solver.
#define MSG_INFO3(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO3.
Definition: spxdefines.h:122
Real m_pricingViolCo
maximal feasibility violation of current solution in coDim
Definition: spxsolver.h:261
DVector * theCoLbound
Lower bound for covars.
Definition: spxsolver.h:360
Real epsilon() const
values are considered to be 0.
Definition: spxsolver.h:774
Debugging, floating point type and parameter definitions.
virtual void loadBasis(const SPxBasis::Desc &)
set a start basis.
Definition: spxsolver.cpp:92
Simplex basis.Consider the linear program as provided from class SPxLP: where , and ...
Definition: spxbasis.h:82
Set of strings.Class NameSet implements a symbol or name table. It allows to store or remove names (i...
Definition: nameset.h:61
void restoreInitialBasis()
Restores initial basis.
int totalboundflips
total number of bound flips
Definition: spxsolver.h:375
int polishCount
number of solution polishing iterations
Definition: spxsolver.h:372
Sequential object-oriented SimPlex.SPxSolver is an LP solver class using the revised Simplex algorith...
Definition: spxsolver.h:84
SolutionPolish polishObj
objective of solution polishing
Definition: spxsolver.h:245
UpdateVector & pVec() const
pricing vector.
Definition: spxsolver.h:1466
virtual void load(SPxSolver *p_solver)
loads LP.
Definition: spxpricer.h:112
bool fullPerturbation
whether to perturb the entire problem or just the bounds relevant for the current pivot ...
Definition: spxsolver.h:308
Full pricing.
Definition: spxsolver.h:160
SSVector * solveVector2
when 2 systems are to be solved at a time; typically for speepest edge weights
Definition: spxsolver.h:272
DIdxSet infeasibilities
Definition: spxsolver.h:411
DVector theLRbound
Lower Row Feasibility bound.
Definition: spxsolver.h:329
DVector theUCbound
Upper Column Feasibility bound.
Definition: spxsolver.h:330
void setDualColBounds()
Definition: spxbounds.cpp:103
virtual void setTerminationIter(int iteration=-1)
set iteration limit.
Definition: spxsolver.cpp:1577
bool isInitialized() const
has the internal data been initialized?
Definition: spxsolver.h:1838
virtual bool read(std::istream &in, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
read LP from input stream.
Definition: spxsolver.cpp:31
int decompIterationLimit
the maximum number of iterations before the decomposition simplex is aborted.
Definition: spxsolver.h:306
Status m_status
status of algorithm.
Definition: spxsolver.h:254
int dim() const
Dimension of vector.
Definition: vectorbase.h:215
Starting basis has not been found yet.
Definition: spxsolver.h:184
Exception base class.This class implements a base class for our SoPlex exceptions We provide a what()...
Definition: exceptions.h:32
int remainingRoundsEnter
Definition: spxsolver.h:435
Everything should be within this namespace.
bool isBasisValid(DataArray< VarStatus > rows, DataArray< VarStatus > cols)
check a given basis for validity.
Definition: spxsolver.cpp:1828
TYPE
types of timers
Definition: timer.h:99
bool EQrel(Real a, Real b, Real eps=Param::epsilon())
returns true iff |relDiff(a,b)| <= eps
Definition: spxdefines.h:428
R getEpsilon() const
Returns the non-zero epsilon used.
Definition: ssvectorbase.h:104
Real theCumulativeTime
cumulative time spent in all calls to method solve()
Definition: spxsolver.h:248
UpdateVector * theFvec
Definition: spxsolver.h:344
virtual void setTester(SPxRatioTester *tester, const bool destroy=false)
setup ratio-tester to use. If destroy is true, tester will be freed in destructor.
Definition: spxsolver.cpp:130
Real dualDegenSum
the sum of the dual degeneracy percentage
Definition: spxsolver.h:382
SSVector * coSolveVector2rhs
when 2 systems are to be solved at a time; typically for speepest edge weights
Definition: spxsolver.h:277
solve() aborted due to detection of cycling.
Definition: spxsolver.h:211
Set of LP columns.Class LPColSetBase implements a set of LPColBase%s. Unless for memory limitations...
Definition: lpcolsetbase.h:43
SPxBasis & operator=(const SPxBasis &rhs)
assignment operator
Definition: spxbasis.cpp:1315
primal variable is set to its lower bound
Definition: spxbasis.h:187
bool m_nonbasicValueUpToDate
true, if the stored objValue is up to date
Definition: spxsolver.h:257
const VectorBase< Real > & maxObj() const
Returns objective vector for maximization problem.
Definition: spxlpbase.h:429
Exception class for incorrect usage of interface methods.
Definition: exceptions.h:126
void setIntegralityInformation(int ncols, int *intInfo)
pass integrality information about the variables to the solver
Definition: spxsolver.cpp:2058
SPxSolver * theLP
the LP
Definition: spxbasis.h:343
DVector theLCbound
Lower Column Feasibility bound.
Definition: spxsolver.h:331
virtual void clearUpdateVecs(void)
Definition: spxsolver.cpp:533
int leaveCount
number of LEAVE iterations
Definition: spxsolver.h:369
nothing known on loaded problem.
Definition: spxsolver.h:219
don&#39;t perform modifications on optimal basis
Definition: spxsolver.h:229
VarStatus getBasisRowStatus(int row) const
gets basis status for a single row
Definition: spxsolver.cpp:1797
virtual void factorize()
factorizes the basis matrix.
Definition: spxbasis.cpp:889
bool isConsistent() const
check consistency.
Definition: spxsolver.cpp:1458
variable is basic.
Definition: spxsolver.h:195
VarStatus getBasisColStatus(int col) const
gets basis status for a single column
Definition: spxsolver.cpp:1803
void computeFrhs()
compute feasibility vector from scratch.
Definition: spxvecs.cpp:42
void setDualRowBounds()
Definition: spxbounds.cpp:133
void clear()
Set vector to 0.
Definition: vectorbase.h:260
SPxBasis::Desc::Status varStatusToBasisStatusCol(int col, VarStatus stat) const
converts VarStatus to basis status for columns
Definition: spxsolver.cpp:1733
SPxRatioTester * theratiotester
Definition: spxsolver.h:385
virtual Real terminationValue() const
return objective limit.
Definition: spxsolver.cpp:1634
void shiftFvec()
Perform initial shifting to optain an feasible or pricable basis.
Definition: spxshift.cpp:25
DVector * theCoPrhs
Definition: spxsolver.h:347
dual variable is set to its lower bound
Definition: spxbasis.h:193
int enterCycles
the number of degenerate steps during the entering algorithm
Definition: spxsolver.h:377
DSVector primalRay
stores primal ray in case of unboundedness
Definition: spxsolver.h:366
int size() const
return nr. of elements.
Definition: dataarray.h:211
virtual void loadDesc(const Desc &)
sets up basis.
Definition: spxbasis.cpp:188
Type type() const
return current Type.
Definition: spxsolver.h:491
DataArray< int > isInfeasibleCo
0: index not violated, 1: index violated, 2: index violated and among candidate list ...
Definition: spxsolver.h:425
Real theShift
sum of all shifts applied to any bound.
Definition: spxsolver.h:266
void unscaleLP()
unscales the lp and clears basis
virtual SPxSolver * solver() const
returns loaded SPxSolver object.
Definition: spxpricer.h:124
int coDim() const
codimension.
Definition: spxsolver.h:1068
bool hyperPricingEnter
true if hyper sparse pricing is turned on in the entering Simplex
Definition: spxsolver.h:432
bool isConsistent() const
Consistency check.
Definition: spxlpbase.h:1854
#define MSG_INFO1(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO1.
Definition: spxdefines.h:118
bool isConsistent() const
DSVector dualFarkas
stores dual farkas proof in case of infeasibility
Definition: spxsolver.h:367
int nCols() const
Returns number of columns in LP.
Definition: spxlpbase.h:157
int enterCount
number of ENTER iterations
Definition: spxsolver.h:370
const Vector & coPrhs() const
Right-hand side vector for coPvec.
Definition: spxsolver.h:1399
DVector weights
dual pricing norms
Definition: spxsolver.h:439
int printCondition
printing the current condition number in the log (0 - off, 1 - estimate,exact, 2 - exact)";ratio esti...
Definition: spxsolver.h:309
Array< UnitVector > unitVecs
array of unit vectors
Definition: spxsolver.h:318
const SVSet * thevectors
the LP vectors according to representation
Definition: spxsolver.h:319
DataArray< int > integerVariables
supplementary variable information, 0: continous variable, 1: integer variable
Definition: spxsolver.h:445
virtual void setEnterBounds()
Definition: spxbounds.cpp:215
dual variable has two bounds
Definition: spxbasis.h:194
Real maxTime
maximum allowed time.
Definition: spxsolver.h:250
Exception class for status exceptions during the computationsThis class is derived from the SoPlex ex...
Definition: exceptions.h:89
void setFeastol(Real d)
set parameter feastol.
Definition: spxsolver.cpp:929
virtual void init()
intialize data structures.
Definition: spxsolver.cpp:317
bool initialized
true, if all vectors are setup.
Definition: spxsolver.h:270
virtual void computeEnterCoPrhs()
compute theCoPrhs for entering Simplex.
Definition: spxvecs.cpp:405
const SVSetBase< R > * colSet() const
Returns the complete SVSetBase.
Definition: lpcolsetbase.h:68
bool isZero(Real a, Real eps=Param::epsilon())
returns true iff |a| <= eps
Definition: spxdefines.h:416
void forceRecompNonbasicValue()
Definition: spxsolver.h:649
#define MSGinconsistent(name)
Definition: spxdefines.h:126
bool weightsAreSetup
are the dual norms already set up?
Definition: spxsolver.h:441
void solve(Vector &x, const Vector &rhs)
Definition: spxbasis.h:631
void initRep(Representation p_rep)
initialize ROW or COLUMN representation.
Definition: spxsolver.cpp:198
SSVector & delta()
update vector , writeable
Definition: updatevector.h:122
DIdxSet updateViolsCo
Definition: spxsolver.h:418
Real opttol() const
allowed optimality, i.e., dual feasibility tolerance.
Definition: spxsolver.h:801
bool m_pricingViolUpToDate
true, if the stored violation is up to date
Definition: spxsolver.h:260
void hyperPricing(bool h)
enable or disable hyper sparse pricing
Definition: spxsolver.cpp:963
void setMax(int newmax=1)
sets the maximum number of indices.
Definition: didxset.cpp:22
Real objLimit
< the number of calls to the method isTimeLimitReached()
Definition: spxsolver.h:253
const SVSetBase< Real > * rowSet() const
Returns the complete SVSet.
Definition: lprowsetbase.h:69
virtual void clear()
clears the LP.
Definition: spxlpbase.h:1098
void computePvec()
compute entire pVec().
Definition: spxvecs.cpp:498
virtual void setTerminationValue(Real value=infinity)
set objective limit.
Definition: spxsolver.cpp:1629
virtual void load(SPxSolver *lp, bool initSlackBasis=true)
loads the LP lp to the basis.
Definition: spxbasis.cpp:326
bool getStartingDecompBasis
flag to indicate whether the simplex is solved to get the starting improved dual simplex basis ...
Definition: spxsolver.h:303
virtual void unLoad()
unloads the LP from the basis.
Definition: spxbasis.h:873
UpdateVector * theCoPvec
Definition: spxsolver.h:348
virtual void clear()
unloads LP.
Status
Status of a variable.
Definition: spxbasis.h:185
SSVector * coSolveVector2
when 2 systems are to be solved at a time; typically for speepest edge weights
Definition: spxsolver.h:276
virtual void reLoad()
reload LP.
Definition: spxsolver.cpp:55
void reSize(int newsize)
reset size to newsize.
Definition: dataarray.h:223
virtual Real maxInfeas() const
maximal infeasibility of basis
Definition: spxsolver.cpp:653
DIdxSet infeasibilitiesCo
Definition: spxsolver.h:414
DVector dualRhs
rhs vector for computing the dual vector
Definition: spxsolver.h:324
bool hyperPricingLeave
true if hyper sparse pricing is turned on in the leaving Simplex
Definition: spxsolver.h:431
const VectorBase< Real > & lower() const
Returns (internal and possibly scaled) lower bound vector.
Definition: spxlpbase.h:483
void setDecompStatus(DecompStatus decomp_stat)
turn on or off the improved dual simplex.
Definition: spxsolver.cpp:449
const Desc & desc() const
Definition: spxbasis.h:463
Representation rep() const
return the current basis representation.
Definition: spxsolver.h:485
Real nonbasicValue()
Compute part of objective value.
Definition: spxsolver.cpp:734
solve() aborted due to objective limit.
Definition: spxsolver.h:214
columnwise representation.
Definition: spxsolver.h:108
void spx_free(T &p)
Release memory.
Definition: spxalloc.h:109
bool isConsistent() const
consistency check.
Definition: spxbasis.cpp:1176
Basis is singular, numerical troubles?
Definition: spxsolver.h:215
UpdateVector * theCPvec
column pricing vector
Definition: spxsolver.h:353
virtual void factorize()
Factorize basis matrix.
Definition: spxsolver.cpp:548
Basis is primal feasible.
Definition: spxbasis.h:96
void resetClockStats()
resets clock average statistics
Definition: spxsolver.cpp:310
SPxSolver * solver() const
returns loaded solver.
Definition: spxbasis.h:563
LP has a usable Basis (maybe LP is changed).
Definition: spxsolver.h:217
bool matrixIsSetup
true iff the pointers in matrix are set up correctly.
Definition: spxbasis.h:349
void setBasisStatus(SPxBasis::SPxStatus stat)
set the lp solver&#39;s basis status.
Definition: spxsolver.h:2038
void setPricing(Pricing pr)
set FULL or PARTIAL pricing.
Definition: spxsolver.cpp:438
LP has been proven to be primal unbounded.
Definition: spxsolver.h:221
No Problem has been loaded to the basis.
Definition: spxbasis.h:92
No linear solver loaded.
Definition: spxsolver.h:207
void setDelta(Real d)
set parameter delta, i.e., set feastol and opttol to same value.
Definition: spxsolver.cpp:953
Timer::TYPE timerType
type of timer (user or wallclock)
Definition: spxsolver.h:247
void computeCoTest()
compute coTest vector.
Definition: enter.cpp:228
Real primalDegenSum
the sum of the primal degeneracy percentage
Definition: spxsolver.h:381