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]
Parameters:
  • 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
destination()[source]
Returns:LatLon point object with agent’s destination point
distance_to(other_point)[source]
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
got_there()[source]
Returns:True if one step or less away
Return type:bool
heading_to(other_point)[source]
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
point()[source]
Returns:LatLon point object with agent’s current location
set_destination(point)[source]

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
set_point(point)[source]

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
step()[source]

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
Parameters:
  • new_point (LatLon point) – new current point to update to
  • update_speed (bool) – wether to update agent’s speed attribute
update_route(points=[])[source]

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',
                host='localhost',
                port=17777,
                profile='fastbike')
points = [# a source
          LatLon(Latitude(19.461332069967366),
                 Longitude(-99.09204483032227)),
          # a destination
          LatLon(Latitude(19.40467336236742),
                 Longitude(-99.17787551879884))]

coarse_route = router.get_route(points=points)

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

finer_route = router.get_route(points=points,
                               speed=3)