Class Grid1D
Defined in File grid1d.h
Inheritance Relationships
Base Type
public kami::GridDomain
(Class GridDomain)
Derived Types
public kami::MultiGrid1D
(Class MultiGrid1D)public kami::SoloGrid1D
(Class SoloGrid1D)
Class Documentation
-
class Grid1D : public kami::GridDomain
A one-dimensional grid where each cell may contain agents.
The grid is linear and may wrap around in its only dimension.
See also
See also
Subclassed by kami::MultiGrid1D, kami::SoloGrid1D
Public Functions
-
explicit Grid1D(unsigned int maximum_x, bool wrap_x = false)
Constructor.
- Parameters
maximum_x – [in] the length of the grid.
wrap_x – [in] should the grid wrap around on itself.
-
virtual AgentID add_agent(AgentID agent_id, const GridCoord1D &coord) = 0
Place agent on the grid at the specified location.
- Parameters
agent_id – [in] the
AgentID
of the agent to add.coord – [in] the coordinates of the agent.
- Returns
false if the agent is not placed at the specified location, otherwise, true.
-
AgentID delete_agent(AgentID agent_id, const GridCoord1D &coord)
Remove agent from the grid at the specified location.
-
AgentID move_agent(AgentID agent_id, const GridCoord1D &coord)
Move an agent to the specified location.
- Parameters
agent_id – [in] the
AgentID
of the agent to move.coord – [in] the coordinates of the agent.
-
bool is_location_empty(const GridCoord1D &coord) const
Inquire if the specified location is empty.
- Parameters
coord – [in] the coordinates of the query.
- Returns
true if the location has no
Agent
s occupying it, false otherwise.
-
bool is_location_valid(const GridCoord1D &coord) const
Inquire if the specified location is valid within the grid.
- Parameters
coord – [in] the coordinates of the query.
- Returns
true if the location specified is valid, false otherwise.
-
GridCoord1D get_location_by_agent(const AgentID &agent_id) const
Get the location of the specified agent.
-
std::shared_ptr<std::set<AgentID>> get_location_contents(const GridCoord1D &coord) const
Get the contents of the specified location.
- Parameters
coord – [in] the coordinates of the query.
- Returns
a pointer to a
set
ofAgentID
s. The pointer is to the internal copy of the agent list at the location, therefore, any changes to that object will update the state of the gird. Further, the pointer should not be deleted when no longer used.
-
bool get_wrap_x() const
Inquire to whether the grid wraps in the
x
dimension.- Returns
true if the grid wraps, and false otherwise
-
std::shared_ptr<std::unordered_set<GridCoord1D>> get_neighborhood(AgentID agent_id, bool include_center) const
Return the neighborhood of the specified Agent.
- Parameters
agent_id – [in] the
AgentID
of the agent in questioninclude_center – [in] should the center-point, occupied by the agent, be in the list.
- Returns
an
unordered_set
ofGridCoord1D
that includes all of the coordinates for all adjacent points.
-
std::shared_ptr<std::unordered_set<GridCoord1D>> get_neighborhood(const GridCoord1D &coord, bool include_center) const
Return the neighborhood of the specified location.
- Parameters
coord – [in] the coordinates of the specified location.
include_center – [in] should the center-point, occupied by the agent, be in the list.
- Returns
an
unordered_set
ofGridCoord1D
that includes all of the coordinates for all adjacent points.
-
unsigned int get_maximum_x() const
Get the size of the grid in the
x
dimension.- Returns
the length of the grid in the
x
dimension
Protected Functions
-
GridCoord1D coord_wrap(const GridCoord1D &coord) const
Automatically adjust a coordinate location for wrapping.
- Parameters
coord – [in] the coordinates of the specified location.
- Returns
the adjusted coordinate wrapped if appropriate.
Protected Attributes
-
const std::vector<GridCoord1D> directions = {GridCoord1D(1), GridCoord1D(-1)}
Direction coordinates.
This can be used for addition to coordinates. Direction
0
is the first direction clockwise from “vertical.” In this case, it can be on a vertically-oriented column, upwards, or to the right on a horizontally-oriented column. Then the additional directions are enumerated clockwise.
-
std::unique_ptr<std::unordered_multimap<GridCoord1D, AgentID>> _agent_grid
An
unordered_set
containing theAgentID
s of all agents assigned to this grid.
-
std::unique_ptr<std::map<AgentID, GridCoord1D>> _agent_index
A map containing the grid location of each agent.
-
explicit Grid1D(unsigned int maximum_x, bool wrap_x = false)