Unordered close-following agents
As requested by Guillaume Sartoretti - the agents should be able to directly follow each other in any order.
Currently they can only follow in agent_id / handle order, because each agent is moved atomically in that order.
- Positions / cell locks are recorded in
rail_env.agent_positions
- when an agent moves, its current cell is unlocked, and the new one locked.
- when the next agent moves, it checks the partially updated table before moving (thus "cross-over" conflicts are avoided)
- it means a higher-id agent can step into the cell vacated by a lower-id one, but not vice-versa.
Implementation
- use / copy existing loop over agents to check speed, valid actions, malfunction, etc
- for each agent ready to move cell (ie whose agent.speed_data position_fraction = 1) create an edge in a DiGraph from the existing cell (row,col) to the new one.
- Check the graph for agent conflicts:
- self loops mean the agent is stationary and this takes priority.
- cell swaps appear as loops of size 2. Mark both agents as cannot move.
- agents trying to move into a cell occupied by a stationary agent are blocked.
- agents close_following another agent are allowed to move, however this means we need to:
- check that chains of agents which are close_following are not blocked.
- A chain of close_following agents can be blocked by a stationary agent, or a cell-swap.
- a chain of close_following agents can be branching so the whole tree is affected by a block at the head.
- Special rule for two agents both trying to move into the same cell:
- The agent with the lower index wins
- Implication: an agent can "butt into" a close-following chain if it has a lower index than the one it will block.
- Implication: at a branch-point in a merging tree of agents, the agent with the lower index goes first.
In the diagram below,
- a black node indicates a moving agent (really the agent is the edge, and the two nodes are its current and next positions)
- a self-loop edge indicates a stationary agent.
- a red node indicates a cell containing a stopped / blocked agent.
- a purple node indicates a cell containing a stopped agent in an attempted swap-over pair.
- a blue node indicates an empty contended cell (two or more agents trying to move into it)
- a magenta node (slightly brighter purple) indicates an occupied contended cell, where the occupying agent is moving out, but two or more agents are trying to move in.
Edited by hagrid67