SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
IcpVariable.h
Go to the documentation of this file.
1 /*
2  * File: variable.h
3  * Author: Stefan Schupp
4  *
5  * Created on January 15, 2013, 10:40 AM
6  */
7 
8 #pragma once
9 
10 #include "ContractionCandidate.h"
11 #include "../LRAModule/LRAModule.h"
13 #include <cassert>
14 
15 namespace smtrat
16 {
17 
18  typedef std::set<icp::ContractionCandidate*, icp::contractionCandidateComp> ContractionCandidates;
19 
20 namespace icp
21 {
22  enum class Updated{
23  // leftBound was updated
24  LEFT,
25  // rightBound was updated
26  RIGHT,
27  // both Bounds were updated
28  BOTH,
29  // no bound was updated
30  NONE
31  };
32 
34 
36  {
37  private:
38 
39  /*
40  * Members
41  */
42  carl::Variable mVar;
43  bool mOriginal;
47  unsigned mActivity;
48  bool mLinear;
49  EvalDoubleIntervalMap::iterator mIntervalPos;
50 
51  // interval Bound generation
52  std::pair<Updated,Updated> mBoundsSet; // internal, external
53  std::pair<Updated,Updated> mUpdated; // internal, external
59 
60  private:
62 
63  public:
64 
65  /*
66  * Constructors
67  */
68  IcpVariable( carl::Variable::Arg _var,
69  bool _original,
70  ModuleInput::iterator _defaultPosition,
71  EvalDoubleIntervalMap::iterator _intervalPos,
72  const LRAVariable* _lraVar = NULL ):
73  mVar( _var ),
74  mOriginal( _original ),
75  mCandidates(),
77  mLraVar( _lraVar ),
78  mActivity( 0 ),
79  mLinear( true ),
80  mIntervalPos( _intervalPos ),
81  mUpdated( std::make_pair(Updated::NONE,Updated::NONE) ),
82  mInternalLeftBound( FormulaT( carl::FormulaType::TRUE ) ),
83  mInternalRightBound( FormulaT( carl::FormulaType::TRUE ) ),
84  mExternalLeftBound( _defaultPosition ),
85  mExternalRightBound( _defaultPosition ),
86  mDefaultPosition( _defaultPosition )
87  {}
88 
90  {}
91 
92  /*
93  * Getter/Setter
94  */
95 
96  carl::Variable::Arg var() const
97  {
98  return mVar;
99  }
100 
102  {
103  return mCandidates;
104  }
105 
106  const LRAVariable* lraVar() const
107  {
108  return mLraVar;
109  }
110 
111  void addCandidate( ContractionCandidate* _candidate )
112  {
113  auto res = mCandidates.insert( _candidate );
114  if( res.second )
115  {
116  (*res.first)->addICPVariable( this );
117  mLinear &= !(*res.first)->is_linear();
118  }
119  }
120 
121  void addCandidates( const ContractionCandidates& _candidates )
122  {
123  for( auto& cc : _candidates )
124  {
125  assert( mCandidates.find( cc ) == mCandidates.end() );
126  cc->addICPVariable( this );
127  mLinear &= !cc->is_linear();
128  }
129  mCandidates.insert( _candidates.begin(), _candidates.end() );
130  }
131 
132  void addOriginalConstraint( const FormulaT& _constraint )
133  {
134  assert( isOriginal() );
135  mOriginalConstraints.insert( _constraint );
136  }
137 
138  void removeOriginalConstraint( const FormulaT& _constraint )
139  {
140  assert( isOriginal() );
141  mOriginalConstraints.erase( _constraint );
142  }
143 
144  void setLraVar( const LRAVariable* _lraVar )
145  {
146  assert( mLraVar == NULL );
147  mLraVar = _lraVar;
148  mUpdated = std::make_pair(Updated::BOTH,Updated::BOTH);
149  }
150 
151  void print( std::ostream& _out = std::cout, bool _withContractionCandidates = false ) const
152  {
153  _out << "Original: " << mOriginal << ", " << mVar << ", ";
154  if( mLinear && (mLraVar != NULL) )
155  {
156  mLraVar->print();
157  }
158  _out << std::endl;
159  if( _withContractionCandidates )
160  {
161 
162  _out << " Contraction candidates:" << std::endl;
163  for( auto& cc : mCandidates )
164  {
165  _out << " ";
166  cc->print( _out );
167  }
168  }
169  }
170 
171  bool isActive() const
172  {
173  return isOriginal() ? !mOriginalConstraints.empty() : (mActivity > 0);
174  }
175 
177  {
178  ++mActivity;
179  }
180 
182  {
183  assert( mActivity > 0 );
184  --mActivity;
185  }
186 
187  bool is_linear()
188  {
189  return mLinear;
190  }
191 
192  EvalDoubleIntervalMap::const_iterator intervalPosition() const
193  {
194  return mIntervalPos;
195  }
196 
197  const DoubleInterval& interval() const
198  {
199  return mIntervalPos->second;
200  }
201 
202  void setInterval( const DoubleInterval& _interval )
203  {
204  if( _interval.lower_bound_type() != mIntervalPos->second.lower_bound_type() || _interval.lower() != mIntervalPos->second.lower() )
205  {
207  mUpdated.second = (mUpdated.second == Updated::BOTH || mUpdated.second == Updated::RIGHT) ? Updated::BOTH : Updated::LEFT;
208  }
209  if( _interval.upper_bound_type() != mIntervalPos->second.upper_bound_type() || _interval.upper() != mIntervalPos->second.upper() )
210  {
212  mUpdated.second = (mUpdated.second == Updated::BOTH || mUpdated.second == Updated::LEFT) ? Updated::BOTH : Updated::RIGHT;
213  }
214  mIntervalPos->second = _interval;
215  }
216 
218  {
219  mUpdated = std::make_pair( Updated::NONE, Updated::NONE );
220  }
221 
223  {
224  mUpdated = std::make_pair( mUpdated.first, Updated::NONE );
225  }
226 
228  {
229  mUpdated = std::make_pair( mUpdated.first, Updated::BOTH );
230  }
231 
233  {
234  mUpdated = std::make_pair( Updated::NONE, mUpdated.second );
235  }
236 
238  {
239  return mUpdated.first;
240  }
241 
243  {
244  return mUpdated.second;
245  }
246 
248  {
249  return mInternalLeftBound;
250  }
251 
253  {
254  return mInternalRightBound;
255  }
256 
258  {
259  return mExternalLeftBound;
260  }
261 
263  {
264  return mExternalRightBound;
265  }
266 
268  {
269  mInternalLeftBound = _left;
270  }
271 
273  {
274  mInternalRightBound = _right;
275  }
276 
278  {
279  mExternalLeftBound = _left;
280  }
281 
283  {
284  mExternalRightBound = _right;
285  }
286 
288  {
289  if( !mInternalLeftBound.is_true() )
290  {
291  if( !mInternalRightBound.is_true() )
292  return Updated::BOTH;
293  return Updated::LEFT;
294  }
295  return Updated::RIGHT;
296  }
297 
298  bool isOriginal() const
299  {
300  return mOriginal;
301  }
302 
303  bool operator< (IcpVariable const& rhs) const
304  {
305  return (this->mVar < rhs.var());
306  }
307 
308  friend std::ostream& operator<<( std::ostream& os, const IcpVariable& _var )
309  {
310  os << _var.var() << " [Orig.: " << _var.isOriginal() << ", act.: " << _var.isActive() << "]";
311  if( _var.mLraVar != NULL )
312  {
313  os << std::endl;
314  _var.mLraVar->print(os);
315  os << std::endl;
316  _var.mLraVar->printAllBounds(os);
317  }
318  return os;
319  }
320 
321  private:
322 
323  /*
324  * Auxiliary functions
325  */
326  };
327 
329  {
330  bool operator() (const IcpVariable* const _lhs, const IcpVariable* const _rhs ) const
331  {
332  return (_lhs->var() < _rhs->var());
333  }
334  };
335 
336  typedef std::set<const IcpVariable*, icpVariableComp> set_icpVariable;
337 } // namespace icp
338 } // namespace smtrat
super::iterator iterator
Passing through the list::iterator.
Definition: ModuleInput.h:144
smtrat::FormulaT mInternalRightBound
Definition: IcpVariable.h:55
carl::Variable::Arg var() const
Definition: IcpVariable.h:96
Updated isExternalUpdated() const
Definition: IcpVariable.h:242
EvalDoubleIntervalMap::iterator mIntervalPos
Definition: IcpVariable.h:49
void removeOriginalConstraint(const FormulaT &_constraint)
Definition: IcpVariable.h:138
bool operator<(IcpVariable const &rhs) const
Definition: IcpVariable.h:303
ModuleInput::iterator externalRightBound() const
Definition: IcpVariable.h:262
void setInternalLeftBound(const smtrat::FormulaT &_left)
Definition: IcpVariable.h:267
const LRAVariable * mLraVar
Definition: IcpVariable.h:46
ModuleInput::iterator externalLeftBound() const
Definition: IcpVariable.h:257
void addOriginalConstraint(const FormulaT &_constraint)
Definition: IcpVariable.h:132
const LRAVariable * lraVar() const
Definition: IcpVariable.h:106
const DoubleInterval & interval() const
Definition: IcpVariable.h:197
Updated isInternalUpdated() const
Definition: IcpVariable.h:237
void setExternalRightBound(ModuleInput::iterator _right)
Definition: IcpVariable.h:282
Updated isInternalBoundsSet() const
Definition: IcpVariable.h:287
const smtrat::FormulaT & internalRightBound() const
Definition: IcpVariable.h:252
FormulaSetT mOriginalConstraints
Definition: IcpVariable.h:45
ContractionCandidates mCandidates
Definition: IcpVariable.h:44
void print(std::ostream &_out=std::cout, bool _withContractionCandidates=false) const
Definition: IcpVariable.h:151
void setInternalRightBound(const smtrat::FormulaT &_right)
Definition: IcpVariable.h:272
IcpVariable(carl::Variable::Arg _var, bool _original, ModuleInput::iterator _defaultPosition, EvalDoubleIntervalMap::iterator _intervalPos, const LRAVariable *_lraVar=NULL)
Definition: IcpVariable.h:68
const smtrat::FormulaT & internalLeftBound() const
Definition: IcpVariable.h:247
void addCandidates(const ContractionCandidates &_candidates)
Definition: IcpVariable.h:121
std::pair< Updated, Updated > mBoundsSet
Definition: IcpVariable.h:52
ContractionCandidates & candidates()
Definition: IcpVariable.h:101
ModuleInput::iterator mExternalLeftBound
Definition: IcpVariable.h:56
std::pair< Updated, Updated > mUpdated
Definition: IcpVariable.h:53
friend std::ostream & operator<<(std::ostream &os, const IcpVariable &_var)
Definition: IcpVariable.h:308
void setInterval(const DoubleInterval &_interval)
Definition: IcpVariable.h:202
carl::Variable mVar
Definition: IcpVariable.h:42
void addCandidate(ContractionCandidate *_candidate)
Definition: IcpVariable.h:111
smtrat::FormulaT mInternalLeftBound
Definition: IcpVariable.h:54
ModuleInput::iterator mExternalRightBound
Definition: IcpVariable.h:57
void setExternalLeftBound(ModuleInput::iterator _left)
Definition: IcpVariable.h:277
void setLraVar(const LRAVariable *_lraVar)
Definition: IcpVariable.h:144
ModuleInput::iterator mDefaultPosition
Definition: IcpVariable.h:58
EvalDoubleIntervalMap::const_iterator intervalPosition() const
Definition: IcpVariable.h:192
void print(std::ostream &_out=std::cout) const
void printAllBounds(std::ostream &_out=std::cout, const std::string _init="") const
LRAModule< LRASettings1 >::LRAVariable LRAVariable
Definition: IcpVariable.h:33
std::set< const IcpVariable *, icpVariableComp > set_icpVariable
Definition: IcpVariable.h:336
Class to create the formulas for axioms.
@ NONE
Definition: types.h:53
carl::FormulaSet< Poly > FormulaSetT
Definition: types.h:41
std::set< icp::ContractionCandidate *, icp::contractionCandidateComp > ContractionCandidates
Definition: IcpVariable.h:18
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Interval< double > DoubleInterval
Definition: model.h:26
bool operator()(const IcpVariable *const _lhs, const IcpVariable *const _rhs) const
Definition: IcpVariable.h:330