SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Bound.h
Go to the documentation of this file.
1 /**
2  * @file Bound.h
3  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
4  * @since 2012-04-05
5  * @version 2014-10-01
6  */
7 
8 #pragma once
9 
10 #include "Value.h"
12 #include <stddef.h>
13 #include <set>
14 
15 namespace smtrat
16 {
17  namespace lra
18  {
19  // Forward declaration.
20  template<class T1, class T2>
21  class Variable;
22 
23  // Forward declaration.
24  template<typename T1, typename T2>
25  class Bound;
26 
27  /**
28  * Stores a bound, which could be an upper "<= b" or a lower bound ">= b" for a bound value b.
29  * In the case that "<= b" and ">= b" hold this bound is a so called equal bound represented by "==b".
30  */
31  template<typename T1, typename T2>
32  class Bound
33  {
34  public:
35  /// The type of the bound: LOWER = ">=", UPPER = "<=", EQUAL "=="
36  enum Type{ LOWER, UPPER, EQUAL };
37 
38  /// A set of pointer to bounds.
39  typedef carl::PointerSet<Bound<T1, T2>> BoundSet;
40 
41  /**
42  * Stores some additional information for a bound.
43  */
44  struct Info
45  {
46  /**
47  * A value to store the information whether this bounds constraint has already been processed (=0),
48  * must be processed (>0) or must be removed from consideration (<0).
49  */
50  int updated;
51  /**
52  * The position of this bounds constraint in a formula, if it has been processed already. Otherwise
53  * it points to the end of a formula.
54  */
56  /// If this bound corresponds to a constraint being p<0 or p>0 for a polynomial p, we store here the constraint p!=0.
58  /**
59  * A flag which is only false, if this bound has been created for a constraint having != as
60  * relation symbol, i.e. p!=0, and not yet for the constraint p<0 or p>0.
61  */
62  bool exists;
63  ///
65 
67  updated( 0 ),
68  position( _position ),
69  neqRepresentation( FormulaT( carl::FormulaType::TRUE ) ),
70  exists( false ),
71  complement( nullptr )
72  {}
73  };
74 
75  private:
76 
77  ///
78  bool mDeduced;
79  ///
80  mutable bool mMarkedAsDeleted;
81  ///
83  ///
84  const Value<T1>* mLimit;
85  ///
87  ///
89  ///
90  std::shared_ptr<std::vector<FormulaT>> mpOrigins;
91  ///
93 
94  public:
95  /**
96  *
97  */
98  Bound() = delete;
99 
100  /**
101  *
102  * @param _limit
103  * @param _var
104  * @param _type
105  * @param _constraint
106  * @param _boundInfo
107  * @param _deduced
108  */
109 #ifdef __VS
110  Bound(const Value<T1>* const _limit, Variable<T1, T2>* const _var, Type _type, const FormulaT& _constraint, Info* _boundInfo = NULL, bool _deduced = false);
111 #else
112  Bound(const Value<T1>* const _limit, Variable<T1, T2>* const _var, Type _type, const FormulaT& _constraint, Bound<T1, T2>::Info* _boundInfo = NULL, bool _deduced = false);
113 #endif
114 
115  /**
116  *
117  */
119 
120  /**
121  *
122  * @param _value
123  * @return
124  */
125  bool operator >( const Value<T1>& _value ) const;
126 
127  /**
128  *
129  * @param _value
130  * @return
131  */
132  bool operator ==( const Value<T1>& _value ) const;
133 
134  /**
135  *
136  * @param _value
137  * @return
138  */
139  bool operator <( const Value<T1>& _value ) const;
140 
141  /**
142  *
143  * @param _bound
144  * @return
145  */
146  bool operator <( const Bound& _bound ) const;
147 
148  /**
149  *
150  * @param _bound
151  * @return
152  */
153  bool operator >( const Bound& _bound ) const;
154 
155  /**
156  *
157  * @param _a
158  * @return
159  */
160  bool operator ==( const T1& _a ) const;
161 
162  /**
163  *
164  * @param _a
165  * @return
166  */
167  bool operator >( const T1& _a ) const;
168 
169  /**
170  *
171  * @param _a
172  * @return
173  */
174  bool operator <( const T1& _a ) const;
175 
176  /**
177  *
178  * @param _a
179  * @return
180  */
181  bool operator >=( const T1& _a ) const;
182 
183  /**
184  *
185  * @param _a
186  * @return
187  */
188  bool operator <=( const T1& _a ) const;
189 
190  /**
191  *
192  * @return
193  */
194  const std::string toString() const;
195 
196  /**
197  *
198  * @param _withOrigins
199  * @param _out
200  * @param _printTypebool
201  */
202  template <typename T3, typename T4> friend std::ostream& operator <<( std::ostream& _ostream, const Bound<T3, T4>& _bound );
203 
204  /**
205  *
206  * @param _withOrigins
207  * @param _out
208  * @param _printTypebool
209  */
210  void print( bool _withOrigins = false, std::ostream& _out = std::cout, bool _printTypebool = false ) const;
211 
212  /**
213  * @return
214  */
215  bool deduced() const
216  {
217  return mDeduced;
218  }
219 
220  /**
221  * @return
222  */
223  bool markedAsDeleted() const
224  {
225  return mMarkedAsDeleted;
226  }
227 
228  /**
229  * @return
230  */
231  void markAsDeleted() const
232  {
233  mMarkedAsDeleted = true;
234  }
235 
236  /**
237  * @return
238  */
239  void unmarkAsDeleted() const
240  {
241  mMarkedAsDeleted = false;
242  }
243 
244  /**
245  * @return
246  */
247  const Value<T1>& limit() const
248  {
249  return *mLimit;
250  }
251 
252  /**
253  * @return
254  */
255  const Value<T1>* pLimit() const
256  {
257  return mLimit;
258  }
259 
260  /**
261  * @return
262  */
263  bool isInfinite() const
264  {
265  return mLimit == NULL;
266  }
267 
268  /**
269  * @return
270  */
272  {
273  return mVar;
274  }
275 
276  /**
277  * @return
278  */
279  const Variable<T1, T2>& variable() const
280  {
281  return *mVar;
282  }
283 
284  /**
285  * @return
286  */
287  Type type() const
288  {
289  return mType;
290  }
291 
292  /**
293  * @return
294  */
295  bool isWeak() const
296  {
297  return mLimit->deltaPart() == 0;
298  }
299 
300  /**
301  * @return
302  */
303  bool isUpperBound() const
304  {
305  return mType != LOWER;
306  }
307 
308  /**
309  * @return
310  */
311  bool isLowerBound() const
312  {
313  return mType != UPPER;
314  }
315 
316  /**
317  * @return
318  */
319  const FormulaT& asConstraint() const
320  {
321  return mAsConstraint;
322  }
323 
324  /**
325  * @return
326  */
327  bool hasNeqRepresentation() const
328  {
329  return mpInfo->neqRepresentation.is_true();
330  }
331 
332  /**
333  * @return
334  */
336  {
337  return mpInfo->neqRepresentation;
338  }
339 
340  /**
341  *
342  * @param _constraint
343  */
344  void setNeqRepresentation( const FormulaT& _constraint ) const
345  {
346  assert( _constraint.type() == carl::FormulaType::CONSTRAINT && _constraint.constraint().relation() == carl::Relation::NEQ );
347  if( mpInfo->neqRepresentation.is_true() )
348  {
349  mpInfo->neqRepresentation = _constraint;
350  }
351  }
352 
354  {
355  mpInfo->neqRepresentation = FormulaT( carl::FormulaType::TRUE );
356  }
357 
358  /**
359  *
360  */
361  void boundExists() const
362  {
363  mpInfo->exists = true;
364  }
365 
366  /**
367  *
368  */
369  void setComplement( const Bound<T1, T2>* _complement ) const
370  {
371  mpInfo->complement = _complement;
372  }
373 
374  /**
375  *
376  */
377  bool exists() const
378  {
379  return mpInfo->exists;
380  }
381 
382  /**
383  * @return
384  */
385  const std::shared_ptr<std::vector<FormulaT>>& pOrigins() const
386  {
387  return mpOrigins;
388  }
389 
390  /**
391  * @return
392  */
393  const std::vector<FormulaT>& origins() const
394  {
395  return *mpOrigins;
396  }
397 
398  /**
399  * @return
400  */
401  bool isActive() const
402  {
403  return !mpOrigins->empty();
404  }
405 
406  /**
407  * @return
408  */
409  bool isComplementActive() const
410  {
411  return mpInfo->complement != nullptr && mpInfo->complement->isActive();
412  }
413 
414  bool isUnassigned() const
415  {
416  return exists() && !isActive() && !isComplementActive();
417  }
418 
419  /**
420  * @return
421  */
422  Info* pInfo() const
423  {
424  return mpInfo;
425  }
426 
427  bool isSatisfied( const T1& _delta ) const
428  {
429  if( isInfinite() )
430  {
431  return true;
432  }
433  const Value<T1>& ass = variable().lastConsistentAssignment();
434  switch( mType )
435  {
436  case UPPER:
437  if( isWeak() )
438  {
439  return limit().mainPart() >= ass.mainPart() + (ass.deltaPart() * _delta);
440  }
441  return limit().mainPart() + (limit().deltaPart() * _delta) > ass.mainPart() + (ass.deltaPart() * _delta);
442  case LOWER:
443  if( isWeak() )
444  {
445  return limit().mainPart() <= ass.mainPart() + (ass.deltaPart() * _delta);
446  }
447  return limit().mainPart() + (limit().deltaPart() * _delta) < ass.mainPart() + (ass.deltaPart() * _delta);
448  default:
449  assert( mType == EQUAL );
450  return limit().mainPart() == ass.mainPart() + (ass.deltaPart() * _delta);
451  }
452  }
453 
454  /**
455  * @return
456  */
457  bool operator >=( const Value<T1>& v ) const
458  {
459  return !((*this) < v);
460  }
461 
462  /**
463  * @return
464  */
465  bool operator <=( const Value<T1>& v ) const
466  {
467  return !((*this) > v);
468  }
469  };
470  } // end namspace lra
471 } // end namspace smtrat
472 
473 #include "Bound.tpp"
super::iterator iterator
Passing through the list::iterator.
Definition: ModuleInput.h:144
Stores a bound, which could be an upper "<= b" or a lower bound ">= b" for a bound value b.
Definition: Bound.h:33
bool operator==(const Value< T1 > &_value) const
Info * pInfo() const
Definition: Bound.h:422
void setComplement(const Bound< T1, T2 > *_complement) const
Definition: Bound.h:369
bool isComplementActive() const
Definition: Bound.h:409
bool markedAsDeleted() const
Definition: Bound.h:223
bool operator>=(const T1 &_a) const
bool operator<(const Value< T1 > &_value) const
bool mMarkedAsDeleted
Definition: Bound.h:80
bool operator>(const Value< T1 > &_value) const
const std::vector< FormulaT > & origins() const
Definition: Bound.h:393
bool exists() const
Definition: Bound.h:377
Info * mpInfo
Definition: Bound.h:92
const Value< T1 > & limit() const
Definition: Bound.h:247
const Value< T1 > * pLimit() const
Definition: Bound.h:255
bool isInfinite() const
Definition: Bound.h:263
const Variable< T1, T2 > & variable() const
Definition: Bound.h:279
bool isSatisfied(const T1 &_delta) const
Definition: Bound.h:427
bool deduced() const
Definition: Bound.h:215
bool isUpperBound() const
Definition: Bound.h:303
const Value< T1 > * mLimit
Definition: Bound.h:84
bool isWeak() const
Definition: Bound.h:295
void boundExists() const
Definition: Bound.h:361
void resetNeqRepresentation() const
Definition: Bound.h:353
const FormulaT & asConstraint() const
Definition: Bound.h:319
carl::PointerSet< Bound< T1, T2 > > BoundSet
A set of pointer to bounds.
Definition: Bound.h:39
bool isLowerBound() const
Definition: Bound.h:311
bool operator<=(const T1 &_a) const
bool isActive() const
Definition: Bound.h:401
Type type() const
Definition: Bound.h:287
const std::shared_ptr< std::vector< FormulaT > > & pOrigins() const
Definition: Bound.h:385
friend std::ostream & operator<<(std::ostream &_ostream, const Bound< T3, T4 > &_bound)
void print(bool _withOrigins=false, std::ostream &_out=std::cout, bool _printTypebool=false) const
bool hasNeqRepresentation() const
Definition: Bound.h:327
const FormulaT & neqRepresentation() const
Definition: Bound.h:335
void setNeqRepresentation(const FormulaT &_constraint) const
Definition: Bound.h:344
const std::string toString() const
FormulaT mAsConstraint
Definition: Bound.h:88
void markAsDeleted() const
Definition: Bound.h:231
Variable< T1, T2 > * pVariable() const
Definition: Bound.h:271
void unmarkAsDeleted() const
Definition: Bound.h:239
Bound(const Value< T1 > *const _limit, Variable< T1, T2 > *const _var, Type _type, const FormulaT &_constraint, Bound< T1, T2 >::Info *_boundInfo=NULL, bool _deduced=false)
Type
The type of the bound: LOWER = ">=", UPPER = "<=", EQUAL "==".
Definition: Bound.h:36
Variable< T1, T2 > *const mVar
Definition: Bound.h:86
std::shared_ptr< std::vector< FormulaT > > mpOrigins
Definition: Bound.h:90
bool isUnassigned() const
Definition: Bound.h:414
const T & deltaPart() const
Definition: Value.h:221
const T & mainPart() const
Definition: Value.h:213
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
Stores some additional information for a bound.
Definition: Bound.h:45
FormulaT neqRepresentation
If this bound corresponds to a constraint being p<0 or p>0 for a polynomial p, we store here the cons...
Definition: Bound.h:57
Info(ModuleInput::iterator _position)
Definition: Bound.h:66
int updated
A value to store the information whether this bounds constraint has already been processed (=0),...
Definition: Bound.h:50
const Bound< T1, T2 > * complement
Definition: Bound.h:64
ModuleInput::iterator position
The position of this bounds constraint in a formula, if it has been processed already.
Definition: Bound.h:55
bool exists
A flag which is only false, if this bound has been created for a constraint having !...
Definition: Bound.h:62