codac 2.0.0
Loading...
Searching...
No Matches
codac2::Slice< T > Class Template Reference

Codomain of a sliced tube over one temporal slice. More...

#include <codac2_Slice.h>

Inheritance diagram for codac2::Slice< T >:
Collaboration diagram for codac2::Slice< T >:

Public Member Functions

 Slice (const SlicedTubeBase &tube, const std::list< TSlice >::iterator &it_tslice, const T &codomain)
 Creates a slice attached to a tube over a temporal slice.
 Slice (const Slice &s, const SlicedTubeBase &tube)
 Creates a slice from another one for a given tube.
const SlicedTube< T > & tube () const
 Returns the sliced tube owning this slice.
std::shared_ptr< SliceBasecopy () const override
 Duplicates this slice.
Index size () const
 Returns the codomain dimension.
T & codomain ()
 Returns a mutable reference to the codomain.
const T & codomain () const
 Returns a constant reference to the codomain.
bool is_gate () const
 Tests whether this slice is a gate.
std::shared_ptr< const Slice< T > > prev_slice () const
 Returns the previous slice.
std::shared_ptr< Slice< T > > prev_slice ()
 Returns the previous slice.
std::shared_ptr< const Slice< T > > next_slice () const
 Returns the next slice.
std::shared_ptr< Slice< T > > next_slice ()
 Returns the next slice.
input_gate () const
 Returns the input gate of this slice.
output_gate () const
 Returns the output gate of this slice.
std::pair< T, T > enclosed_bounds (const Interval &t) const
 Returns enclosed lower and upper bounds over a temporal interval.
void set (const T &x, bool propagate=true)
 Sets the codomain of this slice.
void init ()
 Initializes this codomain to its unbounded value.
void set_empty ()
 Sets this codomain to the empty set.
bool operator== (const Slice &x) const
 Compares two slices.
ConvexPolygon polygon_slice (const Slice< T > &v) const
 Returns the polygonal enclosure associated with this scalar slice.
ConvexPolygon polygon_slice_i (const Slice< T > &v, Index i) const
 Returns the polygonal enclosure associated with one component of a vector slice.
operator() (double t) const
 Returns the evaluation of this slice at \(t\).
operator() (const Interval &t) const
 Returns the evaluation of this slice over \([t]\).
operator() (double t, const Slice< T > &v) const
 Returns the optimal evaluation of this slice at \(t\), based on the derivative information \(\llbracket v\rrbracket(\cdot)\).
operator() (const Interval &t, const Slice< T > &v) const
 Returns the optimal evaluation of this slice over \([t]\), based on the derivative information \(\llbracket v\rrbracket(\cdot)\).
Interval invert (const T &y, const Interval &t=Interval()) const
 Returns the interval inversion \(\llbracket x\rrbracket^{-1}([y])\).
Interval invert (const T &y, const Slice< T > &v, const Interval &t=Interval()) const
 Returns the optimal interval inversion \(\llbracket x\rrbracket^{-1}([y])\).
all_reals_value () const
 Returns the unbounded value associated with this codomain type.
empty_value () const
 Returns the empty value associated with this codomain type.
Public Member Functions inherited from codac2::SliceBase
virtual ~SliceBase ()=default
 Virtual destructor.
const Intervalt0_tf () const
 Returns the temporal domain of this slice.
const TSlicetslice () const
 Returns the temporal slice associated with this object.
std::shared_ptr< const SliceBaseprev_slice () const
 Returns the previous slice of the same tube.
std::shared_ptr< const SliceBasenext_slice () const
 Returns the next slice of the same tube.

Protected Member Functions

void set_empty (bool propagate)
 Sets this codomain to the empty set.
void update_adjacent_codomains ()
 Propagates codomain contractions to adjacent gates.
Protected Member Functions inherited from codac2::SliceBase
 SliceBase (const SlicedTubeBase &tube, const std::list< TSlice >::iterator &it_tslice)
 Creates a slice attached to a tube and a temporal slice.

