SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
State.cpp
Go to the documentation of this file.
1 /**
2  * Class to create a state object.
3  * @author Florian Corzilius
4  * @since 2010-05-11
5  * @version 2013-10-24
6  */
7 
8 #include "State.h"
9 //#include <smtrat-modules/Module.h>
10 #include <carl-arith/interval/SetTheory.h>
11 #include <carl-arith/poly/umvpoly/functions/SturmSequence.h>
12 #include <cmath>
13 #include <float.h>
14 #include <numeric>
15 #include <carl-arith/poly/umvpoly/functions/RootBounds.h>
16 #include <carl-arith/poly/umvpoly/functions/RootCounting.h>
17 #include <carl-arith/constraint/IntervalEvaluation.h>
18 #include <carl-arith/poly/umvpoly/functions/Evaluation.h>
19 
20 //#define VS_DEBUG_VARIABLE_VALUATIONS
21 //#define VS_DEBUG_VARIABLE_BOUNDS
22 //#define VS_DEBUG_LOCAL_CONFLICT_SEARCH
23 //#define VS_DEBUG_ROOTS_CHECK
24 
25 //#define VS_LOG_INFSUBSETS
26 
27 namespace smtrat {
28 namespace vs
29 {
30  State::State( carl::IDPool* _conditionIdAllocator, bool _withVariableBounds ):
31  mConditionsSimplified( false ),
32  mHasChildrenToInsert( false ),
33  mHasRecentlyAddedConditions( false ),
34  mInconsistent( false ),
35  mMarkedAsDeleted( false ),
36  mSubResultsSimplified( false ),
37  mTakeSubResultCombAgain( false ),
38  mTestCandidateCheckedForBounds( false ),
39  mCannotBeSolved( false ),
40  mCannotBeSolvedLazy( false ),
41  mTryToRefreshIndex( false ),
42  mBackendCallValuation( 0 ),
43  mID( 0 ),
44  mValuation( 0 ),
45  mType( TEST_CANDIDATE_TO_GENERATE ),
46  mIndex( carl::Variable::NO_VARIABLE ),
47  mpOriginalCondition( NULL ),
48  mpFather( NULL ),
49  mpSubstitution( NULL ),
50  mpSubstitutionResults( NULL ),
51  mpSubResultCombination( NULL ),
52  mpConditions( new ConditionList() ),
53  mpConflictSets( new ConflictSets() ),
54  mpChildren( new std::list< State* >() ),
55  mpTooHighDegreeConditions( new carl::PointerSet<Condition>() ),
56  mpVariableBounds( _withVariableBounds ? new VariableBoundsCond() : NULL ),
57  mpInfinityChild( NULL ),
58  mMinIntTestCanidate( Rational(1) ),
59  mMaxIntTestCanidate( Rational(-1) ),
60  mCurrentIntRange( 0 ),
61  mpConditionIdAllocator( _conditionIdAllocator ),
62  mRealVarVals(),
63  mIntVarVals(),
64  mBestVarVals()
65  #ifdef SMTRAT_DEVOPTION_Statistics
66  , mpStatistics( nullptr )
67  #endif
68  {}
69 
70  State::State( State* const _father, const Substitution& _substitution, carl::IDPool* _conditionIdAllocator, bool _withVariableBounds ):
71  mConditionsSimplified( false ),
72  mHasChildrenToInsert( false ),
73  mHasRecentlyAddedConditions( false ),
74  mInconsistent( false ),
75  mMarkedAsDeleted( false ),
76  mSubResultsSimplified( false ),
77  mTakeSubResultCombAgain( false ),
78  mTestCandidateCheckedForBounds( false ),
79  mCannotBeSolved( false ),
80  mCannotBeSolvedLazy( false ),
81  mTryToRefreshIndex( false ),
82  mBackendCallValuation( 0 ),
83  mID( 0 ),
84  mValuation( 0 ),
85  mType( SUBSTITUTION_TO_APPLY ),
86  mIndex( carl::Variable::NO_VARIABLE ),
87  mpOriginalCondition( NULL ),
88  mpFather( _father ),
89  mpSubstitution( new Substitution( _substitution ) ),
90  mpSubstitutionResults( NULL ),
91  mpSubResultCombination( NULL ),
92  mpConditions( new ConditionList() ),
93  mpConflictSets( new ConflictSets() ),
94  mpChildren( new std::list< State* >() ),
95  mpTooHighDegreeConditions( new carl::PointerSet<Condition>() ),
96  mpVariableBounds( _withVariableBounds ? new VariableBoundsCond() : NULL ),
97  mpInfinityChild( NULL ),
98  mMinIntTestCanidate( Rational(1) ),
99  mMaxIntTestCanidate( Rational(-1) ),
100  mCurrentIntRange( 0 ),
101  mpConditionIdAllocator( _conditionIdAllocator ),
102  mRealVarVals(),
103  mIntVarVals(),
104  mBestVarVals()
105  #ifdef SMTRAT_DEVOPTION_Statistics
106  , mpStatistics( nullptr )
107  #endif
108  {}
109 
111  {
112  mpTooHighDegreeConditions->clear();
114  while( !mpConflictSets->empty() )
115  {
116  const Substitution* sub = mpConflictSets->begin()->first;
117  mpConflictSets->erase( mpConflictSets->begin() );
118  if( sub != NULL && sub->type() == Substitution::Type::INVALID )
119  {
120  delete sub;
121  }
122  }
123  delete mpConflictSets;
124  while( !children().empty() )
125  {
126  State* rpChild = rChildren().back();
127  rChildren().pop_back();
128  if( rpChild == mpInfinityChild ) mpInfinityChild = NULL;
129  delete rpChild;
130  }
131  delete mpChildren;
132  while( !conditions().empty() )
133  {
134  const Condition* pCond = rConditions().back();
135  rConditions().pop_back();
136  if( mpVariableBounds != NULL )
137  mpVariableBounds->removeBound( pCond->constraint(), pCond );
138  mpConditionIdAllocator->free( pCond->id() );
139  delete pCond;
140  pCond = NULL;
141  }
142  if( mpVariableBounds != NULL )
143  delete mpVariableBounds;
144  delete mpConditions;
145  if( mpSubstitution != NULL )
146  delete mpSubstitution;
147  if( mpSubstitutionResults != NULL )
148  {
149  while( !mpSubstitutionResults->empty() )
150  {
151  while( !mpSubstitutionResults->back().empty() )
152  {
153  while( !mpSubstitutionResults->back().back().first.empty() )
154  {
155  const Condition* rpCond = mpSubstitutionResults->back().back().first.back();
156  mpSubstitutionResults->back().back().first.pop_back();
157  mpConditionIdAllocator->free( rpCond->id() );
158  delete rpCond;
159  rpCond = NULL;
160  }
161  mpSubstitutionResults->back().pop_back();
162  }
163  mpSubstitutionResults->pop_back();
164  }
165  delete mpSubstitutionResults;
166  delete mpSubResultCombination;
167  }
168  }
169 
170  void State::removeStatesFromRanking( const State& toRemove, ValuationMap& _ranking )
171  {
172  UnsignedTriple key = UnsignedTriple( toRemove.valuation(), std::pair<unsigned, unsigned>( toRemove.id(), toRemove.backendCallValuation() ) );
173  _ranking.erase( key );
174  for( const State* child : toRemove.children() )
175  removeStatesFromRanking( *child, _ranking );
176  }
177 
179  {
180  mCannotBeSolvedLazy = false;
181  for( State* child : *mpChildren )
182  child->resetCannotBeSolvedLazyFlags();
183  }
184 
185  unsigned State::treeDepth() const
186  {
187  unsigned depth = 0;
188  const State* currentDT = this;
189  while( !(*currentDT).isRoot() )
190  {
191  ++depth;
192  currentDT = (*currentDT).pFather();
193  }
194  return depth;
195  }
196 
198  {
199  auto cond = conditions().begin();
200  while( cond != conditions().end() )
201  {
202  if( substitutionApplicable( (**cond).constraint() ) )
203  return true;
204  ++cond;
205  }
206  return false;
207  }
208 
209  bool State::substitutionApplicable( const smtrat::ConstraintT& _constraint ) const
210  {
211  if( !isRoot() )
212  if( _constraint.variables().has( substitution().variable() ))
213  return true;
214  return false;
215  }
216 
218  {
219  auto cond = conditions().begin();
220  while( cond != conditions().end() )
221  {
222  if( (*cond)->flag() )
223  ++cond;
224  else
225  return true;
226  }
227  return false;
228  }
229 
230  bool State::allTestCandidatesInvalidated( const Condition* _condition ) const
231  {
232  if( !_condition->flag() || tooHighDegreeConditions().find( _condition ) != tooHighDegreeConditions().end() )
233  return false;
234  for( const State* child : children() )
235  {
236  if( child->substitution().originalConditions().find( _condition ) != child->substitution().originalConditions().end() && !child->isInconsistent() )
237  return false;
238  }
239  return true;
240  }
241 
243  {
244  auto child = children().begin();
245  while( child != children().end() )
246  {
247  if( (*child)->id() == 0 )
248  ++child;
249  else
250  return true;
251  }
252  return false;
253  }
254 
255  bool State::containsState( const State* _state ) const
256  {
257  if( this == _state ) return true;
258  for( const State* child : children() )
259  if( child->containsState( _state ) )
260  return true;
261  return false;
262  }
263 
265  {
266  auto child = children().begin();
267  while( child != children().end() )
268  {
269  if( (*child)->isInconsistent() )
270  ++child;
271  else
272  return false;
273  }
274  return true;
275  }
276 
277  bool State::occursInEquation( const carl::Variable& _variable ) const
278  {
279  for( auto cond = conditions().begin(); cond != conditions().end(); ++cond )
280  if( (*cond)->constraint().relation() == carl::Relation::EQ && (*cond)->constraint().variables().has( _variable ) )
281  return true;
282  return false;
283  }
284 
286  {
287  if( children().size() > 1 )
288  return true;
289  else
290  {
291  for( auto cond = conditions().begin(); cond != conditions().end(); ++cond )
292  if( !(**cond).flag() )
293  return true;
294  return false;
295  }
296  }
297 
298  void State::variables( carl::Variables& _variables ) const
299  {
300  for( auto cond = conditions().begin(); cond != conditions().end(); ++cond ) {
301  auto vars = (**cond).constraint().variables();
302  _variables.insert( vars.begin(), vars.end() );
303  }
304  }
305 
306  unsigned State::numberOfNodes() const
307  {
308  unsigned result = 1;
309  for( auto child = children().begin(); child != children().end(); ++child )
310  result += (**child).numberOfNodes();
311  return result;
312  }
313 
315  {
316  State* currentDT = this;
317  while( !(*currentDT).isRoot() )
318  currentDT = (*currentDT).pFather();
319  return *currentDT;
320  }
321 
322  bool State::getNextIntTestCandidate( smtrat::Rational& _nextIntTestCandidate, size_t _maxIntRange )
323  {
324  assert( _maxIntRange > 0 );
325  assert( father().index().type() == carl::VariableType::VT_INT );
327  if( mCurrentIntRange >= _maxIntRange ) return false;
329  {
330  _nextIntTestCandidate = father().minIntTestCandidate();
331  --_nextIntTestCandidate;
332  }
333  else
334  {
335  _nextIntTestCandidate = father().maxIntTestCandidate();
336  ++_nextIntTestCandidate;
337  }
338  assert( carl::is_integer( _nextIntTestCandidate ) );
340  return true;
341  }
342 
344  {
345  State* minusInfChild = NULL;
346  State* plusInfChild = NULL;
347  smtrat::Rational leastIntTc = 1;
348  smtrat::Rational greatestIntTc = -1;
349  for( auto child : rChildren() )
350  {
351  if( child->substitution().type() == Substitution::MINUS_INFINITY )
352  {
353  assert( minusInfChild == NULL );
354  minusInfChild = child;
355  }
356  else if( child->substitution().type() == Substitution::PLUS_INFINITY )
357  {
358  assert( plusInfChild == NULL );
359  plusInfChild = child;
360  }
361  else if( child->substitution().term().is_integer() )
362  {
363  smtrat::Rational currentTc = child->substitution().term().constant_part().constant_part();
364  if( currentTc < mMinIntTestCanidate ) leastIntTc = currentTc;
365  if( currentTc > mMaxIntTestCanidate ) greatestIntTc = currentTc;
366  }
367  }
368  bool anythingChanged = false;
369  if( leastIntTc != mMinIntTestCanidate )
370  {
371  mMinIntTestCanidate = leastIntTc;
372  if( minusInfChild != NULL )
373  minusInfChild->resetCurrentRangeSize();
374  anythingChanged = true;
375  }
376  if( greatestIntTc != mMaxIntTestCanidate )
377  {
378  mMaxIntTestCanidate = greatestIntTc;
379  if( plusInfChild != NULL )
380  plusInfChild->resetCurrentRangeSize();
381  anythingChanged = true;
382  }
383  return anythingChanged;
384  }
385 
386  bool State::unfinishedAncestor( State*& _unfinAnt )
387  {
388  _unfinAnt = this;
389  while( !_unfinAnt->isRoot() )
390  {
391  if( _unfinAnt->unfinished() )
392  return true;
393  _unfinAnt = _unfinAnt->pFather();
394  }
395  return _unfinAnt->unfinished();
396  }
397 
398  bool State::bestCondition( const Condition*& _bestCondition, size_t _numberOfAllVariables, bool _preferEquation )
399  {
400  auto cond = rConditions().begin();
401  if( cond == conditions().end() )
402  return false;
403  assert( index() != carl::Variable::NO_VARIABLE );
404  // Find the best condition.
405  _bestCondition = *cond;
406  ++cond;
407  double bestConditionValuation = _bestCondition->valuate( index(), _numberOfAllVariables, _preferEquation );
408  double currentConditionValuation = 0;
409  while( cond != conditions().end() )
410  {
411  if( !(**cond).flag() )
412  {
413  if( (*_bestCondition).flag() )
414  {
415  _bestCondition = *cond;
416  bestConditionValuation = _bestCondition->valuate( index(), _numberOfAllVariables, _preferEquation );
417  }
418  else
419  {
420  currentConditionValuation = (**cond).valuate( index(), _numberOfAllVariables, _preferEquation );
421  if( currentConditionValuation != 0 && ( currentConditionValuation < bestConditionValuation || bestConditionValuation == 0 ) )
422  {
423  _bestCondition = *cond;
424  bestConditionValuation = currentConditionValuation;
425  }
426  }
427  }
428  ++cond;
429  }
430  // If all constraints were considered to yield test candidates, return false
431  // which means that there is no condition in general. Otherwise return true.
432  return !(*_bestCondition).flag();
433  }
434 
435  ConditionList::iterator State::constraintExists( const smtrat::ConstraintT& _constraint )
436  {
437  for( auto cond = rConditions().begin(); cond != conditions().end(); ++cond )
438  if( (**cond).constraint() == _constraint )
439  return cond;
440  return rConditions().end();
441  }
442 
443  void State::simplify( ValuationMap& _ranking )
444  {
445  if( !subResultsSimplified() )
446  {
447  if( hasSubstitutionResults() )
448  {
449  // If these conjunction together are consistent, simplify all conjunctions of
450  // conditions in the remaining substitution results being disjunctions.
451  unsigned subResultIndex = 0;
452  auto subResult = mpSubstitutionResults->begin();
453  auto fixedConditions = mpSubstitutionResults->end();
454  while( subResult != mpSubstitutionResults->end() )
455  {
456  assert( !subResult->empty() );
457  auto condConjunction = subResult->begin();
458  bool containsEmptyCase = false;
459  while( condConjunction != subResult->end() && subResult->size() > 1 )
460  {
461  ConditionSetSet conflictingConditionPairs;
462  if( !simplify( condConjunction->first, conflictingConditionPairs, _ranking ) )
463  {
464  while( !condConjunction->first.empty() )
465  {
466  const Condition* rpCond = condConjunction->first.back();
467  condConjunction->first.pop_back();
468  mpConditionIdAllocator->free( rpCond->id() );
469  delete rpCond;
470  rpCond = NULL;
471  }
472  condConjunction = subResult->erase( condConjunction );
473  }
474  else
475  {
476  if( condConjunction->first.empty() )
477  containsEmptyCase = true;
478  ++condConjunction;
479  }
480  }
481  if( containsEmptyCase )
482  {
484  {
485  auto subResComb = rSubResultCombination().begin();
486  while( subResComb != subResultCombination().end() )
487  {
488  if( subResComb->first == subResultIndex )
489  subResComb = rSubResultCombination().erase( subResComb );
490  else if( subResComb->first > subResultIndex )
491  {
492  --(subResComb->first);
493  ++subResComb;
494  }
495  else
496  ++subResComb;
497  }
498  }
499  bool fixedPosWasEndBefore = (fixedConditions == mpSubstitutionResults->end());
500  while( !subResult->empty() )
501  {
502  while( !subResult->back().first.empty() )
503  {
504  const Condition* rpCond = subResult->back().first.back();
505  subResult->back().first.pop_back();
506  mpConditionIdAllocator->free( rpCond->id() );
507  delete rpCond;
508  rpCond = NULL;
509  }
510  subResult->pop_back();
511  }
512  subResult = mpSubstitutionResults->erase( subResult );
513  if( fixedPosWasEndBefore ) fixedConditions = mpSubstitutionResults->end();
515  {
517  assert( mpSubResultCombination->size() <= mpSubstitutionResults->size() );
518  }
519  else
520  mTakeSubResultCombAgain = false;
521  }
522  else
523  {
524  if( subResult->size() == 1 )
525  {
526  if( fixedConditions == mpSubstitutionResults->end() )
527  {
528  fixedConditions = subResult;
529  ++subResult;
530  ++subResultIndex;
531  }
532  else
533  {
534  fixedConditions->back().first.insert( fixedConditions->back().first.end(),
535  subResult->back().first.begin(),
536  subResult->back().first.end() );
538  {
539  auto subResComb = rSubResultCombination().begin();
540  while( subResComb != subResultCombination().end() )
541  {
542  if( subResComb->first == subResultIndex )
543  subResComb = rSubResultCombination().erase( subResComb );
544  else if( subResComb->first > subResultIndex )
545  {
546  --(subResComb->first);
547  ++subResComb;
548  }
549  else
550  ++subResComb;
551  }
552  }
553  subResult = mpSubstitutionResults->erase( subResult );
555  {
557  assert( mpSubResultCombination->size() <= mpSubstitutionResults->size() );
558  }
559  else
560  mTakeSubResultCombAgain = false;
561  }
562  }
563  else
564  {
565  ++subResult;
566  ++subResultIndex;
567  }
568  }
569  }
570  }
571  mSubResultsSimplified = true;
572  }
573  // Simplify the condition vector.
574  if( !conditionsSimplified() )
575  {
576  ConditionSetSet conflictingConditionPairs;
577  if( !simplify( rConditions(), conflictingConditionPairs, _ranking, true ) )
578  {
579  addConflictSet( NULL, std::move(conflictingConditionPairs) );
580  rInconsistent() = true;
581  }
582  mConditionsSimplified = true;
583  }
584  }
585 
586  bool State::simplify( ConditionList& _conditionVectorToSimplify, ConditionSetSet& _conflictSet, ValuationMap& _ranking, bool _stateConditions )
587  {
588  carl::PointerSet<Condition> redundantConditionSet;
589  if( mpVariableBounds != NULL && _stateConditions && !mpVariableBounds->isConflicting() )
590  {
592  for( auto iter = _conditionVectorToSimplify.begin(); iter != _conditionVectorToSimplify.end(); ++iter )
593  {
594  const smtrat::ConstraintT& constr = (*iter)->constraint();
595  if( !carl::is_bound(constr) )
596  {
597  carl::Relation stricterRelation = constr.relation();
598  switch( consistent_with(constr.constr(), varIntervals, stricterRelation ) )
599  {
600  case 0:
601  {
602  auto tmp = mpVariableBounds->getOriginsOfBounds( constr.variables().as_set() );
603  carl::PointerSet<Condition> condSet(tmp.begin(), tmp.end());
604  condSet.insert( *iter );
605  _conflictSet.insert( std::move( condSet ) );
606  break;
607  }
608  case 1:
609  {
610  redundantConditionSet.insert( *iter );
611  #ifdef SMTRAT_DEVOPTION_Statistics
612  mpStatistics->omittedConstraintByVB();
613  #endif
614  break;
615  }
616  default:
617  {
618  if( stricterRelation != constr.relation() )
619  {
620  auto tmp = mpVariableBounds->getOriginsOfBounds( constr.variables().as_set() );
621  carl::PointerSet<Condition> vbcondSet(tmp.begin(), tmp.end());
622  size_t nValuation = (*iter)->valuation();
623  bool nFlag = (*iter)->flag();
624  smtrat::ConstraintT nConstraint = smtrat::ConstraintT( constr.lhs(), stricterRelation );
625  unsigned nConstraintConsistency = nConstraint.is_consistent();
626  if( nConstraintConsistency == 2 )
627  {
628  if( _stateConditions )
629  {
630  carl::PointerSet<Condition> oConds = (*iter)->originalConditions();
631  for( const Condition* vbcond : vbcondSet )
632  oConds.insert( vbcond->originalConditions().begin(), vbcond->originalConditions().end() );
633  addCondition( nConstraint, oConds, nValuation, true, _ranking );
634  }
635  else
636  {
637  const Condition* cond = new Condition( nConstraint, mpConditionIdAllocator->get(), nValuation, nFlag, (*iter)->originalConditions(), true );
638  for( const Condition* vbcond : vbcondSet )
639  cond->pOriginalConditions()->insert( vbcond->originalConditions().begin(), vbcond->originalConditions().end() );
640  _conditionVectorToSimplify.push_back( cond );
641  }
642  redundantConditionSet.insert( *iter );
643  }
644  else if( nConstraint.is_consistent() == 0 )
645  {
646  auto tmp = mpVariableBounds->getOriginsOfBounds( constr.variables().as_set() );
647  carl::PointerSet<Condition> condSet(tmp.begin(), tmp.end());
648  condSet.insert( *iter );
649  _conflictSet.insert( std::move( condSet ) );
650  }
651  }
652  }
653  }
654  }
655  }
656  }
657  if( _conditionVectorToSimplify.size() > 1 )
658  {
659  auto iterA = _conditionVectorToSimplify.begin();
660  // Check all condition combinations.
661  while( iterA != _conditionVectorToSimplify.end() )
662  {
663  auto iterB = iterA;
664  ++iterB;
665  while( iterB != _conditionVectorToSimplify.end() )
666  {
667  const Condition* condA = *iterA;
668  const Condition* condB = *iterB;
669  signed strongProp = carl::compare<smtrat::Poly>( condA->constraint(), condB->constraint() );
670  // If the two conditions have the same solution space.
671  if( strongProp == 2 )
672  {
673  // Choose original conditions.
674  if( !condA->originalConditions().empty() &&!condB->originalConditions().empty() )
675  {
676  // If we have to choose which original conditions to take, choose those, which have been created earlier.
677  if( condB->valuation() < condA->valuation() )
678  {
679  *condA->pOriginalConditions() = carl::PointerSet<Condition>( condB->originalConditions() );
680  condA->rValuation() = condB->valuation();
681  }
682  }
683  else
684  condA->pOriginalConditions()->insert( condB->originalConditions().begin(), condB->originalConditions().end() );
685  redundantConditionSet.insert( condB );
686  }
687  // If cond1's solution space is a subset of the solution space of cond2.
688  else if( strongProp == 1 )
689  redundantConditionSet.insert( condB );
690  // If it is easy to give a condition whose solution space is the intersection of the solution spaces of cond1 and cond2.
691  else if( strongProp == -3 )
692  {
693  const smtrat::ConstraintT& constraintA = condA->constraint();
694  const smtrat::ConstraintT& constraintB = condB->constraint();
695  smtrat::ConstraintT nConstraint;
696  size_t nValuation = 0;
697  bool nFlag = false;
698  if( (constraintA.relation() == carl::Relation::GEQ && constraintB.relation() == carl::Relation::GEQ)
699  || (constraintA.relation() == carl::Relation::GEQ && constraintB.relation() == carl::Relation::LEQ)
700  || (constraintA.relation() == carl::Relation::LEQ && constraintB.relation() == carl::Relation::GEQ)
701  || (constraintA.relation() == carl::Relation::LEQ && constraintB.relation() == carl::Relation::LEQ) )
702  {
703  nConstraint = smtrat::ConstraintT( constraintB.lhs(), carl::Relation::EQ );
704  nValuation = condB->valuation();
705  nFlag = condB->flag();
706  }
707  else if( (constraintA.relation() == carl::Relation::NEQ && constraintB.relation() == carl::Relation::GEQ) )
708  {
709  nConstraint = smtrat::ConstraintT( constraintB.lhs(), carl::Relation::GREATER );
710  nValuation = condB->valuation();
711  nFlag = condB->flag();
712  }
713  else if( (constraintA.relation() == carl::Relation::GEQ && constraintB.relation() == carl::Relation::NEQ) )
714  {
715  nConstraint = smtrat::ConstraintT( constraintA.lhs(), carl::Relation::GREATER );
716  nValuation = condA->valuation();
717  nFlag = condA->flag();
718  }
719  else if( (constraintA.relation() == carl::Relation::NEQ && constraintB.relation() == carl::Relation::LEQ) )
720  {
721  nConstraint = smtrat::ConstraintT( constraintB.lhs(), carl::Relation::LESS );
722  nValuation = condB->valuation();
723  nFlag = condB->flag();
724  }
725  else if( (constraintA.relation() == carl::Relation::LEQ && constraintB.relation() == carl::Relation::NEQ) )
726  {
727  nConstraint = smtrat::ConstraintT( constraintA.lhs(), carl::Relation::LESS );
728  nValuation = condA->valuation();
729  nFlag = condA->flag();
730  }
731  else
732  assert( false );
733  unsigned nConstraintConsistency = nConstraint.is_consistent();
734  if( nConstraintConsistency == 2 )
735  {
736  if( _stateConditions )
737  {
738  carl::PointerSet<Condition> oConds = condB->originalConditions();
739  oConds.insert( condA->originalConditions().begin(), condA->originalConditions().end() );
740  addCondition( nConstraint, oConds, nValuation, true, _ranking );
741  }
742  else
743  {
744  const Condition* cond = new Condition( nConstraint, mpConditionIdAllocator->get(), nValuation, nFlag, condB->originalConditions(), true );
745  cond->pOriginalConditions()->insert( condA->originalConditions().begin(), condA->originalConditions().end() );
746  _conditionVectorToSimplify.push_back( cond );
747  }
748  redundantConditionSet.insert( condA );
749  redundantConditionSet.insert( condB );
750  }
751  else if( nConstraint.is_consistent() == 0 )
752  {
753  carl::PointerSet<Condition> condSet;
754  condSet.insert( condA );
755  condSet.insert( condB );
756  _conflictSet.insert( condSet );
757  }
758  }
759  // If cond1's solution space is a superset of the solution space of cond2.
760  else if( strongProp == -1 )
761  redundantConditionSet.insert( condA );
762  // If it is easy to decide that cond1 and cond2 are conflicting.
763  else if( strongProp == -2 || strongProp == -4 )
764  {
765  carl::PointerSet<Condition> condSet;
766  condSet.insert( condA );
767  condSet.insert( condB );
768  _conflictSet.insert( condSet );
769  }
770  ++iterB;
771  }
772  ++iterA;
773  }
774  // Delete the conflicting conditions from redundant conditions.
775  auto condSet = _conflictSet.begin();
776  while( condSet != _conflictSet.end() )
777  {
778  auto cond = condSet->begin();
779  while( cond != condSet->end() )
780  {
781  redundantConditionSet.erase( *cond );
782  ++cond;
783  }
784  ++condSet;
785  }
786  if( _stateConditions )
787  deleteConditions( redundantConditionSet, _ranking );
788  else
789  {
790  // Delete the redundant conditions of the vector of conditions to simplify.
791  auto cond = _conditionVectorToSimplify.begin();
792  while( cond != _conditionVectorToSimplify.end() )
793  {
794  auto iter = redundantConditionSet.find( *cond );
795  if( iter != redundantConditionSet.end() )
796  {
797  redundantConditionSet.erase( iter );
798  const Condition* toDel = *cond;
799  cond = _conditionVectorToSimplify.erase( cond );
800  mpConditionIdAllocator->free( toDel->id() );
801  delete toDel;
802  toDel = NULL;
803  }
804  else
805  ++cond;
806  }
807  }
808  }
809  return _conflictSet.empty();
810  }
811 
812  void State::setIndex( const carl::Variable& _index )
813  {
814  mIndex = _index;
816  }
817 
818  void State::addConflictSet( const Substitution* _substitution, ConditionSetSet&& _condSetSet )
819  {
820  auto iter = mpConflictSets->find( _substitution );
821  if( iter != mpConflictSets->end() )
822  {
823  iter->second.insert( std::move(_condSetSet) );
824  if( _substitution != NULL && _substitution->type() == Substitution::Type::INVALID )
825  {
826  delete _substitution;
827  }
828  }
829  else
830  {
831  ConditionSetSetSet condSetSetSet;
832  condSetSetSet.insert( std::move(_condSetSet) );
833  mpConflictSets->insert( std::pair<const Substitution*, ConditionSetSetSet>( _substitution, std::move(condSetSetSet) ) );
834  }
835  if( _substitution == NULL )
836  rInconsistent() = true;
837  }
838 
839  void State::addConflicts( const Substitution* _substitution, ConditionSetSet&& _condSetSet )
840  {
841  auto iter = mpConflictSets->find( _substitution );
842  if( iter != mpConflictSets->end() )
843  {
844  ConditionSetSetSet newCondSetSetSet;
845  for( auto condSetSet = iter->second.begin(); condSetSet != iter->second.end(); ++condSetSet )
846  {
847  ConditionSetSet newCondSetSet;
848  newCondSetSet.insert( condSetSet->begin(), condSetSet->end() );
849  newCondSetSet.insert( _condSetSet.begin(), _condSetSet.end() );
850  newCondSetSetSet.insert( std::move(newCondSetSet) );
851  }
852  iter->second = std::move(newCondSetSetSet);
853  }
854  else
855  {
856  ConditionSetSetSet condSetSetSet;
857  condSetSetSet.insert( std::move(_condSetSet) );
858  mpConflictSets->insert( std::pair<const Substitution*, ConditionSetSetSet>( _substitution, std::move(condSetSetSet) ) );
859  }
860  }
861 
863  {
864  if( !mpConflictSets->empty() )
865  {
866  auto conflictSet = mpConflictSets->begin();
867  if( conflictSet->first == NULL )
868  ++conflictSet;
869  mpConflictSets->erase( conflictSet, mpConflictSets->end() );
870  }
871  }
872 
873  bool State::updateOCondsOfSubstitutions( const Substitution& _substitution, std::vector<State*>& _reactivatedStates )
874  {
875  for( auto child = rChildren().begin(); child != children().end(); ++child )
876  {
877  // TODO: If there is a child with a test candidate whose side conditions are a superset of the side conditions of the
878  // given substitution, remove the child and add the test candidates original conditions to the original conditions of
879  // the given substitution. However, when deleting later the original condition of the given substitution, the its
880  // getting nasty.
881  if( (**child).substitution() == _substitution )
882  {
883  if( index().type() == carl::VariableType::VT_INT && mpInfinityChild == *child )
884  {
885  mpInfinityChild = NULL;
886  (**child).rSubstitution().rOriginalConditions().clear();
887  }
888  (**child).rSubstitution().rOriginalConditions().insert( _substitution.originalConditions().begin(), _substitution.originalConditions().end() );
889  return true;
890  }
891  else if( index().type() == carl::VariableType::VT_INT && _substitution.term().is_integer() )
892  {
893  smtrat::Rational intTc = _substitution.term().constant_part().constant_part();
894  if( (**child).substitution().type() == Substitution::MINUS_INFINITY )
895  {
896  if( intTc < (mMinIntTestCanidate - Rational(1)) )
897  {
898  (**child).resetCurrentRangeSize();
899  _reactivatedStates.push_back( *child );
900  }
901  }
902  else if( (**child).substitution().type() == Substitution::PLUS_INFINITY )
903  {
904  if( intTc > (mMaxIntTestCanidate + Rational(1)) )
905  {
906  (**child).resetCurrentRangeSize();
907  _reactivatedStates.push_back( *child );
908  }
909  }
910  }
911  }
912  return false;
913  }
914 
915  void State::addSubstitutionResults( std::vector<DisjunctionOfConditionConjunctions>&& _disjunctionsOfCondConj )
916  {
917  // For each disjunction add a substitution result to the substitution results of this state.
918  if( mpSubstitutionResults == NULL )
920  for( auto disjunction = _disjunctionsOfCondConj.begin(); disjunction != _disjunctionsOfCondConj.end(); ++disjunction )
921  {
922  mpSubstitutionResults->emplace_back();
923  for( auto conjunction = disjunction->begin(); conjunction != disjunction->end(); ++conjunction )
924  mpSubstitutionResults->back().push_back( std::pair<ConditionList, bool>( std::move(*conjunction), false ) );
925  }
926  // Mark this state as not yet simplified.
927  mSubResultsSimplified = false;
928  mCannotBeSolved = false;
929  mMarkedAsDeleted = false;
931  }
932 
934  {
935  assert( subResultsSimplified() );
936  if( mpSubResultCombination == NULL )
938  if( mpSubResultCombination->size() < mpSubstitutionResults->size() )
939  {
940  unsigned bestSubResultIndex = 0;
941  bool notConsideredSubResultFound = false;
942  unsigned subResultIndex = 0;
943  while( subResultIndex < mpSubstitutionResults->size() )
944  {
945  // Set all flags of conjunctions of conditions in the substitution result to false.
946  auto condConj = mpSubstitutionResults->at( subResultIndex ).begin();
947  while( condConj != mpSubstitutionResults->at( subResultIndex ).end() )
948  {
949  condConj->second = false;
950  ++condConj;
951  }
952  // Check whether the sub result has not yet been considered.
953  bool subResultAlreadyConsidered = false;
954  auto subResComb = mpSubResultCombination->begin();
955  while( subResComb != mpSubResultCombination->end() )
956  {
957  if( subResComb->first == subResultIndex )
958  {
959  subResultAlreadyConsidered = true;
960  break;
961  }
962  ++subResComb;
963  }
964 
965  if( !subResultAlreadyConsidered )
966  {
967  if( notConsideredSubResultFound )
968  {
969  // We have already a currently best substitution result and check if
970  // it is better than the substitution result we consider now.
971  if( mpSubstitutionResults->at( subResultIndex ).size() < mpSubstitutionResults->at( bestSubResultIndex ).size() )
972  bestSubResultIndex = subResultIndex;
973  }
974  else
975  {
976  // This is the first not yet considered substitution result, so add take it as the currently best one.
977  assert( mpSubstitutionResults->at( subResultIndex ).size() > 0 );
978  bestSubResultIndex = subResultIndex;
979  notConsideredSubResultFound = true;
980  }
981  }
982  ++subResultIndex;
983  }
984  // Add the found substitution result to the substitution result combinations.
985  mpSubResultCombination->push_back( std::pair<unsigned, unsigned>( bestSubResultIndex, 0 ) );
986  return true;
987  }
988  else
989  return false;
990  }
991 
993  {
994  assert( type() == COMBINE_SUBRESULTS );
995  if( !hasSubResultsCombination() )
996  {
998  return true;
999  }
1000  else
1001  {
1002  assert( mpSubResultCombination->size() <= mpSubstitutionResults->size() );
1003  if( takeSubResultCombAgain() )
1004  mTakeSubResultCombAgain = false;
1005  else
1006  {
1007  SubResultCombination::reverse_iterator rIter = mpSubResultCombination->rbegin();
1008  while( rIter != mpSubResultCombination->rend() )
1009  {
1010  // Take the next conjunction of conditions of the considered substitution result, which
1011  // has the flag false.
1012  mpSubstitutionResults->at( rIter->first ).at( rIter->second ).second = true;
1013  while( rIter->second < mpSubstitutionResults->at( rIter->first ).size() - 1
1014  && mpSubstitutionResults->at( rIter->first ).at( rIter->second ).second )
1015  {
1016  ++(rIter->second);
1017  }
1018  // If it has already been the last conjunction of conditions of the considered substitution result.
1019  if( rIter->second == mpSubstitutionResults->at( rIter->first ).size() - 1
1020  && mpSubstitutionResults->at( rIter->first ).at( rIter->second ).second )
1021  {
1022  // Check if we already have reached the first substitution result.
1023  SubResultCombination::const_reverse_iterator rIterTemp = rIter;
1024  ++rIterTemp;
1025  // If we currently consider the first substitution result, return false,
1026  // which means, that there is no other combination to consider.
1027  if( rIterTemp == mpSubResultCombination->rend() )
1028  return false;
1029  // Otherwise, go back the first conjunction of conditions of the currently considered substitution
1030  // result and try to go to the next conjunction of conditions in the next substitution result.
1031  else
1032  {
1033  for( auto condConj = mpSubstitutionResults->at( rIter->first ).begin();
1034  condConj != mpSubstitutionResults->at( rIter->first ).end(); ++condConj )
1035  {
1036  condConj->second = false;
1037  }
1038  rIter->second = 0;
1039  }
1040  }
1041  // Otherwise we found a valid new combination of condition conjunctions.
1042  else
1043  return true;
1044  ++rIter;
1045  }
1046  }
1047  // A valid new combination of substitution results is established.
1048  return true;
1049  }
1050  }
1051 
1053  {
1054  if( hasSubResultsCombination() )
1055  {
1056  if( mpSubResultCombination->size() == 1 )
1057  {
1058  return mpSubResultCombination->begin()->second;
1059  }
1060  else
1061  {
1062  // First compute the number of combinations being a prefix of the current substitution result combination.
1063  size_t numOfPrefixCombinations = 1;
1064  for( size_t pos = 0; pos < mpSubResultCombination->size()-1; ++pos )
1065  {
1066  numOfPrefixCombinations *= mpSubstitutionResults->at( pos ).size();
1067  }
1068  size_t numOfCurrentCombination = 1;
1069  for( const auto& src : *mpSubResultCombination )
1070  {
1071  numOfCurrentCombination *= src.second;
1072  }
1073  return numOfPrefixCombinations + numOfCurrentCombination;
1074  }
1075  }
1076  return 0;
1077  }
1078 
1080  {
1081  ConditionList currentSubresultCombination;
1082  assert( hasSubResultsCombination() );
1083  auto iter = mpSubResultCombination->begin();
1084  while( iter != mpSubResultCombination->end() )
1085  {
1086  for( auto cond = mpSubstitutionResults->at( iter->first ).at( iter->second ).first.begin();
1087  cond != mpSubstitutionResults->at( iter->first ).at( iter->second ).first.end(); ++cond )
1088  {
1089  currentSubresultCombination.push_back( new Condition( **cond, mpConditionIdAllocator->get() ) );
1090  }
1091  ++iter;
1092  }
1093  return currentSubresultCombination;
1094  }
1095 
1097  {
1098  assert( type() == COMBINE_SUBRESULTS );
1099  bool conditionsChanged = false;
1100  if( !mpSubstitutionResults->empty() )
1101  {
1102  // Get the conditions of the currently considered combination of substitution results.
1103  ConditionList newCombination = getCurrentSubresultCombination();
1104  // Simplify the conditions already here, to avoid unnecessarily adding and deleting conditions.
1105  ConditionSetSet conflictingConditionPairs;
1106  if( !simplify( newCombination, conflictingConditionPairs, _ranking ) )
1107  rInconsistent() = true;
1108  // Delete the conditions of this combination, which do already occur in the considered conditions of this state.
1109  carl::PointerSet<Condition> condsToDelete;
1110  auto cond = rConditions().begin();
1111  while( cond != conditions().end() )
1112  {
1113  // Check if the condition occurs in the new combination. If so, delete
1114  // the corresponding condition in the new combination.
1115  bool condOccursInNewConds = false;
1116  auto newCond = newCombination.begin();
1117  while( newCond != newCombination.end() )
1118  {
1119  if( (**cond).constraint() == (**newCond).constraint() )
1120  {
1121  // Choose original conditions.
1122  if( !(**cond).originalConditions().empty() &&!(**newCond).originalConditions().empty() )
1123  {
1124  // If we have to choose which original conditions to take, choose those, which have been created earlier.
1125  if( (**newCond).valuation() < (**cond).valuation() )
1126  {
1127  *(**cond).pOriginalConditions() = carl::PointerSet<Condition>( (**newCond).originalConditions() );
1128  (**cond).rValuation() = (**newCond).valuation();
1129  }
1130  }
1131  else
1132  (**cond).pOriginalConditions()->insert( (**newCond).originalConditions().begin(), (**newCond).originalConditions().end() );
1133  const Condition* pCond = *newCond;
1134  newCond = newCombination.erase( newCond );
1135  mpConditionIdAllocator->free( pCond->id() );
1136  delete pCond;
1137  pCond = NULL;
1138  condOccursInNewConds = true;
1139  break;
1140  }
1141  else
1142  ++newCond;
1143  }
1144  // Remember the condition not occurring in the current combination.
1145  if( !condOccursInNewConds )
1146  {
1147  condsToDelete.insert( *cond );
1148  }
1149  ++cond;
1150  }
1151  if( !newCombination.empty() )
1152  conditionsChanged = true;
1153  // Delete the conditions, which do not occur in the current combination.
1154  if( !condsToDelete.empty() )
1155  {
1156  conditionsChanged = true;
1157  deleteConditions( condsToDelete, _ranking );
1158  }
1159  // Add the remaining conditions of the current combination to the conditions this state considers.
1160  for( auto newCond = newCombination.begin(); newCond != newCombination.end(); ++newCond )
1161  addCondition( (**newCond).constraint(), (**newCond).originalConditions(), (**newCond).valuation(), true, _ranking );
1162  while( !newCombination.empty() )
1163  {
1164  const Condition* rpCond = newCombination.back();
1165  newCombination.pop_back();
1166  mpConditionIdAllocator->free( rpCond->id() );
1167  delete rpCond; // TODO: this has to be done maybe in some situations or somewhere else
1168  rpCond = NULL;
1169  }
1170  }
1172  if( conditionsChanged )
1173  {
1174  mConditionsSimplified = false;
1175  mTryToRefreshIndex = true;
1176  return true;
1177  }
1178  else
1179  return false;
1180  }
1181 
1183  {
1184  assert( index() != carl::Variable::NO_VARIABLE );
1185  for( auto cond = rConditions().begin(); cond != conditions().end(); ++cond )
1186  {
1187  (**cond).rFlag() = !(**cond).constraint().variables().has( index() );// || (**cond).constraint().isUpperBound();
1188  }
1189  }
1190 
1191  bool State::initIndex( const carl::Variables& _allVariables, const smtrat::VariableValuationStrategy& _vvstrat, bool _preferEquation, bool _tryDifferentVarOrder, bool _useFixedVariableOrder )
1192  {
1193  assert( !_tryDifferentVarOrder || !mTryToRefreshIndex );
1194  if( conditions().empty() )
1195  return false;
1196  if( _allVariables.size() == 1 )
1197  {
1198  if( index() != *_allVariables.begin() )
1199  {
1200  setIndex( *_allVariables.begin() );
1201  return true;
1202  }
1203  return false;
1204  }
1205  if( _tryDifferentVarOrder )
1206  {
1207  if( mBestVarVals.empty() )
1208  return false;
1209  size_t bestVar = mBestVarVals.back();
1210  mBestVarVals.pop_back();
1211  std::vector<std::pair<carl::Variable, std::multiset<double>>>& varVals = mRealVarVals.empty() ? mIntVarVals : mRealVarVals;
1212  assert( index() != varVals[bestVar].first );
1213  setIndex( varVals[bestVar].first );
1214  return true;
1215  }
1216  mTryToRefreshIndex = false;
1217  mRealVarVals.clear();
1218  mIntVarVals.clear();
1219  for( auto var = _allVariables.begin(); var != _allVariables.end(); ++var )
1220  {
1221  if( var->type() == carl::VariableType::VT_INT )
1222  mIntVarVals.push_back( std::pair<carl::Variable, std::multiset<double> >( *var, std::multiset<double>() ) );
1223  else
1224  mRealVarVals.push_back( std::pair<carl::Variable, std::multiset<double> >( *var, std::multiset<double>() ) );
1225  }
1226  std::vector<std::pair<carl::Variable, std::multiset<double>>>& varValsB = mRealVarVals.empty() ? mIntVarVals : mRealVarVals;
1227  // Find for each variable the highest valuation of all conditions' constraints.
1228  for( auto cond = conditions().begin(); cond != conditions().end(); ++cond )
1229  {
1230  // Check for all variables their valuation for the given constraint.
1231  for( auto var = varValsB.begin(); var != varValsB.end(); ++var )
1232  {
1233  double varInConsVal = (**cond).valuate( var->first, _allVariables.size(), _preferEquation );
1234  if( varInConsVal != 0 )
1235  var->second.insert( varInConsVal );
1236  }
1237  }
1238  std::vector<std::pair<carl::Variable, std::multiset<double>>>& varVals = mRealVarVals.empty() ? mIntVarVals : mRealVarVals;
1239  #ifdef VS_DEBUG_VARIABLE_VALUATIONS
1240  for( auto var = varVals.begin(); var != varVals.end(); ++var )
1241  {
1242  std::cout << var->first << ": ";
1243  for( auto varVal = var->second.begin(); varVal != var->second.end(); ++varVal )
1244  std::cout << setprecision(10) << *varVal << " | ";
1245  std::cout << std::endl;
1246  }
1247  #endif
1248  // Find the variable which has in a constraint the best valuation. If more than one have the highest valuation,
1249  // then choose the one having the higher valuation according to the order in _allVariables.
1250  if( _useFixedVariableOrder )
1251  {
1252  for( const auto& varValPair : varVals )
1253  {
1254  if( !varValPair.second.empty() )
1255  {
1256  if( index() != varValPair.first )
1257  {
1258  setIndex( varValPair.first );
1259  return true;
1260  }
1261  return false;
1262  }
1263  }
1264  return false;
1265  }
1266  mBestVarVals.clear();
1267  switch( _vvstrat )
1268  {
1270  bestConstraintValuation( varVals );
1271  break;
1273  averageConstraintValuation( varVals );
1274  break;
1275  default:
1277  worstConstraintValuation( varVals );
1278  break;
1279  }
1280  assert( !mBestVarVals.empty() );
1281  size_t bestVar = mBestVarVals.back();
1282  mBestVarVals.pop_back();
1283  if( index() != varVals[bestVar].first )
1284  {
1285  setIndex( varVals[bestVar].first );
1286  return true;
1287  }
1288  return false;
1289  }
1290 
1291  void State::bestConstraintValuation( const std::vector<std::pair<carl::Variable, std::multiset<double>>>& _varVals )
1292  {
1293  assert( _varVals.size() > 1 );
1294  size_t var = 1;
1295  mBestVarVals.push_back(0);
1296  while( var < _varVals.size() )
1297  {
1298  const auto& vv = _varVals[var];
1299  const auto& bv = _varVals[mBestVarVals.back()];
1300  if( !vv.second.empty() && !bv.second.empty() )
1301  {
1302  if( vv.second.size() == 1 && bv.second.size() == 1 )
1303  {
1304  if( *vv.second.begin() < *bv.second.begin() )
1305  {
1306  mBestVarVals.clear();
1307  mBestVarVals.push_back(var);
1308  }
1309  else if( *vv.second.begin() == *bv.second.begin() )
1310  mBestVarVals.push_back(var);
1311  }
1312  else
1313  {
1314  auto varInConsVal = vv.second.begin();
1315  auto bestVarInConsVal = bv.second.begin();
1316  while( varInConsVal != vv.second.end() && bestVarInConsVal != bv.second.end() )
1317  {
1318  if( *varInConsVal < *bestVarInConsVal )
1319  {
1320  mBestVarVals.clear();
1321  mBestVarVals.push_back(var);
1322  break;
1323  }
1324  else if( *varInConsVal > *bestVarInConsVal )
1325  break;
1326  ++varInConsVal;
1327  ++bestVarInConsVal;
1328  }
1329  if( varInConsVal == vv.second.end() )
1330  {
1331  if( bestVarInConsVal == bv.second.end() )
1332  mBestVarVals.push_back(var);
1333  else
1334  {
1335  mBestVarVals.clear();
1336  mBestVarVals.push_back(var);
1337  }
1338  }
1339  }
1340  }
1341  else if( !vv.second.empty() && bv.second.empty() )
1342  {
1343  mBestVarVals.clear();
1344  mBestVarVals.push_back(var);
1345  }
1346  ++var;
1347  }
1348  }
1349 
1350  void State::averageConstraintValuation( const std::vector<std::pair<carl::Variable, std::multiset<double>>>& _varVals )
1351  {
1352  assert( _varVals.size() > 1 );
1353  std::size_t var = 0;
1354  mBestVarVals.push_back(0);
1355  double bestAvgVal = 0;
1356  const std::multiset<double>& vals = _varVals[var].second;
1357  if( !vals.empty() )
1358  {
1359  bestAvgVal = std::accumulate(vals.begin(), vals.end(), 0.0) / static_cast<double>(vals.size());
1360  }
1361  ++var;
1362  for(; var < _varVals.size(); ++var )
1363  {
1364  const std::multiset<double>& valsB = _varVals[var].second;
1365  if( !valsB.empty() )
1366  {
1367  double curAvgVal = std::accumulate(valsB.begin(), valsB.end(), 0.0) / static_cast<double>(valsB.size());
1368  if( curAvgVal > 0 && (bestAvgVal == 0 || curAvgVal < bestAvgVal) )
1369  {
1370  mBestVarVals.clear();
1371  mBestVarVals.push_back(var);
1372  }
1373  else if( curAvgVal == bestAvgVal )
1374  mBestVarVals.push_back(var);
1375  }
1376  }
1377  }
1378 
1379  void State::worstConstraintValuation( const std::vector<std::pair<carl::Variable, std::multiset<double>>>& _varVals )
1380  {
1381  assert( _varVals.size() > 1 );
1382  size_t var = 1;
1383  mBestVarVals.push_back(0);
1384  while( var < _varVals.size() )
1385  {
1386  const auto& vv = _varVals[var];
1387  const auto& bv = _varVals[mBestVarVals.back()];
1388  if( !vv.second.empty() && !bv.second.empty() )
1389  {
1390  if( vv.second.size() == 1 && bv.second.size() == 1 )
1391  {
1392  if( *vv.second.begin() < *bv.second.begin() )
1393  {
1394  mBestVarVals.clear();
1395  mBestVarVals.push_back(var);
1396  }
1397  else if( *vv.second.begin() == *bv.second.begin() )
1398  mBestVarVals.push_back(var);
1399  }
1400  else
1401  {
1402  auto varInConsVal = vv.second.rbegin();
1403  auto bestVarInConsVal = bv.second.rbegin();
1404  while( varInConsVal != vv.second.rend() && bestVarInConsVal != bv.second.rend() )
1405  {
1406  if( *varInConsVal < *bestVarInConsVal )
1407  {
1408  mBestVarVals.clear();
1409  mBestVarVals.push_back(var);
1410  break;
1411  }
1412  else if( *varInConsVal > *bestVarInConsVal )
1413  break;
1414  ++varInConsVal;
1415  ++bestVarInConsVal;
1416  }
1417  if( varInConsVal == vv.second.rend() )
1418  {
1419  if( bestVarInConsVal == bv.second.rend() )
1420  mBestVarVals.push_back(var);
1421  else
1422  {
1423  mBestVarVals.clear();
1424  mBestVarVals.push_back(var);
1425  }
1426  }
1427  }
1428  }
1429  else if( !vv.second.empty() && bv.second.empty() )
1430  {
1431  mBestVarVals.clear();
1432  mBestVarVals.push_back(var);
1433  }
1434  ++var;
1435  }
1436  }
1437 
1438  void State::addCondition( const smtrat::ConstraintT& _constraint, const carl::PointerSet<Condition>& _originalConditions, size_t _valutation, bool _recentlyAdded, ValuationMap& _ranking )
1439  {
1440  // Check if the constraint is variable-free and consistent. If so, discard it.
1441  unsigned constraintConsistency = _constraint.is_consistent();
1442  assert( constraintConsistency != 0 );
1443  if( constraintConsistency != 1 )
1444  {
1445  // Check if the condition already exists.
1446  mConditionsSimplified = false;
1447  mCannotBeSolved = false;
1448  mMarkedAsDeleted = false;
1449  // The state is not a leaf.
1450  if( index() != carl::Variable::NO_VARIABLE )
1451  {
1452  if( _recentlyAdded )
1454  bool constraintWithFinitlyManySolutionCandidatesInIndexExists = false;
1455  for( auto child = children().begin(); child != children().end(); ++child )
1456  {
1457  if( (**child).pOriginalCondition() != NULL )
1458  constraintWithFinitlyManySolutionCandidatesInIndexExists = true;
1459  break;
1460  }
1461  // Does the constraint contain the variable to eliminate.
1462  if( !_constraint.variables().has( index() )
1463  || constraintWithFinitlyManySolutionCandidatesInIndexExists )
1464  {
1465  rConditions().push_back( new Condition( _constraint, mpConditionIdAllocator->get(), _valutation, true, _originalConditions, _recentlyAdded ) );
1466  if( mpVariableBounds != NULL && mpVariableBounds->addBound( _constraint, rConditions().back() ) )
1468  }
1469  else
1470  {
1471  if( mpInfinityChild != NULL )
1472  {
1475  mpChildren->remove( mpInfinityChild );
1476  delete mpInfinityChild; // DELETE STATE
1477  mpInfinityChild = NULL;
1478  }
1479  rConditions().push_back( new Condition( _constraint, mpConditionIdAllocator->get(), _valutation, false, _originalConditions, _recentlyAdded ) );
1480  if( mpVariableBounds != NULL && mpVariableBounds->addBound( _constraint, rConditions().back() ) )
1482  }
1483  }
1484  // The state is a leaf.
1485  else
1486  {
1487  assert( mpInfinityChild == NULL );
1488  rConditions().push_back( new Condition( _constraint, mpConditionIdAllocator->get(), _valutation, false, _originalConditions, false ) );
1489  if( mpVariableBounds != NULL && mpVariableBounds->addBound( _constraint, rConditions().back() ) )
1491  }
1492  }
1493  }
1494 
1496  {
1498  {
1499  auto iter = mpSubResultCombination->begin();
1500  while( iter != mpSubResultCombination->end() )
1501  {
1502  if( iter->first >= mpSubstitutionResults->size() ) return false;
1503  if( iter->second >= mpSubstitutionResults->at( iter->first ).size() ) return false;
1504  ++iter;
1505  }
1506  }
1507  return true;
1508  }
1509 
1510  int State::deleteOrigins( carl::PointerSet<Condition>& _originsToDelete, ValuationMap& _ranking )
1511  {
1512  if( _originsToDelete.empty() ) return 1;
1513  if( !isRoot() )
1514  {
1515  // Check if the substitution has a condition to delete as original condition.
1516  for( auto condToDel = _originsToDelete.begin(); condToDel != _originsToDelete.end(); ++condToDel )
1517  {
1518  auto oCondInSub = rSubstitution().rOriginalConditions().begin();
1519  while( oCondInSub != substitution().originalConditions().end() )
1520  {
1521  if( *oCondInSub == *condToDel )
1522  rSubstitution().rOriginalConditions().erase( oCondInSub++ );
1523  else
1524  ++oCondInSub;
1525  }
1526  if( substitution().originalConditions().empty() )
1527  {
1528  // If the substitutions original conditions are all deleted, then delete the corresponding child.
1529  // TODO: Maybe it is better to keep these children/test candidates.
1530  int result = 0;
1531  if( pOriginalCondition() != NULL ) result = -1;
1532  return result;
1533  }
1534  }
1535  }
1536  // Remove conditions from the currently considered condition vector, which are originated by any of the given origins.
1537  bool conditionDeleted = false;
1538  bool recentlyAddedConditionLeft = false;
1539  carl::PointerSet<Condition> deletedConditions;
1540  carl::PointerSet<Condition> originsToRemove;
1541  for( auto originToDelete = _originsToDelete.begin(); originToDelete != _originsToDelete.end(); ++originToDelete )
1542  {
1543  auto condition = rConditions().begin();
1544  while( condition != conditions().end() )
1545  {
1546  if( (*condition)->originalConditions().find( *originToDelete ) != (*condition)->originalConditions().end() )
1547  {
1548  if( mpVariableBounds != NULL )
1549  {
1550  carl::Variable* changedVar;
1551  unsigned boundRemoved = mpVariableBounds->removeBound( (*condition)->constraint(), *condition, changedVar );
1552  if( boundRemoved == 2 )
1553  {
1554  for( auto condB = rConditions().begin(); condB != conditions().end(); ++condB )
1555  {
1556  if( (*condB)->constraint().variables().has( *changedVar ) )
1557  {
1558  originsToRemove.insert( *condB );
1559  (*condB)->rRecentlyAdded() = true;
1560  recentlyAddedConditionLeft = true;
1561  if( index() != carl::Variable::NO_VARIABLE )
1562  (*condB)->rFlag() = !(*condB)->constraint().variables().has( index() );
1563  }
1564  }
1565  delete changedVar;
1566  }
1567  }
1568  // Delete the condition to delete from the set of conditions with too high degree to
1569  // be entirely used for test candidate generation.
1570  mpTooHighDegreeConditions->erase( *condition );
1571  deletedConditions.insert( *condition );
1572  originsToRemove.insert( *condition );
1573  condition = rConditions().erase( condition );
1574  conditionDeleted = true;
1575  }
1576  else
1577  {
1578  if( (*condition)->recentlyAdded() ) recentlyAddedConditionLeft = true;
1579  ++condition;
1580  }
1581  }
1582  }
1583  if( conditionDeleted )
1584  {
1585  mInconsistent = false;
1586  mHasRecentlyAddedConditions = recentlyAddedConditionLeft;
1587  }
1588  mCannotBeSolved = false;
1589  mMarkedAsDeleted = false;
1590  mTryToRefreshIndex = true;
1591  // Delete everything originated by it in all children of this state.
1592  deleteOriginsFromChildren( originsToRemove, _ranking );
1593  // Delete the conditions in the conflict sets which are originated by any of the given origins.
1594  deleteOriginsFromConflictSets( _originsToDelete, false );
1595  // Delete the conditions.
1596  while( !deletedConditions.empty() )
1597  {
1598  const Condition* pCond = *deletedConditions.begin();
1599  deletedConditions.erase( deletedConditions.begin() );
1600  mpConditionIdAllocator->free( pCond->id() );
1601  delete pCond;
1602  pCond = NULL;
1603  }
1604  // Delete all conditions in the substitution result which are originated by any of the
1605  // given origins and adapt the currently considered substitution result combination.
1606  deleteOriginsFromSubstitutionResults( _originsToDelete );
1607  return 1;
1608  }
1609 
1610  void State::deleteConditions( carl::PointerSet<Condition>& _conditionsToDelete, ValuationMap& _ranking )
1611  {
1612  if( _conditionsToDelete.empty() ) return;
1613  // Delete the conditions to delete from the set of conditions with too high degree to
1614  // be entirely used for test candidate generation.
1615  for( auto cond = _conditionsToDelete.begin(); cond != _conditionsToDelete.end(); ++cond )
1616  {
1617  mpTooHighDegreeConditions->erase( *cond );
1618  }
1619  // Remove the given conditions from this state.
1620  bool conditionDeleted = false;
1621  bool recentlyAddedConditionLeft = false;
1622  std::vector<const Condition* > condsToDelete;
1623  carl::PointerSet<Condition> originsToRemove;
1624  for( auto cond = rConditions().begin(); cond != conditions().end(); )
1625  {
1626  // Delete the condition from the vector this state considers.
1627  if( _conditionsToDelete.find( *cond ) != _conditionsToDelete.end() )
1628  {
1629  if( mpVariableBounds != NULL )
1630  {
1631  carl::Variable* changedVar;
1632  unsigned boundRemoved = mpVariableBounds->removeBound( (*cond)->constraint(), *cond, changedVar );
1633  if( boundRemoved == 2 )
1634  {
1635  for( auto condB = rConditions().begin(); condB != conditions().end(); ++condB )
1636  {
1637  if( (*condB)->constraint().variables().has( *changedVar ) )
1638  {
1639  originsToRemove.insert( *condB );
1640  (*condB)->rRecentlyAdded() = true;
1641  recentlyAddedConditionLeft = true;
1642  if( index() != carl::Variable::NO_VARIABLE )
1643  (*condB)->rFlag() = !(*condB)->constraint().variables().has( index() );
1644  }
1645  }
1646  delete changedVar;
1647  }
1648  }
1649  conditionDeleted = true;
1650  condsToDelete.push_back( *cond );
1651  cond = rConditions().erase( cond );
1652  }
1653  else
1654  {
1655  if( (*cond)->recentlyAdded() ) recentlyAddedConditionLeft = true;
1656  ++cond;
1657  }
1658  }
1659  if( conditionDeleted )
1660  {
1661  mInconsistent = false;
1662  mHasRecentlyAddedConditions = recentlyAddedConditionLeft;
1663  }
1664  originsToRemove.insert( _conditionsToDelete.begin(), _conditionsToDelete.end() );
1665  // Delete everything originated by the given conditions in all children of this state.
1666  deleteOriginsFromChildren( originsToRemove, _ranking );
1667  // Delete the conditions from the conflict sets.
1668  deleteOriginsFromConflictSets( originsToRemove, true );
1669  while( !condsToDelete.empty() )
1670  {
1671  const Condition* condToDel = condsToDelete.back();
1672  condsToDelete.pop_back();
1673  mpConditionIdAllocator->free( condToDel->id() );
1674  delete condToDel;
1675  condToDel = NULL;
1676  }
1677  mCannotBeSolved = false;
1678  mMarkedAsDeleted = false;
1679  mTryToRefreshIndex = true;
1680  }
1681 
1682  void State::deleteOriginsFromChildren( carl::PointerSet<Condition>& _originsToDelete, ValuationMap& _ranking )
1683  {
1684  bool childWithIntTcDeleted = false;
1685  auto child = rChildren().begin();
1686  while( child != children().end() )
1687  {
1688  int result = (*child)->deleteOrigins( _originsToDelete, _ranking );
1689  if( result < 0 )
1691  if( result < 1 )
1692  {
1693  if( index().type() == carl::VariableType::VT_INT && (*child)->substitution().type() != Substitution::MINUS_INFINITY
1694  && (*child)->substitution().type() != Substitution::PLUS_INFINITY && (*child)->substitution().term().is_integer() )
1695  {
1696  childWithIntTcDeleted = true;
1697  }
1698  auto conflictSet = rConflictSets().find( (*child)->pSubstitution() );
1699  if( conflictSet != conflictSets().end() )
1700  rConflictSets().erase( conflictSet );
1701  State* toDelete = *child;
1702  removeStatesFromRanking( *toDelete, _ranking );
1703  child = rChildren().erase( child );
1704  if( toDelete == mpInfinityChild ) mpInfinityChild = NULL;
1705  delete toDelete; // DELETE STATE
1706  }
1707  else
1708  ++child;
1709  }
1710  if( childWithIntTcDeleted )
1712  }
1713 
1714  void State::deleteOriginsFromConflictSets( carl::PointerSet<Condition>& _originsToDelete, bool _originsAreCurrentConditions )
1715  {
1716  auto conflictSet = mpConflictSets->begin();
1717  while( conflictSet != mpConflictSets->end() )
1718  {
1719  ConditionSetSetSet updatedCondSetSetSet;
1720  auto condSetSet = conflictSet->second.begin();
1721  bool emptyReasonOccured = false;
1722  while( condSetSet != conflictSet->second.end() )
1723  {
1724  ConditionSetSet updatedCondSetSet;
1725  auto condSet = condSetSet->begin();
1726  while( condSet != condSetSet->end() )
1727  {
1728  carl::PointerSet<Condition> updatedCondSet;
1729  auto cond = condSet->begin();
1730  bool condToDelOccured = false;
1731  while( cond != condSet->end() )
1732  {
1733  if( _originsAreCurrentConditions )
1734  {
1735  if( _originsToDelete.find( *cond ) != _originsToDelete.end() )
1736  {
1737  condToDelOccured = true;
1738  break;
1739  }
1740  else
1741  updatedCondSet.insert( *cond );
1742  }
1743  else
1744  {
1745  auto condToDel = _originsToDelete.begin();
1746  while( condToDel != _originsToDelete.end() )
1747  {
1748  if( (*cond)->originalConditions().find( *condToDel ) != (*cond)->originalConditions().end() )
1749  break;
1750  ++condToDel;
1751  }
1752  if( condToDel == _originsToDelete.end() )
1753  updatedCondSet.insert( *cond );
1754  else
1755  {
1756  condToDelOccured = true;
1757  break;
1758  }
1759  }
1760  ++cond;
1761  }
1762  if( !condToDelOccured )
1763  updatedCondSetSet.insert( updatedCondSet );
1764  ++condSet;
1765  }
1766  if( !updatedCondSetSet.empty() )
1767  updatedCondSetSetSet.insert( updatedCondSetSet );
1768  else
1769  {
1770  emptyReasonOccured = true;
1771  break;
1772  }
1773  ++condSetSet;
1774  }
1775  if( !emptyReasonOccured )
1776  {
1777  conflictSet->second = updatedCondSetSetSet;
1778  ++conflictSet;
1779  }
1780  else
1781  {
1782  if( conflictSet->first == NULL )
1783  rInconsistent() = false;
1784  if( mpVariableBounds != NULL && conflictSet->first != NULL && conflictSet->first->type() == Substitution::INVALID )
1785  {
1786  for( auto oCond = conflictSet->first->originalConditions().begin(); oCond != conflictSet->first->originalConditions().end(); ++oCond )
1787  {
1788  (*oCond)->rFlag() = false;
1789  }
1790  const Substitution* subToDelete = conflictSet->first;
1791  mpConflictSets->erase( conflictSet++ );
1792  delete subToDelete;
1793  }
1794  else
1795  {
1796  mpConflictSets->erase( conflictSet++ );
1797  }
1798  }
1799  }
1800  auto child = rChildren().begin();
1801  while( child != children().end() )
1802  {
1803  if( mpConflictSets->find( (*child)->pSubstitution() ) == mpConflictSets->end() )
1804  {
1805  // Delete the entry of the test candidate whose conflict set is empty
1806  // and set "inconsistent flag" of the corresponding child to false.
1807  if( (*child)->hasSubstitutionResults() )
1808  {
1809  if( (*child)->hasSubResultsCombination() )
1810  {
1811  auto subResComb = (**child).rSubResultCombination().begin();
1812  while( subResComb != (*child)->subResultCombination().end() )
1813  {
1814  subResComb->second = 0;
1815  ++subResComb;
1816  }
1817  }
1818  auto subResult = (*child)->rSubstitutionResults().begin();
1819  while( subResult != (*child)->substitutionResults().end() )
1820  {
1821  auto condConj = subResult->begin();
1822  while( condConj != subResult->end() )
1823  {
1824  condConj->second = false;
1825  ++condConj;
1826  }
1827  ++subResult;
1828  }
1829  }
1830  if( (*child)->type() != SUBSTITUTION_TO_APPLY )
1831  {
1832  (*child)->rType() = COMBINE_SUBRESULTS;
1833  if( (*child)->hasSubstitutionResults() && (*child)->hasSubResultsCombination() )
1834  {
1835  (*child)->rTakeSubResultCombAgain() = true;
1836  }
1837  else
1838  (*child)->rTakeSubResultCombAgain() = false;
1839  }
1840  (*child)->rInconsistent() = false;
1841  }
1842  ++child;
1843  }
1844  }
1845 
1846  void State::deleteOriginsFromSubstitutionResults( carl::PointerSet<Condition>& _originsToDelete )
1847  {
1848  if( hasSubstitutionResults() )
1849  {
1850  unsigned subResultIndex = 0;
1851  auto subResult = rSubstitutionResults().begin();
1852  while( subResult != substitutionResults().end() )
1853  {
1854  unsigned subResultConjunctionIndex = 0;
1855  auto condConj = subResult->begin();
1856  while( condConj != subResult->end() )
1857  {
1858  ConditionList conditionsToAdd;
1859  auto cond = condConj->first.begin();
1860  while( cond != condConj->first.end() )
1861  {
1862  bool oCondsDeleted = false;
1863  auto oCond = (**cond).pOriginalConditions()->begin();
1864  while( oCond != (**cond).originalConditions().end() )
1865  {
1866  if( _originsToDelete.find( *oCond ) != _originsToDelete.end() )
1867  {
1868  (**cond).pOriginalConditions()->erase( oCond++ );
1869  oCondsDeleted = true;
1870  }
1871  else
1872  ++oCond;
1873  }
1874  if( oCondsDeleted )
1875  {
1876  oCond = (**cond).pOriginalConditions()->begin();
1877  while( oCond != (**cond).originalConditions().end() )
1878  {
1879  carl::PointerSet<Condition> oConds;
1880  oConds.insert( *oCond );
1881  conditionsToAdd.push_back( new Condition( (**oCond).constraint(), mpConditionIdAllocator->get(), (**cond).valuation(), false, oConds ) );
1882  ++oCond;
1883  }
1884  const Condition* rpCond = *cond;
1885  cond = condConj->first.erase( cond );
1886  condConj->second = false;
1887  mpConditionIdAllocator->free( rpCond->id() );
1888  delete rpCond;
1889  rpCond = NULL;
1890  rSubResultsSimplified() = false;
1891  }
1892  else
1893  {
1894  ++cond;
1895  }
1896  }
1897  condConj->first.insert( condConj->first.end(), conditionsToAdd.begin(), conditionsToAdd.end() );
1898  if( condConj->first.empty() )
1899  {
1900  if( hasSubResultsCombination() )
1901  {
1902  // If the currently considered substitution result is part of the substitution result combination of this state.
1903  auto subResComb = rSubResultCombination().begin();
1904  while( subResComb != rSubResultCombination().end() && subResComb->first != subResultIndex )
1905  ++subResComb;
1906  if( subResComb != subResultCombination().end() )
1907  {
1908  // If the currently considered condition conjunction in the currently considered substitution result
1909  // is part of the substitution result combination of this state.
1910  if( subResComb->second == subResultConjunctionIndex )
1911  rSubResultCombination().erase( subResComb ); // Remove this entry of the substitution result combinations.
1912  // If the currently considered condition conjunction in the currently considered substitution result
1913  // is NOT part of the substitution result combination of this state, but another condition conjunction in
1914  // the currently considered substitution result with higher index, decrease this index.
1915  else if( subResComb->second > subResultConjunctionIndex )
1916  --(subResComb->second);
1917  }
1918  if( subResult->size() == 1 )
1919  {
1920  auto subResCombB = rSubResultCombination().begin();
1921  while( subResCombB != subResultCombination().end() )
1922  {
1923  if( subResCombB->first > subResultIndex )
1924  --(subResCombB->first);
1925  ++subResCombB;
1926  }
1927  }
1928  }
1929  condConj = subResult->erase( condConj );
1930  }
1931  else
1932  {
1933  ++condConj;
1934  ++subResultConjunctionIndex;
1935  }
1936  }
1937  // Remove the substitution result if it is empty.
1938  if( subResult->empty() )
1939  subResult = rSubstitutionResults().erase( subResult );
1940  else
1941  {
1942  ++subResult;
1943  ++subResultIndex;
1944  }
1945  }
1946  if( hasSubResultsCombination() )
1947  {
1948  mTakeSubResultCombAgain = true;
1949  }
1950  else
1951  {
1952  mTakeSubResultCombAgain = false;
1953  }
1954  }
1955  }
1956 
1957  std::vector<State*> State::addChild( const Substitution& _substitution )
1958  {
1959  std::vector<State*> result;
1960  if( !updateOCondsOfSubstitutions( _substitution, result ) )
1961  {
1962  if( index().type() == carl::VariableType::VT_INT && _substitution.type() == Substitution::NORMAL && _substitution.term().is_integer() )
1963  {
1964  smtrat::Rational intTC = _substitution.term().constant_part().constant_part();
1965  if( intTC > mMaxIntTestCanidate )
1966  {
1967  mMaxIntTestCanidate = intTC;
1968  }
1969  if( intTC < mMinIntTestCanidate )
1970  {
1971  mMinIntTestCanidate = intTC;
1972  }
1973  }
1974  State* state = new State( this, _substitution, mpConditionIdAllocator, mpVariableBounds != NULL );
1975  #ifdef SMTRAT_DEVOPTION_Statistics
1976  state->setStatistics( mpStatistics );
1977  mpStatistics->createTestCandidate();
1978  #endif
1979  const smtrat::ConstraintsT& sideConds = _substitution.sideCondition();
1980  for( auto sideCond = sideConds.begin(); sideCond != sideConds.end(); ++sideCond )
1981  {
1982 // if( _substitution.variable().type() != carl::VariableType::VT_INT || sideCond->relation() != carl::Relation::NEQ )
1983 // {
1984  std::vector<DisjunctionOfConditionConjunctions> subResults;
1985  subResults.emplace_back();
1986  subResults.back().emplace_back();
1987  subResults.back().back().push_back( new Condition( *sideCond, mpConditionIdAllocator->get(), state->treeDepth(), false, _substitution.originalConditions(), false ) );
1988  state->addSubstitutionResults( std::move(subResults) );
1989  state->rType() = SUBSTITUTION_TO_APPLY;
1990 // }
1991 // else
1992 // {
1993 // smtrat::ConstraintT denomPos = smtrat::ConstraintT( sideCond->lhs(), carl::Relation::GREATER );
1994 // smtrat::ConstraintT denomNeg = smtrat::ConstraintT( sideCond->lhs(), carl::Relation::LESS );
1995 // assert( denomPos != ConstraintT( false ) || denomNeg != ConstraintT( false ) );
1996 // // add (p<0 or p>0) to the substitution results, with the constraint being p!=0
1997 // if( denomPos != ConstraintT( true ) && denomNeg != ConstraintT( true ) )
1998 // {
1999 // DisjunctionOfConditionConjunctions cases;
2000 // if( denomPos != ConstraintT( false ) )
2001 // {
2002 // cases.emplace_back();
2003 // cases.back().push_back( new vs::Condition( denomPos, mpConditionIdAllocator->get(), state->treeDepth(), false, _substitution.originalConditions(), false ) );
2004 // }
2005 // if( denomNeg != ConstraintT( false ) )
2006 // {
2007 // cases.emplace_back()
2008 // cases.back().push_back( new vs::Condition( denomNeg, mpConditionIdAllocator->get(), state->treeDepth(), false, _substitution.originalConditions(), false ) );
2009 // }
2010 // std::vector<DisjunctionOfConditionConjunctions> subResults;
2011 // subResults.push_back( cases );
2012 // state->addSubstitutionResults( std::move(subResults) );
2013 // state->rType() = SUBSTITUTION_TO_APPLY;
2014 // }
2015 // }
2016  }
2017  rChildren().push_back( state );
2018  result.push_back( state );
2019  }
2020  return result;
2021  }
2022 
2023  void State::updateValuation( bool _lazy )
2024  {
2025  if( _lazy )
2026  mValuation = 1;
2027  else
2028  mValuation = 0;
2029  if( mCannotBeSolved )
2030  {
2031  mValuation += 1;
2033  }
2034  else
2035  {
2036  if( !isRoot() )
2037  mValuation += 100 * treeDepth() + 10 * substitution().valuate( substitution().variable().type() == carl::VariableType::VT_REAL );
2038  else
2039  mValuation += 1;
2040  if( isInconsistent() )
2041  mValuation += 7;
2042  else if( hasRecentlyAddedConditions() )
2043  mValuation += 6;
2044  else if( type() == TEST_CANDIDATE_TO_GENERATE && conditions().empty() )
2045  mValuation += 5;
2046  else
2047  {
2048  if( type() == SUBSTITUTION_TO_APPLY )
2049  mValuation += 3;
2050  else if( type() == TEST_CANDIDATE_TO_GENERATE )
2051  {
2052  mValuation += 4;
2053  }
2054  else
2055  mValuation += 3;
2056  }
2057  }
2058  }
2059 
2061  {
2062  carl::Variables occuringVars = carl::Variables();
2063  std::set<carl::Relation> relationSymbols = std::set<carl::Relation>();
2064  for( auto cond = conditions().begin(); cond != conditions().end(); ++cond )
2065  {
2066  auto vars = (*cond)->constraint().variables();
2067  occuringVars.insert( vars.begin(), vars.end() );
2068  relationSymbols.insert( (*cond)->constraint().relation() );
2069  }
2070  mBackendCallValuation = 300000*occuringVars.size();
2071  if( relationSymbols.find( carl::Relation::EQ ) != relationSymbols.end() )
2072  {
2073  mBackendCallValuation += 200000;
2074  }
2075  else if( relationSymbols.find( carl::Relation::LEQ ) != relationSymbols.end() || relationSymbols.find( carl::Relation::GEQ ) != relationSymbols.end() )
2076  {
2077  mBackendCallValuation += 100000;
2078  }
2079  mBackendCallValuation += conditions().size();
2080  }
2081 
2082  void State::passConflictToFather( bool _checkConflictForSideCondition, bool _useBackjumping, bool _includeInconsistentTestCandidates )
2083  {
2084  assert( isInconsistent() );
2085  bool coverSetOCondsContainIndexOfFather = false;
2086  if( index().type() != carl::VariableType::VT_INT || !mpConflictSets->empty() )
2087  {
2088  // Determine a covering set of the conflict sets.
2089  carl::PointerSet<Condition> covSet;
2090  ConditionSetSetSet confSets;
2091  auto nullConfSet = rConflictSets().find( NULL );
2092  if( nullConfSet != conflictSets().end() && !_includeInconsistentTestCandidates )
2093  {
2094  confSets.insert( nullConfSet->second.begin(), nullConfSet->second.end() );
2095  }
2096  else
2097  {
2098  for( auto confSet = rConflictSets().begin(); confSet != conflictSets().end(); ++confSet )
2099  confSets.insert( confSet->second.begin(), confSet->second.end() );
2100  }
2101  coveringSet( confSets, covSet, treeDepth() );
2102  #ifdef SMTRAT_DEVOPTION_Statistics
2103  mpStatistics->coveringSet( covSet.size(), conditions().size() );
2104  #endif
2105  #ifdef VS_LOG_INFSUBSETS
2106  smtrat::ConstraintsT constraints;
2107  for( auto cond = covSet.begin(); cond != covSet.end(); ++cond )
2108  constraints.insert( (**cond).constraint() );
2109  SMTRAT_VALIDATION_ADD("smtrat.modules.vs","VSModule_IS_1",constraints,false);
2110  #endif
2111  // Get the original conditions to the covering set.
2112  carl::PointerSet<Condition> coverSetOConds;
2113  bool sideConditionIsPartOfConflict = !_checkConflictForSideCondition || (pOriginalCondition() == NULL || originalCondition().constraint().relation() != carl::Relation::EQ);
2114  const smtrat::ConstraintsT& subsSideConds = substitution().sideCondition();
2115  for( auto cond = covSet.begin(); cond != covSet.end(); ++cond )
2116  {
2117  // Add the original conditions of the condition to the conflict set.
2118  if( !(**cond).originalConditions().empty() )
2119  {
2120  auto oCond = (**cond).originalConditions().begin();
2121  while( oCond != (**cond).originalConditions().end() )
2122  {
2123  assert( father().index() != carl::Variable::NO_VARIABLE );
2124  if( (**oCond).constraint().variables().has( father().index() ) )
2125  coverSetOCondsContainIndexOfFather = true;
2126  coverSetOConds.insert( *oCond );
2127  oCond++;
2128  }
2129  }
2130  sideConditionIsPartOfConflict |= subsSideConds.find( (*cond)->constraint() ) != subsSideConds.end();
2131  }
2132  if( !sideConditionIsPartOfConflict )
2133  {
2134  for( auto cond = rFather().rConditions().begin(); cond != father().conditions().end(); ++cond )
2135  (*cond)->rFlag() = true;
2136  }
2137  // If a test candidate was provided by an equation and its side condition hold always,
2138  // add the corresponding constraint to the conflict set. (Because we omit the other test candidates )
2139  if( pOriginalCondition() != NULL )
2140  {
2141  // Add the corresponding original condition to the conflict set.
2142  coverSetOConds.insert( pOriginalCondition() );
2143  // This original condition of course contains the index of the father, as it served as test candidate provider.
2144  coverSetOCondsContainIndexOfFather = true;
2145  }
2146  ConditionSetSet conflictSet;
2147  assert( !coverSetOConds.empty() );
2148  conflictSet.insert( std::move(coverSetOConds) );
2149  // Add the original conditions of the covering set as a conflict set to the father.
2150  if( _useBackjumping || coverSetOCondsContainIndexOfFather )
2151  rFather().addConflictSet( pSubstitution(), std::move(conflictSet) );
2152  else
2153  {
2154  #ifdef SMTRAT_DEVOPTION_Statistics
2155  mpStatistics->backjumping( numberOfUnusedConditions() );
2156  #endif
2157  rFather().addConflictSet( NULL, std::move(conflictSet) );
2158  }
2159  // Delete the conflict sets.
2160  mpConflictSets->clear();
2161  }
2162  // Delete all children, the conflict sets and the conditions of this state.
2163  while( !children().empty() )
2164  {
2165  State* toDelete = rChildren().back();
2166  rChildren().pop_back();
2167  if( toDelete == mpInfinityChild ) mpInfinityChild = NULL;
2168  delete toDelete;
2169  }
2170  mpTooHighDegreeConditions->clear();
2171  while( !conditions().empty() )
2172  {
2173  const Condition* pCond = rConditions().back();
2174  rConditions().pop_back();
2175  if( mpVariableBounds != NULL )
2176  mpVariableBounds->removeBound( pCond->constraint(), pCond );
2177  mpConditionIdAllocator->free( pCond->id() );
2178  delete pCond;
2179  pCond = NULL;
2180  }
2181  // Reset all necessary flags.
2182  rHasRecentlyAddedConditions() = false;
2183  rTakeSubResultCombAgain() = false;
2184  rFather().rMarkedAsDeleted() = false;
2185  bool fixedConditions = false;
2186  if( hasSubResultsCombination() )
2187  {
2188  if( subResultCombination().size() == 1 )
2189  fixedConditions = substitutionResults().at( subResultCombination().back().first ).size() == 1;
2190  }
2191  else
2192  fixedConditions = true;
2193  if( coverSetOCondsContainIndexOfFather && !fixedConditions )
2194  {
2195  rMarkedAsDeleted() = false;
2196  rInconsistent() = false;
2198  }
2199  }
2200 
2202  {
2203  if( conflictSets().empty() || !tooHighDegreeConditions().empty() || !hasOnlyInconsistentChildren() ) return false;
2204  #ifdef VS_DEBUG_LOCAL_CONFLICT_SEARCH
2205  printAlone();
2206  #endif
2207  // Construct the local conflict consisting of all of the currently considered conditions,
2208  // which have been considered for test candidate construction.
2209  carl::PointerSet<Condition> localConflictSet;
2210  for( auto cond = conditions().begin(); cond != conditions().end(); ++cond )
2211  {
2212  if( (*cond)->flag() ) localConflictSet.insert( *cond );
2213  }
2214  // Check whether the local conflict set covers for each test candidate, its conditions have generated,
2215  // one of its conflict sets.
2216  #ifdef VS_DEBUG_LOCAL_CONFLICT_SEARCH
2217  std::cout << "local conflict: { ";
2218  for( auto iter = localConflictSet.begin(); iter != localConflictSet.end(); ++iter )
2219  std::cout << (*iter)->constraint() << " ";
2220  std::cout << "}" << std::endl;
2221  #endif
2222  carl::PointerSet<Condition> infSubset;
2223  bool containsConflictToCover = false;
2224  for( auto conflict = conflictSets().begin(); conflict != conflictSets().end(); ++conflict )
2225  {
2226  containsConflictToCover = true;
2227  for( auto condSetSet = conflict->second.begin(); condSetSet != conflict->second.end(); ++condSetSet )
2228  {
2229  auto condSet = condSetSet->begin();
2230  for( ; condSet != condSetSet->end(); ++condSet )
2231  {
2232  auto condA = condSet->begin();
2233  auto condB = localConflictSet.begin();
2234  assert( condA != condSet->end() );
2235  #ifdef VS_DEBUG_LOCAL_CONFLICT_SEARCH
2236  std::cout << "covers: { ";
2237  for( auto iter = condSet->begin(); iter != condSet->end(); ++iter )
2238  std::cout << (*iter)->constraint() << " ";
2239  std::cout << "} ??";
2240  #endif
2241  while( condA != condSet->end() && condB != localConflictSet.end() )
2242  {
2243  if( (*condB) < (*condA) )
2244  ++condB;
2245  else if( (*condA) < (*condB) )
2246  break;
2247  else
2248  {
2249  ++condA;
2250  ++condB;
2251  }
2252  }
2253  if( condA == condSet->end() )
2254  {
2255  infSubset.insert( condSet->begin(), condSet->end() );
2256  #ifdef VS_DEBUG_LOCAL_CONFLICT_SEARCH
2257  std::cout << " Yes!" << std::endl;
2258  #endif
2259  break;
2260  }
2261  else
2262  {
2263  #ifdef VS_DEBUG_LOCAL_CONFLICT_SEARCH
2264  std::cout << " No!" << std::endl;
2265  #endif
2266  }
2267  }
2268  if( condSet == condSetSet->end() )
2269  {
2270  #ifdef VS_DEBUG_LOCAL_CONFLICT_SEARCH
2271  std::cout << "No conflict set in conflict is covered!" << std::endl;
2272  #endif
2273  return false;
2274  }
2275  #ifdef VS_DEBUG_LOCAL_CONFLICT_SEARCH
2276  else
2277  {
2278  std::cout << "A conflict set in conflict is covered!" << std::endl;
2279  }
2280  #endif
2281  }
2282  }
2283  if( containsConflictToCover )
2284  {
2285  ConditionSetSet localConflict;
2286  localConflict.insert( infSubset );
2287  addConflictSet( NULL, std::move(localConflict) );
2288  #ifdef SMTRAT_DEVOPTION_Statistics
2289  mpStatistics->localConflict( numberOfUnusedConditions() );
2290  #endif
2291  return true;
2292  }
2293  else
2294  return false;
2295  }
2296 
2298  {
2299  if( mTestCandidateCheckedForBounds ) return true;
2301  if( !isRoot() )
2302  {
2304  #ifdef VS_DEBUG_VARIABLE_BOUNDS
2305  std::cout << ">>> Check test candidate " << substitution() << " against:" << std::endl;
2306  father().variableBounds().print( std::cout, ">>> " );
2307  #endif
2308  carl::PointerSet<Condition> conflict;
2309  std::vector< smtrat::DoubleInterval > solutionSpaces = solutionSpace( conflict );
2310  if( solutionSpaces.empty() )
2311  {
2312  ConditionSetSet conflicts;
2313  conflicts.insert( std::move(conflict) );
2314  pFather()->addConflictSet( pSubstitution(), std::move(conflicts) );
2315  #ifdef SMTRAT_DEVOPTION_Statistics
2316  mpStatistics->omittedTestCandidateWithVB( numberOfUnusedConditions() );
2317  #endif
2318  return false;
2319  }
2320  }
2321  return true;
2322  }
2323 
2324  std::vector< smtrat::DoubleInterval > State::solutionSpace( carl::PointerSet<Condition>& _conflictReason ) const
2325  {
2326  std::vector< smtrat::DoubleInterval > result;
2327  assert( !isRoot() );
2329  {
2330  if( father().variableBounds().getDoubleInterval( substitution().variable() ).lower_bound_type() == carl::BoundType::INFTY )
2331  result.push_back( smtrat::DoubleInterval::unbounded_interval() );
2332  else
2333  {
2334  auto conflictBounds = father().variableBounds().getOriginsOfBounds( substitution().variable() );
2335  _conflictReason.insert( conflictBounds.begin(), conflictBounds.end() );
2336  }
2337  return result;
2338  }
2340  {
2341  if( father().variableBounds().getDoubleInterval( substitution().variable() ).upper_bound_type() == carl::BoundType::INFTY )
2342  result.push_back( smtrat::DoubleInterval::unbounded_interval() );
2343  else
2344  {
2345  auto conflictBounds = father().variableBounds().getOriginsOfBounds( substitution().variable() );
2346  assert( !conflictBounds.empty() );
2347  _conflictReason.insert( conflictBounds.begin(), conflictBounds.end() );
2348  }
2349  return result;
2350  }
2351  else
2352  {
2354  smtrat::DoubleInterval solutionSpaceConst = carl::evaluate( substitution().term().constant_part(), intervals );
2355  smtrat::DoubleInterval solutionSpaceFactor = carl::evaluate( substitution().term().factor(), intervals );
2356  smtrat::DoubleInterval solutionSpaceRadicand = carl::evaluate( substitution().term().radicand(), intervals );
2357  smtrat::DoubleInterval solutionSpaceSqrt = carl::sqrt(solutionSpaceRadicand);
2358  smtrat::DoubleInterval solutionSpaceDenom = carl::evaluate( substitution().term().denominator(), intervals );
2359  smtrat::DoubleInterval solutionSpace = solutionSpaceFactor * solutionSpaceSqrt;
2360  solutionSpace = solutionSpace + solutionSpaceConst;
2361  #ifdef VS_DEBUG_VARIABLE_BOUNDS
2362  std::cout << ">>> Results in:" << std::endl;
2363  std::cout << ">>> constant part : " << solutionSpaceConst << std::endl;
2364  std::cout << ">>> factor part : " << solutionSpaceFactor << std::endl;
2365  std::cout << ">>> radicand part : " << solutionSpaceRadicand << std::endl;
2366  std::cout << ">>> square root part : " << solutionSpaceSqrt << std::endl;
2367  std::cout << ">>> denominator part : " << solutionSpaceDenom << std::endl;
2368  std::cout << ">>> numerator part : " << solutionSpace << std::endl;
2369  #endif
2372  bool splitOccurred = solutionSpace.div_ext( solutionSpaceDenom, resA, resB );
2373  const smtrat::DoubleInterval& subVarInterval = intervals[substitution().variable()];
2374  if( substitution().type() == Substitution::PLUS_EPSILON && resA.lower_bound_type() != carl::BoundType::INFTY )
2375  {
2376  if( resA.upper_bound_type() == carl::BoundType::INFTY || resA.upper() == DBL_MAX )
2377  {
2378  resA = smtrat::DoubleInterval( resA.lower(), carl::BoundType::STRICT, (double)0, carl::BoundType::INFTY );
2379  if( splitOccurred )
2380  resB = smtrat::DoubleInterval( resB.lower(), carl::BoundType::STRICT, (double)0, carl::BoundType::INFTY );
2381  }
2382  else
2383  {
2384  resA = smtrat::DoubleInterval( resA.lower(), carl::BoundType::STRICT, std::nextafter( resA.upper(), INFINITY ), carl::BoundType::WEAK );
2385  if( splitOccurred )
2386  resB = smtrat::DoubleInterval( resB.lower(), carl::BoundType::STRICT, std::nextafter( resB.upper(), INFINITY ), carl::BoundType::WEAK );
2387  }
2388  }
2389  #ifdef VS_DEBUG_VARIABLE_BOUNDS
2390  std::cout << ">>> division part 1 : " << std::setprecision(100) << resA << std::endl;
2391  std::cout << ">>> subVarInterval : " << std::setprecision(100) << subVarInterval << std::endl;
2392  #endif
2393  resA = carl::set_intersection(resA, subVarInterval);
2394  #ifdef VS_DEBUG_VARIABLE_BOUNDS
2395  std::cout << ">>> intersection part 1: " << std::setprecision(100) << resA << std::endl;
2396  #endif
2397  if( !resA.is_empty() )
2398  result.push_back( resA );
2399  if( splitOccurred )
2400  {
2401  #ifdef VS_DEBUG_VARIABLE_BOUNDS
2402  std::cout << ">>> division part 2: " << resB << std::endl;
2403  #endif
2404  resB = carl::set_intersection(resB, subVarInterval );
2405  #ifdef VS_DEBUG_VARIABLE_BOUNDS
2406  std::cout << ">>> intersection part 1: " << resB << std::endl;
2407  #endif
2408  if( !resB.is_empty() )
2409  result.push_back( resB );
2410  }
2411  if( result.empty() )
2412  {
2413  carl::Variables conflictVars = substitution().termVariables();
2414  conflictVars.insert( substitution().variable() );
2415  auto conflictBounds = father().variableBounds().getOriginsOfBounds( conflictVars );
2416  _conflictReason.insert( conflictBounds.begin(), conflictBounds.end() );
2417  _conflictReason.insert( substitution().originalConditions().begin(), substitution().originalConditions().end() );
2418  }
2419  }
2420  return result;
2421  }
2422 
2423  bool State::hasRootsInVariableBounds( const Condition* _condition, bool _useSturmSequence )
2424  {
2425  #ifdef VS_DEBUG_ROOTS_CHECK
2426  std::cout << __func__ << ": " << _condition->constraint() << std::endl;
2427  #endif
2428  assert( index() != carl::Variable::NO_VARIABLE );
2429  const smtrat::ConstraintT& cons = _condition->constraint();
2431  if( cons.lhs().is_univariate() )
2432  {
2434  smtrat::Rational cb = carl::cauchyBound(carl::to_univariate_polynomial(cons.lhs()));
2435  #ifdef VS_DEBUG_ROOTS_CHECK
2436  std::cout << "Cauchy bound of " << cons.lhs() << " is " << cb << "." << std::endl;
2437  #endif
2438  smtrat::DoubleInterval cbInterval = smtrat::DoubleInterval( smtrat::Rational(-cb), carl::BoundType::STRICT, cb, carl::BoundType::STRICT );
2439  varDomain = carl::set_intersection(varDomain, cbInterval );
2440  #ifdef VS_DEBUG_ROOTS_CHECK
2441  std::cout << varDomain << std::endl;
2442  #endif
2443  intervals[index()] = varDomain;
2444  }
2445  else
2446  intervals = variableBounds().getIntervalMap();
2447  carl::Relation rel = cons.relation();
2448  if( rel == carl::Relation::GREATER || rel == carl::Relation::LESS || rel == carl::Relation::NEQ )
2449  {
2450  auto indexDomain = intervals.find( index() );
2451  if( indexDomain->second.lower_bound_type() == carl::BoundType::STRICT )
2452  indexDomain->second.set_lower_bound_type( carl::BoundType::WEAK );
2453  }
2454  smtrat::DoubleInterval solutionSpace = carl::evaluate( cons.lhs(), intervals );
2455  // TODO: if the condition is an equation and the degree in the index less than 3,
2456  // then it is maybe better to consider the according test candidates
2457  #ifdef VS_DEBUG_ROOTS_CHECK
2458  std::cout << "solutionSpace: " << solutionSpace << std::endl;
2459  #endif
2460  if( solutionSpace.contains( 0 ) )
2461  {
2462  if( _useSturmSequence && cons.variables().size() == 1 ) // TODO: fails when having a multiple root at the boundary of the given interval for ss-computation
2463  {
2464  carl::UnivariatePolynomial<smtrat::Rational> rup = carl::to_univariate_polynomial(cons.lhs());
2465  auto seq = carl::sturm_sequence(rup);
2466  smtrat::Rational leftBound = carl::rationalize<smtrat::Rational>( intervals.begin()->second.lower() );
2467  smtrat::Rational rightBound = carl::rationalize<smtrat::Rational>( intervals.begin()->second.upper() );
2468  smtrat::RationalInterval interv( leftBound, carl::BoundType::WEAK, rightBound, carl::BoundType::WEAK );
2469  int numberOfRoots = carl::count_real_roots( seq, interv );
2470  assert( index() != carl::Variable::NO_VARIABLE );
2471  smtrat::Rational imageOfLeftBound = carl::evaluate(rup, leftBound);
2472  smtrat::Rational imageOfRightBound = carl::evaluate(rup, rightBound);
2473  if( imageOfLeftBound == Rational(0) )
2474  ++numberOfRoots;
2475  if( imageOfRightBound == Rational(0) )
2476  {
2477  if( intervals.begin()->second.upper_bound_type() == carl::BoundType::STRICT && numberOfRoots != 0 )
2478  --numberOfRoots;
2479  if( intervals.begin()->second.upper_bound_type() == carl::BoundType::WEAK )
2480  ++numberOfRoots;
2481  }
2482  #ifdef VS_DEBUG_ROOTS_CHECK
2483  std::cout << "Image of left bound : " << imageOfLeftBound << std::endl;
2484  std::cout << "Image of right bound : " << imageOfRightBound << std::endl;
2485  std::cout << "Number of roots according sturm sequence: " << numberOfRoots << std::endl;
2486  #endif
2487  bool constraintInconsistent = false;
2488  if( numberOfRoots == 0 )
2489  {
2490  if( cons.relation() == carl::Relation::EQ )
2491  constraintInconsistent = true;
2492  else if( imageOfLeftBound > 0 && (cons.relation() == carl::Relation::LESS || cons.relation() == carl::Relation::LEQ) )
2493  constraintInconsistent = true;
2494  else if( imageOfLeftBound < 0 && (cons.relation() == carl::Relation::GREATER || cons.relation() == carl::Relation::GEQ) )
2495  constraintInconsistent = true;
2496  }
2497  else if( numberOfRoots == 1 )
2498  {
2499  if( imageOfLeftBound > Rational(0) && imageOfRightBound > Rational(0) && cons.relation() == carl::Relation::LESS )
2500  constraintInconsistent = true;
2501  if( imageOfLeftBound < Rational(0) && imageOfRightBound < Rational(0) && cons.relation() == carl::Relation::GREATER )
2502  constraintInconsistent = true;
2503  }
2504  if( constraintInconsistent )
2505  {
2506  carl::PointerSet<Condition> origins;
2507  origins.insert( _condition );
2508  auto conflictingBounds = variableBounds().getOriginsOfBounds( index() );
2509  origins.insert( conflictingBounds.begin(), conflictingBounds.end() );
2510  ConditionSetSet conflicts;
2511  conflicts.insert( std::move(origins) );
2512  addConflictSet( NULL, std::move(conflicts) );
2513  rInconsistent() = true;
2514  #ifdef VS_DEBUG_ROOTS_CHECK
2515  std::cout << " -> false (1)" << std::endl;
2516  #endif
2517  return false;
2518  }
2519  if( numberOfRoots > 0 )
2520  {
2521  #ifdef VS_DEBUG_ROOTS_CHECK
2522  std::cout << " -> true (1)" << std::endl;
2523  #endif
2524  return true;
2525  }
2526  }
2527  else
2528  {
2529  #ifdef VS_DEBUG_ROOTS_CHECK
2530  std::cout << " -> true (3)" << std::endl;
2531  #endif
2532  return true;
2533  }
2534  }
2535  bool constraintInconsistent = false;
2536  if( cons.relation() == carl::Relation::EQ )
2537  constraintInconsistent = true;
2538  else if( solutionSpace.lower() > 0 && cons.relation() == carl::Relation::LEQ )
2539  constraintInconsistent = true;
2540  else if( solutionSpace.upper() < 0 && cons.relation() == carl::Relation::GEQ )
2541  constraintInconsistent = true;
2542  else if( solutionSpace.lower() >= 0 && cons.relation() == carl::Relation::LESS )
2543  constraintInconsistent = true;
2544  else if( solutionSpace.upper() <= 0 && cons.relation() == carl::Relation::GREATER )
2545  constraintInconsistent = true;
2546  carl::PointerSet<Condition> origins;
2547  origins.insert( _condition );
2548  auto conflictingBounds = variableBounds().getOriginsOfBounds( cons.variables().as_set() );
2549  origins.insert( conflictingBounds.begin(), conflictingBounds.end() );
2550  ConditionSetSet conflicts;
2551  conflicts.insert( std::move(origins) );
2552  Substitution* sub = NULL;
2553  if( !constraintInconsistent )
2554  {
2555  smtrat::ConstraintsT constraints;
2556  constraints.insert( _condition->constraint() );
2557  carl::PointerSet<Condition> subsOrigins;
2558  subsOrigins.insert( _condition );
2559  sub = new Substitution( index(), Substitution::INVALID, std::move(subsOrigins), std::move(constraints) );
2560  }
2561  addConflictSet( sub, std::move(conflicts) );
2562  #ifdef VS_DEBUG_ROOTS_CHECK
2563  std::cout << " -> false (2)" << std::endl;
2564  #endif
2565  return false;
2566  }
2567 
2568  #ifdef VS_STATE_DEBUG_METHODS
2569 
2570  void State::print( const std::string _initiation, std::ostream& _out ) const
2571  {
2572  printAlone( _initiation, _out );
2573  _out << _initiation << " " << "Children:" << std::endl;
2574  if( !children().empty() )
2575  for( auto child = children().begin(); child != children().end(); ++child )
2576  (**child).print( _initiation + " ", _out );
2577  else _out << _initiation << " no" << std::endl;
2578  }
2579 
2580  void State::printAlone( const std::string _initiation, std::ostream& _out ) const
2581  {
2582  _out << _initiation << " State: ( reference: " << this << std::endl;
2583  _out << _initiation << " valuation: " << valuation() << std::endl;
2584  _out << _initiation << " ID: " << mID << std::endl;
2585  switch( type() )
2586  {
2587  case COMBINE_SUBRESULTS:
2588  _out << _initiation << " state type: COMBINE_SUBRESULTS" << std::endl;
2589  break;
2590  case SUBSTITUTION_TO_APPLY:
2591  _out << _initiation << " state type: SUBSTITUTION_TO_APPLY" << std::endl;
2592  break;
2594  _out << _initiation << " state type: TEST_CANDIDATE_TO_GENERATE" << std::endl;
2595  break;
2596  default:
2597  _out << _initiation << " state type: Undefined" << std::endl;
2598  break;
2599  }
2601  _out << _initiation << " hasRecentlyAddedConditions: yes" << std::endl;
2602  else
2603  _out << _initiation << " hasRecentlyAddedConditions: no" << std::endl;
2604  if( isInconsistent() )
2605  _out << _initiation << " isInconsistent: yes" << std::endl;
2606  else
2607  _out << _initiation << " isInconsistent: no" << std::endl;
2608  if( cannotBeSolved(false) )
2609  _out << _initiation << " cannotBeSolved: yes" << std::endl;
2610  else
2611  _out << _initiation << " cannotBeSolved: no" << std::endl;
2612  if( conditionsSimplified() )
2613  _out << _initiation << " conditionsSimplified: yes" << std::endl;
2614  else
2615  _out << _initiation << " conditionsSimplified: no" << std::endl;
2616  if( subResultsSimplified() )
2617  _out << _initiation << " subResultsSimplified: yes" << std::endl;
2618  else
2619  _out << _initiation << " subResultsSimplified: no" << std::endl;
2620  if( takeSubResultCombAgain() )
2621  _out << _initiation << " takeSubResultCombAgain: yes" << std::endl;
2622  else
2623  _out << _initiation << " takeSubResultCombAgain: no" << std::endl;
2624  if( tryToRefreshIndex() )
2625  _out << _initiation << " tryToRefreshIndex: yes" << std::endl;
2626  else
2627  _out << _initiation << " tryToRefreshIndex: no" << std::endl;
2628  if( mCannotBeSolved )
2629  _out << _initiation << " toHighDegree: yes" << std::endl;
2630  else
2631  _out << _initiation << " toHighDegree: no" << std::endl;
2632  if( markedAsDeleted() )
2633  _out << _initiation << " markedAsDeleted: yes" << std::endl;
2634  else
2635  _out << _initiation << " markedAsDeleted: no" << std::endl;
2636  if( pOriginalCondition() != NULL )
2637  {
2638  _out << _initiation << " original condition: ";
2639  _out << originalCondition().constraint() << " [";
2640  _out << pOriginalCondition() << "]" << std::endl;
2641  }
2642  if( mpInfinityChild != NULL )
2643  {
2644  _out << _initiation << " infinity child: " << mpInfinityChild << std::endl;
2645  }
2646  _out << _initiation << " index: " << index() << " " << index().type() << " )" << std::endl;
2647  printConditions( _initiation + " ", _out );
2648  if( !isRoot() )
2649  {
2650  _out << _initiation + " " << "Substitution: ";
2651  substitution().print( false, false, _out );
2652  }
2653  printSubstitutionResults( _initiation + " ", _out );
2654  _out << _initiation << std::endl;
2655  printSubstitutionResultCombination( _initiation + " ", _out );
2656  _out << _initiation << std::endl;
2657  printConflictSets( _initiation + " ", _out );
2658  if( mpVariableBounds != NULL )
2659  {
2660  _out << _initiation << std::endl;
2661  mpVariableBounds->print( _out, _initiation );
2662  _out << _initiation << std::endl;
2663  }
2664  }
2665 
2666  void State::printConditions( const std::string _initiation, std::ostream& _out, bool _onlyAsConstraints ) const
2667  {
2668  _out << _initiation << "Condititons:" << std::endl;
2669  for( auto cond = conditions().begin(); cond != conditions().end(); ++cond )
2670  {
2671  _out << _initiation << " ";
2672  if( _onlyAsConstraints )
2673  _out << (**cond).constraint();
2674  else
2675  (**cond).print( _out );
2676  _out << std::endl;
2677  }
2678  }
2679 
2680  void State::printSubstitutionResults( const std::string _initiation, std::ostream& _out ) const
2681  {
2682  if( hasSubstitutionResults() )
2683  {
2684  for( auto subResult = mpSubstitutionResults->begin(); subResult != mpSubstitutionResults->end(); ++subResult )
2685  {
2686  if( subResult == mpSubstitutionResults->begin() )
2687  _out << _initiation << " [ ";
2688  else
2689  _out << _initiation << " and [ ";
2690  for( auto condConjunction = subResult->begin(); condConjunction != subResult->end(); ++condConjunction )
2691  {
2692  if( condConjunction == subResult->begin() )
2693  _out << " ( ";
2694  else
2695  _out << _initiation << " or ( ";
2696 
2697  for( auto cond = condConjunction->first.begin(); cond != condConjunction->first.end(); ++cond )
2698  {
2699  if( cond != condConjunction->first.begin() ) _out << " and ";
2700  std::cout << (*cond)->constraint();
2701  }
2702  _out << " )";
2703  auto nextCondConjunction = condConjunction;
2704  ++nextCondConjunction;
2705  if( nextCondConjunction != subResult->end() ) _out << std::endl;
2706  }
2707  _out << " ]" << std::endl;
2708  }
2709  }
2710  }
2711 
2712  void State::printSubstitutionResultCombination( const std::string _initiation, std::ostream& _out ) const
2713  {
2714  if( hasSubstitutionResults() )
2715  {
2716  if( hasSubResultsCombination() )
2717  {
2718  _out << _initiation << "Substitution result combination:" << std::endl;
2719  for( auto subResComb = mpSubResultCombination->begin(); subResComb != mpSubResultCombination->end(); ++subResComb )
2720  {
2721  _out << _initiation << " ( ";
2722  for( auto cond = mpSubstitutionResults->at( subResComb->first ).at( subResComb->second ).first.begin();
2723  cond != mpSubstitutionResults->at( subResComb->first ).at( subResComb->second ).first.end(); ++cond )
2724  {
2725  if( cond != mpSubstitutionResults->at( subResComb->first ).at( subResComb->second ).first.begin() )
2726  _out << " and ";
2727  _out << (**cond).constraint();
2728  }
2729  _out << " )" << std::endl;
2730  }
2731  }
2732  }
2733  }
2734 
2735  void State::printSubstitutionResultCombinationAsNumbers( const std::string _initiation, std::ostream& _out ) const
2736  {
2737  if( hasSubstitutionResults() )
2738  {
2739  if( mpSubResultCombination != NULL )
2740  {
2741  _out << _initiation << "Substitution result combination: ";
2742  for( auto subResComb = mpSubResultCombination->begin(); subResComb != mpSubResultCombination->end(); ++subResComb )
2743  _out << "(" << subResComb->first << ", " << subResComb->second << ") ";
2744  _out << std::endl;
2745  }
2746  }
2747  }
2748 
2749  void State::printConflictSets( const std::string _initiation, std::ostream& _out ) const
2750  {
2751  _out << _initiation << "Conflict sets: " << std::endl;
2752  for( auto conflictSet = conflictSets().begin(); conflictSet != conflictSets().end(); ++conflictSet )
2753  {
2754  if( conflictSet->first != NULL )
2755  conflictSet->first->print( true, true, _out, _initiation + " " );
2756  else
2757  _out << _initiation << " NULL" << std::endl;
2758  for( auto condSetSet = conflictSet->second.begin(); condSetSet != conflictSet->second.end(); ++condSetSet )
2759  {
2760  auto condSet = condSetSet->begin();
2761  if( condSet != condSetSet->end() )
2762  {
2763  _out << _initiation << " {";
2764  auto cond = (*condSet).begin();
2765  if( cond != (*condSet).end() )
2766  {
2767  _out << " { [";
2768  _out << (**cond).constraint();
2769  _out << "]" << "_" << (**cond).valuation();
2770  ++cond;
2771  while( cond != (*condSet).end() )
2772  {
2773  _out << ", [";
2774  _out << (**cond).constraint();
2775  _out << "]" << "_" << (**cond).valuation();
2776  ++cond;
2777  }
2778  _out << " }";
2779  }
2780  else
2781  _out << " {}";
2782  ++condSet;
2783  while( condSet != condSetSet->end() )
2784  {
2785  _out << "," << std::endl;
2786  _out << _initiation << " ";
2787  auto cond = (*condSet).begin();
2788  if( cond != (*condSet).end() )
2789  {
2790  _out << " { [";
2791  _out << (**cond).constraint();
2792  _out << "]" << "_" << (**cond).valuation();
2793  ++cond;
2794  while( cond != (*condSet).end() )
2795  {
2796  _out << ", [";
2797  _out << (**cond).constraint();
2798  _out << "]" << "_" << (**cond).valuation();
2799  ++cond;
2800  }
2801  _out << " }";
2802  }
2803  else
2804  _out << " {}";
2805  ++condSet;
2806  }
2807  _out << " }" << std::endl;
2808  }
2809  else
2810  _out << _initiation << " {}" << std::endl;
2811  }
2812  }
2813  }
2814 
2815  #endif
2816 
2817  size_t State::coveringSet( const ConditionSetSetSet& _conflictSets, carl::PointerSet<Condition>& _coveringSet, unsigned _currentTreeDepth )
2818  {
2819  // Greatest tree depth of the original conditions of the conditions in the covering set.
2820  size_t greatestTreeDepth = 0;
2821  for( auto conflictSet = _conflictSets.begin(); conflictSet != _conflictSets.end(); ++conflictSet )
2822  {
2823  if( !conflictSet->empty() )
2824  {
2825  // Greatest tree depth of the original conditions of the conditions in the currently best set of conditions in this conflict set.
2826  size_t greatestTreeDepthConflictSet = 0;
2827  // The number of conditions in the currently best set of conditions, which are not covered of the so far created covering set.
2828  size_t numUncovCondsConflictSet = 0;
2829  auto bestConditionSet = conflictSet->begin();
2830  for( auto conditionSet = conflictSet->begin(); conditionSet != conflictSet->end(); ++conditionSet )
2831  {
2832  size_t numUncovCondsCondSet = 0;
2833  size_t greatestTreeDepthCondSet = 0;
2834  bool justEmptyOConds = true;
2835  for( auto condition = conditionSet->begin(); condition != conditionSet->end(); ++condition )
2836  {
2837  if( _coveringSet.find( *condition ) == _coveringSet.end() )
2838  numUncovCondsCondSet++;
2839  assert( *condition != NULL );
2840  for( auto oCond = (**condition).originalConditions().begin(); oCond != (**condition).originalConditions().end(); ++oCond )
2841  {
2842  assert( *oCond != NULL );
2843  justEmptyOConds = false;
2844  if( (**oCond).valuation() > greatestTreeDepthCondSet )
2845  greatestTreeDepthCondSet = (**oCond).valuation();
2846  }
2847  }
2848  if( justEmptyOConds )
2849  greatestTreeDepthCondSet = _currentTreeDepth - 1;
2850  if( conditionSet == conflictSet->begin() || (greatestTreeDepthCondSet < greatestTreeDepthConflictSet)
2851  || ((greatestTreeDepthCondSet == greatestTreeDepthConflictSet && numUncovCondsCondSet < numUncovCondsConflictSet)) )
2852  {
2853  bestConditionSet = conditionSet;
2854  greatestTreeDepthConflictSet = greatestTreeDepthCondSet;
2855  numUncovCondsConflictSet = numUncovCondsCondSet;
2856  }
2857  }
2858  if( greatestTreeDepthConflictSet > greatestTreeDepth )
2859  greatestTreeDepth = greatestTreeDepthConflictSet;
2860  _coveringSet.insert( bestConditionSet->begin(), bestConditionSet->end() );
2861  }
2862  }
2863  return greatestTreeDepth;
2864  }
2865 } // end namspace vs
2866 }
#define SMTRAT_VALIDATION_ADD(channel, name, formula, consistent)
Definition: Validation.h:26
Class to manage the bounds of a variable.
void print(std::ostream &_out=std::cout, const std::string _init="", bool _printAllBounds=false) const
Prints the variable bounds.
const smtrat::EvalDoubleIntervalMap & getIntervalMap() const
Creates an interval map corresponding to the variable bounds.
unsigned removeBound(const ConstraintT &_constraint, const T &_origin)
Removes all effects the given constraint has on the variable bounds.
const carl::Interval< double > & getDoubleInterval(const carl::Variable &_var) const
Creates a double interval corresponding to the variable bounds of the given variable.
bool addBound(const ConstraintT &_constraint, const T &_origin)
Updates the variable bounds by the given constraint.
std::vector< T > getOriginsOfBounds(const carl::Variable &_var) const
const smtrat::ConstraintT & constraint() const
Definition: Condition.h:81
double valuate(const carl::Variable &, size_t, bool) const
Valuates the constraint according to a variable (it possibly not contains).
Definition: Condition.cpp:49
carl::PointerSet< Condition > * pOriginalConditions() const
Definition: Condition.h:86
size_t id() const
Definition: Condition.h:76
bool flag() const
Definition: Condition.h:51
size_t valuation() const
Definition: Condition.h:71
size_t & rValuation() const
Definition: Condition.h:66
const carl::PointerSet< Condition > & originalConditions() const
Definition: Condition.h:91
void printSubstitutionResults(const std::string _initiation="***", std::ostream &_out=std::cout) const
Prints the substitution results of this state.
Definition: State.cpp:2680
const std::list< State * > & children() const
Definition: State.h:331
bool hasSubstitutionResults() const
Definition: State.h:552
const Substitution * pSubstitution() const
Definition: State.h:486
ConditionList & rConditions()
Definition: State.h:414
bool refreshConditions(ValuationMap &_ranking)
Determines the condition vector corresponding to the current combination of the conjunctions of condi...
Definition: State.cpp:1096
ConflictSets * mpConflictSets
Stores for each already considered and failed test candidate all conflicts which have been found for ...
Definition: State.h:149
bool hasFurtherUncheckedTestCandidates() const
Checks whether there exist more than one test candidate, which has still not been checked.
Definition: State.cpp:285
const smtrat::Rational & minIntTestCandidate() const
Definition: State.h:672
void printSubstitutionResultCombination(const std::string _initiation="***", std::ostream &_out=std::cout) const
Prints the combination of substitution results used in this state.
Definition: State.cpp:2712
void resetCurrentRangeSize()
Definition: State.h:662
void deleteOriginsFromSubstitutionResults(carl::PointerSet< Condition > &_originsToDelete)
Deletes everything originated by the given conditions in the substitution results of this state.
Definition: State.cpp:1846
SubResultCombination * mpSubResultCombination
The currently considered combination of conjunctions of constraints in the substitution result vector...
Definition: State.h:145
bool mMarkedAsDeleted
A flag indicating whether this state has already marked as deleted, which means that there is no need...
Definition: State.h:92
size_t mID
A unique id identifying this state.
Definition: State.h:118
smtrat::Rational mMinIntTestCanidate
Definition: State.h:162
bool mInconsistent
A flag that indicates whether this state is already inconsistent.
Definition: State.h:89
bool hasNoninvolvedCondition() const
Checks whether a condition exists, which was not involved in an elimination step.
Definition: State.cpp:217
bool isRoot() const
Definition: State.h:209
size_t mValuation
A heuristically determined value stating the expected difficulty of this state's considered condition...
Definition: State.h:123
bool mSubResultsSimplified
A flag indicating whether the substitution results this state are simplified.
Definition: State.h:94
bool mHasRecentlyAddedConditions
A flag that indicates whether this state has conditions in its considered list of conditions,...
Definition: State.h:86
unsigned treeDepth() const
Definition: State.cpp:185
Type type() const
Definition: State.h:571
smtrat::Rational mMaxIntTestCanidate
Definition: State.h:164
size_t mCurrentIntRange
Definition: State.h:166
std::list< State * > & rChildren()
Definition: State.h:323
void printConflictSets(const std::string _initiation="***", std::ostream &_out=std::cout) const
Prints the conflict sets of this state.
Definition: State.cpp:2749
bool unfinished() const
Definition: State.h:561
void variables(carl::Variables &_variables) const
Finds the variables, which occur in this state.
Definition: State.cpp:298
const SubResultCombination & subResultCombination() const
Definition: State.h:478
void updateBackendCallValuation()
Valuates the state's currently considered conditions according to a backend call.
Definition: State.cpp:2060
State * pFather() const
Definition: State.h:339
bool hasChildWithID() const
Checks whether a child exists, which has no ID (!=0).
Definition: State.cpp:242
void setIndex(const carl::Variable &_index)
Sets the index of this state.
Definition: State.cpp:812
std::vector< size_t > mBestVarVals
Definition: State.h:174
std::vector< std::pair< unsigned, unsigned > > SubResultCombination
Definition: State.h:73
SubstitutionResults * mpSubstitutionResults
The vector storing the substitution results, that is for each application of the substitution in this...
Definition: State.h:142
bool hasLocalConflict()
Checks whether the currently considered conditions, which have been considered for test candidate con...
Definition: State.cpp:2201
bool unfinishedAncestor(State *&_unfinAnt)
Determines (if it exists) a ancestor node, which is unfinished, that is it has still substitution res...
Definition: State.cpp:386
bool & rInconsistent()
Definition: State.h:397
static void removeStatesFromRanking(const State &toRemove, ValuationMap &_ranking)
Definition: State.cpp:170
Type mType
The type of this state, which states whether this state has still a substitution to apply or either t...
Definition: State.h:127
bool mTryToRefreshIndex
A flag indicating whether the index (the variable to eliminate in this state) should be reconsidered ...
Definition: State.h:112
bool mCannotBeSolvedLazy
Definition: State.h:109
void simplify(ValuationMap &_ranking)
Cleans up all conditions in this state according to comparison between the corresponding constraints.
Definition: State.cpp:443
bool getNextIntTestCandidate(smtrat::Rational &_nextIntTestCandidate, size_t _maxIntRange)
Definition: State.cpp:322
bool & rTakeSubResultCombAgain()
Definition: State.h:528
SubResultCombination & rSubResultCombination()
Definition: State.h:468
bool mTakeSubResultCombAgain
A flag indicating whether to take the current combination of substitution results once again.
Definition: State.h:97
bool hasSubResultsCombination() const
Definition: State.h:544
bool nextSubResultCombination()
If the state contains a substitution result, which is a conjunction of disjunctions of conjunctions o...
Definition: State.cpp:992
carl::Variable::Arg index() const
Definition: State.h:282
void worstConstraintValuation(const std::vector< std::pair< carl::Variable, std::multiset< double >>> &_varVals)
Definition: State.cpp:1379
bool conditionsSimplified() const
Definition: State.h:494
const ConflictSets & conflictSets() const
Definition: State.h:371
ConditionList getCurrentSubresultCombination() const
Gets the current substitution result combination as condition vector.
Definition: State.cpp:1079
bool hasOnlyInconsistentChildren() const
Checks whether a child exists, which is not yet marked as inconsistent.
Definition: State.cpp:264
const smtrat::Rational & maxIntTestCandidate() const
Definition: State.h:680
const VariableBoundsCond & variableBounds() const
Definition: State.h:626
void printAlone(const std::string="***", std::ostream &_out=std::cout) const
Prints the conditions, the substitution and the substitution results of this state.
Definition: State.cpp:2580
std::vector< std::pair< carl::Variable, std::multiset< double > > > mRealVarVals
Definition: State.h:170
void initConditionFlags()
Sets all flags of the conditions to true, if it contains the variable given by the states index.
Definition: State.cpp:1182
~State()
Destructor.
Definition: State.cpp:110
bool & rMarkedAsDeleted()
Definition: State.h:254
bool extendSubResultCombination()
Extends the currently considered combination of conjunctions in the substitution results.
Definition: State.cpp:933
unsigned numberOfNodes() const
Determines the number of nodes in the tree with this state as root.
Definition: State.cpp:306
std::vector< SubstitutionResult > SubstitutionResults
Definition: State.h:72
State(carl::IDPool *_conditionIdAllocator, bool _withVariableBounds)
Constructs an empty state (no conditions yet) being the root (hence neither a substitution) of the st...
Definition: State.cpp:30
State & rFather()
Definition: State.h:355
Type & rType()
Definition: State.h:581
carl::IDPool * mpConditionIdAllocator
Definition: State.h:168
bool takeSubResultCombAgain() const
Definition: State.h:519
void bestConstraintValuation(const std::vector< std::pair< carl::Variable, std::multiset< double >>> &_varVals)
Definition: State.cpp:1291
const Substitution & substitution() const
Definition: State.h:440
void deleteConditions(carl::PointerSet< Condition > &_conditionsToDelete, ValuationMap &_ranking)
Delete everything originated by the given conditions from the entire subtree with this state as root.
Definition: State.cpp:1610
void resetCannotBeSolvedLazyFlags()
Definition: State.cpp:178
bool markedAsDeleted() const
Definition: State.h:245
void deleteOriginsFromConflictSets(carl::PointerSet< Condition > &_originsToDelete, bool _originsAreCurrentConditions)
Deletes everything originated by the given conditions in the conflict sets of this state.
Definition: State.cpp:1714
bool updateIntTestCandidates()
Definition: State.cpp:343
carl::FastPointerMapB< Substitution, ConditionSetSetSet > ConflictSets
Definition: State.h:70
static size_t coveringSet(const ConditionSetSetSet &_conflictSets, carl::PointerSet< Condition > &_minCovSet, unsigned _currentTreeDepth)
Finds a covering set of a vector of sets of sets due to some heuristics.
Definition: State.cpp:2817
std::vector< State * > addChild(const Substitution &_substitution)
Adds a state as child to this state with the given substitution.
Definition: State.cpp:1957
State * mpInfinityChild
Definition: State.h:160
void resetConflictSets()
Clears the conflict sets.
Definition: State.cpp:862
bool subResultsSimplified() const
Definition: State.h:502
ConditionList * mpConditions
The currently considered conditions of this state, for which the satisfiability must be checked.
Definition: State.h:147
void printConditions(const std::string _initiation="***", std::ostream &_out=std::cout, bool=false) const
Prints the conditions of this state.
Definition: State.cpp:2666
const State & father() const
Definition: State.h:347
bool isInconsistent() const
Definition: State.h:406
size_t getNumberOfCurrentSubresultCombination() const
Definition: State.cpp:1052
void updateValuation(bool _lazy)
Updates the valuation of this state.
Definition: State.cpp:2023
const Condition * pOriginalCondition() const
Definition: State.h:590
bool bestCondition(const Condition *&_bestCondition, size_t _numberOfAllVariables, bool _preferEquation)
Determines the most adequate condition and in it the most adequate variable in the state to generate ...
Definition: State.cpp:398
bool containsState(const State *_state) const
Definition: State.cpp:255
std::vector< smtrat::DoubleInterval > solutionSpace(carl::PointerSet< Condition > &_conflictReason) const
Determines the solution space of the test candidate of this state regarding to the variable bounds of...
Definition: State.cpp:2324
bool & rHasRecentlyAddedConditions()
Definition: State.h:380
size_t backendCallValuation() const
Definition: State.h:299
size_t id() const
Definition: State.h:307
Substitution & rSubstitution()
Definition: State.h:431
carl::Variable mIndex
The variable which is going to be eliminated from this state's considered conditions.
Definition: State.h:130
SubstitutionResults & rSubstitutionResults()
Definition: State.h:449
void print(const std::string _initiation="***", std::ostream &_out=std::cout) const
Prints the conditions, the substitution and the substitution results of this state and all its childr...
Definition: State.cpp:2570
void addConflictSet(const Substitution *_substitution, ConditionSetSet &&_condSetSet)
Adds a conflict set to the map of substitutions to conflict sets.
Definition: State.cpp:818
void addCondition(const smtrat::ConstraintT &_constraint, const carl::PointerSet< Condition > &_originalConditions, size_t _valutation, bool _recentlyAdded, ValuationMap &_ranking)
Adds a constraint to the conditions of this state.
Definition: State.cpp:1438
Substitution * mpSubstitution
The substitution this state considers. Note that it is NULL if this state is the root.
Definition: State.h:139
void addSubstitutionResults(std::vector< DisjunctionOfConditionConjunctions > &&_disjunctionsOfCondConj)
Adds the given substitution results to this state.
Definition: State.cpp:915
bool tryToRefreshIndex() const
Definition: State.h:536
bool checkTestCandidatesForBounds()
Checks whether the test candidate of this state is valid against the variable intervals in the father...
Definition: State.cpp:2297
bool occursInEquation(const carl::Variable &) const
Checks whether the given variable occurs in a equation.
Definition: State.cpp:277
bool updateOCondsOfSubstitutions(const Substitution &_substitution, std::vector< State * > &_reactivatedStates)
Updates the original conditions of substitutions having the same test candidate as the given.
Definition: State.cpp:873
carl::PointerSet< Condition > * mpTooHighDegreeConditions
The conditions of this state, which cannot be solved by the virtual substitution.
Definition: State.h:154
void passConflictToFather(bool _checkConflictForSideCondition, bool _useBackjumping=true, bool _includeInconsistentTestCandidates=false)
Passes the original conditions of the covering set of the conflicts of this state to its father.
Definition: State.cpp:2082
void averageConstraintValuation(const std::vector< std::pair< carl::Variable, std::multiset< double >>> &_varVals)
Definition: State.cpp:1350
bool substitutionApplicable() const
Checks if a substitution can be applied.
Definition: State.cpp:197
bool mConditionsSimplified
A flag indicating whether the conditions this state considers are simplified.
Definition: State.h:80
bool mTestCandidateCheckedForBounds
A flag indicating whether the test candidate contained by this state has already been check for the b...
Definition: State.h:100
void addConflicts(const Substitution *_substitution, ConditionSetSet &&_condSetSet)
Adds all conflicts to all sets of the conflict set of the given substitution.
Definition: State.cpp:839
const SubstitutionResults & substitutionResults() const
Definition: State.h:458
std::list< State * > * mpChildren
The children states of this state.
Definition: State.h:152
void deleteOriginsFromChildren(carl::PointerSet< Condition > &_originsToDelete, ValuationMap &_ranking)
Deletes everything originated by the given conditions in the children of this state.
Definition: State.cpp:1682
int deleteOrigins(carl::PointerSet< Condition > &_originsToDelete, ValuationMap &_ranking)
Removes everything in this state originated by the given vector of conditions.
Definition: State.cpp:1510
bool & rSubResultsSimplified()
Definition: State.h:510
bool checkSubresultCombinations() const
This is just for debug purpose.
Definition: State.cpp:1495
ConditionList::iterator constraintExists(const smtrat::ConstraintT &_constraint)
Checks if the given constraint already exists as condition in the state.
Definition: State.cpp:435
bool initIndex(const carl::Variables &_allVariables, const smtrat::VariableValuationStrategy &_vvstrat, bool _preferEquation, bool _tryDifferentVarOrder=false, bool _useFixedVariableOrder=false)
Sets, if it has not already happened, the index of the state to the name of the most adequate variabl...
Definition: State.cpp:1191
size_t mBackendCallValuation
A heuristically determined value stating the expected difficulty of this state's considered condition...
Definition: State.h:116
const Condition & originalCondition() const
Definition: State.h:599
bool hasRootsInVariableBounds(const Condition *_condition, bool _useSturmSequence)
Checks whether there are no zeros for the left-hand side of the constraint of the given condition.
Definition: State.cpp:2423
void printSubstitutionResultCombinationAsNumbers(const std::string _initiation="***", std::ostream &_out=std::cout) const
Prints the combination of substitution results, expressed in numbers, used in this state.
Definition: State.cpp:2735
bool hasRecentlyAddedConditions() const
Definition: State.h:388
State & root()
Definition: State.cpp:314
const ConditionList & conditions() const
Definition: State.h:422
ConflictSets & rConflictSets()
Definition: State.h:363
@ SUBSTITUTION_TO_APPLY
Definition: State.h:68
@ TEST_CANDIDATE_TO_GENERATE
Definition: State.h:68
@ COMBINE_SUBRESULTS
Definition: State.h:68
const carl::PointerSet< Condition > & tooHighDegreeConditions() const
Definition: State.h:608
bool cannotBeSolved(bool _lazy) const
Definition: State.h:218
bool mCannotBeSolved
A flag indicating whether this state has been progressed until a point where a condition must be invo...
Definition: State.h:107
size_t valuation() const
Definition: State.h:291
bool allTestCandidatesInvalidated(const Condition *_condition) const
Definition: State.cpp:230
VariableBoundsCond * mpVariableBounds
A pointer to an object which manages and stores the bounds on the variables occurring in this state.
Definition: State.h:158
std::vector< std::pair< carl::Variable, std::multiset< double > > > mIntVarVals
Definition: State.h:172
const carl::Variables & termVariables() const
Definition: Substitution.h:142
carl::PointerSet< Condition > & rOriginalConditions()
Definition: Substitution.h:118
void print(bool _withOrigins=false, bool _withSideConditions=false, std::ostream &_out=std::cout, const std::string &_init="") const
Prints this substitution on the given stream, with some additional information.
const smtrat::SqrtEx & term() const
Definition: Substitution.h:83
const smtrat::ConstraintsT & sideCondition() const
Definition: Substitution.h:134
const carl::Variable & variable() const
Definition: Substitution.h:75
const carl::PointerSet< Condition > & originalConditions() const
Definition: Substitution.h:126
unsigned valuate(bool _preferMinusInf=true) const
const Type & type() const
Definition: Substitution.h:110
int var(Lit p)
Definition: SolverTypes.h:64
static bool find(V &ts, const T &t)
Definition: Alg.h:47
Rational evaluate(carl::Variable v, const Poly &p, const Rational &r)
Definition: utils.h:11
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:43
std::pair< size_t, std::pair< size_t, size_t > > UnsignedTriple
Definition: State.h:33
std::set< ConditionSetSet > ConditionSetSetSet
Definition: State.h:29
std::list< const Condition * > ConditionList
Definition: State.h:30
std::set< carl::PointerSet< Condition > > ConditionSetSet
Definition: State.h:28
std::map< UnsignedTriple, vs::State *, unsignedTripleCmp > ValuationMap
Definition: State.h:62
Class to create the formulas for axioms.
carl::Constraints< Poly > ConstraintsT
Definition: types.h:31
VariableValuationStrategy
Definition: VSSettings.h:14
carl::Interval< double > DoubleInterval
Definition: model.h:26
carl::Interval< Rational > RationalInterval
Definition: model.h:27
carl::Constraint< Poly > ConstraintT
Definition: types.h:29
mpq_class Rational
Definition: types.h:19
std::map< carl::Variable, DoubleInterval > EvalDoubleIntervalMap
Definition: model.h:29