Class base_arena_map
Defined in File base_arena_map.hpp
Nested Relationships
Nested Types
Inheritance Relationships
Base Types
public rer::client< base_arena_map >
public rpdecorator::decorator< ds::arena_grid >
public rmultithread::lockable
Derived Type
public cosm::arena::caching_arena_map
(Class caching_arena_map)
Class Documentation
-
class base_arena_map : public rer::client<base_arena_map>, public rpdecorator::decorator<ds::arena_grid>, public rmultithread::lockable
The core data structure for swarm-arena interactions.
Combines a 2D grid with sets of objects (blocks, caches, nests, etc.) that populate the grid and move around as the state of the arena changes. The idea is that the arena map should be as simple as possible, providing accessors and mutators, but not more complex logic, separating the data in manages from the algorithms that operate on that data.
Note that the arena map does not expose owning access to the objects it manages. This avoids extensive use of std::shared_ptr, and greatly increases efficiency with large numbers of objects.
Subclassed by cosm::arena::caching_arena_map
Public Types
-
using const_grid_view = rds::base_grid2D<cds::cell2D>::const_grid_view
-
using grid_view = rds::base_grid2D<cds::cell2D>::grid_view
Public Functions
-
base_arena_map(base_arena_map&&) = delete
-
base_arena_map(const base_arena_map&) = delete
-
base_arena_map(const caconfig::arena_map_config *config, rmath::rng *rng)
-
~base_arena_map(void) override
-
template<size_t Index>
inline ds::arena_grid::layer_value_type<Index>::value_type &access(const rmath::vector2z &d)
-
template<size_t Index>
inline const ds::arena_grid::layer_value_type<Index>::value_type &access(const rmath::vector2z &d) const
-
template<size_t Index>
inline ds::arena_grid::layer_value_type<Index>::value_type &access(size_t i, size_t j)
-
template<size_t Index>
inline const ds::arena_grid::layer_value_type<Index>::value_type &access(size_t i, size_t j) const
-
inline const rmath::vector3d &block_bb(void) const
Get the bounding box large enough to contain all blocks specified in the manifest.
-
cfbd::base_distributor *block_distributor(void)
-
const cfbd::base_distributor *block_distributor(void) const
-
inline std::shared_mutex *block_mtx(void)
Protects simultaneous updates to the blocks vector.
-
inline std::shared_mutex *block_mtx(void) const
-
inline cds::block3D_vectorno &blocks(void)
Get the list of all the blocks currently present in the arena.
-
inline const cds::block3D_vectorno &blocks(void) const
-
inline const cads::loctree *bloctree(void) const
-
virtual void bloctree_update(const crepr::sim_block3D *block, const locking &locking)
Update the location index tree after the specified block has moved.
This operation requires holding the block mutex in multithreaded contexts for writing, and takes it internally if not held.
-
const rmath::rangez &distributable_cellsx(void) const
-
const rmath::rangez &distributable_cellsy(void) const
-
void distribute_single_block(crepr::sim_block3D *block, const locking &locking)
Distribute a particular block in the arena, according to whatever policy was specified in the .argos file.
Note
This operation requires holding the block and grid mutexes for writing, and takes them internally if they are not held.
- Parameters:
block – The block to distribute.
locking – Currently held locks.
-
virtual cds::block3D_vectorno free_blocks(bool oos_ok) const
Get the free blocks in the arena. Does no locking, so this is only safe to call in non-concurrent contexts.
- Parameters:
oos_ok – Are out of sight (OOS) blocks OK to include? In general they are not, BUT for powerlaw block distributions which require deferred arena map initialization, all blocks are out of sight pre-init when cluster locations are computed which causes problems with clusters overlapping with caches. See COSM#142.
-
template<typename ...Args>
inline auto Func(Args&&... args) -> decltype(std::declval<decltype(Member)>().Func(args...))
-
template<typename ...Args>
inline auto Func(Args&&... args) -> decltype(std::declval<decltype(Member)>().Func(args...))
-
template<typename ...Args>
inline auto Func(Args&&... args) -> decltype(std::declval<decltype(Member)>().Func(args...))
-
template<typename ...Args>
inline auto Func(Args&&... args) -> decltype(std::declval<decltype(Member)>().Func(args...))
-
template<typename ...Args>
inline auto Func(Args&&... args) -> decltype(std::declval<decltype(Member)>().Func(args...))
-
template<typename ...Args>
inline auto Func(Args&&... args) -> decltype(std::declval<decltype(Member)>().Func(args...))
-
inline std::shared_mutex *grid_mtx(void)
-
inline rtypes::discretize_ratio grid_resolution(void) const
-
virtual bool initialize(cpargos::swarm_manager_adaptor *sm, const crepr::config::nests_config *nests)
Perform deferred initialization. This is not part the constructor so that it can be verified via return code. Currently it does the following:
Initializes the block distributor and distributes all blocks.
Initializes nest lights
Calculates block minimal bounding box
(Possibly) initializes additional nests.
- Parameters:
sm – The swarm manager.
nests – Additional nests to initialize (can be NULL).
-
const crepr::nest *nest(const rtypes::type_uuid &id) const
Get a specific nest in the arena by UUID.
-
ds::nest_vectorro nests(void) const
Get the set of all nests in the arena.
-
inline const cads::loctree *nloctree(void) const
-
base_arena_map &operator=(base_arena_map&&) = delete
-
const base_arena_map &operator=(const base_arena_map&) = delete
-
virtual bool placement_conflict(const crepr::sim_block3D *block, const rmath::vector2d &loc) const
Determine if placing the specified block at the specified location will cause a conflict with any entities in the arena.
Calls spatial::conflict_checker internally to do the actual checking.
-
void post_step_update(const rtypes::timestep &t, size_t blocks_transported, bool convergence_status)
Update the arena map on the current timestep, after robot controllers are run.
Currently updates the following, in order:
Block distribution status via cforaging::block_dist::redist_governor.
Does no locking, so only safe to call in non-concurrent contexts.
- Parameters:
t – The current timestep.
blocks_transported – How many blocks have been cumuluatively transported/collected so far in simulation.
convergence_status – Has the currently converged, according to configured convergence measures?
-
update_status pre_step_update(const rtypes::timestep &t)
Update the arena map on the current timestep, before robot controllers are run.
Currently updates the following, in order:
Block motion via foraging::block_mover.
- Parameters:
t – The current timestep.
-
RCPPSW_PTRREF_DECLDEF(redist_governor, m_redist_governor)
-
RCPPSW_PTRREF_DECLDEF_CONST(block_motion_handler, m_bm_handler)
Get a handle to the block motion handler.
-
rtypes::type_uuid robot_in_nest(const rmath::vector2d &pos) const
Determine if a robot is currently within the boundaries of a nest.
While robots also have their own means of checking if they are in the nest or not, there can be false positives, so this function is used as the final arbiter when deciding whether or not to trigger nest related events.
-
virtual rtypes::type_uuid robot_on_block(const rmath::vector2d &pos, const rtypes::type_uuid &ent_id) const
Determine if a robot is currently on top of a block (i.e. if the center of the robot has crossed over into the space occupied by the block extent).
While the robots also have their own means of checking if they are on a block or not, there are some false positives, so this function is used as the final arbiter when deciding whether or not to trigger a block relted events.
Note
The block mutex must be held when calling this function.
- Parameters:
pos – The position of a robot.
ent_id – The ID of the block the robot THINKS it is on.
- Returns:
The ID of the block that the robot is on, or -1 if the robot is not actually on a block.
Protected Functions
-
inline cfbd::dispatcher *block_dispatcher(void) const
-
virtual bool bloctree_verify(void) const
-
bool distribute_all_blocks(void)
Distribute all blocks in the arena. Resets arena state. Called as part of initialize().
Note
This operation requires holding the block and grid mutexes in multi-threaded contetxts.
-
inline virtual cds::const_spatial_entity_vector initial_dist_precalc(const crepr::sim_block3D*) const
-
virtual void post_block_dist_unlock(const locking &locking)
Perform necessary unlocking after block distribution.
-
virtual void pre_block_dist_lock(const locking &locking)
Perform necessary locking prior to (1) gathering the list of entities that need to be avoided during block distribution, and (2) doing block distribution.
-
inline rmath::rng *rng(void) const
-
using const_grid_view = rds::base_grid2D<cds::cell2D>::const_grid_view