Module simulationEnvironment :: Class SimulationEnvironment
[hide private]
[frames] | no frames]

Class SimulationEnvironment

source code

Based on AIMA's environment: Abstract class representing an Environment. 'Real' Environment classes inherit from this. Your Environment will typically need to implement: percept: Define the percept that an agent sees. executeAction: Define the effects of executing an action.

Instance Methods [hide private]
 
__init__(self, initialState, shipAgents)
Initialize the simulation environment.
source code
 
percept(self, agentIndex)
Return the percept that the agent sees at this point.
source code
 
executeAction(self, agentIndex, action)
Change the world to reflect this action.
source code
 
exogenousChange(self)
Compute a change in the world state, that is external to the agent.
source code
 
step(self)
Run the SimulationEnvironment for one time step (One second).
source code
 
isDone(self)
By default, we're done when we can't find a live agent.
source code
 
run(self, steps=250000)
Run the SimulationEnvironment for given number of time steps.
source code
 
updateShipExternalState(self, shipIndex)
Compute ship position change in time, given the current state.
source code
 
computeChangeInSeaConditions(self, timePassed)
Compute sea state change in time
source code
 
processAgentsMessages(self)
The communication module of the simulator.
source code
 
processCompositeMessage(self, compositeMsg, agentIndex)
Processes a Composite messages by breaking it into primitive messages and using the appropriate callbacks based on the message type.
source code
 
processMsgVisit(self, msg, agentIndex)
Processes a msg that notifies about an agent visit at a point.
source code
 
processMsgEdgeLength(self, msg, agentIndex)
Processes a msg that notifies the length of an edge that an agent just completed.
source code
Method Details [hide private]

__init__(self, initialState, shipAgents)
(Constructor)

source code 

Initialize the simulation environment.

Parameters:
  • initialState (State) - The initial state of the sea and ships
  • shipAgents (array of Agents) - The initial state of the sea and ships

percept(self, agentIndex)

source code 

Return the percept that the agent sees at this point. We view the world such that the complete state is sent to a ship, and a ship can only extract from it what it can percept.

executeAction(self, agentIndex, action)

source code 

Change the world to reflect this action. Here, we only change the ship's internal state. The external state will be changed in exogenousChange()

Parameters:
  • agentIndex (int) - sort of an agent-id - an agent's index in the array of all agents
  • action (CompositeAction) - An action chosen by the agent, to be executed on the ship

exogenousChange(self)

source code 

Compute a change in the world state, that is external to the agent. This function is called in every simulation step, after computing the effects of the agent's actions.

Here the change that is computed is:

  • A change in the ships' external states, which are outside the control of the agent. (Ships' internal states are changed by agent actions.)
  • A change in the sea conditions

step(self)

source code 

Run the SimulationEnvironment for one time step (One second).

Clarification, originally from the AIMA book's code: If the actions and exogenous changes are independent, this method will do. If there are interactions between them, you'll need to override this method.

updateShipExternalState(self, shipIndex)

source code 

Compute ship position change in time, given the current state.

Computation of the next state is based on the world state, the ship internal and external state and time passed.

Currently, we approximate ship movement using the following model:

  • For forward motion, we model forward force that operates on the ship by the engine, and a drag, which is quadratic in the ship's speed.
  • For turning, there is an rotational torque that is applied by the rudder, and is proportional to the ship's speed, and to sin(rudder-steering-angle), which is the projection of the rudder on the lateral direction. There is also a rotational drag force, that is quadratic in the ship's angular speed, (need to check about the accuracy of this modelling).
  • Based on the above forces and the ship's mass, we compute the forward and angular accelerations.
  • Then based on the average forward and angular speed in a given time step, computed using the above accelerations, we infer the turn radius, and based on that, compute the ship position at the end of this time-step.

Approximations we make:

  • Although the angular acceleration depends on forward speed, which is changing due to forward acceleration, we still assume constant angular acceleration, based on the avg. speed in this step.
  • Forward acceleration computation does not take into account the affects of turning which (might?) slow it down.
  • Forward acceleration depends on the drag, which is changing with speed change, but we approximate the drag based on the initial speed of a time step

processAgentsMessages(self)

source code 

The communication module of the simulator. Each round, all agents' messages are being processed.

processCompositeMessage(self, compositeMsg, agentIndex)

source code 

Processes a Composite messages by breaking it into primitive messages and using the appropriate callbacks based on the message type.

Parameters:
  • compositeMsg (compositeMsg) - Contains 0 or more primitive messages from one agent.
  • agentIndex (int) - sort of an agent-id - an agent's index in the array of all agents

processMsgVisit(self, msg, agentIndex)

source code 

Processes a msg that notifies about an agent visit at a point.

Parameters:
  • msg (messages.PrimitiveMessage) - a message with a specifically assumed format (see below)
  • agentIndex (int) - sort of an agent-id - an agent's index in the array of all agents

processMsgEdgeLength(self, msg, agentIndex)

source code 

Processes a msg that notifies the length of an edge that an agent just completed.

Parameters:
  • msg (messages.PrimitiveMessage) - a message with a specifically assumed format (see below)
  • agentIndex (int) - sort of an agent-id - an agent's index in the array of all agents