[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[sumo-user] Assign Polygon as Parking lot in SUMO-TraCI
|
Hello,
I would like to create Parking lot using polygon option and treating it as a
black box instead of directly using Parking function in SUMO.
I have done coding for my parking lot(capacity, veh:entry, exit etc..) in
python. And separately created the parking spot using polygons in SUMO. Now
I would like to know how to assign this polygon as Parking space. ?
Attached is my code:
import os
import sys
import random
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME'")
import traci
import traci.constants as tc
traci.init(9999)
#contains traci control loop
def run():
step = 0
vehicles=[]
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
print(step)
vehicles= traci.vehicle.getIDList()
step += 1
print(*vehicles, sep = ", ")
#parking lot
floors=1
slots_per_floor=3
total_capacity= floors* slots_per_floor
slot= [-1]*total_capacity
available= 3
occupied= 0
slotid= 0
def display_cars():
print(*vehicles, sep = ", ")
def available_spaces():
print('The number of open spaces available are:')
available = total_capacity - occupied
print(available)
def get_empty_slot():
global slot
for i in range(len(slot)):
if slot[i]== -1:
return i
def add_vehicle(vehicles):
global occupied, total_capacity, slot
if occupied < total_capacity:
slotid= get_empty_slot()
slot[slotid]= vehicles
slotid= slotid+1
print("vehicle is parked", vehicles, "slotid", slotid)
# traci.vehicle.setStop(vehicles, "e1", pos=38.0)
occupied= occupied +1
return slotid
else:
print("Slots not available")
return -1
def empty_slot(slotid,vehicles):
global occupied, slot
if occupied>0 and slot[slotid-1] != -1:
slot[slotid-1] = -1
occupied = occupied - 1
# traci.vehicle.resume(vehicles)
return True
else:
return False
def status():
print("slotno. \t vehicle id.")
for i in range(len(slot)):
if slot[i] != -1:
print( str(i+1)+ "\t\t" + str(slot[i]))
traci.close()
sys.stdout.flush()
#main entry point
if __name__ == '__main__':
sumoBinary = "C:/Program Files (x86)/Eclipse/Sumo/bin/sumo-gui"
sumoCmd = [sumoBinary, "-c", "a.sumocfg"]
run()
--
Sent from: http://sumo-user-mailing-list.90755.n8.nabble.com/