Package mosp :: Module core :: Class Person
[hide private]
[frames] | no frames]

Class Person

source code


A basic simulated Person.

Instance Methods [hide private]
 
__getstate__(self)
Returns Person information for pickling using the pickle module.
source code
 
__init__(self, id, sim, random, speed=1.4, **kwargs)
Initializes the Person.
source code
 
_get_classname(self) source code
 
act_at_node(self, node)
Actions of the person when arriving at a node.
source code
 
calculate_duration(self)
Calculate the time needed for walking to the next node.
source code
 
call_stop_actions(self)
Sets stop_all_actions und interrupts.
source code
 
collide_circle(self, x, y, radius)
Checks if this person collides with the given circle.
source code
 
collide_rectangle(self, x_min, y_min, x_max, y_max)
Checks if this person collides with the given rectangle.
source code
 
current_coords_impl(self)
Calculates the current position from remaining time using last_coord and target_coord to implement road width
source code
mosp.group.PersonGroup
get_near(self, dist, self_included=True)
Returns Persons near this Person.
source code
 
get_properties(self)
Return all the person's properties (variables and properties p_*) as a dictionary.
source code
 
get_random_way_node(self, include_exits=True)
Returns a random way_node from sim.way_nodes.
source code
 
get_speed(self)
property speed: movement speed of the Person.
source code
 
go(self)
The main-loop of every person.
source code
 
handle_interrupts(self)
Find out, what caused an interrupt and act accordingly.
source code
 
next_target(self)
Finds a new target to move to.
source code
 
next_target_coord(self)
Calculates new target coordinates based on next_node coordinates plus orthogonal to road offset defined by self.road_orthogonal_offset.
source code
 
pause_movement(self, duration, location_offset_xy=0, deactivateActions=False)
Stops movement of person.
source code
 
reactivate(self, at='undefined', delay='undefined', prior=False)
Reactivates passivated person and optionally restarts stopped actions.
source code
 
readd_actions(self)
Do things, when person is readded via Simulation.readd().
source code
 
receive(self, message, sender)
Receive a message and handle it.
source code
 
restart_actions(self)
Restarts all actions that where stopped via stop_actions.
source code
 
send(self, receiver, message, earliest_arrival=None, interrupt=False)
Send a message to another Person.
source code
 
set_speed(self, speed)
Sets movement speed of the Person.
source code
 
start_action(self, action)
Start an action.
source code
 
stop_action(self, action)
Stop an action.
source code
 
stop_actions(self, removal=False)
Stop all actions of the Person.
source code
 
think(self)
Think about what to do next.
source code

Inherited from SimPy.Lib.Process: acquired, active, cancel, interrupt, interruptReset, interrupted, passive, queuing, start, stored, terminated

Inherited from SimPy.Lib.Process (private): _hold, _passivate

Inherited from SimPy.Lister.Lister: __repr__, __str__, attrnames

Inherited from collide.Point: collide_polygon, get_points

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]

Inherited from SimPy.Lister.Lister: indent

Instance Variables [hide private]
  _actions
stores all actions of the Person
  _duration
time to next round of go()
  _location_offset
used by pause_movement as input for random offset to current position while pausing
  _messages
stores callback messages of the Person - calling back must still be implemented (todo)
  _p_speed
speed of Person
  _random
random object of the Person
  _start_time
the tick when this person started the current walk from last to target node
  _stopped_actions
stores stopped actions
  _stopped_actions_for_removal
stores actions that were stopped when removing the person from the simulation
  current_coords
returns current coordinates of Person
  current_way
current way the Person is assigned to, used for collision
  dest_node
final node of current routed walk
  last_coord
coordinates where current walking starts = coordinates of last_node plus offset
  last_node
node where current walking starts
  need_next_target
if True, self.next_target() will be called and this will be set to False
  next_node
node where current walking stops, next node to walk to
  p_color
property color id: marker color of Person - DEPRECATED, use color_rgba instead
  p_color_rgba
property color: marker color of Person as RGBA 4-tuple
  p_id
property id: unique id of the Person
  passivate
if true, Person is passivated on next round of go()
  passivate_with_stop_actions
if True, the Person's actions are stopped when Person is passivated
  remove_from_sim
if True: Person's event loop will be broken on next round of go() to remove Person from simulation
  road_orthogonal_offset
walking offset from midline for road width implementation - 2-tuple - see next_target_coord
  start_node
start node of current routed walk
  stop_all_actions
if true: all Person's actions are stopped on next round of go()
  target_coord
coordinates where current walking stops = coordinates of next_node plus offset
Properties [hide private]
  p_agenttype
  p_speed
property speed: movement speed of the Person.
  x
Should not be used.
  y
Should not be used.

Inherited from object: __class__

Method Details [hide private]

__init__(self, id, sim, random, speed=1.4, **kwargs)
(Constructor)

source code 

Initializes the Person.

Parameters:
  • id - unique id of a person
  • sim - reference to superordinate mosp.core.Simulation
  • random - random object for Person - use superordinate mosp.core.Simulation.random
  • speed - basic walking speed of person in meter/tick
  • kwargs - additonal keyword arguments intended for inheriting classes
Overrides: object.__init__
Authors:
F. Ludwig, P. Tute, B. Henne

act_at_node(self, node)

source code 

Actions of the person when arriving at a node. To be overwritten with an implementation.

