node.mobility module¶
Module mobility contains various classes to describe node mobility.
Note
Created by: CH Foh (2021)
List of Classes¶
BaseMobility¶
This is the base mobility. It provides specification and several useful methods.
Stationary¶
This is a class used for none moving node.
StaticPath¶
This is a static mobility model. It describes a predefined mobility and the mobility is executed in a static way. The model may be used in a dynamic way, but the user simulation must redefine the model in the simulation event to make that happens.
-
class
node.mobility.BaseMobility¶ Bases:
abc.ABCThis is an abstract base class for all mobility classes to extend. Use node.mobility.BaseMobility.get_name() to find out which subclass this instance belong to.
The subclass can access to several convenient functions via the base class.
Methods
get_dir()This method returns the current direction.
This method returns the displacement of the node in the last simulation time step.
get_loc()This method returns the current location.
get_name()Call this method to get the name of this class, which is useful to find out which subclass this instance belong to.
get_node()Get the node that uses this mobility instance.
This method returns the targeted travelling speed.
is_pause()Check if the movement of the node is paused.
pause([pause_flag])Apply a pause to the movement of the node, or resume the movement from a pause.
set_dir(direction)This method provides a direction to this mobility model.
sim__do_move(time_step)Call this method to make this node to move over a time_step.
-
__init__()¶ Default constructor.
-
abstract
get_name()¶ Call this method to get the name of this class, which is useful to find out which subclass this instance belong to. This method must be reimplemented in the subclass and the method should return a unique name.
- Returns
- str
The string describing name of this class.
-
abstract
sim__do_move(time_step) → bool¶ Call this method to make this node to move over a time_step. This method is used within the simulation engine, not for user simulation.
- Parameters
- time_stepfloat
The time to move forward to (in seconds).
- Returns
- bool
It indicates whether the provided movement for this class is completed and that no more movement is to be performed.
-
abstract
get_loc()¶ This method returns the current location.
- Returns
- sim.loc.LOC subclass
The current location.
-
abstract
get_speed()¶ This method returns the targeted travelling speed. The actual speed may be lower due to other slow moving vehicles in front.
- Returns
- float
The current speed, non-negative.
-
abstract
get_dir()¶ This method returns the current direction.
- Returns
- sim.direction.DIR subclass
The current direction.
-
abstract
set_dir(direction)¶ This method provides a direction to this mobility model.
Providing a direction to a node is needed when the node is stationary. If a mobility model is used, the mobility model will override the set direction, and hence using this method to set a direction is not necessary. The subclass controlling the direction internally will simply ignore this call.
- Parameters
- directionsim.direction.DIR subclass
The direction object to use.
-
get_displacement()¶ This method returns the displacement of the node in the last simulation time step. The displacement is useful to calculate the actual speed of a node.
- Returns
- float
The displacement of the node in the last simulation time step.
-
pause(pause_flag=True)¶ Apply a pause to the movement of the node, or resume the movement from a pause.
- Parameters
- pause_flagbool, optional, default=True
Specify whether the movement of the node should be paused or resumed from a pause.
-
is_pause()¶ Check if the movement of the node is paused.
- Returns
- bool
It returns if the movement of the node is paused.
-
get_node()¶ Get the node that uses this mobility instance.
- Returns
node.node.BaseNodesubclassIt returns the node that uses this mobility.
-
-
class
node.mobility.Stationary(location, direction=None)¶ Bases:
node.mobility.BaseMobilityThis class provides a specification of a static location for a non-moving node to use.
- Parameters
- locationsim.loc.LOC subclass
The node that has this mobility.
- directionsim.direction.DIR subclass, optional, default=None
The current direction. If None is used, it has the same behavior as sim.direction.NorthDir object.
Methods
get_dir()See the base class for details.
get_displacement()This method returns the displacement of the node in the last simulation time step.
get_loc()See the base class for details.
get_name()Call this method to get the name of this class.
get_node()Get the node that uses this mobility instance.
See the base class for details.
is_pause()Check if the movement of the node is paused.
pause([pause_flag])Apply a pause to the movement of the node, or resume the movement from a pause.
set_dir(direction)This is a stationary class, thus explicitly setting a direction is needed.
sim__do_move(time_step)This is a stationary mobility class, so calling this method does nothing.
-
__init__(location, direction=None)¶ This is the constructor.
- Parameters
- locationsim.loc.LOC subclass
The node that has this mobility.
- directionsim.direction.DIR subclass, optional, default=None
The current direction. If None is used, it has the same behavior as sim.direction.NorthDir object.
-
get_name()¶ Call this method to get the name of this class.
-
sim__do_move(time_step) → bool¶ This is a stationary mobility class, so calling this method does nothing. See also the base class for details.
-
get_loc()¶ See the base class for details.
-
get_speed()¶ See the base class for details.
-
get_dir()¶ See the base class for details.
-
set_dir(direction)¶ This is a stationary class, thus explicitly setting a direction is needed. If not, None is used which has the same behaviour of a north pointing direction.
- Parameters
- directionsim.direction.DIR subclass
Provide a direction instance to describe the pointing direction.
-
class
node.mobility.StaticPath(start_loc, path=[], delay_start=0)¶ Bases:
node.mobility.BaseMobilityThis class provides a specification of a static path for a node to move statically along the defined path independent to other vehicles.
- Parameters
- start_loc
sim.loc.LOCsubclass The starting location.
- patha list of (speed,location) tuple
The list containing a series of speed-location pairs describing the movement. From the previous location (or start_loc), the node moves to the next location with speed based on the current tuple.
- delay_startfloat
Apply a delay start to the mobility based on this input
- start_loc
Methods
add_path(speed, loc)Use this method to append a new path to the path list.
get_dir()See the base class for details.
get_displacement()This method returns the displacement of the node in the last simulation time step.
get_loc()See the base class for details.
get_name()Call this method to get the name of this class.
get_node()Get the node that uses this mobility instance.
See the base class for details.
is_pause()Check if the movement of the node is paused.
pause([pause_flag])Apply a pause to the movement of the node, or resume the movement from a pause.
reset_path(speed, loc[, delay_start])Use this method to clear all existing paths and add a new path without changing the current location.
restart([delay_start])Use this method to restart the mobility.
set_dir(direction)The method in this class will not do anything, since the direction is calculated automatically based on the moving direction.
sim__do_move(time_step)This method is used within the simulation engine, not for user simulation.
-
__init__(start_loc, path=[], delay_start=0)¶ This is the constructor.
- Parameters
- start_loc
sim.loc.LOCsubclass The starting location.
- patha list of (speed,location) tuple
The list containing a series of speed-location pairs describing the movement.
- delay_startfloat
Apply a delay start to the mobility based on this input
- start_loc
-
get_name()¶ Call this method to get the name of this class.
-
add_path(speed, loc)¶ Use this method to append a new path to the path list. When a node has completed all its movements, use this method to add a new path for the node to start moving again.
- Parameters
- speedfloat
The speed of the new path
- locsim.loc.LOC subclass
The end point of the new path
-
restart(delay_start=None)¶ Use this method to restart the mobility.
-
reset_path(speed, loc, delay_start=0)¶ Use this method to clear all existing paths and add a new path without changing the current location. The node will forget all the past movement and start moving based on the new path from its current location.
- Parameters
- speedfloat
The speed of the new path.
- loc
sim.loc.LOCsubclass The end point of the new path.
- delay_startfloat
Apply a delay start to the mobility based on this input.
-
sim__do_move(time_step) → bool¶ This method is used within the simulation engine, not for user simulation. This method to used by the simulation engine to make this node to move over a time_step. See the base class for details.
- Parameters
- time_stepfloat
The time to move forward to (in seconds).
- Returns
- boolean
Whether the mobility has reached an end. It always returns False when the movement is paused.
-
get_speed()¶ See the base class for details.
-
get_loc()¶ See the base class for details.
-
set_dir(direction)¶ The method in this class will not do anything, since the direction is calculated automatically based on the moving direction.
-
get_dir()¶ See the base class for details.