Additional Inherited Members

Protected Attributes inherited from codac2::SliceBase
const SlicedTubeBase_tube
 Parent sliced tube.
std::list< TSlice >::iterator _it_tslice
 Iterator to the associated temporal slice.

Detailed Description

template<class T>
class codac2::Slice< T >

Codomain of a sliced tube over one temporal slice.

A Slice<T> represents the codomain of a SlicedTube<T> over one temporal interval of a TDomain.

This object is attached to one temporal slice TSlice and stores a codomain of type T. The type T is typically Interval or IntervalVector, or any custom domain implemented by the user.

The inheritance from T is protected so that modifications of the codomain remain controlled by the Slice interface. Indeed, changing the codomain of a slice may require propagating contractions to adjacent gates.

Template Parameters
Tcodomain type

Constructor & Destructor Documentation

◆ Slice() [1/2]

template<class T>
codac2::Slice< T >::Slice ( const SlicedTubeBase & tube,
const std::list< TSlice< T > >::iterator & it_tslice,
const T & codomain )
inlineexplicit

Creates a slice attached to a tube over a temporal slice.

Parameters
tubesliced tube owning this slice
it_tsliceiterator to the associated temporal slice
codomaincodomain associated with this slice
54 { }
SliceBase(const SlicedTubeBase &tube, const std::list< TSlice >::iterator &it_tslice)
Creates a slice attached to a tube and a temporal slice.
Codomain of a sliced tube over one temporal slice.
Definition codac2_Slice.h:42
T & codomain()
Returns a mutable reference to the codomain.
Definition codac2_Slice.h:113
const SlicedTube< T > & tube() const
Returns the sliced tube owning this slice.
Definition codac2_Slice.h:81

◆ Slice() [2/2]

template<class T>
codac2::Slice< T >::Slice ( const Slice< T > & s,
const SlicedTubeBase & tube )
inline

Creates a slice from another one for a given tube.

This constructor duplicates the codomain and keeps the same temporal support.

Parameters
ssource slice
tubesliced tube owning the copied slice
67 { }
std::list< TSlice >::iterator _it_tslice
Iterator to the associated temporal slice.
Definition codac2_SliceBase.h:115

Member Function Documentation

◆ tube()

template<class T>
const SlicedTube< T > & codac2::Slice< T >::tube ( ) const
inline

Returns the sliced tube owning this slice.

Returns
reference to the parent sliced tube
82 {
83 return static_cast<const SlicedTube<T>&>(_tube);
84 }
const SlicedTubeBase & _tube
Parent sliced tube.
Definition codac2_SliceBase.h:110

◆ copy()

template<class T>
std::shared_ptr< SliceBase > codac2::Slice< T >::copy ( ) const
inlineoverridevirtual

Duplicates this slice.

Returns
shared pointer to a copy of this slice

Implements codac2::SliceBase.

92 {
93 return std::make_shared<Slice>(*this, this->_tube);
94 }

◆ size()

template<class T>
Index codac2::Slice< T >::size ( ) const
inline

Returns the codomain dimension.

Returns
size of the codomain
102 {
103 return this->T::size();
104 }

◆ codomain() [1/2]

template<class T>
T & codac2::Slice< T >::codomain ( )
inline

Returns a mutable reference to the codomain.

Note
Prefer set() when adjacency propagation is required.
Returns
mutable reference to the codomain
114 {
115 return static_cast<T&>(*this);
116 }

◆ codomain() [2/2]

template<class T>
const T & codac2::Slice< T >::codomain ( ) const
inline

Returns a constant reference to the codomain.

Returns
constant reference to the codomain
124 {
125 return static_cast<const T&>(*this);
126 }

◆ is_gate()

template<class T>
bool codac2::Slice< T >::is_gate ( ) const
inline

Tests whether this slice is a gate.

A slice is considered a gate when its temporal support is degenerate.

