Beispiel #1
0
#init traci
current_time = 86390
traci.init(config.SUMO_PORT)

# get random 2 vehicles
conn = sqlite3.connect(config.DATABASE_FILE)
conn.row_factory = sqlite3.Row
cur = conn.cursor()
sql = "select * from day_plans where type='MOVING' and route is not null ORDER BY RANDOM() limit 2"
cur.execute(sql)
actions = cur.fetchall()
vehicles = []
for row_day_plans in actions:
    action_time = row_day_plans['time']
    action = {'action_id': utility.generate_random_string(20),
              'edges': row_day_plans['route'],
              'time': current_time + 1,
              'vehicle': 'default_car'}
    vehicles.append(action)

#ser time for each vehicle and run
vehicles[0]['time'] = current_time + 2
vehicles[1]['time'] = current_time + 20

#go to 23:59:50
print('finish init ' + str(traci_helper.get_simulate_time()))
traci.simulationStep(current_time)
print('at 86390')
traci_helper.add_vehicle(vehicles[0])
traci_helper.add_vehicle(vehicles[1])
def add_congestion(edge_id, position):
    id = "BLOCKED_" + utility.generate_random_string(20)
    add_route(id, edge_id)

    traci.vehicle.addFull(id, id, typeID="congestion_thing", departPos=str(position))
    traci.vehicle.subscribe(id, (tc.VAR_ROAD_ID, tc.VAR_LANEPOSITION))