This method is executes when the Person arrives at a node.

Parameters:
  • node - is the next_node the Person arrives at

collide_circle(self, x, y, radius)

source code 

Checks if this person collides with the given circle. Overwrites point.collide_circle for performance optimization: call current_coords only once per x-y-pair

Overrides: collide.Point.collide_circle

collide_rectangle(self, x_min, y_min, x_max, y_max)

source code 

Checks if this person collides with the given rectangle. Overwrites point.collide_rectangle for performance optimization: call current_coords only once per x-y-pair

Overrides: collide.Point.collide_rectangle

get_near(self, dist, self_included=True)

source code 

Returns Persons near this Person.

Parameters:
  • dist - lookup radius
  • self_included - if True, this Person itself is included in resulting PersonGroup
Returns: mosp.group.PersonGroup
PersonGroup containing all Persons in distance

get_random_way_node(self, include_exits=True)

source code 

Returns a random way_node from sim.way_nodes.

Formerly known as get_random_node(). Todo: push to geo model at mosp.geo!

Parameters:
  • include_exits - if True, also nodes marked as border nodes are regarded

go(self)

source code 

The main-loop of every person.

The way a person behaves can be modified by implementing own versions of Person.handle_interrupts Person.think, Person.receive and Person.next_target.

Author: P. Tute

handle_interrupts(self)

source code 

Find out, what caused an interrupt and act accordingly.

This method is called whenever a person is interrupted. This is the place to implement own reactions to interrupts. Calling methods that were send via a send() call is done BEFORE this method is called. Handling pause, stop, removal and change of movement speed is done automatically AFTER this method is called. Removing the corresponding flag (setting it to False) in this method allows for handling these things on your own.

Note: This method does nothing per default. Implement it to react to interrupts. If you do not want or need to react to interrupts, ignore this method.

next_target(self)

source code 

Finds a new target to move to. Sets next_node, maybe dest_node. Must be overwritten with an implementation.

next_target_coord(self)

source code 

Calculates new target coordinates based on next_node coordinates plus orthogonal to road offset defined by self.road_orthogonal_offset. Examples of different values for self.road_orthogonal_offset:

  • [0,0]: No road width
  • [0,5]: random offset 0-5m to the right of the road in movement direction. Walking on a two way single lane road, walking in the right side.
  • [3,5]: random offset 3-5m to the right of the road in movement direction. Walking on the right sidewalk, road width 3m, sidewalk width 2m.
  • [-2,2]: random offset of 0-2m to the left and the right of the way. Walking on both 2m width lanes, the own and the opposite direction's lane in both directions Same as walking on a 6m width street in both directions, no distinct lanes.

pause_movement(self, duration, location_offset_xy=0, deactivateActions=False)

source code 

Stops movement of person. Currently only works with passivating at next_node. Currently cannot be used to stop on a way like after infect!

Parameters:
  • duration - pause duration
  • location_offset_xy - optional random offset to be added to current location when stopping.
  • deactivateActions - deactive actions while pausing?

readd_actions(self)

source code 

Do things, when person is readded via Simulation.readd().

This does nothing by default. It could be implemented by a simulation, if needed.

receive(self, message, sender)

source code 

Receive a message and handle it.

Removal from the message queue and earliest arrival time are handled automatically.

Parameters:
  • message - a message from the persons message queue.
  • sender - the sender of the message.
Returns:
True if the message should be removed from the queue, False else. It will then be delivered again in the next cycle.

send(self, receiver, message, earliest_arrival=None, interrupt=False)

source code 

Send a message to another Person.

Person.receive() must be implemented for anything to actually happen. Without implementation of that method, messages will simply be removed at earliest_arrival. Messages are received, whenever the receiver wakes up, before interrupts are handled or think() is called.

Parameters:
  • receiver (mosp.Person or group.PersonGroup) - a Person to receive the message
  • message - any type of message to be delivered. Implement Person.receive() accordingly.
  • earliest_arrival - the earliest tick to receive the message. Default is the next tick (self.sim.now() + 1).
  • interrupt - interrupt the receiver, after this message was queued.

stop_actions(self, removal=False)

source code 

Stop all actions of the Person.

For all actions if the Person: call stop and store as stopped action

Parameters:
  • removal - used to signal removal of the person. Actions are then stored in seperate list.

think(self)

source code 

Think about what to do next.

This method can include all logic of the person (what to do, where to go etc.). Decisions could be made by using flags for example. This is where a new self.dest_node and self.start_node should be set if necessary. self.next_node should not be set here. This should be done in self.next_target.

Returns:
time until next wakeup (int, ticks), returning a negative number or 0 will cause self.go() to find a time

Note: This method provides only the most basic functionality. Overwrite (and if necessary call) it to implement own behaviour.


Property Details [hide private]

p_agenttype

Get Method:
_get_classname(self)

p_speed

property speed: movement speed of the Person.

Get Method:
get_speed(self) - property speed: movement speed of the Person.
Set Method:
set_speed(self, speed) - Sets movement speed of the Person.

x

Should not be used. In most cases x and y are needed the same time. So properties x and y duplicate the number of calls of current_coords().

Get Method:
unreachable.x(self) - Should not be used.

y

Should not be used. In most cases x and y are needed the same time. So properties x and y duplicate the number of calls of current_coords().

Get Method:
unreachable.y(self) - Should not be used.