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 <utility>
13#include "codac2_Ctc.h"
14#include "codac2_SlicedTube.h"
15
16namespace codac2
17{
30 class CtcEval
31 {
32 public:
33
38 { }
39
52 template<typename T>
53 void contract(Interval& t, T& z, SlicedTube<T>& x, const SlicedTube<T>& v) const
54 requires std::is_same_v<T,Interval> || std::is_same_v<T,IntervalVector>
55 {
56 contract_impl<T>(t,z,x,v,nullptr);
57 }
58
82 template<typename T>
83 void contract(Interval& t, T& z, SlicedTube<T>& x, const SlicedTube<T>& v,
84 const std::pair<SlicedTube<T>,SlicedTube<T>>& primitives) const
85 requires std::is_same_v<T,Interval> || std::is_same_v<T,IntervalVector>
86 {
87 assert_release(x.tdomain() == v.tdomain());
88 assert_release(primitives.first.tdomain() == v.tdomain());
89 assert_release(primitives.second.tdomain() == v.tdomain());
90 contract_impl(t,z,x,v,&primitives);
91 }
92
93 private:
94
95 template<typename T>
96 void contract_impl(Interval& t, T& z, SlicedTube<T>& x, const SlicedTube<T>& v,
97 const std::pair<SlicedTube<T>,SlicedTube<T>>* primitives) const
98 {
99 assert_release(TDomain::are_same(x.tdomain(), v.tdomain()));
100 assert_release(x.size() == v.size());
101 assert_release(z.size() == x.size());
102
103 if(t.is_empty() || z.is_empty() || x.is_empty() || v.is_empty())
104 {
105 t.set_empty();
106 z.set_empty();
107 x.set(x.empty_value());
108 return;
109 }
110
111 t &= x.invert(z, v, t);
112
113 if(!t.is_empty())
114 {
115 z &= x(t, v);
116
117 if(t.is_degenerated())
118 {
119 x.set(x(t.lb()) & z, t.lb());
120 // This will create a new gate at t
121 return;
122 }
123
124 // Sampling the tube with the creation of two gates
125 auto it_t_beg = x.tdomain()->sample(t.lb(),true);
126 auto it_t = it_t_beg;
127 auto it_t_end = std::next(x.tdomain()->sample(t.ub(),true));
128
129 // For each t in [t]
130 while(it_t != it_t_end)
131 {
132 if(it_t->is_gate())
133 {
134 T slices_union = x.empty_value();
135
136 // For each t1 in [t]
137 auto it_t1 = it_t_beg;
138 auto it_t1_end = it_t_end;
139 while(it_t1 != it_t1_end)
140 {
141 if(it_t1->is_gate())
142 {
143 T y1 = x(it_t1->lb()) & z;
144
145 if(!y1.is_empty())
146 {
147 // Transporting y1 to t
148 if(it_t1 != it_t)
149 {
150 if(primitives)
151 y1 += v.integral(Interval(it_t1->lb()),Interval(it_t->lb()),*primitives);
152 else
153 y1 += v.integral(Interval(it_t1->lb()),Interval(it_t->lb()));
154 }
155
156 slices_union |= y1;
157 }
158 }
159
160 it_t1++;
161 }
162
163 x.slice(it_t)->set(slices_union);
164 }
165
166 it_t++;
167 }
168
169 CtcDeriv ctc_deriv(TimePropag::FWD_BWD, true);
170 ctc_deriv.restrict_tdomain(t);
171 ctc_deriv.contract(x,v);
172 }
173
174 if(t.is_empty() || z.is_empty() || x.is_empty())
175 {
176 t.set_empty();
177 z.set_empty();
178 x.set(x.empty_value());
179 }
180 }
181 };
182}
void contract(Interval &t, T &z, SlicedTube< T > &x, const SlicedTube< T > &v) const
: contracts the observation and the tube subject to and .
Definition codac2_CtcEval.h:53
CtcEval()
Creates the evaluation contractor .
Definition codac2_CtcEval.h:37
void contract(Interval &t, T &z, SlicedTube< T > &x, const SlicedTube< T > &v, const std::pair< SlicedTube< T >, SlicedTube< T > > &primitives) const
: contracts the observation and the tube subject to and , using precomputed partial primitives of ...
Definition codac2_CtcEval.h:83
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:50
bool is_empty() const
Tests if this is empty.
Definition codac2_Interval_impl.h:221
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:131
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:241
void set_empty()
Sets this interval to the empty set.
Definition codac2_Interval_impl.h:216
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:126
Tube represented over a sliced temporal domain.
Definition codac2_SlicedTube.h:38
void set(const T &codomain)
Sets all codomains of this tube to the same value.
Definition codac2_SlicedTube.h:443
T empty_value() const
Returns the empty codomain value associated with T.
Definition codac2_SlicedTube.h:1225
Index size() const
Returns the codomain dimension.
Definition codac2_SlicedTube.h:163
bool is_empty() const
Tests whether this tube is empty.
Definition codac2_SlicedTube.h:315
Interval invert(const T &y) const
Returns the interval inversion .
Definition codac2_SlicedTube.h:793
std::shared_ptr< Slice< T > > slice(const std::list< TSlice >::iterator &it)
Returns the slice attached to a temporal iterator.
Definition codac2_SlicedTube.h:249
static bool are_same(const std::shared_ptr< const TDomain > &tdom1, const std::shared_ptr< const TDomain > &tdom2)
Tests whether two temporal domains share the same temporal partition.
const std::shared_ptr< TDomain > & tdomain() const
Returns the temporal domain of this tube.
Definition codac2_TubeBase.h:49
T integral(const Interval &t) const
Returns an enclosure of the integrals of this tube from to .
Definition codac2_SlicedTube_integral_impl.h:20
Definition codac2_OctaSym.h:21