Ejemplo n.º 1
0
    #calculate energy requirements
    ComputeEnergy(intsInRange, vehicle)  #
    routes_force = OptimalEnergyInitial(intsInRange, routes, args['routes'],
                                        Console)  #
    recalc = OptimalEnergyDetailed(intsInRange, 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))
    """routes, recom = EcoCartographer(args)"""

else:  #called by command line or PHP
    args = {
        'start': sys.argv[1].replace('+', ' '),
        'end': sys.argv[2].replace('+', ' '),
        'mass': int(sys.argv[3]),
        'cd': float(sys.argv[4]),
        'area': float(sys.argv[5]),
        'disp': float(sys.argv[6]) / 1000000,  #input is in cm^3, not m^3
        'routes': int(sys.argv[7]),
        'id': 'routes/' + sys.argv[8]
    }
    print args
Ejemplo n.º 2
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
Ejemplo n.º 3
0
                                                    interpol_refs, Console)

    #calculate energy requirements
    ComputeEnergy(final_inter, used_cons, vehicle)
    recalc = OptimalEnergy(final_inter, routes, args['routes'], vehicle,
                           Console)
    recom = Micropath(recom, vehicle)
    recom_distance = sum([pt.pt.distanceTo(pt.next.pt) for pt in recom[:-1]])
    recom_instructions = Longpath(recom, vehicle, ('energy', recom.energy),
                                  ('distance', recom_distance),
                                  ('time', recom.time))

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

else:  #called by command line or PHP
    args = {
        'start': sys.argv[1].replace('+', ' '),
        'end': sys.argv[2].replace('+', ' '),
        'mass': int(sys.argv[3]),
        'cd': float(sys.argv[4]),
        'area': float(sys.argv[5]),
        'disp': float(sys.argv[6]) / 1000000,  #input is in cm^3, not m^3
        'routes': int(sys.argv[7]),
        'id': 'routes/' + sys.argv[8]
    }
    print args