import os
import sys
if 'SUMO_HOME' in os.environ:
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
from traci.exceptions import TraCIException
import traci.constants as tc
import libsumo as traci
else:
sys.exit("please declare environment variable 'SUMO_HOME'")
sumo_cfg = './scenario_sublane/sumo.cfg.xml'#.format(pathlib.Path(__file__).parent.absolute())
sumo_parameters = ['sumo', '-c', sumo_cfg]
# traci.start(sumo_parameters) # without GUI
traci.init(9999) # with GUI
END = 86400.0
NUMBER_OF_VEH = 100
LC_MODE = 1557 # everything except drive right changes; 512 to disable ALL
GHOST_POS = 750.0
BLOCK_LENGTH = 250.0
BLOCK_LANE = 0
type_id = 'ghost'
traci.vehicletype.copy('DEFAULT_VEHTYPE', type_id)
traci.vehicle.add(vehID='ghost1', routeID='r0', typeID='ghost', depart=0, departLane=BLOCK_LANE, departPos=GHOST_POS, departSpeed='random', arrivalLane='current', arrivalPos=GHOST_POS)
traci.vehicle.setColor(typeID='ghost1',color=(255,0,0))
traci.vehicle.setLength(typeID='ghost1',length=BLOCK_LENGTH)
traci.vehicle.setStop(vehID='ghost1', edgeID='1f2', pos=GHOST_POS, laneIndex=BLOCK_LANE, duration=10, until=END)
STEP = 0
arrived = 0
while arrived < NUMBER_OF_VEH:
print('################ SIM TIME: {} ##################'.format(traci.simulation.getTime()))
print('################ SIM STEP COUNT: {} ################'.format(STEP))
print('\n')
for vh in traci.vehicle.getIDList():
if 'ghost' not in vh:
traci.vehicle.setLaneChangeMode(vh, LC_MODE)
else:
continue
STEP+=1
arrived += traci.simulation.getArrivedNumber()
traci.simulationStep()
traci.close()
print('ARRIVED: {}'.format(arrived))