Пример #1
0
def EcoCartographer(args):
    '''Main function. Returns routes objects and saves files.'''

    start_time = time.time()

    #prepare files
    util.mkdir(args['id'])
    Console = ecio.Console(args['id'] + '/console.html')

    start, success = Geocoder.geocode(args['start'], Console, 1, 2, 0)
    if not success:
        ecio.WriteFail(args['id'] + '/output.json')
        return False
    end, success = Geocoder.geocode(args['end'], Console, 2, 2, 0)
    if not success:
        ecio.WriteFail(args['id'] + '/output.json')
        return False
    vehicle = Vehicle(mass=args['mass'],
                      drag_coefficient=args['cd'],
                      area=args['area'],
                      displacement=args['disp'])

    #generate pts and references
    '''Update shape of network generation'''
    pts, bounds, recom, success = GetPoints(start, end, Console)
    if not success:
        ecio.WriteFail(args['id'] + '/output.json')
        return False
    references = References(pts, Console)

    #get Overpass API data
    '''pts = Overpasser.overpass(pts, references, bounds, Console)'''
    #moved later on after elev_refs and interpol_refs were calculated to reduce number of refs to sift through

    #generate original intersections, without filtering based on connections
    intind = OriginalIntersections(pts, Console)
    net = IntersectionsJoin(pts, intind, Console)
    intersections = IntersectionsBuild(net, pts, Console)

    #calculate likely routes through intersections
    routes = OptimalDistance(intersections, Console)

    #filter intersections by being in calculated intersections already
    intsInRange = util.uniquify(
        util.flatten(map(lambda a: a[0], routes))
    )  #makes list of intersections within reasonable distance to start/end
    ultimate_trim = sorted(
        util.flatten(
            map(lambda a: intersections[a].references[0].references,
                intsInRange)))  #points included in intersections
    final_inter = IntersectionsBuild(
        IntersectionsJoin(pts, ultimate_trim, Console), pts, Console)
    '''final_refs = ValidReferences(final_inter)'''

    #get elevation data of relevant pts
    '''Add in support for interpolation'''
    elev_refs, interpol_refs = Elevator.getInterpolations(
        routes, final_inter, Console)
    final_refs = elev_refs + [ref for ref, ref1, ref2 in interpol_refs]
    ref_chunks = Overpasser.chunk(pts, final_refs)
    pts = Overpasser.overpass(pts, final_refs, ref_chunks, bounds, Console)
    pts, elev_queries, success = Elevator.elevation(pts, elev_refs,
                                                    interpol_refs, Console)
    if not success:
        ecio.WriteFail(args['id'] + '/output.json')
        return False

    #calculate energy requirements
    ComputeEnergy(final_inter, vehicle)
    routes_force = OptimalEnergyInitial(final_inter, routes, args['routes'],
                                        Console)
    recalc = OptimalEnergyDetailed(final_inter, routes_force, vehicle,
                                   args['routes'], Console)
    recom = Path(recom, vehicle)

    #make instructions
    for route in recalc:
        route.getInstructions(vehicle)

    #output instructions to files
    '''Output to JSON and HTML'''
    ecio.JSON(args['id'] + '/output.json', recalc, recom)
    ecio.HTML(args['id'] + '/output.html', recalc, recom)
    Console.add('Finished', error=': ' + str(time.time() - start_time))

    return recalc, recom  #final routes
Пример #2
0
    args = {
        'start': '6936 Millbridge Road, Clemmons, NC',
        'end': '330 Knollwood Street, NC',
        'mass': 1500,
        'cd': 0.35,
        'area': 3.0,
        'disp': 0.002,
        'routes': 10,
        'id': '../routes/' + input('path (remember: string!): ')
    }

    start_time = time.time()

    #prepare files
    util.mkdir(args['id'])
    Console = ecio.Console(args['id'] + '/console.html')

    start, success = Geocoder.geocode(args['start'], Console, 1, 2, 0)
    end, success = Geocoder.geocode(args['end'], Console, 2, 2, 0)
    vehicle = Vehicle(mass=args['mass'],
                      drag_coefficient=args['cd'],
                      area=args['area'],
                      displacement=args['disp'])

    #generate pts and references
    '''Update shape of network generation'''
    pts, bounds, recom, success = GetPoints(start, end, Console)
    references = References(pts, Console)

    #get Overpass API data
    '''pts = Overpasser.overpass(pts, references, bounds, Console)'''