Returns
true if this slice is a gate, false otherwise
136 {
137 return t0_tf().is_degenerated();
138 }
bool is_degenerated() const
Tests if this is degenerated, that is, in the form of .
Definition codac2_Interval_impl.h:225
const Interval & t0_tf() const
Returns the temporal domain of this slice.

◆ prev_slice() [1/2]

template<class T>
std::shared_ptr< const Slice< T > > codac2::Slice< T >::prev_slice ( ) const
inline

Returns the previous slice.

Returns
shared pointer to the previous slice, or nullptr if none exists
146 {
148 this->SliceBase::prev_slice());
149 }
std::shared_ptr< const SliceBase > prev_slice() const
Returns the previous slice of the same tube.

◆ prev_slice() [2/2]

template<class T>
std::shared_ptr< Slice< T > > codac2::Slice< T >::prev_slice ( )
inline

Returns the previous slice.

Returns
shared pointer to the previous slice, or nullptr if none exists
157 {
159 static_cast<const Slice<T>&>(*this).prev_slice());
160 }
Slice(const SlicedTubeBase &tube, const std::list< TSlice >::iterator &it_tslice, const T &codomain)
Creates a slice attached to a tube over a temporal slice.
Definition codac2_Slice.h:52

◆ next_slice() [1/2]

template<class T>
std::shared_ptr< const Slice< T > > codac2::Slice< T >::next_slice ( ) const
inline

Returns the next slice.

Returns
shared pointer to the next slice, or nullptr if none exists
168 {
170 this->SliceBase::next_slice());
171 }
std::shared_ptr< const SliceBase > next_slice() const
Returns the next slice of the same tube.

◆ next_slice() [2/2]

template<class T>
std::shared_ptr< Slice< T > > codac2::Slice< T >::next_slice ( )
inline

Returns the next slice.

Returns
shared pointer to the next slice, or nullptr if none exists
179 {
181 static_cast<const Slice<T>&>(*this).next_slice());
182 }

◆ input_gate()

template<class T>
T codac2::Slice< T >::input_gate ( ) const
inline

Returns the input gate of this slice.

If the previous temporal element is an explicit gate, its codomain is returned. Otherwise, the returned value is the intersection between this codomain and the codomain of the previous slice. If no previous slice exists, the codomain of this slice is returned.

Returns
enclosure of the input gate
195 {
196 if(!prev_slice())
197 return codomain();
198
199 else
200 {
201 if(prev_slice()->is_gate())
202 return prev_slice()->codomain();
203 else
204 return codomain() & prev_slice()->codomain();
205 }
206 }
bool is_gate() const
Tests whether this slice is a gate.
Definition codac2_Slice.h:135
std::shared_ptr< const Slice< T > > prev_slice() const
Returns the previous slice.
Definition codac2_Slice.h:145

◆ output_gate()

template<class T>
T codac2::Slice< T >::output_gate ( ) const
inline

Returns the output gate of this slice.

If the next temporal element is an explicit gate, its codomain is returned. Otherwise, the returned value is the intersection between this codomain and the codomain of the next slice. If no next slice exists, the codomain of this slice is returned.

Returns
enclosure of the output gate
219 {
220 if(!next_slice())
221 return codomain();
222
223 else
224 {
225 if(next_slice()->is_gate())
226 return next_slice()->codomain();
227 else
228 return codomain() & next_slice()->codomain();
229 }
230 }
std::shared_ptr< const Slice< T > > next_slice() const
Returns the next slice.
Definition codac2_Slice.h:167

◆ enclosed_bounds()

template<class T>
std::pair< T, T > codac2::Slice< T >::enclosed_bounds ( const Interval & t) const
inline

Returns enclosed lower and upper bounds over a temporal interval.

This method returns a pair whose first component encloses the reachable lower bounds and whose second component encloses the reachable upper bounds over t.

