Agents Module Documentation

Occupant

class soba.agents.occupant.Occupant(unique_id, model, json, speed=0.71428)[source]

Base class to models occupants as Occupant objects. The occupants are agents with their activity defined by markov states.

Attributes:
color: Color with which the occupant will be represented in the visualization. positionByState: Position associated to each state for an occupant. timeActivity: Time that is required to complete an activity (state) in minutes. schedule: Activity periods (hours:minutes). states: States of the occupant. machine: State machine defined by the attribute ‘states’. movements: List of movements that will be followed by the occupant. pos_to_go: Position to which the occupant wishes to move. markov_machine: Object of the Markov class that regulates markovian behavior.
Methods:
setTodaySchedule: Calculate and define the schedules of the occupants. start_activity: Defines the actions that are made when a state is started. finish_activity: Defines the actions that are made when a state is finished. changeSchedule: Force a possible change of state to reach a certain end of period. getPeriod: Get the temporary period in which the occupant is. step: Method invoked by the Model scheduler in each step. Step common to all occupants.
changeSchedule()[source]

Force a possible change of state to reach a certain end of period.

Return:
True if the period has been changed, False otherwise.
finish_activity()[source]

Defines the actions that are made when a state is finished.

getPeriod()[source]

Get the temporary period in which the occupant is.

Return:
Current period as String
setTodaySchedule()[source]

Calculate and define the schedules of the occupants applying the information provided and normal Gaussian variations.

start_activity()[source]

Defines the actions that are made when a state is started. Default, this method calculates the value of the attributes ‘time_activity’ and ‘movements’ corresponding to the new state.

step()[source]

Method invoked by the Model scheduler in each step. Step common to all occupants.

Continuous Occupant

class soba.agents.continuousOccupant.ContinuousOccupant(unique_id, model, json, speed=0.71428)[source]

This class enables to create occupants that are modelled with a continuous space models. based on considering a scaled grid (x, y). Cell size of 0.5m ^ 2 by default. The occupants are agents with their activity defined by markov states.

Attributes:
Those Inherited from the Occupant class. fov: List of positions (x, y) that the occupant can see.
Methods:
getPosState: Auxiliary method to distribute the occupants between the points of interests with same id for more than one occupant. getWay: Invocation of the AStar resource to calculate the optimal path. getPlaceToGo: Obtaining the position associated with the current state. posInMyFOV: Check if a position is in my field of vision. evalAvoid: Check the future movement to be made by another agent to assess a possible collision. checkFreeSharedPOI: Get a free position of a shared point of interest if possible. checkCanMove: Get a new path in case of possible collision. evalCollision: Evaluate a possible collision with an agent and solve it if necessary by calculating another path. makeMovement: Carry out a movement: displacement between cells or reduction of the movement cost parameter. reportMovement: Auxiliary method to notify a movement giving its orientation and speed. checkLeaveArrive: Evaluates the entrance and exit of the building by an occupying agent. getFOV: Calculation of the occupant’s field of vision, registered in the attribute fov. step: Method invoked by the Model scheduler in each step.
checkCanMove()[source]
Get a new path in case of possible collision.
Return: List of positions
checkFreeSharedPOI()[source]
Get a free position of a shared point of interest if possible.
Return: POI object
checkLeaveArrive()[source]

Evaluates the entrance and exit of the building by an occupying agent.

evalAvoid(otherAgent)[source]
Check the future movement to be made by another agent to assess a possible collision.
Args:
otherAgent: The other agent to be avoid.

Return: Boolean

evalCollision()[source]
Evaluate a possible collision with an agent, invoking the evalAvoid method, and solve it if necessary by calculating another path.
Return: True if the collision exists and is avoided, False otherwise.
getFOV()[source]

Calculation of the occupant’s field of vision, registered in the attribute fov

getPlaceToGo()[source]
Obtaining the position associated with the current state. It is invoked when you enter a new state.
Return: Position as coordinate (x, y).
getPosState(name)[source]
Auxiliary method to distribute the occupants between the points of interests with same id for more than one occupant.
Args:
name: Poi id/name.

Return: Position associated with this occupant.

