Class caching_arena_map

Inheritance Relationships

Base Types

Class Documentation

class caching_arena_map : public rer::client<caching_arena_map>, public cosm::arena::base_arena_map

Decorates base_arena_map to add the ability to manage caches.

Public Functions

caching_arena_map(const caconfig::arena_map_config *config, rmath::rng *rng)
~caching_arena_map(void) override
virtual void bloctree_update(const crepr::sim_block3D *block, const locking &locking) override

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.

inline std::shared_mutex *cache_mtx(void)

Protects simultaneous updates to the caches vector.

inline std::shared_mutex *cache_mtx(void) const
void cache_remove(repr::arena_cache *victim, cpargos::swarm_manager_adaptor *sm)

Remove a cache from the list of caches.

Note

Cache mutex assumed to be held by the caller for writing.

Parameters:
  • victim – The cache to remove.

  • sm – The swarm manager (to remove light for cache).

inline cads::acache_vectorno &caches(void)

Get the list of all the caches currently present in the arena and active.

inline const cads::acache_vectorno &caches(void) const
void caches_add(const cads::acache_vectoro &caches, cpargos::swarm_manager_adaptor *sm)

Add caches that have been created (by a cache manager or by robots) in the arena to the current set of active caches.

Note

Cache mutex assumed to be held by the caller for writing.

Parameters:
  • caches – The caches to add.

  • sm – The cpargos::swarm_manager_adaptor.

inline const cads::loctree *cloctree(void) const
void cloctree_update(const carepr::arena_cache *cache)
inline void created_caches(const cads::acache_vectorro &created_caches)
inline void created_caches_clear(void)
virtual cds::block3D_vectorno free_blocks(bool oos_ok) const override

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.

virtual cds::const_spatial_entity_vector initial_dist_precalc(const crepr::sim_block3D *block) const override
virtual bool initialize(cpargos::swarm_manager_adaptor *sm, const crepr::config::nests_config *nests) override

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).

inline size_t n_caches(void) const

Get the # of caches currently in the arena.

virtual void ordered_lock(const locking &locking) override
virtual void ordered_unlock(const locking &locking) override
virtual bool placement_conflict(const crepr::sim_block3D *block, const rmath::vector2d &loc) const override

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.

virtual rtypes::type_uuid robot_on_block(const rmath::vector2d &pos, const rtypes::type_uuid &ent_id) const override

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 related event for a particular robot.

Note

The cache AND block mutexes must be held when calling this function.

rtypes::type_uuid robot_on_cache(const rmath::vector2d &pos) const

Determine if a robot is currently on top of a cache (i.e. if the center of the robot has crossed over into the space occupied by the cache extent).

While the robots also have their own means of checking if they are on a cache or not, there are some false positives, so this function is used as the final arbiter when deciding whether or not to trigger a cache related event for a particular robot.

Note

The cache mutex must be held when calling this function.

Parameters:

pos – The position of a robot.

Returns:

The ID of the cache that the robot is on, or -1 if the robot is not actually on a cache.

inline const cads::acache_vectoro &zombie_caches(void) const
inline void zombie_caches_clear(void)

Clear the list of caches that have been removed this timestep.

Having such a list is necessary in order to be able to correctly gather metrics from caches that have been depleted THIS timestep about block pickups. Normal cache metric collection does not encompass such zombie caches.