Parameters
ttemporal interval
Returns
pair made of enclosed lower and upper bounds
243 {
244 T x = *this; x.set_empty();
245 auto bounds = std::make_pair(x,x);
246
247 if(t.lb() < t0_tf().lb() || t.ub() > t0_tf().ub())
248 {
249 x.init(Interval(-oo,0));
250 bounds.first |= x;
251 x.init(Interval(0,oo));
252 bounds.second |= x;
253 }
254
255 if(t.contains(t0_tf().lb()))
256 {
257 bounds.first |= input_gate().lb();
258 bounds.second |= input_gate().ub();
259 }
260
261 if(t.contains(t0_tf().ub()))
262 {
263 bounds.first |= output_gate().lb();
264 bounds.second |= output_gate().ub();
265 }
266
267 if(t.is_subset(t0_tf()) && t != t0_tf().lb() && t != t0_tf().ub())
268 {
269 bounds.first |= this->lb();
270 bounds.second |= this->ub();
271 }
272
273 return bounds;
274 }
T input_gate() const
Returns the input gate of this slice.
Definition codac2_Slice.h:194
void set_empty()
Sets this codomain to the empty set.
Definition codac2_Slice.h:309
T output_gate() const
Returns the output gate of this slice.
Definition codac2_Slice.h:218
void init()
Initializes this codomain to its unbounded value.
Definition codac2_Slice.h:298
auto ub() const
Returns a matrix containing the upper bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:103
auto lb() const
Returns a matrix containing the lower bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:91

◆ set()

template<class T>
void codac2::Slice< T >::set ( const T & x,
bool propagate = true )
inline

Sets the codomain of this slice.

If propagate is set to true, adjacent gates are updated in order to preserve temporal consistency.

Parameters
xnew codomain
propagateif set to true, propagates the update to adjacent gates
286 {
287 assert_release(x.size() == this->size());
288 codomain() = x;
289 if(propagate)
291 }
Index size() const
Returns the codomain dimension.
Definition codac2_Slice.h:101
void update_adjacent_codomains()
Propagates codomain contractions to adjacent gates.
Definition codac2_Slice.h:602

◆ init()

template<class T>
void codac2::Slice< T >::init ( )
inlinevirtual

Initializes this codomain to its unbounded value.

No propagation is performed on adjacent slices.

Implements codac2::SliceBase.

299 {
300 this->T::init();
301 // Nothing to propagate to adjacent codomains
302 }

◆ set_empty() [1/2]

template<class T>
void codac2::Slice< T >::set_empty ( )
inlinevirtual

Sets this codomain to the empty set.

Adjacent gates are updated accordingly.

Implements codac2::SliceBase.

310 {
311 set_empty(true);
312 }

◆ operator==()

template<class T>
bool codac2::Slice< T >::operator== ( const Slice< T > & x) const
inline

Compares two slices.

The comparison only involves the codomain of the slices.

Parameters
xslice to compare with
Returns
true if both codomains are equal, false otherwise
323 {
324 return codomain() == x.codomain();
325 }

◆ polygon_slice()

template<class T>
ConvexPolygon codac2::Slice< T >::polygon_slice ( const Slice< T > & v) const
inline

Returns the polygonal enclosure associated with this scalar slice.

The enclosure is built from the codomain of this slice, its input/output gates and the derivative information provided by v.

Parameters
vderivative slice
Returns
polygonal enclosure of this slice
338 {
339 const Interval& t = this->t0_tf();
340 Interval input = this->input_gate(), output = this->output_gate();
341
342 // /!\ .diam() method is not reliable (floating point result)
343 // -> We need to compute the diameter with intervals
344 Interval d = Interval(t.ub())-Interval(t.lb());
345
348
350 t, *this,
353 v);
354 }

◆ polygon_slice_i()

template<class T>
ConvexPolygon codac2::Slice< T >::polygon_slice_i ( const Slice< T > & v,
Index i ) const
inline

Returns the polygonal enclosure associated with one component of a vector slice.