getWay(pos=None, pos_to_go=None, other=[])[source]
Invocation of the AStar resource to calculate the optimal path.
Args:
pos: Initial position, by default the current position of the occupant. pos_to_go: Final position, by default the value of the ‘pos_to_go’ attribute of the occupant. other: List of auxiliary positions given to be considered impenetrable by the occupants, that is, they will not be used by the AStar.

Return: List of positions (x, y).

makeMovement()[source]

Carry out a movement: displacement between cells or reduction of the movement cost parameter.

posInMyFOV(pos)[source]
Check if the position is in my field of vision
Args:
pos: Position to be checked

Return: Boolean

reportMovement()[source]

Auxiliary method to notify a movement giving its orientation and speed.

step()[source]

Method invoked by the Model scheduler in each step. Evaluate if appropriate and, if so, perform: A change of state, a movement or advance in the cost of a movement, or an advance in the performance of an activity.

Rooms Occupant

class soba.agents.roomsOccupant.RoomsOccupant(unique_id, model, json, speed=0.7)[source]

This class enables to create occupants that are modelled with a simplified models based on a discrete space associated with rooms. The occupants are agents with their activity defined by markov states.

Attributes:
Those inherited from the Occupant class.
Methods:
getPosState: Auxiliary method to distribute the occupants between the rooms shared by more than one occupant object. getWay: Invocation of the AStar resource to calculate the optimal path. occupantMovePos: Calculation of the control attributes that regulate the cost (steps) of the movement between rooms according to their size. getPlaceToGo: Obtaining the position associated with the current state. step: Method invoked by the Model scheduler in each step.
getPlaceToGo()[source]
Obtaining the position associated with the current state. It is invoked when you enter a new state.
Return: Position as coordinate (x, y).
getPosState(name, posAux)[source]
Auxiliary method to distribute the occupants between the rooms shared by more than one occupant object.
Args:
name: State name. posAux: Name of the room associated with this state, string, or dictionary of room names with number of occupants. {‘RoomName1’: numberofOccupantsAssigned1, ‘RoomName2’: numberofOccupantsAssigned2… }

Return: Position associated with this occupant

getWay(pos=None, pos_to_go=None)[source]
Invocation of the AStar resource to calculate the optimal path.
Args:
pos: Initial position, by default the current position of the occupant. pos_to_go: Final position, by default the value of the ‘pos_to_go’ attribute of the occupant.

Return: List of positions (x, y).

occupantMovePos(new_position)[source]
Calculation of the control attributes that regulate the cost (steps) of the movement between rooms according to their size.
Args:
new_position: Room object to which it moves.
step()[source]

Method invoked by the Model scheduler in each step. Evaluate if appropriate and, if so, perform: A change of state, a movement or advance in the cost of a movement, or an advance in the performance of an activity.

Avatar

class soba.agents.avatar.Avatar(unique_id, model, initial_pos, color='red', initial_state='walking')[source]

This class enables to create avatars that represent virtual occupants, that is, they are not controlled by the simulation but by an API Rest. However, certain important aspects such as position in space inherit from the occupant class.

Attributes:
model: Simulation model. unique_id: Unique avatar identifier as an occupant. fov: List of positions (x, y) that the avatar can see. state: Current avatar state. pos: Current avatar position. color: Color of the avatar in the visualization. shape: Shape of the avatar in the visualization.
Methods:
getWay: Invocation of the AStar resource to calculate the optimal path. posInMyFOV: Check if a position is in my field of vision. makeMovementAvatar: Carry out a movement: displacement between cells. checkLeaveArrive: Notify the entrance and exit of the building by an occupying agent. getFOV: Calculation of the occupant’s field of vision, registered in the attribute fov.
checkLeaveArrive()[source]

Notify the entrance and exit of the building by an occupying agent.

getFOV()[source]

Calculation of the occupant’s field of vision, registered in the attribute fov

getWay(pos=None, pos_to_go=None, other=[])[source]
Invocation of the AStar resource to calculate the optimal path.
Args:
pos: Initial position, by default the current position of the occupant. pos_to_go: Final position, by default the value of the ‘pos_to_go’ attribute of the occupant. other: List of auxiliary positions given to be considered impenetrable by the occupants, that is, they will not be used by the AStar.

