Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
Utopia::DataIO::Default::IntervalDecider< Model > Struct Template Reference

A decider that returns true when within certain time intervals. More...

#include <defaults.hh>

Inheritance diagram for Utopia::DataIO::Default::IntervalDecider< Model >:
Inheritance graph
[legend]
Collaboration diagram for Utopia::DataIO::Default::IntervalDecider< Model >:
Collaboration graph
[legend]

Public Types

using Base = Decider< Model >
 The base class.
 

Public Member Functions

virtual bool operator() (Model &m) override
 
virtual void set_from_cfg (const Config &cfg) override
 Set the decider up from a given config node.
 
 IntervalDecider ()=default
 
 IntervalDecider (const IntervalDecider &)=default
 
 IntervalDecider (IntervalDecider &&)=default
 
IntervalDecideroperator= (const IntervalDecider &)=default
 
IntervalDecideroperator= (IntervalDecider &&)=default
 
virtual ~IntervalDecider ()=default
 
- Public Member Functions inherited from Utopia::DataIO::Default::Decider< Model >
 Decider ()=default
 
 Decider (const Decider &)=default
 
 Decider (Decider &&)=default
 
Decideroperator= (const Decider &)=default
 
Decideroperator= (Decider &&)=default
 
virtual ~Decider ()=default
 

Public Attributes

std::list< std::array< std::size_t, 3 > > intervals
 The sequence of intervals within to return true.
 

Detailed Description

template<typename Model>
struct Utopia::DataIO::Default::IntervalDecider< Model >

A decider that returns true when within certain time intervals.

Every interval is of shape [start, stop), stride where the third argument is optional and defines a stepping size.

Member Typedef Documentation

◆ Base

The base class.

Constructor & Destructor Documentation

◆ IntervalDecider() [1/3]

template<typename Model >
Utopia::DataIO::Default::IntervalDecider< Model >::IntervalDecider ( )
default

◆ IntervalDecider() [2/3]

template<typename Model >
Utopia::DataIO::Default::IntervalDecider< Model >::IntervalDecider ( const IntervalDecider< Model > &  )
default

◆ IntervalDecider() [3/3]

template<typename Model >
Utopia::DataIO::Default::IntervalDecider< Model >::IntervalDecider ( IntervalDecider< Model > &&  )
default

◆ ~IntervalDecider()

Member Function Documentation

◆ operator()()

Implements Utopia::DataIO::Default::Decider< Model >.

198 {
199 // Are at the end of the current interval; pop it, such that
200 // at next invocation the front is the new interval
201 if (intervals.size() != 0 and m.get_time() == intervals.front()[1])
202 {
203 intervals.pop_front();
204 }
205
206 if (intervals.size() != 0)
207 {
208 const auto [start, stop, step] = intervals.front();
209 // Check if within [start, end) interval
210 if ((m.get_time() >= start) and (m.get_time() < stop) and
211 ((m.get_time() - start) % step == 0))
212 {
213 return true;
214 }
215 }
216 return false;
217 }
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
std::list< std::array< std::size_t, 3 > > intervals
The sequence of intervals within to return true.
Definition defaults.hh:194

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ set_from_cfg()

template<typename Model >
virtual void Utopia::DataIO::Default::IntervalDecider< Model >::set_from_cfg ( const Config cfg)
inlineoverridevirtual

Set the decider up from a given config node.

Parameters
cfgconfig node containing arguments for this decider

Implements Utopia::DataIO::Default::Decider< Model >.

225 {
227 "intervals", cfg);
228 for (std::vector< std::size_t > tmp_interval : tmp)
229 {
230 if (tmp_interval.size() == 2)
231 {
232 tmp_interval.push_back(1);
233 }
234 else if (tmp_interval.size() != 3)
235 {
236 throw Utopia::KeyError("intervals", cfg,
237 fmt::format("Array of unexpected length {}! "
238 "Expected array of length 2 or 3 [start, stop, step] "
239 "with step optional (default 1).",
240 tmp_interval.size())
241 );
242 }
243
244 std::array< std::size_t, 3 > interval;
245 std::copy(tmp_interval.begin(), tmp_interval.end(),
246 interval.begin());
247 intervals.push_back(interval);
248 }
249 }
For access to a dict-like structure with a bad key.
Definition exceptions.hh:67
OutputIt copy(const Utopia::ExecPolicy policy, InputIt first, InputIt last, OutputIt d_first)
Copy the input range to a new range.
Definition parallel.hh:324

Member Data Documentation

◆ intervals

template<typename Model >
std::list< std::array< std::size_t, 3 > > Utopia::DataIO::Default::IntervalDecider< Model >::intervals

The sequence of intervals within to return true.


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