codac 2.0.0
Loading...
Searching...
No Matches
codac2::CtcInter< X > Class Template Reference

Sequential intersection of several contractors: More...

#include <codac2_CtcInter.h>

Public Member Functions

 CtcInter (Index n)
 Builds a neutral intersection contractor with a prescribed domain size.
template<typename C>
 CtcInter (const C &c)
 Builds an intersection contractor from a single contractor.
template<typename... C>
 CtcInter (const C &... c)
 Builds an intersection contractor from several contractors.
size_t nb () const
 Returns the number of stored contractors.
void contract (X &... x) const
 Contracts the given domain(s) by applying all stored contractors in sequence.
template<typename C>
CtcInter< X... > & operator&= (const C &c)
 Appends a contractor to the current intersection.

Protected Attributes

Collection< CtcBase< X... > > _ctcs
 Internal collection of contractors composing the intersection.

Detailed Description

template<typename... X>
class codac2::CtcInter< X >

Sequential intersection of several contractors:

\[\mathcal{C}_{\mathrm{inter}} = \mathcal{C}_1 \cap \mathcal{C}_2 \cap \dots \cap \mathcal{C}_n. \]

Each sub-contractor is applied successively to the current domain. If two contractors implement two constraints, then their intersection corresponds to the logical conjunction of these constraints. This corresponds to the classical intersection/composition pattern of contractor programming.

CtcInter stores a collection of contractors acting on the same contracted types and applies them one after the other. For instance, for contractors acting on a single box \([\mathbf{x}]\):

\[\left(\mathcal{C}_1 \cap \mathcal{C}_2\right)([\mathbf{x}]) := \mathcal{C}_1([\mathbf{x}]) \cap \mathcal{C}_2([\mathbf{x}]). \]

In practice, each stored contractor contracts the current domain in place; the next one then works on the already reduced result. It does not perform any fixpoint iteration. If the domain becomes empty at some step, the contraction stops immediately.

A CtcInter object can be built explicitly, extended incrementally with &=, or constructed implicitly with the binary & operator between two contractors.

In C++, a variadic .contract(..) function is available when the intersected contractors act on several domains rather than on a single box. Such contractors can be combined provided they are homogeneous, i.e. they act on the same sequence of input types.

Template Parameters
XContracted domain type(s). For the common box-contractor case, this is typically IntervalVector.

Constructor & Destructor Documentation

◆ CtcInter() [1/3]

template<typename... X>
codac2::CtcInter< X >::CtcInter ( Index n)
inlineexplicit

Builds a neutral intersection contractor with a prescribed domain size.

This constructor is mainly useful when building a contractor incrementally with operator&=. Otherwise it has no effect.

Parameters
nDimension of the contracted object.
Note
When X... is Interval, the size must be 1.
69 : Ctc<CtcInter<X...>,X...>(n)
70 {
71 if constexpr(std::is_same_v<X...,Interval>)
72 {
73 assert(n == 1);
74 }
75 }
Sequential intersection of several contractors:
Definition codac2_CtcInter.h:55
CtcInter(Index n)
Builds a neutral intersection contractor with a prescribed domain size.
Definition codac2_CtcInter.h:68

◆ CtcInter() [2/3]

template<typename... X>
template<typename C>
codac2::CtcInter< X >::CtcInter ( const C & c)
inline

Builds an intersection contractor from a single contractor.

The contractor is stored internally in the collection of composed contractors.

Template Parameters
CType of the contractor or contractor pointer.
Parameters
cContractor to store.
88 : Ctc<CtcInter<X...>,X...>(size_of(c)), _ctcs(c)
89 { }
Collection< CtcBase< X... > > _ctcs
Internal collection of contractors composing the intersection.
Definition codac2_CtcInter.h:157

◆ CtcInter() [3/3]

template<typename... X>
template<typename... C>
codac2::CtcInter< X >::CtcInter ( const C &... c)
inline

Builds an intersection contractor from several contractors.

All contractors must act on contracted objects of the same size.

Template Parameters
CContractor or contractor-pointer types.
Parameters
cContractors to compose sequentially.
102 : Ctc<CtcInter<X...>,X...>(size_first_item(c...)), _ctcs(c...)
103 {
105 }

Member Function Documentation

◆ nb()

template<typename... X>
size_t codac2::CtcInter< X >::nb ( ) const
inline

Returns the number of stored contractors.

Returns
Size of the internal contractor collection.
113 {
114 return _ctcs.size();
115 }

◆ contract()

template<typename... X>
void codac2::CtcInter< X >::contract ( X &... x) const
inline

Contracts the given domain(s) by applying all stored contractors in sequence.

The domains are updated in place. If one contractor empties one of the domains, the remaining contractors are not evaluated.

Parameters
xDomain(s) to contract.
126 {
127 for(const auto& ci : _ctcs)
128 {
129 ci->contract(x...);
130 if((x.is_empty() | ...))
131 return;
132 }
133 }
void contract(X &... x) const
Contracts the given domain(s) by applying all stored contractors in sequence.
Definition codac2_CtcInter.h:125

◆ operator&=()

template<typename... X>
template<typename C>
CtcInter< X... > & codac2::CtcInter< X >::operator&= ( const C & c)
inline

Appends a contractor to the current intersection.

The contractor is added at the end of the internal sequence, so it will be applied after the already stored ones.

Template Parameters
CType of the contractor or contractor pointer.
Parameters
cContractor to append.
Returns
A reference to *this.
148 {
149 assert_release(size_of(c) == this->size());
150 _ctcs.push_back(c);
151 return *this;
152 }

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