I use boost ICL to model a mapping of time to states and event, where I model time as double. Some events are momentary, i.e. they do not occur over an interval of time, but rather at a single point of time, which I can model conceptually as a singleton interval. When trying to add these concept as singleton intervals to boost ICL, I am facing some problems however.
A
boost::icl::right_open_interval(the default type when with#define BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS) singleton appears to not be valid -boost::icl::intersectsreturnsfalsein all cases and the intersection returns[0,0)in all cases. The latter seems to even indicate an invalid interval. This is understandable insofar as[a,a)denotes the set{x | a <= x < a}, i.e. an empty set.A
boost::icl::closed_intervalseems therefore more suited to model a singleton. It is however, not default-constructible with aDomainTofdoubledue to a static assertBOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));. The interval containers require default constructible intervals however.
So I am a bit stuck on what to do. Is this just a question of choosing the right interval type or defining a custom one? Do singleton intervals even work at all with continuous types, or is this a conceptual misunderstanding on my part? After all, the concepts of "touching" intervals and intersections with singletons get very muddied. The intervals [a,b), [b,c) obviously touch, whereas with closed intervals [a,b], [b,c] would intersect in the singleton [b,b]. So maybe singletons don't work at all and need to be modeled by some finite [a, a+ε)?
Yes, I think you can remove all the issues you describe by using a discrete time domain. It moves all the "muddy-ness" to the sampling edge of your data, instead of encumbering your logic with the complexities.
Also, it will be fit for use with more operations on statically bounded intervals. E.g. continuous domains do not allow singletons with static intervals. This restriction is documented in Table 1.14
_interval
_interval
_interval
_interval
_interval
_interval
T singleton(const P&)T construct(const P&, const P&)and more detailed under Interval Construction:
T singleton(const P& value)Example
There's a library example that demonstrates/clarifies most of these points, and the comments are worth reading. It even defines a toy
Timetype to model time discretely. It should be easy to replace it withstd::chronotime_pointe.g. since C++11 is probably ubiquitous. Here's the example mildly modernized:Printing