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-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 #include <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  , infeasibilities(0)
1024  , infeasibilitiesCo(0)
1025  , isInfeasible(0)
1026  , isInfeasibleCo(0)
1027  , sparsePricingLeave(false)
1028  , sparsePricingEnter(false)
1029  , sparsePricingEnterCo(false)
1030  , hyperPricingLeave(true)
1031  , hyperPricingEnter(true)
1035  , weights(0)
1036  , coWeights(0)
1037  , weightsAreSetup(false)
1038  , integerVariables(0)
1039 {
1041 
1043 
1044  theLP = this;
1045  initRep(p_rep);
1046 
1047  // info: SPxBasis is not consistent in this moment.
1048  //assert(SPxSolver::isConsistent());
1049 }
1050 
1052 {
1053  assert(!freePricer || thepricer != 0);
1054  assert(!freeRatioTester || theratiotester != 0);
1055  assert(!freeStarter || thestarter != 0);
1056 
1057  if(freePricer)
1058  {
1059  delete thepricer;
1060  thepricer = 0;
1061  }
1062 
1063  if(freeRatioTester)
1064  {
1065  delete theratiotester;
1066  theratiotester = 0;
1067  }
1068 
1069  if(freeStarter)
1070  {
1071  delete thestarter;
1072  thestarter = 0;
1073  }
1074 
1075  // free timer
1076  assert(theTime);
1077  theTime->~Timer();
1078  spx_free(theTime);
1079 }
1080 
1081 
1083 {
1084  if(this != &base)
1085  {
1086  SPxLP::operator=(base);
1087  SPxBasis::operator=(base);
1088  theType = base.theType;
1089  thePricing = base.thePricing;
1090  theRep = base.theRep;
1091  polishObj = base.polishObj;
1092  timerType = base.timerType;
1093  maxIters = base.maxIters;
1094  maxTime = base.maxTime;
1095  objLimit = base.objLimit;
1096  m_status = base.m_status;
1103  m_entertol = base.m_entertol;
1104  m_leavetol = base.m_leavetol;
1105  theShift = base.theShift;
1106  lastShift = base.lastShift;
1107  m_maxCycle = base.m_maxCycle;
1108  m_numCycle = base.m_numCycle;
1109  initialized = base.initialized;
1116  displayLine = base.displayLine;
1117  displayFreq = base.displayFreq;
1125  unitVecs = base.unitVecs;
1126  primRhs = base.primRhs;
1127  primVec = base.primVec;
1128  dualRhs = base.dualRhs;
1129  dualVec = base.dualVec;
1130  addVec = base.addVec;
1131  theURbound = base.theURbound;
1132  theLRbound = base.theLRbound;
1133  theUCbound = base.theUCbound;
1134  theLCbound = base.theLCbound;
1135  theUBbound = base.theUBbound;
1136  theLBbound = base.theLBbound;
1137  theCoTest = base.theCoTest;
1138  theTest = base.theTest;
1139  primalRay = base.primalRay;
1140  dualFarkas = base.dualFarkas;
1141  leaveCount = base.leaveCount;
1142  enterCount = base.enterCount;
1144  primalCount = base.primalCount;
1145  polishCount = base.polishCount;
1146  boundflips = base.boundflips;
1148  enterCycles = base.enterCycles;
1149  leaveCycles = base.leaveCycles;
1155  isInfeasible = base.isInfeasible;
1166  weights = base.weights;
1167  coWeights = base.coWeights;
1169  spxout = base.spxout;
1171 
1172  if (base.theRep == COLUMN)
1173  {
1174  thevectors = colSet();
1175  thecovectors = rowSet();
1176  theFrhs = &primRhs;
1177  theFvec = &primVec;
1178  theCoPrhs = &dualRhs;
1179  theCoPvec = &dualVec;
1180  thePvec = &addVec;
1181  theRPvec = theCoPvec;
1182  theCPvec = thePvec;
1183  theUbound = &theUCbound;
1184  theLbound = &theLCbound;
1187  }
1188  else
1189  {
1190  assert(base.theRep == ROW);
1191 
1192  thevectors = rowSet();
1193  thecovectors = colSet();
1194  theFrhs = &dualRhs;
1195  theFvec = &dualVec;
1196  theCoPrhs = &primRhs;
1197  theCoPvec = &primVec;
1198  thePvec = &addVec;
1199  theRPvec = thePvec;
1200  theCPvec = theCoPvec;
1201  theUbound = &theURbound;
1202  theLbound = &theLRbound;
1205  }
1206 
1207  SPxBasis::theLP = this;
1208 
1209  assert(!freePricer || thepricer != 0);
1210  assert(!freeRatioTester || theratiotester != 0);
1211  assert(!freeStarter || thestarter != 0);
1212 
1213  // thepricer
1214  if(freePricer)
1215  {
1216  delete thepricer;
1217  thepricer = 0;
1218  }
1219  if(base.thepricer == 0)
1220  {
1221  thepricer = 0;
1222  freePricer = false;
1223  }
1224  else
1225  {
1226  thepricer = base.thepricer->clone();
1227  freePricer = true;
1228  thepricer->load(this);
1229  }
1230 
1231  // theratiotester
1232  if(freeRatioTester)
1233  {
1234  delete theratiotester;
1235  theratiotester = 0;
1236  }
1237  if(base.theratiotester == 0)
1238  {
1239  theratiotester = 0;
1240  freeRatioTester = false;
1241  }
1242  else
1243  {
1245  freeRatioTester = true;
1246  theratiotester->load(this);
1247  }
1248 
1249  // thestarter
1250  if(freeStarter)
1251  {
1252  delete thestarter;
1253  thestarter = 0;
1254  }
1255  if(base.thestarter == 0)
1256  {
1257  thestarter = 0;
1258  freeStarter = false;
1259  }
1260  else
1261  {
1262  thestarter = base.thestarter->clone();
1263  freeStarter = true;
1264  }
1265 
1266  assert(SPxSolver::isConsistent());
1267  }
1268 
1269  return *this;
1270 }
1271 
1272 
1274  : SPxLP (base)
1275  , SPxBasis(base)
1276  , theType(base.theType)
1277  , thePricing(base.thePricing)
1278  , theRep(base.theRep)
1279  , polishObj(base.polishObj)
1280  , timerType(base.timerType)
1282  , maxIters(base.maxIters)
1283  , maxTime(base.maxTime)
1286  , objLimit(base.objLimit)
1287  , m_status(base.m_status)
1294  , m_entertol(base.m_entertol)
1295  , m_leavetol(base.m_leavetol)
1296  , theShift(base.theShift)
1297  , lastShift(base.lastShift)
1298  , m_maxCycle(base.m_maxCycle)
1299  , m_numCycle(base.m_numCycle)
1300  , initialized(base.initialized)
1301  , solveVector2 (0)
1303  , solveVector3 (0)
1305  , coSolveVector2(0)
1307  , coSolveVector3(0)
1315  , displayLine(base.displayLine)
1316  , displayFreq(base.displayFreq)
1324  , unitVecs(base.unitVecs)
1325  , primRhs(base.primRhs)
1326  , primVec(base.primVec)
1327  , dualRhs(base.dualRhs)
1328  , dualVec(base.dualVec)
1329  , addVec(base.addVec)
1330  , theURbound(base.theURbound)
1331  , theLRbound(base.theLRbound)
1332  , theUCbound(base.theUCbound)
1333  , theLCbound(base.theLCbound)
1334  , theUBbound(base.theUBbound)
1335  , theLBbound(base.theLBbound)
1336  , theCoTest(base.theCoTest)
1337  , theTest(base.theTest)
1338  , primalRay(base.primalRay)
1339  , dualFarkas(base.dualFarkas)
1340  , leaveCount(base.leaveCount)
1341  , enterCount(base.enterCount)
1342  , primalCount(base.primalCount)
1343  , polishCount(base.polishCount)
1344  , boundflips(base.boundflips)
1346  , enterCycles(base.enterCycles)
1347  , leaveCycles(base.leaveCycles)
1351  , dualDegenSum(base.dualDegenSum)
1354  , isInfeasible(base.isInfeasible)
1364  , weights(base.weights)
1365  , coWeights(base.coWeights)
1367  , spxout(base.spxout)
1369 {
1371 
1372  if (base.theRep == COLUMN)
1373  {
1374  thevectors = colSet();
1375  thecovectors = rowSet();
1376  theFrhs = &primRhs;
1377  theFvec = &primVec;
1378  theCoPrhs = &dualRhs;
1379  theCoPvec = &dualVec;
1380  thePvec = &addVec;
1381  theRPvec = theCoPvec;
1382  theCPvec = thePvec;
1383  theUbound = &theUCbound;
1384  theLbound = &theLCbound;
1387  }
1388  else
1389  {
1390  assert(base.theRep == ROW);
1391 
1392  thevectors = rowSet();
1393  thecovectors = colSet();
1394  theFrhs = &dualRhs;
1395  theFvec = &dualVec;
1396  theCoPrhs = &primRhs;
1397  theCoPvec = &primVec;
1398  thePvec = &addVec;
1399  theRPvec = thePvec;
1400  theCPvec = theCoPvec;
1401  theUbound = &theURbound;
1402  theLbound = &theLRbound;
1405  }
1406 
1407  SPxBasis::theLP = this;
1408 
1409  if(base.thepricer == 0)
1410  {
1411  thepricer = 0;
1412  freePricer = false;
1413  }
1414  else
1415  {
1416  thepricer = base.thepricer->clone();
1417  freePricer = true;
1418  thepricer->clear();
1419  thepricer->load(this);
1420  }
1421 
1422  if(base.theratiotester == 0)
1423  {
1424  theratiotester = 0;
1425  freeRatioTester = false;
1426  }
1427  else
1428  {
1430  freeRatioTester = true;
1431  theratiotester->clear();
1432  theratiotester->load(this);
1433  }
1434 
1435  if(base.thestarter == 0)
1436  {
1437  thestarter = 0;
1438  freeStarter = false;
1439  }
1440  else
1441  {
1442  thestarter = base.thestarter->clone();
1443  freeStarter = true;
1444  }
1445 
1446  assert(SPxSolver::isConsistent());
1447 }
1448 
1450 {
1451 #ifdef ENABLE_CONSISTENCY_CHECKS
1452  if (epsilon() < 0)
1453  return MSGinconsistent("SPxSolver");
1454 
1456  return MSGinconsistent("SPxSolver");
1457 
1458  if (dualVec.delta().getEpsilon() != addVec.delta().getEpsilon())
1459  return MSGinconsistent("SPxSolver");
1460 
1461  if (unitVecs.size() < SPxLP::nCols() || unitVecs.size() < SPxLP::nRows())
1462  return MSGinconsistent("SPxSolver");
1463 
1464  if (initialized)
1465  {
1466  if (theFrhs->dim() != dim())
1467  return MSGinconsistent("SPxSolver");
1468  if (theFvec->dim() != dim())
1469  return MSGinconsistent("SPxSolver");
1470 
1471  if (theCoPrhs->dim() != dim())
1472  return MSGinconsistent("SPxSolver");
1473  if (thePvec->dim() != coDim())
1474  return MSGinconsistent("SPxSolver");
1475  if (theCoPvec->dim() != dim())
1476  return MSGinconsistent("SPxSolver");
1477 
1478  if (theTest.dim() != coDim())
1479  return MSGinconsistent("SPxSolver");
1480  if (theCoTest.dim() != dim())
1481  return MSGinconsistent("SPxSolver");
1482 
1483  if (theURbound.dim() != SPxLP::nRows())
1484  return MSGinconsistent("SPxSolver");
1485  if (theLRbound.dim() != SPxLP::nRows())
1486  return MSGinconsistent("SPxSolver");
1487  if (theUCbound.dim() != SPxLP::nCols())
1488  return MSGinconsistent("SPxSolver");
1489  if (theLCbound.dim() != SPxLP::nCols())
1490  return MSGinconsistent("SPxSolver");
1491  if (theUBbound.dim() != dim())
1492  return MSGinconsistent("SPxSolver");
1493  if (theLBbound.dim() != dim())
1494  return MSGinconsistent("SPxSolver");
1495  }
1496 
1497  if (rep() == COLUMN)
1498  {
1499  if(thecovectors !=
1500  reinterpret_cast<const SVSet*>(static_cast<const LPRowSet*>(this))
1501  || thevectors !=
1502  reinterpret_cast<const SVSet*>(static_cast<const LPColSet*>(this))
1503  || theFrhs != &primRhs ||
1504  theFvec != &primVec ||
1505  theCoPrhs != &dualRhs ||
1506  theCoPvec != &dualVec ||
1507  thePvec != &addVec ||
1508  theRPvec != theCoPvec ||
1509  theCPvec != thePvec ||
1510  theUbound != &theUCbound ||
1511  theLbound != &theLCbound ||
1512  theCoUbound != &theURbound ||
1513  theCoLbound != &theLRbound)
1514  return MSGinconsistent("SPxSolver");
1515  }
1516  else
1517  {
1518  if (thecovectors
1519  != reinterpret_cast<const SVSet*>(static_cast<const LPColSet*>(this))
1520  || thevectors
1521  != reinterpret_cast<const SVSet*>(static_cast<const LPRowSet*>(this))
1522  || theFrhs != &dualRhs ||
1523  theFvec != &dualVec ||
1524  theCoPrhs != &primRhs ||
1525  theCoPvec != &primVec ||
1526  thePvec != &addVec ||
1527  theRPvec != thePvec ||
1528  theCPvec != theCoPvec ||
1529  theUbound != &theURbound ||
1530  theLbound != &theLRbound ||
1531  theCoUbound != &theUCbound ||
1532  theCoLbound != &theLCbound)
1533  return MSGinconsistent("SPxSolver");
1534  }
1535 
1536  return SPxLP::isConsistent()
1537  && primRhs.isConsistent()
1538  && primVec.isConsistent()
1539  && dualRhs.isConsistent()
1540  && dualVec.isConsistent()
1541  && addVec.isConsistent()
1542  && theTest.isConsistent()
1543  && theCoTest.isConsistent()
1549  ;
1550 #else
1551  return true;
1552 #endif
1553 }
1554 
1555 
1557 {
1558  if( p_time < 0.0 )
1559  p_time = 0.0;
1560  maxTime = p_time;
1561 }
1562 
1564 {
1565  return maxTime;
1566 }
1567 
1568 void SPxSolver::setTerminationIter(int p_iteration)
1569 {
1570  if( p_iteration < 0 )
1571  p_iteration = -1;
1572  maxIters = p_iteration;
1573 }
1574 
1576 {
1577  return maxIters;
1578 }
1579 
1580 // returns whether current time limit is reached; call to time() may be skipped unless \p forceCheck is true
1581 bool SPxSolver::isTimeLimitReached(const bool forceCheck)
1582 {
1583  // always update the number of calls, since the user might set a time limit later in the solving process
1584  ++nCallsToTimelim;
1585 
1586  // check if a time limit is actually set
1587  if( maxTime >= infinity )
1588  return false;
1589 
1590  // check if the expensive system call to update the time should be skipped again
1591  if( forceCheck || nCallsToTimelim < NINITCALLS || nClckSkipsLeft <= 0 )
1592  {
1593  Real currtime = time();
1594 
1595  if( currtime >= maxTime )
1596  return true;
1597 
1598  // determine the number of times the clock can be skipped again.
1599  int nClckSkips = MAXNCLCKSKIPS;
1600  Real avgtimeinterval = (currtime + cumulativeTime()) / (Real)(nCallsToTimelim);
1601 
1602  // it would not be safe to skip the clock so many times since we are approaching the time limit
1603  if( SAFETYFACTOR * (maxTime - currtime) / (avgtimeinterval + 1e-6) < nClckSkips )
1604  nClckSkips = 0;
1605  nClckSkipsLeft = nClckSkips;
1606  }
1607  else
1608  --nClckSkipsLeft;
1609 
1610  return false;
1611 }
1612 
1613 
1614 /**@todo A first version for the termination value is
1615  * implemented. Currently we check if no bound violations (shifting)
1616  * is present. It might be even possible to use this termination
1617  * value in case of bound violations (shifting) but in this case it
1618  * is quite difficult to determine if we already reached the limit.
1619  */
1621 {
1622  objLimit = p_value;
1623 }
1624 
1626 {
1627  return objLimit;
1628 }
1629 
1632 {
1633  VarStatus vstat;
1634 
1635  switch( stat )
1636  {
1638  vstat = ON_LOWER;
1639  break;
1641  vstat = ON_UPPER;
1642  break;
1644  vstat = FIXED;
1645  break;
1647  vstat = ZERO;
1648  break;
1654  vstat = BASIC;
1655  break;
1656  default:
1657  MSG_ERROR( std::cerr << "ESOLVE26 ERROR: unknown basis status (" << stat << ")"
1658  << std::endl; )
1659  throw SPxInternalCodeException("XSOLVE22 This should never happen.");
1660  }
1661  return vstat;
1662 }
1663 
1666 {
1667  SPxBasis::Desc::Status rstat;
1668 
1669  switch( stat )
1670  {
1671  case FIXED :
1672  assert(rhs(row) == lhs(row));
1673  rstat = SPxBasis::Desc::P_FIXED;
1674  break;
1675  case ON_UPPER :
1676  assert(rhs(row) < infinity);
1677  rstat = lhs(row) < rhs(row)
1680  break;
1681  case ON_LOWER :
1682  assert(lhs(row) > -infinity);
1683  rstat = lhs(row) < rhs(row)
1686  break;
1687  case ZERO :
1688  /* A 'free' row (i.e., infinite lower & upper bounds) does not really make sense. The user
1689  * might (think to) know better, e.g., when temporarily turning off a row. We therefore apply
1690  * the same adjustment as in the column case in varStatusToBasisStatusCol(). */
1691  if (lhs(row) <= -infinity && rhs(row) >= infinity)
1692  rstat = SPxBasis::Desc::P_FREE;
1693  else
1694  {
1695  if ( lhs(row) == rhs(row) )
1696  {
1697  assert( rhs(row) < infinity );
1698  rstat = SPxBasis::Desc::P_FIXED;
1699  }
1700  else
1701  {
1702  if ( lhs(row) > -infinity )
1704  else
1705  {
1706  assert( rhs(row) < infinity );
1708  }
1709  }
1710  }
1711  break;
1712  case BASIC :
1713  rstat = dualRowStatus(row);
1714  break;
1715  default:
1716  MSG_ERROR( std::cerr << "ESOLVE27 ERROR: unknown VarStatus (" << int(stat) << ")"
1717  << std::endl; )
1718  throw SPxInternalCodeException("XSOLVE23 This should never happen.");
1719  }
1720  return rstat;
1721 }
1722 
1725 {
1726  SPxBasis::Desc::Status cstat;
1727 
1728  switch( stat )
1729  {
1730  case FIXED :
1731  if (upper(col) == lower(col))
1732  cstat = SPxBasis::Desc::P_FIXED;
1733  else if (maxObj(col) > 0.0)
1735  else
1737  break;
1738  case ON_UPPER :
1739  assert(upper(col) < infinity);
1740  cstat = lower(col) < upper(col)
1743  break;
1744  case ON_LOWER :
1745  assert(lower(col) > -infinity);
1746  cstat = lower(col) < upper(col)
1749  break;
1750  case ZERO :
1751  /* In this case the upper and lower bounds on the variable should be infinite. The bounds
1752  * might, however, have changed and we try to recover from this by changing the status to
1753  * 'resonable' settings. A solve has to find the correct values afterwards. Note that the
1754  * approach below is consistent with changesoplex.cpp (e.g., changeUpperStatus() and
1755  * changeLowerStatus() ). */
1756  if (lower(col) <= -infinity && upper(col) >= infinity)
1757  cstat = SPxBasis::Desc::P_FREE;
1758  else
1759  {
1760  if ( lower(col) == upper(col) )
1761  {
1762  assert( upper(col) < infinity );
1763  cstat = SPxBasis::Desc::P_FIXED;
1764  }
1765  else
1766  {
1767  if ( lower(col) > -infinity )
1769  else
1770  {
1771  assert( upper(col) < infinity );
1773  }
1774  }
1775  }
1776  break;
1777  case BASIC :
1778  cstat = dualColStatus(col);
1779  break;
1780  default:
1781  MSG_ERROR( std::cerr << "ESOLVE28 ERROR: unknown VarStatus (" << int(stat) << ")"
1782  << std::endl; )
1783  throw SPxInternalCodeException("XSOLVE24 This should never happen.");
1784  }
1785  return cstat;
1786 }
1787 
1789 {
1790  assert( 0 <= row && row < nRows() );
1791  return basisStatusToVarStatus( desc().rowStatus( row ) );
1792 }
1793 
1795 {
1796  assert( 0 <= col && col < nCols() );
1797  return basisStatusToVarStatus( desc().colStatus( col ) );
1798 }
1799 
1800 SPxSolver::Status SPxSolver::getBasis(VarStatus row[], VarStatus col[], const int rowsSize, const int colsSize) const
1801 {
1802  const SPxBasis::Desc& d = desc();
1803  int i;
1804 
1805  assert(rowsSize < 0 || rowsSize >= nRows());
1806  assert(colsSize < 0 || colsSize >= nCols());
1807 
1808  if (col)
1809  for (i = nCols() - 1; i >= 0; --i)
1810  col[i] = basisStatusToVarStatus( d.colStatus(i) );
1811 
1812  if (row)
1813  for (i = nRows() - 1; i >= 0; --i)
1814  row[i] = basisStatusToVarStatus( d.rowStatus(i) );
1815 
1816  return status();
1817 }
1818 
1820 {
1821 
1822  int basisdim;
1823 
1824  if ( p_rows.size() != nRows() || p_cols.size() != nCols() )
1825  return false;
1826 
1827  basisdim = 0;
1828  for ( int row = nRows()-1; row >= 0; --row )
1829  {
1830  if ( p_rows[row] == UNDEFINED )
1831  return false;
1832  // row is basic
1833  else if ( p_rows[row] == BASIC )
1834  {
1835  basisdim++;
1836  }
1837  // row is nonbasic
1838  else
1839  {
1840  if ( (p_rows[row] == FIXED && lhs(row) != rhs(row))
1841  || (p_rows[row] == ON_UPPER && rhs(row) >= infinity)
1842  || (p_rows[row] == ON_LOWER && lhs(row) <= -infinity) )
1843  return false;
1844  }
1845  }
1846 
1847  for ( int col = nCols()-1; col >= 0; --col )
1848  {
1849  if ( p_cols[col] == UNDEFINED )
1850  return false;
1851  // col is basic
1852  else if ( p_cols[col] == BASIC )
1853  {
1854  basisdim++;
1855  }
1856  // col is nonbasic
1857  else
1858  {
1859  if ( (p_cols[col] == FIXED && lower(col) != upper(col))
1860  || (p_cols[col] == ON_UPPER && upper(col) >= infinity)
1861  || (p_cols[col] == ON_LOWER && lower(col) <= -infinity) )
1862  return false;
1863  }
1864  }
1865 
1866  if ( basisdim != dim() )
1867  return false;
1868 
1869  // basis valid
1870  return true;
1871 }
1872 
1873 void SPxSolver::setBasis(const VarStatus p_rows[], const VarStatus p_cols[])
1874 {
1876  SPxBasis::load(this, false);
1877 
1878  SPxBasis::Desc ds = desc();
1879  int i;
1880 
1881  for(i = 0; i < nRows(); i++)
1882  ds.rowStatus(i) = varStatusToBasisStatusRow( i, p_rows[i] );
1883 
1884  for(i = 0; i < nCols(); i++)
1885  ds.colStatus(i) = varStatusToBasisStatusCol( i, p_cols[i] );
1886 
1887  loadBasis(ds);
1889 }
1890 
1891 // NOTE: This only works for the row representation. Need to update to account for column representation.
1892 // The degenvec differs relative to the algorithm being used.
1893 // For the primal simplex, degenvec is the primal solution values.
1894 // For the dual simplex, the degenvec is the feasvec (ROW) and pVec (COLUMN).
1896 {
1897  int numDegenerate = 0;
1898  Real degeneracyLevel = 0;
1899 
1900  // iterating over all columns in the basis matrix
1901  // this identifies the basis indices and those that have a zero dual multiplier (rows) or zero reduced cost (cols).
1902  if( rep() == ROW )
1903  {
1904  for( int i = 0; i < nCols(); ++i ) // @todo Check the use of numColsReal for the reduced problem.
1905  {
1906  // degeneracy in the dual simplex exists if there are rows with a zero dual multiplier or columns with a zero
1907  // reduced costs. This requirement is regardless of the objective sense.
1908  if( isZero(degenvec[i], feastol()) )
1909  numDegenerate++;
1910  }
1911 
1912  if( type() == ENTER ) // dual simplex
1913  degeneracyLevel = Real(numDegenerate)/nCols();
1914  else // primal simplex
1915  {
1916  assert(type() == LEAVE);
1917  Real degenVars = (numDegenerate > (nCols() - nRows())) ? Real(numDegenerate - (nCols() - nRows())) : 0.0;
1918  degeneracyLevel = degenVars/nRows();
1919  }
1920  }
1921  else
1922  {
1923  assert(rep() == COLUMN);
1924 
1925  for( int i = 0; i < nCols(); i++ )
1926  {
1927  if( type() == LEAVE ) // dual simplex
1928  {
1929  if( isZero(maxObj()[i] - degenvec[i], feastol()) )
1930  numDegenerate++;
1931  }
1932  else // primal simplex
1933  {
1934  assert( type() == ENTER );
1935  if( isZero(degenvec[i], feastol()) )
1936  numDegenerate++;
1937  }
1938  }
1939 
1940 
1941  if( type() == LEAVE ) // dual simplex
1942  {
1943  Real degenVars = nRows() > numDegenerate ? Real(nRows() - numDegenerate) : 0.0;
1944  degeneracyLevel = degenVars/nCols();
1945  }
1946  else // primal simplex
1947  {
1948  assert(type() == ENTER);
1949  Real degenVars = (numDegenerate > (nCols() - nRows())) ? Real(numDegenerate - (nCols() - nRows())) : 0.0;
1950  degeneracyLevel = degenVars/nRows();
1951  }
1952  }
1953 
1954  return degeneracyLevel;
1955 }
1956 
1957 void SPxSolver::getNdualNorms(int& nnormsRow, int& nnormsCol) const
1958 {
1959  nnormsRow = 0;
1960  nnormsCol = 0;
1961 
1962  if( weightsAreSetup )
1963  {
1964  if( type() == SPxSolver::LEAVE && rep() == SPxSolver::COLUMN )
1965  {
1966  nnormsRow = coWeights.dim();
1967  nnormsCol = 0;
1968 
1969  assert(nnormsRow == dim());
1970  }
1971  else if( type() == SPxSolver::ENTER && rep() == SPxSolver::ROW )
1972  {
1973  nnormsRow = weights.dim();
1974  nnormsCol = coWeights.dim();
1975 
1976  assert(nnormsRow == coDim());
1977  assert(nnormsCol == dim());
1978  }
1979  }
1980 }
1981 
1982 bool SPxSolver::getDualNorms(int& nnormsRow, int& nnormsCol, Real* norms) const
1983 {
1984  nnormsRow = 0;
1985  nnormsCol = 0;
1986 
1987  if( !weightsAreSetup )
1988  return false;
1989 
1990  if( type() == SPxSolver::LEAVE && rep() == SPxSolver::COLUMN )
1991  {
1992  nnormsCol = 0;
1993  nnormsRow = coWeights.dim();
1994 
1995  assert(nnormsRow == dim());
1996 
1997  for( int i = 0; i < nnormsRow; ++i)
1998  norms[i] = coWeights[i];
1999  }
2000  else if( type() == SPxSolver::ENTER && rep() == SPxSolver::ROW )
2001  {
2002  nnormsRow = weights.dim();
2003  nnormsCol = coWeights.dim();
2004 
2005  assert(nnormsCol == dim());
2006  assert(nnormsRow == coDim());
2007 
2008  for( int i = 0; i < nnormsRow; ++i )
2009  norms[i] = weights[i];
2010 
2011  for( int i = 0; i < nnormsCol; ++i )
2012  norms[nnormsRow + i] = coWeights[i];
2013  }
2014  else
2015  return false;
2016 
2017  return true;
2018 }
2019 
2020 bool SPxSolver::setDualNorms(int nnormsRow, int nnormsCol, Real* norms)
2021 {
2022  weightsAreSetup = false;
2023 
2024  if( type() == SPxSolver::LEAVE && rep() == SPxSolver::COLUMN)
2025  {
2026  coWeights.reDim(dim(), false);
2027  assert(coWeights.dim() >= nnormsRow);
2028  for( int i = 0; i < nnormsRow; ++i )
2029  coWeights[i] = norms[i];
2030  weightsAreSetup = true;
2031  }
2032  else if( type() == SPxSolver::ENTER && rep() == SPxSolver::ROW)
2033  {
2034  weights.reDim(coDim(), false);
2035  coWeights.reDim(dim(), false);
2036  assert(weights.dim() >= nnormsRow);
2037  assert(coWeights.dim() >= nnormsCol);
2038  for( int i = 0; i < nnormsRow; ++i )
2039  weights[i] = norms[i];
2040  for( int i = 0; i < nnormsCol; ++i )
2041  coWeights[i] = norms[nnormsRow + i];
2042  weightsAreSetup = true;
2043  }
2044  else
2045  return false;
2046  return true;
2047 }
2048 
2049 void SPxSolver::setIntegralityInformation(int ncols, int* intInfo)
2050 {
2051  assert(ncols == nCols() || (ncols == 0 && intInfo == NULL));
2052 
2053  integerVariables.reSize(ncols);
2054  for( int i = 0; i < ncols; ++i )
2055  {
2056  integerVariables[i] = intInfo[i];
2057  }
2058 }
2059 
2060 
2061 
2062 //
2063 // Auxiliary functions.
2064 //
2065 
2066 // Pretty-printing of variable status.
2067 std::ostream& operator<<( std::ostream& os,
2068  const SPxSolver::VarStatus& status )
2069 {
2070  switch( status )
2071  {
2072  case SPxSolver::BASIC:
2073  os << "BASIC";
2074  break;
2075  case SPxSolver::FIXED:
2076  os << "FIXED";
2077  break;
2078  case SPxSolver::ON_LOWER:
2079  os << "ON_LOWER";
2080  break;
2081  case SPxSolver::ON_UPPER:
2082  os << "ON_UPPER";
2083  break;
2084  case SPxSolver::ZERO:
2085  os << "ZERO";
2086  break;
2087  case SPxSolver::UNDEFINED:
2088  os << "UNDEFINED";
2089  break;
2090  default:
2091  os << "?invalid?";
2092  break;
2093  }
2094  return os;
2095 }
2096 
2097 // Pretty-printing of solver status.
2098 std::ostream& operator<<( std::ostream& os,
2099  const SPxSolver::Status& status )
2100 {
2101  switch ( status )
2102  {
2103  case SPxSolver::ERROR:
2104  os << "ERROR";
2105  break;
2107  os << "NO_RATIOTESTER";
2108  break;
2109  case SPxSolver::NO_PRICER:
2110  os << "NO_PRICER";
2111  break;
2112  case SPxSolver::NO_SOLVER:
2113  os << "NO_SOLVER";
2114  break;
2115  case SPxSolver::NOT_INIT:
2116  os << "NOT_INIT";
2117  break;
2119  os << "ABORT_CYCLING";
2120  break;
2121  case SPxSolver::ABORT_TIME:
2122  os << "ABORT_TIME";
2123  break;
2124  case SPxSolver::ABORT_ITER:
2125  os << "ABORT_ITER";
2126  break;
2128  os << "ABORT_VALUE";
2129  break;
2130  case SPxSolver::SINGULAR:
2131  os << "SINGULAR";
2132  break;
2133  case SPxSolver::NO_PROBLEM:
2134  os << "NO_PROBLEM";
2135  break;
2136  case SPxSolver::REGULAR:
2137  os << "REGULAR";
2138  break;
2139  case SPxSolver::RUNNING:
2140  os << "RUNNING";
2141  break;
2142  case SPxSolver::UNKNOWN:
2143  os << "UNKNOWN";
2144  break;
2145  case SPxSolver::OPTIMAL:
2146  os << "OPTIMAL";
2147  break;
2148  case SPxSolver::UNBOUNDED:
2149  os << "UNBOUNDED";
2150  break;
2151  case SPxSolver::INFEASIBLE:
2152  os << "INFEASIBLE";
2153  break;
2154  default:
2155  os << "?other?";
2156  break;
2157  }
2158  return os;
2159 }
2160 
2161 // Pretty-printing of algorithm.
2162 std::ostream& operator<<( std::ostream& os,
2163  const SPxSolver::Type& status )
2164 {
2165  switch ( status )
2166  {
2167  case SPxSolver::ENTER:
2168  os << "ENTER";
2169  break;
2170  case SPxSolver::LEAVE:
2171  os << "LEAVE";
2172  break;
2173  default:
2174  os << "?other?";
2175  break;
2176  }
2177  return os;
2178 }
2179 
2180 // Pretty-printing of representation.
2181 std::ostream& operator<<( std::ostream& os,
2183 {
2184  switch ( status )
2185  {
2186  case SPxSolver::ROW:
2187  os << "ROW";
2188  break;
2189  case SPxSolver::COLUMN:
2190  os << "COLUMN";
2191  break;
2192  default:
2193  os << "?other?";
2194  break;
2195  }
2196  return os;
2197 }
2198 
2199 
2200 } // 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
void clearUpdate()
clear ,
Definition: updatevector.h:160
virtual ~SPxSolver()
Definition: spxsolver.cpp:1051
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:1982
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:1957
DIdxSet updateViols
store indices that were changed in the previous iteration and must be checked in hyper pricing ...
Definition: spxsolver.h:410
SPxOut * spxout
message handler
Definition: spxsolver.h:436
bool sparsePricingLeave
These values enable or disable sparse pricing.
Definition: spxsolver.h:421
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:490
void setBasis(const VarStatus rows[], const VarStatus cols[])
set the lp solver&#39;s basis.
Definition: spxsolver.cpp:1873
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:779
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:1800
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:786
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:423
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:1631
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:1575
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:417
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:2629
int dim() const
dimension of basis matrix.
Definition: spxsolver.h:1056
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:1581
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:2116
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:2020
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:1556
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:1895
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:1317
primal variable is set to its upper bound
Definition: spxbasis.h:188
UpdateVector & coPvec() const
copricing vector.
Definition: spxsolver.h:1379
int remainingRoundsLeave
number of dense rounds/refactorizations until sparsePricing is enabled again
Definition: spxsolver.h:427
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:1910
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:1834
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:772
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:1665
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:2132
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:1563
UpdateVector & fVec() const
feasibility vector.
Definition: spxsolver.h:1304
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:433
primal variable is left free, but unset
Definition: spxbasis.h:189
const VectorBase< Real > & lhs() const
Returns left hand side vector.
Definition: spxlpbase.h:253
SPxSolver & operator=(const SPxSolver &base)
assignment operator
Definition: spxsolver.cpp:1082
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:422
int remainingRoundsEnterCo
Definition: spxsolver.h:429
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:767
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:1459
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:404
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:1568
bool isInitialized() const
has the internal data been initialized?
Definition: spxsolver.h:1825
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:428
Everything should be within this namespace.
bool isBasisValid(DataArray< VarStatus > rows, DataArray< VarStatus > cols)
check a given basis for validity.
Definition: spxsolver.cpp:1819
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:2049
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:1788
virtual void factorize()
factorizes the basis matrix.
Definition: spxbasis.cpp:889
bool isConsistent() const
check consistency.
Definition: spxsolver.cpp:1449
variable is basic.
Definition: spxsolver.h:195
VarStatus getBasisColStatus(int col) const
gets basis status for a single column
Definition: spxsolver.cpp:1794
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:1724
SPxRatioTester * theratiotester
Definition: spxsolver.h:385
virtual Real terminationValue() const
return objective limit.
Definition: spxsolver.cpp:1625
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:484
DataArray< int > isInfeasibleCo
0: index not violated, 1: index violated, 2: index violated and among candidate list ...
Definition: spxsolver.h:418
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:1061
bool hyperPricingEnter
true if hyper sparse pricing is turned on in the entering Simplex
Definition: spxsolver.h:425
bool isConsistent() const
Consistency check.
Definition: spxlpbase.h:1841
#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:1392
DVector weights
dual pricing norms
Definition: spxsolver.h:432
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:438
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:642
#define MSGinconsistent(name)
Definition: spxdefines.h:126
bool weightsAreSetup
are the dual norms already set up?
Definition: spxsolver.h:434
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:411
Real opttol() const
allowed optimality, i.e., dual feasibility tolerance.
Definition: spxsolver.h:794
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:1620
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:407
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:424
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:478
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:2025
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