$darkmode
minimator::MinimatorSimulator Class Reference
Inheritance diagram for minimator::MinimatorSimulator:
Collaboration diagram for minimator::MinimatorSimulator:

Public Member Functions

 MinimatorSimulator (const std::string &name, const MinimatorConfiguration &c)
 
virtual ~MinimatorSimulator () noexcept=default
 
void connect () final
 
void disconnect () final
 
void reset () final
 
void abort () final
 
void enroll (cloe::Registrar &r) final
 
size_t num_vehicles () const final
 
std::shared_ptr< cloe::Vehicleget_vehicle (size_t i) const final
 
std::shared_ptr< cloe::Vehicleget_vehicle (const std::string &key) const final
 
cloe::Duration process (const cloe::Sync &sync) final
 
- Public Member Functions inherited from cloe::Model
virtual ~Model () noexcept=default
 
virtual Duration resolution () const
 
virtual bool is_connected () const
 
virtual bool is_operational () const
 
virtual void start (const Sync &)
 
virtual void pause (const Sync &)
 
virtual void resume (const Sync &)
 
virtual void stop (const Sync &)
 
 Entity (std::string name)
 
 Entity (std::string name, std::string desc)
 
- Public Member Functions inherited from cloe::Entity
 Entity (std::string name)
 
 Entity (std::string name, std::string desc)
 
const std::string & name () const
 
void set_name (std::string name)
 
const std::string & description () const
 
void set_description (std::string desc)
 

Friends

void to_json (cloe::Json &j, const MinimatorSimulator &b)
 

Additional Inherited Members

- Protected Member Functions inherited from cloe::Entity
virtual Logger logger () const
 
- Protected Attributes inherited from cloe::Model
bool connected_ {false}
 
bool operational_ {false}
 
- Protected Attributes inherited from cloe::Entity
std::string name_
 
std::string desc_
 

Detailed Description

MinimatorSimulator binds all the above classes together in a coherent structure.

It receives the configuration, creates and provides vehicles, and maintains the connection to the underlying simulator (if any).

This class implements the Simulator and the Model interfaces, which are very well documented. Have a look!

See also
cloe/simulator.hpp
cloe/model.hpp

Constructor & Destructor Documentation

◆ MinimatorSimulator()

minimator::MinimatorSimulator::MinimatorSimulator ( const std::string &  name,
const MinimatorConfiguration c 
)
inline

Construct a MinimatorSimulator instance with the given name and configuration.

This signature is required by the factory class at the end of this file. Having any additional signatures is not really needed by Cloe; the only reason you might have additional ones is for testing or if you want to implement the factory make method yourself. See end of this file for the macro calls that define the factory and the make method.

  • name Unique name by which this simulator will be referenced
  • c Configuration of this instance

◆ ~MinimatorSimulator()

virtual minimator::MinimatorSimulator::~MinimatorSimulator ( )
virtualdefaultnoexcept

Destruct a MinimatorSimulator instance.

We're not doing anything special, so the default will do just fine.

Member Function Documentation

◆ abort()

void minimator::MinimatorSimulator::abort ( )
inlinefinalvirtual

Abort the simulator.

This method may be called asynchronously. See the documentation of the interface for more on this. It may also be called while a connect is still in progress. The idea is that calling abort should somehow cause this simulator binding to exit out of some waiting state it might be in.

Have a look at the VTD simulator plugin for how we make use of the AbortFlag if this is relevant to your plugin.

See also
Model::abort
Model::connect
Model::process

Reimplemented from cloe::Model.

◆ connect()

void minimator::MinimatorSimulator::connect ( )
inlinefinalvirtual

Initiate a connection to the simulator and initialize all data.

We're not actually connecting to some other simulator, so all we will do here is create some vehicles and make these available to the simulation.

See also
Model::connect

If you need to make use of a TCP connection, have a look at the TcpTransceiver class. If this method makes any use of I/O, it is also expected that a call to abort will let us cleanly exit out. The TcpTransceiverFactory class aids us in this by using the AbortFlag type as a way to prematurely exit.

See also
cloe/core/abort.hpp
cloe/utility/tcp_transceiver.hpp
Model::abort

Reimplemented from cloe::Model.

Here is the caller graph for this function:

◆ disconnect()

void minimator::MinimatorSimulator::disconnect ( )
inlinefinalvirtual

Tear down the connection to the simulator and remove all data.

This is effectively the reverse action to a connect.

See also
Model::disconnect

Reimplemented from cloe::Model.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enroll()

void minimator::MinimatorSimulator::enroll ( cloe::Registrar r)
inlinefinalvirtual

Register any events, actions, or handlers with the registrar.

Events and Actions are part of the trigger framework in Cloe. These let the user specify event-action pairs to dynamically affect the simulation. If there are any events or actions that a Simulator may want to expose, this is the place to do it.

Handlers are HTTP handlers that can simply expose data or provide hooks for changing the simulation. It is not recommended for handlers to have side-effects however, as these are not tracked by Cloe for ensuring a reproducible simulation. Actions are a much better solution for this.

See also
Model::enroll
cloe/registrar.hpp
cloe/trigger.hpp
cloe/handler.hpp

Reimplemented from cloe::Model.

◆ get_vehicle() [1/2]

std::shared_ptr<cloe::Vehicle> minimator::MinimatorSimulator::get_vehicle ( const std::string &  key) const
inlinefinalvirtual

Return the vehicle specified.

See also
Simulator::get_vehicle

Implements cloe::Simulator.

◆ get_vehicle() [2/2]

std::shared_ptr<cloe::Vehicle> minimator::MinimatorSimulator::get_vehicle ( size_t  i) const
inlinefinalvirtual

Return the vehicle specified.

See also
Simulator::get_vehicle

Implements cloe::Simulator.

Here is the call graph for this function:

◆ num_vehicles()

size_t minimator::MinimatorSimulator::num_vehicles ( ) const
inlinefinalvirtual

Return the number of vehicles that are available.

This only needs to work after a connect.

See also
Simulator::num_vehicles

Implements cloe::Simulator.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

cloe::Duration minimator::MinimatorSimulator::process ( const cloe::Sync sync)
inlinefinalvirtual

Process everything up until the time given in sync.

This is where all the step-for-step work in the simulator binding will occur. When the work is done, the new simulation time should be returned. This indicates that this model has reached that point in time with its processing. Because Vehicle::process is also called, it may not be necessary for this method to do much work.

If a scenario or some other user interaction in the simulator causes the simulator to stop, the operational_ boolean can be toggled.

See also
Model::process
cloe/sync.hpp

Implements cloe::Simulator.

Here is the call graph for this function:

◆ reset()

void minimator::MinimatorSimulator::reset ( )
inlinefinalvirtual

Reset the simulator.

This is useful for use-cases such as machine-learning where we want to restart the simulation, but not necessarily change the scenario or have to completely stop and start the simulation.

This method does not need to be implemented. The default implementation will throw a ModelError notifying the simulation that this operation is not supported. But it's fairly simple for us to implement it, so we will.

See also
Model::reset

Reimplemented from cloe::Model.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ to_json

void to_json ( cloe::Json &  j,
const MinimatorSimulator b 
)
friend

Serialize MinimatorSimulator into JSON.

This is required for the ToJson handler that is used in the enroll method.


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