SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Tableau.h
Go to the documentation of this file.
1 /**
2  * @file Tableau.h
3  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
4  * @since 2012-04-05
5  * @version 2014-10-01
6  */
7 
8 #pragma once
9 
10 #include <vector>
11 #include <stack>
12 #include <map>
13 #include <deque>
14 #include <limits>
15 #include "Variable.h"
16 #include <carl-common/memory/IDPool.h>
17 
18 namespace smtrat
19 {
20  namespace lra
21  {
22  /**
23  *
24  */
25  template<typename T1, typename T2>
27  {
28  private:
29  ///
31  ///
33  ///
35  ///
37  ///
39  ///
41  ///
43 
44  public:
45  /**
46  *
47  */
49  mUp( LAST_ENTRY_ID ),
53  mRowVar( NULL ),
54  mColumnVar( NULL ),
55  mpContent()
56  {}
57 
58  /**
59  *
60  * @param _up
61  * @param _down
62  * @param _left
63  * @param _right
64  * @param _rowVar
65  * @param _columnVar
66  * @param _content
67  */
68  TableauEntry( EntryID _up, EntryID _down, EntryID _left, EntryID _right, Variable<T1, T2>* _rowVar, Variable<T1, T2>* _columnVar, const T2& _content ):
69  mUp( _up ),
70  mDown( _down ),
71  mLeft( _left ),
72  mRight( _right ),
73  mRowVar( _rowVar ),
74  mColumnVar( _columnVar ),
75  mpContent( _content )
76  {}
77 
78  /**
79  *
80  * @param _entry
81  */
82  TableauEntry( const TableauEntry& _entry ):
83  mUp( _entry.mUp ),
84  mDown( _entry.mDown ),
85  mLeft( _entry.mLeft ),
86  mRight( _entry.mRight ),
87  mRowVar( _entry.mRowVar ),
88  mColumnVar( _entry.mColumnVar ),
89  mpContent( _entry.mpContent )
90  {}
91 
92  /**
93  *
94  */
96  {}
97 
98  /**
99  *
100  * @param downwards
101  * @param _entryId
102  */
103  void setVNext( bool downwards, const EntryID _entryId )
104  {
105  if( downwards )
106  mDown = _entryId;
107  else
108  mUp = _entryId;
109  }
110 
111  /**
112  *
113  * @param leftwards
114  * @param _entryId
115  */
116  void setHNext( bool leftwards, const EntryID _entryId )
117  {
118  if( leftwards )
119  mLeft = _entryId;
120  else
121  mRight = _entryId;
122  }
123 
124  /**
125  *
126  * @param downwards
127  * @return
128  */
129  EntryID vNext( bool downwards )
130  {
131  if( downwards )
132  return mDown;
133  else
134  return mUp;
135  }
136 
137  /**
138  *
139  * @param leftwards
140  * @return
141  */
142  EntryID hNext( bool leftwards )
143  {
144  if( leftwards )
145  return mLeft;
146  else
147  return mRight;
148  }
149 
150  /**
151  * @return
152  */
154  {
155  return mRowVar;
156  }
157 
158  /**
159  *
160  * @param _rowVar
161  */
162  void setRowVar( Variable<T1, T2>* _rowVar )
163  {
164  mRowVar = _rowVar;
165  }
166 
167  /**
168  * @return
169  */
171  {
172  return mColumnVar;
173  }
174 
175  /**
176  *
177  * @param _columnVar
178  */
179  void setColumnVar( Variable<T1, T2>* _columnVar )
180  {
181  mColumnVar = _columnVar;
182  }
183 
184  /**
185  * @return
186  */
187  const T2& content() const
188  {
189  return mpContent;
190  }
191 
192  /**
193  * @return
194  */
195  T2& rContent()
196  {
197  return mpContent;
198  }
199  };
200 
201  /**
202  *
203  */
204  template<class Settings, typename T1, typename T2>
205  class Tableau
206  {
207  public:
208  /**
209  *
210  */
212  {
213  ///
215  ///
217  ///
219  ///
220  std::vector< const Bound<T1, T2>*> premise;
221 
222  LearnedBound() = delete;
223  LearnedBound( const LearnedBound& ) = delete;
224  LearnedBound( LearnedBound&& _toMove ) :
225  newBound( _toMove.newBound ),
226  newLimit( std::move( _toMove.newLimit ) ),
227  nextWeakerBound( _toMove.nextWeakerBound ),
228  premise( std::move( _toMove.premise ) )
229  {}
230  LearnedBound( const Value<T1>& _limit, const Bound<T1, T2>* _newBound, typename Bound<T1, T2>::BoundSet::const_iterator _nextWeakerBound, std::vector< const Bound<T1, T2>*>&& _premise ):
231  newBound( _newBound ),
232  newLimit( _limit ),
233  nextWeakerBound( _nextWeakerBound ),
234  premise( std::move( _premise ) )
235  {}
236 
238  };
239  private:
240  ///
242  ///
243  size_t mWidth;
244  ///
246  ///
248  ///
250  ///
252  ///
253  std::stack<EntryID> mUnusedIDs;
254  /// Id allocator for the variables.
255  carl::IDPool mVariableIdAllocator;
256  ///
257  std::vector<Variable<T1,T2>*> mRows; // First element is the head of the row and the second the length of the row.
258  ///
259  std::vector<Variable<T1,T2>*> mColumns; // First element is the end of the column and the second the length of the column.
260  ///
261  std::list<std::list<std::pair<Variable<T1,T2>*,T2>>> mNonActiveBasics;
262  ///
263  std::vector<TableauEntry<T1,T2> >* mpEntries;
264  ///
265  std::vector<Variable<T1,T2>*> mConflictingRows;
266  ///
268  ///
269  bool onlyUpdate = false;
270  ///
271  mutable T1 mCurDelta;
272  ///
273  carl::FastMap<carl::Variable, Variable<T1,T2>*> mOriginalVars;
274  ///
275  carl::FastPointerMap<typename Poly::PolyType, Variable<T1,T2>*> mSlackVars;
276  ///
277  carl::FastMap<FormulaT, std::vector<const Bound<T1, T2>*>*> mConstraintToBound;
278  ///
279  carl::FastPointerMap<Variable<T1,T2>, LearnedBound> mLearnedLowerBounds;
280  ///
281  carl::FastPointerMap<Variable<T1,T2>, LearnedBound> mLearnedUpperBounds;
282  ///
283  std::vector<typename carl::FastPointerMap<Variable<T1,T2>, LearnedBound>::iterator> mNewLearnedBounds;
284 
285  // Helper variables used to controll changes in violation sum and throw assertions
286  Value<T1> mOldVioSum = Value<T1>(-1); // stored violation sum
287  Value<T1> mOld_dVioSum = Value<T1>(1);// stored change in violation sum -> new violation sum == old violation sum + dVio
288 
289  // Locally stored infeasibility row to prevent recomputation is every loop.
290  std::vector<T2> mInfeasibilityRow;
291 
292  // Const after when the canidate search is dynamically adjusted
293  std::size_t mFullCandidateSearch = 3;
294 
295  /**
296  *
297  */
298  class Iterator
299  {
300  private:
301  ///
303  ///
304  std::vector<TableauEntry<T1,T2> >* mpEntries;
305 
306  public:
307  /**
308  *
309  * @param _start
310  * @param _entries
311  */
312  Iterator( EntryID _start, std::vector<TableauEntry<T1,T2> >* const _entries ):
313  mEntryID( _start ),
314  mpEntries( _entries )
315  {}
316 
317  /**
318  *
319  * @param _iter
320  */
321  Iterator( const Iterator& _iter ):
322  mEntryID( _iter.entryID() ),
323  mpEntries( _iter.pEntries() )
324  {}
325 
326  void operator=(const Iterator& _iter ) {
327  mEntryID = _iter.entryID();
328  mpEntries = _iter.pEntries();
329  }
330 
331  void operator=(Iterator&& _iter ) {
332  mEntryID = _iter.entryID();
333  mpEntries = std::move(_iter.pEntries());
334  }
335 
336  /**
337  * @return
338  */
339  EntryID entryID() const
340  {
341  return mEntryID;
342  }
343 
344  /**
345  * @return
346  */
348  {
349  return (*mpEntries)[mEntryID];
350  }
351 
352  /**
353  * @return
354  */
355  bool vEnd( bool downwards ) const
356  {
357  return (*mpEntries)[mEntryID].vNext( downwards ) == LAST_ENTRY_ID;
358  }
359 
360  /**
361  * @return
362  */
363  bool hEnd( bool leftwards ) const
364  {
365  return (*mpEntries)[mEntryID].hNext( leftwards ) == LAST_ENTRY_ID;
366  }
367 
368  /**
369  *
370  * @param downwards
371  */
372  void vMove( bool downwards )
373  {
374  assert( !vEnd( downwards ) );
375  mEntryID = (*mpEntries)[mEntryID].vNext( downwards );
376  }
377 
378  /**
379  *
380  * @param leftwards
381  */
382  void hMove( bool leftwards )
383  {
384  assert( !hEnd( leftwards ) );
385  mEntryID = (*mpEntries)[mEntryID].hNext( leftwards );
386  }
387 
388  /**
389  * @return
390  */
391  std::vector<TableauEntry<T1,T2> >* pEntries() const
392  {
393  return mpEntries;
394  }
395 
396  /**
397  * @return
398  */
399  bool operator ==( const Iterator& _iter ) const
400  {
401  return mEntryID == _iter.entryID();
402  }
403 
404  /**
405  * @return
406  */
407  bool operator !=( const Iterator& _iter ) const
408  {
409  return mEntryID != _iter.entryID();
410  }
411  }; /* class Tableau<Settings,T1,T2>::Iterator */
412 
413  public:
414  /**
415  *
416  * @param _defaultBoundPosition
417  */
418  Tableau( ModuleInput::iterator _defaultBoundPosition );
419 
420  /**
421  *
422  */
424 
425  /**
426  *
427  * @param _expectedHeight
428  * @param _expectedWidth
429  * @param _expectedNumberOfBounds
430  */
431  void setSize( size_t _expectedHeight, size_t _expectedWidth, size_t _expectedNumberOfBounds )
432  {
433  mRows.reserve( _expectedHeight );
434  mColumns.reserve( _expectedWidth );
435  mpEntries->reserve( _expectedHeight*_expectedWidth+1 );
436  }
437 
438  /**
439  * @return
440  */
441  size_t size() const
442  {
443  return mpEntries->size()-1;
444  }
445 
446  /**
447  *
448  */
449  void setBlandsRuleStart( size_t _start )
450  {
452  }
453 
454  /**
455  * @return
456  */
457  const std::vector<Variable<T1, T2>*>& rows() const
458  {
459  return mRows;
460  }
461 
462  /**
463  * @return
464  */
465  const std::vector<Variable<T1, T2>*>& columns() const
466  {
467  return mColumns;
468  }
469 
470  /**
471  * @return
472  */
473  const carl::FastMap< carl::Variable, Variable<T1,T2>*>& originalVars() const
474  {
475  return mOriginalVars;
476  }
477 
478  /**
479  * @return
480  */
481  const carl::FastPointerMap<typename Poly::PolyType, Variable<T1,T2>*>& slackVars() const
482  {
483  return mSlackVars;
484  }
485 
486  const T1& currentDelta() const
487  {
488  return mCurDelta;
489  }
490 
491  /**
492  * @return
493  */
494  const carl::FastMap<FormulaT, std::vector<const Bound<T1, T2>*>*>& constraintToBound() const
495  {
496  return mConstraintToBound;
497  }
498 
499  /**
500  * @return
501  */
502  carl::FastMap<FormulaT, std::vector<const Bound<T1, T2>*>*>& rConstraintToBound()
503  {
504  return mConstraintToBound;
505  }
506 
507  /**
508  * @return
509  */
510  size_t numberOfPivotingSteps() const
511  {
512  return mPivotingSteps;
513  }
514 
515  /**
516  *
517  */
519  {
520  mPivotingSteps = 0;
521  }
522 
523  /**
524  * @return
525  */
526  carl::FastPointerMap<Variable<T1,T2>, LearnedBound>& rLearnedLowerBounds()
527  {
528  return mLearnedLowerBounds;
529  }
530 
531  /**
532  * @return
533  */
534  carl::FastPointerMap<Variable<T1,T2>, LearnedBound>& rLearnedUpperBounds()
535  {
536  return mLearnedUpperBounds;
537  }
538 
539  void resetTheta()
540  {
541  *mpTheta = Value<T1>( T1( 0 ) );
542  }
543 
544  /**
545  * @return
546  */
547  std::vector<typename carl::FastPointerMap<Variable<T1,T2>, LearnedBound>::iterator>& rNewLearnedBounds()
548  {
549  return mNewLearnedBounds;
550  }
551 
552  bool entryIsPositive( const TableauEntry<T1,T2>& _entry ) const
553  {
554  if( Settings::omit_division )
555  {
556  const Variable<T1, T2>& basicVar = *_entry.rowVar();
557  return (_entry.content() > 0 && basicVar.factor() > 0) || (_entry.content() < 0 && basicVar.factor() < 0);
558  }
559  else
560  return _entry.content() > 0;
561  }
562 
563  bool entryIsNegative( const TableauEntry<T1,T2>& _entry ) const
564  {
565  if( Settings::omit_division )
566  {
567  const Variable<T1, T2>& basicVar = *_entry.rowVar();
568  return (_entry.content() < 0 && basicVar.factor() > 0) || (_entry.content() > 0 && basicVar.factor() < 0);
569  }
570  else
571  return _entry.content() < 0;
572  }
573 
574  /**
575  * @return
576  */
577  auto defaultBoundPosition() const
578  {
579  return mDefaultBoundPosition;
580  }
581 
582  bool isActive( const Variable<T1, T2>& _var ) const
583  {
584  return _var.positionInNonActives() != mNonActiveBasics.end();
585  }
586 
587  /**
588  *
589  * @param _content
590  * @return
591  */
592  EntryID newTableauEntry( const T2& _content );
593 
594  /**
595  *
596  * @param _entryID
597  */
598  void removeEntry( EntryID _entryID );
599 
600  Variable<T1,T2>* getVariable( const Poly& _lhs, T1& _factor, T1& _boundValue );
601 
603 
604  /**
605  *
606  * @param _constraint
607  * @return
608  */
609  std::pair<const Bound<T1,T2>*, bool> newBound( const FormulaT& _constraint );
610  void removeBound( const FormulaT& _constraint );
611 
612  /**
613  *
614  * @param _bound
615  * @param _formula
616  */
617  void activateBound( const Bound<T1,T2>* _bound, const FormulaT& _formula );
618 
619  /**
620  *
621  * @param _variable
622  */
623  void deleteVariable( Variable<T1, T2>* _variable, bool _optimizationVar = false );
624 
625  /**
626  *
627  * @param _poly
628  * @param _isInteger
629  * @return
630  */
631  Variable<T1, T2>* newNonbasicVariable( const typename Poly::PolyType* _poly, bool _isInteger );
632 
633  /**
634  *
635  * @param _poly
636  * @param _originalVars
637  * @param _isInteger
638  * @return
639  */
640  Variable<T1, T2>* newBasicVariable( const typename Poly::PolyType* _poly, bool _isInteger );
641 
642  /**
643  * g
644  * @param _var
645  */
647 
648  /**
649  *
650  * @param _var
651  */
653 
654  /**
655  *
656  */
658 
659  /**
660  *
661  */
663 
664  /**
665  *
666  * @return
667  */
669 
670  void adaptDelta( const Variable<T1,T2>& _variable, bool _upperBound, T1& _minDelta ) const;
671 
672  /**
673  *
674  */
675  void compressRows();
676 
677  /**
678  * Returns true, if the next pivoting element is selected by blands rule.
679  */
681 
682  /**
683  * @return In SUM-Simplex a conflict is possibly created with multiple rows.
684  * This function returns true iff the multi-conflict settings occured.
685  */
687 
688  /**
689  * @return In SUM-Simplex a conflict is possibly created with multiple rows.
690  * This function returns the single conflict if possible and otherwise construct the multiline conflict.
691  */
692  std::vector< const Bound<T1, T2>* > getMultilineConflict();
693 
694  /**
695  *
696  * @return
697  */
698  std::pair<EntryID, bool> nextPivotingElement();
699 
700  /**
701  * Method to compute the sum of derivations to the closest bounds.
702  */
704 
705  /**
706  * Computes the change in the violation sum when an the update value is added to the assignment of the nonbassi variable nVar.
707  * @param nVar variable to be updated
708  * @param update Update value
709  */
711 
712  /**
713  * Used as assertion-function to check the progress of the tableau.
714  */
716  return mOld_dVioSum;
717  }
718 
719  /**
720  * Updated Method to computed dVio more efficienlty. For this the fact is used, that VioSum is piecewise linear (the proof can be found in the SoI paper).
721  * @param candidates Update candidates, IMPORTANT: Must be sorted with an stabloe sorting algorithm
722  * @param nVar The updated nonbasic variable
723  * @param positive Whether the positve or negative update values are checked
724  */
725  std::map<Value<T1>, Value<T1>> compute_dVio(const std::vector< std::pair< Value<T1>, Variable<T1,T2>* > >& candidates, const Variable<T1,T2>& nVar, bool positive);
726 
727  /**
728  * Method for next pivoting element according to "Simplex with Sum of Infeasibilities for SMT" by Tim King and Clark Barrett.
729  * Herefore, one counts the vialation of every bound and searches for elements who minimize the violation sum of the next iteration.
730  * @return
731  */
732  std::pair<EntryID, bool> nextPivotingElementInfeasibilities();
733 
734  /**
735  * Helper method to compute leavind candidates used in nextPivotingElementInfeasibilities.
736  * Computes for every non-basic variable the breaking points.
737  * Updates from non-basic vars of 0 are omitted to prevent loops.
738  * @param i : Index if entering (nonbasic ) variable.
739  * @param leaving_candidates : Used as storage object for update candidates.
740  */
741  void computeLeavingCandidates(const std::size_t i, std::vector< std::pair< Value<T1>, Variable<T1,T2>* > >& leaving_candidates);
742 
743  /**
744  * Updates a nonbasic variable by the assignment stored in mpTheta and triggers updates of depending basic variables.
745  * @param _pivotingElement Element in the row of the nonbasic variable
746  */
747  void updateNonbasicVariable(EntryID _pivotingElement);
748 
749  /**
750  * Updates a nonbasic variable by the given assignment and triggers updates of depending basic variables.
751  * @param _pivotingElement Element in the row of the nonbasic variable
752  * @param update Update Value of non-basic var
753  */
755 
756  /**
757  * Checks if a conflicting pair exists. In a conflict is found, the cell and false is returned. If not, LAST_ENTRY_ID and true is returned.
758  */
759  std::pair<EntryID,bool> hasConflict();
760 
761  void printEntries(){
762  for(auto h: *mpEntries){
763  std::cout <<h.content()<< '\n';
764  }
765  }
766 
767  /**
768  * Method to compute the infeasibility row to the current tableau.
769  */
770  std::vector<T2> getInfeasibilityRow();
771 
772  /**
773  * Method to set the initital infeasibility row to avoid recomputation in every round.
774  */
776 
777  /**
778  *
779  * @param _objective
780  * @return
781  */
782  std::pair<EntryID,bool> optimizeIndependentNonbasics( const Variable<T1, T2>& _objective );
783 
784  /**
785  *
786  * @return
787  */
788  std::pair<EntryID,bool> nextPivotingElementForOptimizing( const Variable<T1, T2>& _objective );
789  std::pair<EntryID,bool> nextZeroPivotingElementForOptimizing( const Variable<T1, T2>& _objective ) const;
790 
791  /**
792  *
793  * @param _basicVar
794  * @param _forIncreasingAssignment
795  * @return
796  */
797  EntryID isSuitable( const Variable<T1, T2>& _basicVar, bool _forIncreasingAssignment ) const;
798 
799  /**
800  * Checks if the basic variable is pivotable.
801  * Returns LAST_ENTRY_ID as EntryID if a conflict was found. In difference to isSuitable returns this function an EntryID as soon as
802  * the EntryID bestEntry is unequal to LAST_ENTRY_ID. The assertions are still checked.
803  * @param _basicVar
804  * @param _forIncreasingAssignment
805  * @return
806  */
807  EntryID isSuitableConflictDetection( const Variable<T1, T2>& _basicVar, bool _forIncreasingAssignment ) const;
808 
809  /**
810  *
811  * @param _isBetter
812  * @param _than
813  * @return
814  */
815  bool betterEntry( EntryID _isBetter, EntryID _than ) const;
816 
817  /**
818  *
819  * @param _rowEntry
820  * @return
821  */
822  std::vector< const Bound<T1, T2>* > getConflict( EntryID _rowEntry ) const;
823 
824  /**
825  *
826  * @param _rowEntry
827  * @return
828  */
829  std::vector< std::vector< const Bound<T1, T2>* > > getConflictsFrom( EntryID _rowEntry ) const;
830 
831  /**
832  *
833  * @param _column
834  * @param _change
835  */
836  void updateBasicAssignments( size_t _column, const Value<T1>& _change );
837 
838  /**
839  *
840  * @param _pivotingElement
841  * @param updateAssignments
842  * @return
843  */
844  Variable<T1, T2>* pivot( EntryID _pivotingElement, bool _optimizing = false );
845 
846  /**
847  * Updates the tableau according to the new values in the pivoting row containing the given pivoting element. The updating is
848  * applied from the pivoting row downwards, if the given flag _downwards is true, and upwards, otherwise.
849  *
850  * @param _downwards The flag indicating whether to update the tableau downwards or upwards starting from the pivoting row.
851  * @param _pivotingElement The id of the current pivoting element.
852  * @param _pivotingRowLeftSide For every element in the pivoting row, which is positioned left of the pivoting element, this
853  * vector contains an iterator. The closer the element is to the pivoting element, the smaller is the
854  * iterator's index in the vector.
855  * @param _pivotingRowRightSide For every element in the pivoting row, which is positioned right of the pivoting element, this
856  * vector contains an iterator. The closer the element is to the pivoting element, the smaller is the
857  * iterator's index in the vector.
858  * @param _updateAssignments If true, the assignments of all variables will be updated after pivoting.
859  */
860  void update( bool _downwards, EntryID _pivotingElement, std::vector<Iterator>& _pivotingRowLeftSide, std::vector<Iterator>& _pivotingRowRightSide, bool _optimizing = false );
861 
862  /**
863  * Adds the given value to the entry being at the position (i,j), where i is the vertical position of the given horizontal
864  * iterator and j is the horizontal position of the given vertical iterator. Note, that the entry might not exist, if its
865  * current value is 0. Then the horizontal iterator is located horizontally before or after the entry to change and the
866  * vertical iterator is located vertically before or after the entry to add.
867  *
868  * @param _toAdd The value to add to the content of the entry specified by the given iterators and their relative position
869  * to each other.
870  * @param _horiIter The iterator moving horizontally and, hence, giving the vertical position of the entry to add the given value to.
871  * @param _horiIterLeftFromVertIter true, if the horizontally moving iterator is left from or equal to the horizontal position of the
872  * iterator moving vertically, and, hence, left from or equal to the position of the entry to add
873  * the given value to;
874  * false, it is right or equal to this position.
875  * @param _vertIter The iterator moving vertically and, hence, giving the horizontal position of the entry to add the given value to.
876  * @param _vertIterBelowHoriIter true, if the vertically moving iterator is below or exactly at the vertical position of the
877  * iterator moving horizontally, and, hence, below or exactly at the position of the entry to add
878  * the given value to;
879  * false, it is above or equal to this position.
880  * @sideeffect If the entry existed (!=0) and is removed because of becoming 0, the iterators are set according to the given relative
881  * positioning.
882  */
883  void addToEntry( const T2& _toAdd, Iterator& _horiIter, bool _horiIterLeftFromVertIter, Iterator& _vertIter, bool _vertIterBelowHoriIter );
884 
885  /**
886  * Tries to refine the supremum and infimum of the given basic variable.
887  * @param _basicVar The basic variable for which to refine the supremum and infimum.
888  */
889  void rowRefinement( Variable<T1, T2>* _basicVar );
890 
891  /**
892  *
893  * @param _var
894  * @param _stopCriterium
895  * @return
896  */
897  size_t boundedVariables( const Variable<T1,T2>& _var, size_t _stopCriterium = 0 ) const;
898 
899  /**
900  *
901  * @param _var
902  * @param _stopCriterium
903  * @return
904  */
905  size_t unboundedVariables( const Variable<T1,T2>& _var, size_t _stopCriterium = 0 ) const;
906 
907  /**
908  *
909  * @return
910  */
911  size_t checkCorrectness() const;
912 
913  /**
914  *
915  * @param _rowNumber
916  * @return
917  */
918  bool rowCorrect( size_t _rowNumber ) const;
919 
920  bool isConflicting() const;
921 
922  /**
923  * Creates a constraint referring to Gomory Cuts, if possible.
924  * @param _ass
925  * @param _rowVar
926  * @return NULL, if the cut can´t be constructed;
927  * otherwise the valid constraint is returned.
928  */
929  const typename Poly::PolyType* gomoryCut( const T2& _ass, Variable<T1,T2>* _rowVar );
930 
931  /**
932  * @param _rowVar
933  * @return number of entries in the row belonging to _rowVar
934  */
936 
937  /**
938  * Collects the premises for branch and bound and stores them in premises.
939  * @param _rowVar
940  * @param premises
941  */
942  void collect_premises( const Variable<T1,T2>* _rowVar, FormulasT& premises ) const;
943 
944  /**
945  *
946  * @param _out
947  * @param _maxEntryLength
948  * @param _init
949  */
950  void printHeap( std::ostream& _out = std::cout, int _maxEntryLength = 30, const std::string _init = "" ) const;
951 
952  /**
953  *
954  * @param _entry
955  * @param _out
956  * @param _maxEntryLength
957  */
958  void printEntry( EntryID _entry, std::ostream& _out = std::cout, int _maxEntryLength = 20 ) const;
959 
960  /**
961  *
962  * @param _allBounds
963  * @param _out
964  * @param _init
965  */
966  void printVariables( bool _allBounds = true, std::ostream& _out = std::cout, const std::string _init = "" ) const;
967 
968  /**
969  *
970  * @param _init
971  * @param _out
972  */
973  void printLearnedBounds( const std::string _init = "", std::ostream& _out = std::cout ) const;
974 
975  /**
976  *
977  * @param _var
978  * @param _learnedBound
979  * @param _init
980  * @param _out
981  */
982  void printLearnedBound( const Variable<T1,T2>& _var, const LearnedBound& _learnedBound, const std::string _init = "", std::ostream& _out = std::cout ) const;
983 
984  /**
985  *
986  * @param _pivotingElement
987  * @param _out
988  * @param _init
989  * @param _friendlyNames
990  * @param _withZeroColumns
991  */
992  void print( EntryID _pivotingElement = LAST_ENTRY_ID, std::ostream& _out = std::cout, const std::string _init = "", bool _friendlyNames = true, bool _withZeroColumns = false ) const;
993 
994  };
995  } // end namspace lra
996 } // end namspace smtrat
997 
998 #include "Tableau.tpp"
super::iterator iterator
Passing through the list::iterator.
Definition: ModuleInput.h:144
Stores a bound, which could be an upper "<= b" or a lower bound ">= b" for a bound value b.
Definition: Bound.h:33
EntryID vNext(bool downwards)
Definition: Tableau.h:129
TableauEntry(EntryID _up, EntryID _down, EntryID _left, EntryID _right, Variable< T1, T2 > *_rowVar, Variable< T1, T2 > *_columnVar, const T2 &_content)
Definition: Tableau.h:68
Variable< T1, T2 > * rowVar() const
Definition: Tableau.h:153
void setHNext(bool leftwards, const EntryID _entryId)
Definition: Tableau.h:116
Variable< T1, T2 > * mRowVar
Definition: Tableau.h:38
const T2 & content() const
Definition: Tableau.h:187
Variable< T1, T2 > * columnVar() const
Definition: Tableau.h:170
EntryID hNext(bool leftwards)
Definition: Tableau.h:142
TableauEntry(const TableauEntry &_entry)
Definition: Tableau.h:82
Variable< T1, T2 > * mColumnVar
Definition: Tableau.h:40
void setVNext(bool downwards, const EntryID _entryId)
Definition: Tableau.h:103
void setColumnVar(Variable< T1, T2 > *_columnVar)
Definition: Tableau.h:179
void setRowVar(Variable< T1, T2 > *_rowVar)
Definition: Tableau.h:162
Iterator(const Iterator &_iter)
Definition: Tableau.h:321
bool hEnd(bool leftwards) const
Definition: Tableau.h:363
bool vEnd(bool downwards) const
Definition: Tableau.h:355
void operator=(Iterator &&_iter)
Definition: Tableau.h:331
Iterator(EntryID _start, std::vector< TableauEntry< T1, T2 > > *const _entries)
Definition: Tableau.h:312
void vMove(bool downwards)
Definition: Tableau.h:372
bool operator!=(const Iterator &_iter) const
Definition: Tableau.h:407
void hMove(bool leftwards)
Definition: Tableau.h:382
TableauEntry< T1, T2 > & operator*()
Definition: Tableau.h:347
void operator=(const Iterator &_iter)
Definition: Tableau.h:326
bool operator==(const Iterator &_iter) const
Definition: Tableau.h:399
std::vector< TableauEntry< T1, T2 > > * mpEntries
Definition: Tableau.h:304
EntryID entryID() const
Definition: Tableau.h:339
std::vector< TableauEntry< T1, T2 > > * pEntries() const
Definition: Tableau.h:391
void rowRefinement(Variable< T1, T2 > *_basicVar)
Tries to refine the supremum and infimum of the given basic variable.
std::vector< Variable< T1, T2 > * > mConflictingRows
Definition: Tableau.h:265
carl::FastPointerMap< Variable< T1, T2 >, LearnedBound > mLearnedLowerBounds
Definition: Tableau.h:279
void printVariables(bool _allBounds=true, std::ostream &_out=std::cout, const std::string _init="") const
void addToEntry(const T2 &_toAdd, Iterator &_horiIter, bool _horiIterLeftFromVertIter, Iterator &_vertIter, bool _vertIterBelowHoriIter)
Adds the given value to the entry being at the position (i,j), where i is the vertical position of th...
std::stack< EntryID > mUnusedIDs
Definition: Tableau.h:253
bool betterEntry(EntryID _isBetter, EntryID _than) const
const std::vector< Variable< T1, T2 > * > & columns() const
Definition: Tableau.h:465
carl::FastMap< carl::Variable, Variable< T1, T2 > * > mOriginalVars
Definition: Tableau.h:273
void updateBasicAssignments(size_t _column, const Value< T1 > &_change)
const carl::FastMap< FormulaT, std::vector< const Bound< T1, T2 > * > * > & constraintToBound() const
Definition: Tableau.h:494
std::vector< const Bound< T1, T2 > * > getMultilineConflict()
std::pair< EntryID, bool > hasConflict()
Checks if a conflicting pair exists.
void adaptDelta(const Variable< T1, T2 > &_variable, bool _upperBound, T1 &_minDelta) const
std::vector< Variable< T1, T2 > * > mRows
Definition: Tableau.h:257
carl::FastMap< FormulaT, std::vector< const Bound< T1, T2 > * > * > mConstraintToBound
Definition: Tableau.h:277
ModuleInput::iterator mDefaultBoundPosition
Definition: Tableau.h:251
void computeLeavingCandidates(const std::size_t i, std::vector< std::pair< Value< T1 >, Variable< T1, T2 > * > > &leaving_candidates)
Helper method to compute leavind candidates used in nextPivotingElementInfeasibilities.
size_t numberOfPivotingSteps() const
Definition: Tableau.h:510
void resetNumberOfPivotingSteps()
Definition: Tableau.h:518
bool rowCorrect(size_t _rowNumber) const
void setBlandsRuleStart(size_t _start)
Definition: Tableau.h:449
std::pair< EntryID, bool > nextPivotingElementInfeasibilities()
Method for next pivoting element according to "Simplex with Sum of Infeasibilities for SMT" by Tim Ki...
carl::FastPointerMap< Variable< T1, T2 >, LearnedBound > & rLearnedUpperBounds()
Definition: Tableau.h:534
RationalAssignment getRationalAssignment() const
size_t boundedVariables(const Variable< T1, T2 > &_var, size_t _stopCriterium=0) const
Variable< T1, T2 > * getObjectiveVariable(const Poly &_lhs)
bool isActive(const Variable< T1, T2 > &_var) const
Definition: Tableau.h:582
void collect_premises(const Variable< T1, T2 > *_rowVar, FormulasT &premises) const
Collects the premises for branch and bound and stores them in premises.
void updateNonbasicVariable(EntryID _pivotingElement)
Updates a nonbasic variable by the assignment stored in mpTheta and triggers updates of depending bas...
Value< T1 > mOld_dVioSum
Definition: Tableau.h:287
const T1 & currentDelta() const
Definition: Tableau.h:486
const carl::FastPointerMap< typename Poly::PolyType, Variable< T1, T2 > * > & slackVars() const
Definition: Tableau.h:481
carl::IDPool mVariableIdAllocator
Id allocator for the variables.
Definition: Tableau.h:255
bool entryIsPositive(const TableauEntry< T1, T2 > &_entry) const
Definition: Tableau.h:552
std::vector< T2 > mInfeasibilityRow
Definition: Tableau.h:290
Value< T1 > * mpTheta
Definition: Tableau.h:267
std::map< Value< T1 >, Value< T1 > > compute_dVio(const std::vector< std::pair< Value< T1 >, Variable< T1, T2 > * > > &candidates, const Variable< T1, T2 > &nVar, bool positive)
Updated Method to computed dVio more efficienlty.
size_t getNumberOfEntries(Variable< T1, T2 > *_rowVar)
void printLearnedBound(const Variable< T1, T2 > &_var, const LearnedBound &_learnedBound, const std::string _init="", std::ostream &_out=std::cout) const
EntryID isSuitableConflictDetection(const Variable< T1, T2 > &_basicVar, bool _forIncreasingAssignment) const
Checks if the basic variable is pivotable.
EntryID isSuitable(const Variable< T1, T2 > &_basicVar, bool _forIncreasingAssignment) const
void update(bool _downwards, EntryID _pivotingElement, std::vector< Iterator > &_pivotingRowLeftSide, std::vector< Iterator > &_pivotingRowRightSide, bool _optimizing=false)
Updates the tableau according to the new values in the pivoting row containing the given pivoting ele...
Tableau(ModuleInput::iterator _defaultBoundPosition)
const carl::FastMap< carl::Variable, Variable< T1, T2 > * > & originalVars() const
Definition: Tableau.h:473
void print(EntryID _pivotingElement=LAST_ENTRY_ID, std::ostream &_out=std::cout, const std::string _init="", bool _friendlyNames=true, bool _withZeroColumns=false) const
std::vector< std::vector< const Bound< T1, T2 > * > > getConflictsFrom(EntryID _rowEntry) const
std::pair< EntryID, bool > nextPivotingElementForOptimizing(const Variable< T1, T2 > &_objective)
std::pair< EntryID, bool > optimizeIndependentNonbasics(const Variable< T1, T2 > &_objective)
std::vector< TableauEntry< T1, T2 > > * mpEntries
Definition: Tableau.h:263
const std::vector< Variable< T1, T2 > * > & rows() const
Definition: Tableau.h:457
void removeBound(const FormulaT &_constraint)
void printHeap(std::ostream &_out=std::cout, int _maxEntryLength=30, const std::string _init="") const
std::list< std::list< std::pair< Variable< T1, T2 > *, T2 > > > mNonActiveBasics
Definition: Tableau.h:261
size_t mPivotingSteps
Definition: Tableau.h:245
size_t mVarIDCounter
Definition: Tableau.h:249
Value< T1 > violationSum()
Method to compute the sum of derivations to the closest bounds.
Variable< T1, T2 > * newBasicVariable(const typename Poly::PolyType *_poly, bool _isInteger)
auto defaultBoundPosition() const
Definition: Tableau.h:577
void activateBound(const Bound< T1, T2 > *_bound, const FormulaT &_formula)
Value< T1 > dViolationSum(const Variable< T1, T2 > *nVar, const Value< T1 > &update)
Computes the change in the violation sum when an the update value is added to the assignment of the n...
std::vector< Variable< T1, T2 > * > mColumns
Definition: Tableau.h:259
carl::FastPointerMap< Variable< T1, T2 >, LearnedBound > mLearnedUpperBounds
Definition: Tableau.h:281
bool usedBlandsRule()
Returns true, if the next pivoting element is selected by blands rule.
size_t unboundedVariables(const Variable< T1, T2 > &_var, size_t _stopCriterium=0) const
void deactivateBasicVar(Variable< T1, T2 > *_var)
void updateNonbasicVariable(EntryID _pivotingElement, Value< T1 > update)
Updates a nonbasic variable by the given assignment and triggers updates of depending basic variables...
size_t checkCorrectness() const
std::pair< EntryID, bool > nextZeroPivotingElementForOptimizing(const Variable< T1, T2 > &_objective) const
std::vector< typename carl::FastPointerMap< Variable< T1, T2 >, LearnedBound >::iterator > & rNewLearnedBounds()
Definition: Tableau.h:547
void setInfeasibilityRow()
Method to set the initital infeasibility row to avoid recomputation in every round.
Value< T1 > mOldVioSum
Definition: Tableau.h:286
void printEntry(EntryID _entry, std::ostream &_out=std::cout, int _maxEntryLength=20) const
std::pair< const Bound< T1, T2 > *, bool > newBound(const FormulaT &_constraint)
void printLearnedBounds(const std::string _init="", std::ostream &_out=std::cout) const
Variable< T1, T2 > * newNonbasicVariable(const typename Poly::PolyType *_poly, bool _isInteger)
carl::FastMap< FormulaT, std::vector< const Bound< T1, T2 > * > * > & rConstraintToBound()
Definition: Tableau.h:502
std::vector< typename carl::FastPointerMap< Variable< T1, T2 >, LearnedBound >::iterator > mNewLearnedBounds
Definition: Tableau.h:283
std::vector< const Bound< T1, T2 > * > getConflict(EntryID _rowEntry) const
std::pair< EntryID, bool > nextPivotingElement()
bool isConflicting() const
std::vector< T2 > getInfeasibilityRow()
Method to compute the infeasibility row to the current tableau.
size_t size() const
Definition: Tableau.h:441
carl::FastPointerMap< typename Poly::PolyType, Variable< T1, T2 > * > mSlackVars
Definition: Tableau.h:275
bool entryIsNegative(const TableauEntry< T1, T2 > &_entry) const
Definition: Tableau.h:563
std::size_t mFullCandidateSearch
Definition: Tableau.h:293
Value< T1 > get_dVioSum()
Used as assertion-function to check the progress of the tableau.
Definition: Tableau.h:715
size_t mMaxPivotsWithoutBlandsRule
Definition: Tableau.h:247
void removeEntry(EntryID _entryID)
void deleteVariable(Variable< T1, T2 > *_variable, bool _optimizationVar=false)
void setSize(size_t _expectedHeight, size_t _expectedWidth, size_t _expectedNumberOfBounds)
Definition: Tableau.h:431
void activateBasicVar(Variable< T1, T2 > *_var)
g
Variable< T1, T2 > * pivot(EntryID _pivotingElement, bool _optimizing=false)
EntryID newTableauEntry(const T2 &_content)
Variable< T1, T2 > * getVariable(const Poly &_lhs, T1 &_factor, T1 &_boundValue)
const Poly::PolyType * gomoryCut(const T2 &_ass, Variable< T1, T2 > *_rowVar)
Creates a constraint referring to Gomory Cuts, if possible.
carl::FastPointerMap< Variable< T1, T2 >, LearnedBound > & rLearnedLowerBounds()
Definition: Tableau.h:526
std::list< std::list< std::pair< Variable< T1, T2 > *, T2 > > >::iterator positionInNonActives() const
Definition: Variable.h:309
const T2 & factor() const
Definition: Variable.h:400
size_t EntryID
Definition: Variable.h:23
static EntryID LAST_ENTRY_ID
Definition: Variable.h:25
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Assignment< Rational > RationalAssignment
Definition: types.h:45
carl::MultivariatePolynomial< Rational > Poly
Definition: types.h:25
carl::Formulas< Poly > FormulasT
Definition: types.h:39
LearnedBound(const LearnedBound &)=delete
LearnedBound(LearnedBound &&_toMove)
Definition: Tableau.h:224
LearnedBound(const Value< T1 > &_limit, const Bound< T1, T2 > *_newBound, typename Bound< T1, T2 >::BoundSet::const_iterator _nextWeakerBound, std::vector< const Bound< T1, T2 > * > &&_premise)
Definition: Tableau.h:230
const Bound< T1, T2 > * newBound
Definition: Tableau.h:214
std::vector< const Bound< T1, T2 > * > premise
Definition: Tableau.h:220
Bound< T1, T2 >::BoundSet::const_iterator nextWeakerBound
Definition: Tableau.h:218