Parameters
vderivative slice
icomponent index
Returns
polygonal enclosure of the \(i\)-th component
366 {
367 const Interval& t = this->t0_tf();
368
369 // /!\ .diam() method is not reliable (floating point result)
370 // -> We need to compute the diameter with intervals
371 Interval d = Interval(t.ub())-Interval(t.lb());
372
373 Interval input = this->input_gate()[i], output = this->output_gate()[i];
374 Interval proj_output = input + d * v[i];
375 Interval proj_input = output - d * v[i];
376
378 t, (*this)[i],
381 v[i]);
382 }

◆ operator()() [1/4]

template<class T>
T codac2::Slice< T >::operator() ( double t) const
inline

Returns the evaluation of this slice at \(t\).

Parameters
ttemporal input (outside Slice's tdomain, result is unbounded)
Returns
value of \(\llbracket x\rrbracket(t)\)
391 {
392 if(t == t0_tf().lb())
393 return input_gate();
394
395 else if(t == t0_tf().ub())
396 return output_gate();
397
398 else if(t0_tf().contains(t))
399 return codomain();
400
401 else
402 return all_reals_value();
403 }
T all_reals_value() const
Returns the unbounded value associated with this codomain type.
Definition codac2_Slice.h:559
bool contains(const Matrix< double, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks if this interval matrix contains the specified matrix x.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:408

◆ operator()() [2/4]

template<class T>
T codac2::Slice< T >::operator() ( const Interval & t) const
inline

Returns the evaluation of this slice over \([t]\).

Parameters
tInterval temporal input (outside Slice's tdomain, result is unbounded)
Returns
value of \(\llbracket x\rrbracket([t])\)
412 {
413 if(t.is_degenerated())
414 return operator()(t.lb());
415
416 else if(t.is_subset(t0_tf()))
417 return codomain();
418
419 else
420 return all_reals_value();
421 }
T operator()(double t) const
Returns the evaluation of this slice at .
Definition codac2_Slice.h:390

◆ operator()() [3/4]

template<class T>
T codac2::Slice< T >::operator() ( double t,
const Slice< T > & v ) const
inline

Returns the optimal evaluation of this slice at \(t\), based on the derivative information \(\llbracket v\rrbracket(\cdot)\).

Parameters
ttemporal input (outside Slice's tdomain, result is unbounded)
vderivative slice such that \(\dot{x}(\cdot)\in\llbracket v\rrbracket(\cdot)\)
Returns
Interval value of \(\llbracket x\rrbracket(t)\)
433 {
434 return operator()(Interval(t),v);
435 }

◆ operator()() [4/4]

template<class T>
T codac2::Slice< T >::operator() ( const Interval & t,
const Slice< T > & v ) const
inline

Returns the optimal evaluation of this slice over \([t]\), based on the derivative information \(\llbracket v\rrbracket(\cdot)\).

Parameters
tInterval temporal input (outside Slice's tdomain, result is unbounded)
vderivative slice such that \(\dot{x}(\cdot)\in\llbracket v\rrbracket(\cdot)\)
Returns
Interval value of \(\llbracket x\rrbracket([t])\)
447 {
448 if constexpr(std::is_same_v<T,Interval>)
450
451 else if constexpr(std::is_same_v<T,IntervalVector>)
452 {
453 T y = all_reals_value();
455 for(Index i = 0 ; i < size() ; i++)
457 return y;
458 }
459 }
ConvexPolygon polygon_slice_i(const Slice< T > &v, Index i) const
Returns the polygonal enclosure associated with one component of a vector slice.
Definition codac2_Slice.h:364
ConvexPolygon polygon_slice(const Slice< T > &v) const
Returns the polygonal enclosure associated with this scalar slice.
Definition codac2_Slice.h:336

◆ invert() [1/2]

template<class T>
Interval codac2::Slice< T >::invert ( const T & y,
const Interval & t = Interval() ) const
inline

Returns the interval inversion \(\llbracket x\rrbracket^{-1}([y])\).

Parameters
yInterval codomain
toptional interval tdomain on which the inversion will be performed
Returns
hull of \(\llbracket x\rrbracket^{-1}([y])\cap[t]\)
469 {
470 if(t.is_empty())
471 return Interval::empty();
472
473 else if(t.is_strict_superset(t0_tf()))
474 return Interval();
475
476 else if((t0_tf() & t) == t0_tf() && codomain().is_subset(y))
477 return t0_tf();
478
479 else if(t == t0_tf().lb())
480 {
481 if(y.intersects(input_gate()))
482 return t0_tf().lb();
483 else
484 return Interval::empty();
485 }
486
487 else if(t == t0_tf().ub())
488 {
489 if(y.intersects(output_gate()))
490 return t0_tf().ub();
491 else
492 return Interval::empty();
493 }
494
495 else
496 {
497 if(y.intersects(codomain()))
498 return t & t0_tf();
499 else
500 return Interval::empty();
501 }
502 }
double ub() const
Returns the upper bound of this.
Definition codac2_Interval_impl.h:115
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:110
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:568
bool is_subset(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix is a subset of another interval matrix.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:678

◆ invert() [2/2]

template<class T>
Interval codac2::Slice< T >::invert ( const T & y,
const Slice< T > & v,
const Interval & t = Interval() ) const
inline

Returns the optimal interval inversion \(\llbracket x\rrbracket^{-1}([y])\).

Note
The knowledge of the derivative slice \(\llbracket v\rrbracket(\cdot)\) allows a finer inversion.
Parameters
yInterval codomain
vderivative slice such that \(\dot{x}(\cdot)\in\llbracket v\rrbracket(\cdot)\)
tthe optional interval tdomain on which the inversion will be performed
Returns
hull of \(\llbracket x\rrbracket^{-1}([y])\cap[t]\)
516 {
517 if(t.is_empty() || y.is_empty())
518 return Interval::empty();
519
520 else if(!t.is_subset(t0_tf()))
521 return Interval();
522
523 else
524 {
525 if constexpr(std::is_same_v<T,Interval>)
527
528 else if constexpr(std::is_same_v<T,IntervalVector>)
529 {
530 Interval t_(t);
531 for(Index i = 0 ; i < size() ; i++)
532 if(!t_.is_empty())
534 return t_;
535 }
536 }
537 }

◆ all_reals_value()

template<class T>
T codac2::Slice< T >::all_reals_value ( ) const
inline

Returns the unbounded value associated with this codomain type.

Returns
unbounded value of type T
560 {
561 T x = codomain();
562 x.init();
563 return x;
564 }

◆ empty_value()

template<class T>
T codac2::Slice< T >::empty_value ( ) const
inline

Returns the empty value associated with this codomain type.

Returns
empty value of type T
572 {
573 T x = codomain();
574 x.set_empty();
575 return x;
576 }

◆ set_empty() [2/2]

template<class T>
void codac2::Slice< T >::set_empty ( bool propagate)
inlineprotected

Sets this codomain to the empty set.

Parameters
propagateif set to true, propagates the update to adjacent gates
590 {
591 this->T::set_empty();
592 if(propagate)
594 }

◆ update_adjacent_codomains()

template<class T>
void codac2::Slice< T >::update_adjacent_codomains ( )
inlineprotected

Propagates codomain contractions to adjacent gates.

This method preserves consistency between a slice and its neighboring gates when one of them is contracted.

603 {
604 if(prev_slice())
605 {
606 assert(prev_slice()->size() == this->size());
607 if(is_gate())
608 codomain() &= prev_slice()->codomain();
609 else if(prev_slice()->is_gate())
610 prev_slice()->codomain() &= codomain();
611 }
612
613 if(next_slice())
614 {
615 assert(next_slice()->size() == this->size());
616 if(is_gate())
617 codomain() &= next_slice()->codomain();
618 else if(next_slice()->is_gate())
619 next_slice()->codomain() &= codomain();
620 }
621 }

The documentation for this class was generated from the following files: