Exemple #1
0
import numpy as np
from efficientroutes.model import Bicyclist, Route, Trip

bicyclist = Bicyclist()

flatNoStopData = np.recfromcsv('../data/flat_no_stops.csv')
stopLocations = []
for i, device in enumerate(flatNoStopData['traffic_control']):
    if device != '' and device != False:
        stopLocations.append(flatNoStopData['distance'][i])
flatNoStopRoute = Route(flatNoStopData['distance'],
        flatNoStopData['elevation'], flatNoStopData['speed_limit'],
        stopLocations=np.array(stopLocations))

flatNoStopTrip = Trip(bicyclist, flatNoStopRoute)
flatNoStopTrip.solve()
print "==============================="
print "Flat with no stops route stats:"
print "==============================="
flatNoStopTrip.stats()

flatNoStopFig = flatNoStopTrip.plot()
flatNoStopFig.suptitle('Flat, No Stops')
flatNoStopFig.set_figheight(8.0)
flatNoStopFig.savefig('../data/flat-no-stops.png', dpi=200)
flatNoStopFig.show()

flatWithStopData = np.recfromcsv('../data/flat_with_stops.csv')
stopLocations = []
for i, device in enumerate(flatWithStopData['traffic_control']):
    if device != '' and device != False:
bicyclist = Bicyclist()

routes = {}
for way in ['third', 'fifth', 'eighth']:
    routeData = np.recfromcsv('../data/fifth_to_hutchinson_via_' + way + '.csv')

    stopLocations = []
    for i, device in enumerate(routeData['traffic_control']):
        if device != '':
            stopLocations.append(routeData['distance'][i])

    routes[way] = Route(routeData['distance'],
            routeData['elevation'], routeData['speed_limit'],
            stopLocations=np.array(stopLocations))

for k, v in routes.items():
    trip = Trip(bicyclist, v)
    trip.solve()
    string = '{} route stats:'.format(k.capitalize())
    print "=" * len(string)
    print string
    print "=" * len(string)
    trip.stats()

    fig = trip.plot()
    fig.suptitle('Via {}'.format(k.capitalize()))
    fig.set_figheight(8.0)
    fig.savefig('../data/fith-to-hutchinson-via-' + k + '.png', dpi=200)
    fig.show()
bicyclist = Bicyclist()

# Load in the the planned bicycle route data and process the traffic controls
# column.
bicycleRouteData = np.recfromcsv('../data/columbia_river_crossing_bicycle.csv')
stopLocations = []
for i, device in enumerate(bicycleRouteData['traffic_control']):
    if device != '':
        stopLocations.append(bicycleRouteData['distance'][i])
bicycleRoute = Route(bicycleRouteData['distance'],
        bicycleRouteData['elevation'], bicycleRouteData['speed_limit'],
        stopLocations=np.array(stopLocations))

# Setup and compute the results for the trip across the planned bicycle route.
bicycleTrip = Trip(bicyclist, bicycleRoute)
bicycleTrip.solve()
print "===================="
print "Bicycle route stats:"
print "===================="
bicycleTrip.stats()

bicycleFig = bicycleTrip.plot()
bicycleFig.suptitle('Bicycle Route')
bicycleFig.set_figheight(8.0)
bicycleFig.savefig('../data/columbia_river_crossing_bicycle.png', dpi=200)
bicycleFig.show()

# Load in the data for the automobile path.
autoRouteData = np.recfromcsv('../data/columbia_river_crossing_auto.csv')
autoRoute = Route(autoRouteData['distance'],
        autoRouteData['elevation'], autoRouteData['speed_limit'] - 17.88)