Package: intersection-control
IntersectionControl:warning: This repository is underactive developmentfor my BEng thesis and there is a high chance many APIs
and components will change in the near futureAn environment-agnostic framework for implementing and comparing intersection control algorithmsGetting StartedInstallation$pipinstallintersection-controlRefer to thedocumentationfor all
installation optionsUsageFor a more detailed description of various use-cases, please refer to thedocumentation.To run a simple experiment using the QBIM algorithm and SumoEnvironment:Import the desired algorithm/environment:fromintersection_control.environments.sumoimportSumoEnvironment,RandomDemandGeneratorfromintersection_control.algorithms.qb_imimportQBIMIntersectionManager,QBIMVehicleInstantiate the environment:The RandomDemandGenerator here is used to programmatically add vehicles to specifically to the Sumo environment. 
Alternatively, Sumo based [demand generation](https://sumo.dlr.de/docs/Demand/Introduction_to_demand_modelling_in_SUMO.html)
could be useddemand_generator=RandomDemandGenerator({"NE":2,"NS":2,"NW":2,"EN":2,"ES":2,"EW":2,"SN":2,"SE":2,"SW":2,"WN":2,"WE":2,"WS":2},0.05)env=SumoEnvironment("path/to/intersection.sumocfg",demand_generator=demand_generator,time_step=0.05,gui=True)Instantiate the vehicles and intersection managers:intersection_managers={QBIMIntersectionManager(intersection_id,env,10,0.05)forintersection_idinenv.intersections.get_ids()}# In this Sumo network there is only one intersectionvehicles={QBIMVehicle(vehicle_id,env,communication_range=75)forvehicle_idinenv.vehicles.get_ids()}Run the main loop:STEP_COUNT=360000# 1 hourfor_inrange(STEP_COUNT):env.step()removed_vehicles={vforvinvehiclesifv.get_id()inenv.get_removed_vehicles()}forvinremoved_vehicles:v.destroy()new_vehicles={QBIMVehicle(vehicle_id,env,communication_range=75)forvehicle_idinenv.get_added_vehicles()}vehicles=(vehicles-removed_vehicles).union(new_vehicles)forvehicleinvehicles:vehicle.step()forintersection_managerinintersection_managers:intersection_manager.step()This simple example is available inmisc/main.py:Exploring the codeFor a full description of the code's structure please refer to
thedocumentationThe directory structure is as follows:IntersectionControl
├── docs  # Documentation images and files
├── intersection_control  # The main source code package
│   ├── core  # Defines all interfaces and defines the component structure
│   │   ├── environment  # Provides an interface for any environment to implement
│   │   │   ├── environment.py  # Defines the base Environment class
│   │   │   ├── intersectiont_handler.py  # Defines the base IntersectionHandler class 
│   │   │   └── vehicle_handler.py  # Defines the base VehicleHandler class
│   │   ├── algorithm
│   │   │   ├── vehicle.py  # Defines the base Vehicle class
│   │   │   └── intersection_manager.py  # Defines the base IntersectionManager class
│   │   ├── communication.py  # Provides an interface for communication - V2V or V2I is possible. Specifically, defines the base MessagingUnit class
│   │   └── performance_indication.py  # Defines the base PerformanceIndicator class (Not yet implemented)
│   ├── algorithms  # A collection of intersection control algorithm implementations (for now only QBIM). These are implementations of core.Vehicle and core.IntersectionManager
│   ├── environments  # A collection of environment implementations (for now only SUMO). These are implementations of core.Environment
│   └── communication  # A collection of communication implementations (for now only DistanceBasedUnit). These are implementations of core.MessagingUnit
├── test  # unit tests for various components
└── misc  # Miscellaneous stand-alone scripts and experiments