codac 2.0.0
Loading...
Searching...
No Matches
codac2_CtcEval.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Ctc.h"
13#include "codac2_SlicedTube.h"
14
15namespace codac2
16{
17 class CtcEval
18 {
19 public:
20
21 CtcEval()
22 { }
23
24 template<typename T>
25 void contract(Interval& t, T& z, SlicedTube<T>& x, const SlicedTube<T>& v) const
26 requires std::is_same_v<T,Interval> || std::is_same_v<T,IntervalVector>
27 {
28 assert_release(TDomain::are_same(x.tdomain(), v.tdomain()));
29 assert_release(x.size() == v.size());
30 assert_release(z.size() == x.size());
31
32 if(t.is_empty() || z.is_empty() || x.is_empty() || v.is_empty())
33 {
34 t.set_empty();
35 z.set_empty();
36 x.set(x.empty_value());
37 return;
38 }
39
40 t &= x.invert(z, v, t);
41
42 if(!t.is_empty())
43 {
44 z &= x(t, v);
45
46 if(t.is_degenerated())
47 {
48 x.set(x(t.lb()) & z, t.lb());
49 // This will create a new gate at t
50 return;
51 }
52
53 // Sampling the tube with the creation of two gates
54 auto it_t_beg = x.tdomain()->sample(t.lb(),true);
55 auto it_t = it_t_beg;
56 auto it_t_end = std::next(x.tdomain()->sample(t.ub(),true));
57
58 // For each t in [t]
59 while(it_t != it_t_end)
60 {
61 if(it_t->is_gate())
62 {
63 T slices_union = x.empty_value();
64
65 // For each t1 in [t]
66 auto it_t1 = x.tdomain()->sample(t.lb(),true);
67 auto it_t1_end = it_t_end;
68 while(it_t1 != it_t1_end)
69 {
70 if(it_t1->is_gate())
71 {
72 T y1 = x(it_t1->lb()) & z;
73
74 if(!y1.is_empty())
75 {
76 // Transporting y1 to t
77 auto it_t1_t = it_t1;
78 auto it_t1_t_end = it_t;
79 while(it_t1_t != it_t1_t_end)
80 {
81 if(!it_t1_t->is_gate())
82 {
83 // /!\ .diam() method is not reliable (floating point result)
84 // -> We need to compute the diameter with intervals
85 Interval d = Interval(it_t1_t->ub())-Interval(it_t1_t->lb());
86 if(it_t1->lb() > it_t->lb())
87 d *= -1; // going backward
88 y1 += d*v.slice(it_t1_t)->codomain();
89 }
90
91 if(it_t1->lb() < it_t->lb())
92 it_t1_t++;
93 else
94 it_t1_t--;
95 }
96
97 slices_union |= y1;
98 }
99 }
100
101 it_t1++;
102 }
103
104 x.slice(it_t)->set(slices_union);
105 }
106
107 it_t++;
108 }
109
110 CtcDeriv ctc_deriv(TimePropag::FWD_BWD, true);
111 ctc_deriv.restrict_tdomain(t);
112 ctc_deriv.contract(x,v);
113 }
114
115 if(t.is_empty() || z.is_empty() || x.is_empty())
116 {
117 t.set_empty();
118 z.set_empty();
119 x.set(x.empty_value());
120 }
121 }
122 };
123}
Definition codac2_OctaSym.h:21