Aplication Programming Interface

Agent class

To define autonomous agents one creates instances of the Agent class. This framework emphazises the simulation of agents moving through streets, so methods are included for setting agents’ locations, destinations, and routes.

Points are mostly represented by LatLon points as defined by the LatLon library. Points in routes are just tuples of (lon, lat) because that’s what BRouter returns.

class road_agent.Agent(point, dest, router, speed=3)[source]

Agents are located at ther point, which is a lat-lon coordinate pair. They move through their route, which is a series of points that connect their current location to their destination.

__init__(point, dest, router, speed=3)[source]
  • point (LatLon point) – current location of agent
  • dest (LatLon point) – destination point of agent
  • speed (float) – speed in metres per second
  • router (NXRouter or BRouter instance) – a router instance
Returns:LatLon point object with agent’s destination point
Returns:distance from agent to another point, in metres.
Return type:float
Parameters:other_point (LatLon point) – return distance from agent’s point to here
Returns:True if one step or less away
Return type:bool
Returns:Heading from my point to @other_point, in degrees.
Return type:float
Parameters:other_point (LatLon point) – return heading from agent’s point to here
Returns:LatLon point object with agent’s current location

Get lat and lon from LatLon point object, set them as agent’s destination point.

Parameters:point (LatLon point) – set agent’s destination to point

Get lat and lon from LatLon point object, set them as agent’s point.

Parameters:point (LatLon point object) – set agent’s point to here

Calls update method to move agent to next point in route. Pops first item of route point list.

update(new_point, update_speed=False)[source]

Updates time stamp and speed.

uses @new_point to update:
  • point
  • heading
  • destination_heading
  • speed, if update_speed=True
  • new_point (LatLon point) – new current point to update to
  • update_speed (bool) – wether to update agent’s speed attribute

Query route server for points connecting current location to destination.

If @points is given, route connects current location, sequence of points, and destination.

Parameters:points – list of LatLon points
Returns:True if succesful update of route, False if route is empty

Router module

The router module includes two routing classes.

NXRouter class uses the NetworkX library to compute shortest paths between nodes to use as routes. It is simpler but not very robust.

BRouter class uses the requests library to query a BRouter server for routes. BRouter is specialized on routing for bicycles and can use different profiles for routing, including custom profiles supplied by the user.

Here’s an example of the intended use of the BRouter class:

# by default the class will query a local BRouter server
# but a different one can be supplied here
router = Router(protocol='http',
points = [# a source
          # a destination

coarse_route = router.get_route(points=points)

# speed in m/s
fine_route = router.get_route(points=points,

finer_route = router.get_route(points=points,