Base class#

#include "navground/sim/scenario.h"
struct Scenario : public virtual navground::core::HasRegister<Scenario>#

A scenario is a generator of World.

Sub-classes should override init_world with a custom initialization that is performed each time a world is sampled (e.g., during an experiment).

They can also be customized by adding groups using add_group and/or initializers using add_init, although these are not exposed to YAML.

Subclassed by navground::sim::AntipodalScenario, navground::sim::CollisionsScenario, navground::sim::CorridorScenario, navground::sim::CrossScenario, navground::sim::CrossTorusScenario, navground::sim::SimpleScenario

Public Types

using Type = Scenario#
using Init = std::function<void(World*, std::optional<unsigned>)>#

A world initializer: a function that takes as input world and optional seed and perform some initialization on the world.

using Inits = std::map<std::string, Init>#

A collection of world initializers

using Groups = std::vector<std::shared_ptr<Group>>#

A collection of groups

using PropertySamplers = std::map<std::string, std::shared_ptr<PropertySampler>>#

A collection of property samplers

Public Functions

inline explicit Scenario(const Inits &inits = {})#

Constructs a new instance.

Parameters:

inits[in] The collection of world initializers to use.

virtual void init_world(World *world, std::optional<int> seed = std::nullopt)#

Initializes the world.

Users can specialize this method to specialize a scenario but should call make_world when creating a world.

Parameters:
  • world – The world

  • seed – The random seed

void apply_inits(World *world)#

Applies the initializers from get_inits.

Should be called after init_world to complete the initialization, as make_world does automatically.

Parameters:

world – The world

std::shared_ptr<World> make_world(std::optional<int> seed = std::nullopt)#

Creates and initialize a world.

Parameters:

seed – The random seed

inline std::string add_init(const Init &initializer)#

Adds a world initializer.

Parameters:

initializer[in] The initializer

Returns:

The associated key

inline void set_init(const std::string &key, const Init &initializer)#

Sets a world initializer.

Parameters:
  • key[in] The key

  • initializer[in] The initializer

inline void remove_init(const std::string &key)#

Remove the last added world initializer.

Parameters:

key[in] The key

inline void clear_inits()#

Removed all initializers.

inline const Inits &get_inits() const#

Gets the world initializers.

Returns:

The initializers.

inline const Groups &get_groups() const#

Gets the groups.

Returns:

The groups.

inline std::shared_ptr<Group> get_group(size_t index) const#

Gets a group.

Parameters:

index[in] The index

Returns:

The group or null if the index is not defined.

inline void add_group(const std::shared_ptr<Group> &group)#

Adds a group.

Parameters:

group[in] The group

inline void remove_group(const std::shared_ptr<Group> &group)#

Remove the added group.

Parameters:

group[in] The group

inline void remove_group_at_index(size_t index)#

Remove the added group.

Parameters:

index[in] The index

inline void clear_groups()#

Remove all groups.

inline const PropertySamplers &get_property_samplers() const#

Returns the samplers that this scenario uses for its properties.

Returns:

The samplers.

inline void add_property_sampler(const std::string &name, const std::shared_ptr<PropertySampler> &value)#

Adds a property sampler.

Parameters:
  • name[in] The name of the property

  • value[in] The sampler

inline void remove_property_sampler(const std::string &name)#

Removes a property sampler.

Parameters:

name[in] The name of the property

inline void clear_property_samplers()#

Clears the property samplers.

inline void reset(std::optional<unsigned> index = std::nullopt)#
void set_attributes(World *world)#

Sets world attributes from scenario properties.

Sets an attribute with the current value for each (registered) property.

Parameters:

world – The world

Public Members

std::vector<Disc> obstacles#

Obstacles

std::vector<LineSegment> walls#

Walls to add

std::optional<sim::BoundingBox> bounding_box#

An optional bounding box

struct Group#

A group of agents that can be generated and added to the world.

Subclassed by navground::sim::AgentSampler< W >

Public Functions

virtual void add_to_world(World *world, std::optional<unsigned> seed = std::nullopt) = 0#

Generate and add agents to the world.

Parameters:
  • world – The world

  • seed – An optional random seed

virtual ~Group() = default#