Return: List of positions (x, y).

makeMovementAvatar(pos)[source]
Carry out a movement: displacement between cells.
Args:
pos: Position to be moved.
posInMyFOV(pos)[source]
Check if the position is in my field of vision
Args:
pos: Position to be checked

Return: Boolean

step()[source]

Method invoked by the Model scheduler in each step. Step common to all occupants.

Agent Modules

AStar

soba.agents.resources.aStar.canMovePos(model, cellPos, posAux, others=[])[source]
Evaluate if a position is reachable in a continuous space.
Args:
model: Model which invokes the algorithm. cellPos: a first one position given as (x, y). posAux: a second one position given as (x, y). others: List of auxiliary positions given to be considered impenetrable, that is, they will not be used by the AStar.

Return: List of positions (x, y).

soba.agents.resources.aStar.getConectedCellsContinuous(model, cell, others)[source]
Gets a list of connected cells in a continuous space.
Args:
model: Model which invokes the algorithm. cell: cell object corresponding to the position. other: List of auxiliary positions given to be considered impenetrable, that is, they will not be used by the AStar.

Return: List of positions (x, y).

soba.agents.resources.aStar.getConectedCellsRooms(model, cell)[source]
Gets a list of connected cells in a space defined by rooms.
Args:
model: Model which invokes the algorithm. cell: cell object corresponding to the room.

Return: List of positions (x, y).

soba.agents.resources.aStar.getPathContinuous(model, start, finish, other=[])[source]
Calculate the optimal path in the models with the space continuous.
Args:
model: Model which invokes the algorithm. start: Initial position. finish: Final position. other: List of auxiliary positions given to be considered impenetrable, that is, they will not be used by the AStar.

Return: List of positions (x, y).

soba.agents.resources.aStar.getPathRooms(model, start, finish)[source]
Calculate the optimal path in the models with the space defined by rooms.
Args:
model: Model which invokes the algorithm. start: Initial position. finish: Final position.

Return: List of positions (x, y).

soba.agents.resources.aStar.print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100)[source]

Call in a loop to create terminal progress bar @params:

iteration - Required : current iteration (Int) total - Required : total iterations (Int) prefix - Optional : prefix string (Str) suffix - Optional : suffix string (Str) decimals - Optional : positive number of decimals in percent complete (Int) bar_length - Optional : character length of bar (Int)

Markov

class soba.agents.resources.behaviourMarkov.Markov(agent_aux)[source]

Base class to models the activity of the agents by means of Markovian behavior.

Attributes:
agent: Agent that is controlled by this models.
Methods:
runStep: Execute a Markovian state change by evaluating the initial state and the probabilities associated with each possible state. getNextState: Evaluate a random change based on the probabilities corresponding to each state.
getNextState(markov_matrix, NumberCurrentState)[source]
Evaluate a random change based on the probabilities corresponding to each state.
Args:
markov_matrix: Markov matrix corresponding to a certain moment. NumberCurrentState: Unique id as number of the current state.
runStep(markov_matrix)[source]
Execute a Markovian state change by evaluating the initial state and the probabilities associated with each possible state.
Args:
markov_matrix: Markov matrix corresponding to a certain moment.

FOV

soba.agents.resources.fov.FOV_RADIUS = 30000

In the file aStar.py the filed of vision algorithm is implemented.

class soba.agents.resources.fov.Map(map)[source]

Class to calculate the field of vision (fov).

Attributes:
data: Map to which to apply the algorithm.
Methods:
do_fov: Calculate the field of view from a position (x, y).
More information:
http://www.roguebasin.com/index.php?title=Python_shadowcasting_implementation
do_fov(x, y)[source]
Calculate the field of view from a position (x, y).
Args:
x, y: Observer’s position

Return: Array of sight positions.

soba.agents.resources.fov.makeFOV(dungeon, pos)[source]
Create the invocation object of the fov algorithm and invoke it.
Args:
dungeon: Array pos: Observer’s position

Return: Array of sight positions.