def initialize(traci):
    print("Initializing targets...",end='')
    # load the node target IDs from file.
    target_node_ids = []
    try:
        with open(env.options.targets,'r') as f:
            for line in f:
                if '%' in line:
                    continue
                target_node_ids.append(line.strip())
                continue
    except FileNotFoundError:
        print('\nCould not open "%s"' % (env.options.targets))
        sys.exit(1)
    
    # Then retrieve the nodes
    env.target_nodes = purr.flattenlist(purr.batchfilterdicts(env.nodes,'id',target_node_ids))
    
    # Mark the targets on the map
    for node in env.target_nodes:
        xy = (float(node['x']),float(node['y']))
        preprocess.add_radius_polygon(traci,xy,30,(255,0,255))
    
    # Add target dictionaries to the env
    for node in env.target_nodes:
        target = {
            'id':node['id'],
            'sampling times':[],
            'sampling vids':[]
        }
        env.targets.append(target)
        continue
    
    print("Complete!")
    return
Ejemplo n.º 2
0
def initialize(traci):
    # Load targets from file
    if not env.target_file == None:
        print("Loading targets from file \"%s\"." % (env.target_file))
        env.target_nodes = purr.readJSON(env.target_file)
    # Otherwise use cone spread
    else:
        env.target_nodes = cone_spread()
        purr.save("temp/targets.json", env.target_nodes)
        if env.target_generate:
            print(
                "Target's Generated. Exiting. Check temp/targets.json for targets."
            )
            sys.exit(0)

    # Mark the targets on the map
    for node in env.target_nodes:
        xy = (float(node['x']), float(node['y']))
        preprocess.add_radius_polygon(traci, xy, 30, (255, 153, 204), layer=3)

    # Add target dictionaries to the env
    for node in env.target_nodes:
        target = {'id': node['id'], 'sampling times': [], 'sampling vids': []}
        env.targets.append(target)
        continue

    print("Complete!")
    return
Ejemplo n.º 3
0
def initialize(traci):
    env.target_nodes = env.tP

    # Mark the targets on the map
    for node in env.target_nodes:
        xy = (float(node['x']), float(node['y']))
        preprocess.add_radius_polygon(xy, 50, (0, 255, 0), layer=3)
        preprocess.add_radius_polygon(xy, 10, (255, 255, 0), layer=4)

    # Add target dictionaries to the env
    for node in env.target_nodes:
        target = {'id': node['id'], 'sampling times': [], 'sampling vids': []}
        env.targets.append(target)
        continue

    print("Complete!")
    return
Ejemplo n.º 4
0
def initialize():
    env.vehicles = [None for iveh in range(env.veh_total)]
    for i, item in enumerate(env.vehicles):
        veh = vehdict()
        veh['id'] = 'veh%d' % (i)
        try:
            veh['shortest path'] = shortest_path(i)
            
            # Starting points
            xy = (float(env.vPs[i]['x']),float(env.vPs[i]['y']))
            preprocess.add_radius_polygon(xy,50,(0,0,255),3)
            preprocess.add_radius_polygon(xy,10,(0,255,255),4)
            
             # Ending points
            xy = (float(env.vPd[i]['x']),float(env.vPd[i]['y']))
            preprocess.add_radius_polygon(xy,50,(255,0,0),3)
            preprocess.add_radius_polygon(xy,10,(255,255,0),4)        
        except nx.NetworkXNoPath:
            # Starting points
            xy0 = (float(env.vPs[i]['x']),float(env.vPs[i]['y']))
            preprocess.add_radius_polygon(xy0,50,(0,0,150),i+3)
            preprocess.add_radius_polygon(xy0,10,(0,150,150),i+4)
            
             # Ending points
            xy1 = (float(env.vPd[i]['x']),float(env.vPd[i]['y']))
            preprocess.add_radius_polygon(xy1,50,(150,0,0),i+3)
            preprocess.add_radius_polygon(xy1,10,(150,150,0),i+4)
            
            purr.save(env.status_file,False)
            print("\nPoints improperly placed.")
            sys.exit(0)
            pass
        veh['source'] = veh['shortest path']['nids'][0]
        veh['destination'] = veh['shortest path']['nids'][-1]
        veh['shortest path length'] = veh['shortest path']['weight']
        env.vehicles[i] = veh
        purr.update(i+1,env.veh_total,"Initializing vehicles ")
        continue

    return