codac
codac_CtcUnion.h
Go to the documentation of this file.
1 
12 #ifndef __CODAC_CTCUNION_H__
13 #define __CODAC_CTCUNION_H__
14 
15 #include <memory>
16 //#include "ibex_CtcUnion.h"
17 #include "codac_Ctc.h"
18 
19 namespace codac
20 {
21  class MultiCtc : public Ctc
22  {
23  public:
24 
25  MultiCtc(int nb_var) : Ctc(nb_var)
26  { }
27 
28  template<typename C1>
29  MultiCtc(const C1& c1) : Ctc(c1.nb_var)
30  {
31  add_shared_ptr(std::make_shared<C1>(c1));
32  }
33 
34  template<typename C1,typename... C>
35  MultiCtc(const C1& c1, const C&... c) : MultiCtc(c1)
36  {
37  (add_shared_ptr(std::make_shared<C>(c)), ...);
38  for(const auto& ci : _v_ctc) { assert(ci->nb_var == nb_var); }
39  }
40 
41  template<typename T>
42  void add_shared_ptr(std::shared_ptr<T> shrd_ptr)
43  {
44  _v_ctc.push_back(shrd_ptr);
45  _v_ctc_ptrs.push_back(shrd_ptr.get());
46  }
47 
48  void add_raw_ptr(Ctc *c)
49  {
50  _v_ctc_ptrs.push_back(c);
51  }
52 
53  protected:
54 
55  std::vector<std::shared_ptr<Ctc>> _v_ctc;
56  std::vector<Ctc*> _v_ctc_ptrs;
57  };
58 
59  class CtcUnion : public MultiCtc
60  {
61  public:
62 
63  CtcUnion(int nb_var) : MultiCtc(nb_var)
64  { }
65 
66  template<typename C1>
67  CtcUnion(const C1& c1) : MultiCtc(c1)
68  { }
69 
70  template<typename C1,typename... C>
71  CtcUnion(const C1& c1, const C&... c) : MultiCtc(c1, c...)
72  { }
73 
74  void contract(IntervalVector& x)
75  {
76  IntervalVector result(nb_var, Interval::empty_set());
77 
78  for(auto& ci : _v_ctc_ptrs)
79  {
80  IntervalVector saved_x = x;
81  ci->contract(saved_x);
82  result |= saved_x;
83  }
84 
85  x = result;
86  }
87 
88  template<typename C>
89  CtcUnion& operator|=(const C& c)
90  {
91  assert(c.nb_var == nb_var);
92  add_shared_ptr(std::make_shared<C>(c));
93  return *this;
94  }
95  };
96 }
97 
98 #endif
FixPoint of a separator The fixpoint of a separator is computed by calling the "::"separate function ...
Definition: codac_capd_helpers.h:9