Code for the paper "Formalizing Traffic Rules for Uncontrolled Intersections", Abolfazl Karimi and Parasara Sridhar Duggirala, ACM/IEEE International Conference on Cyber-Physical Systems (ICCPS), 2020, pp. 41–50.
An Unreal Engine plugin for CARLA that decides, in real time and with a stated reason, which vehicle at an uncontrolled intersection is required to yield to which.
An autonomous vehicle and the humans around it need to be following the same rules. But
the rules people actually learn are written in prose, in a driver handbook, and "the
vehicle that arrives first goes first, unless two arrive together, in which case the one
on the right goes first, unless…" is exactly the shape of statement that resists being
written as a chain of if statements. Each new clause can defeat an earlier conclusion.
So this project keeps the rules in a formalism built for that. Taking California's DMV driver handbook as the working example, each rule is written as a clause in Answer Set Programming, using Clingo. ASP is non-monotonic: adding a rule can retract a conclusion that previously held, which is what "unless" means, and it is expressed here with negation as failure rather than with control flow. The result is that the mapping from a sentence in the handbook to a clause in the program is close to one-for-one, and adding a rule is a local edit rather than a rewrite.
Because the rule set is a logic program rather than a procedure, the monitor does not
just return a verdict. Its output predicate is mustYieldToForRule/3: this vehicle
must yield to that one, because of that rule. The obligation comes with its
justification, which is what makes the monitor usable for fault determination after an
incident rather than only for control during one.
The plugin turns a running simulation into logic and hands it to a solver.
- Instrument the intersection.
AIntersectionMonitoris an Unreal actor placed on an intersection. On construction it discovers the approaches (Fork), theirLanes andExits, sets up entrance and exit trigger volumes, and writes the static geometry out as ASP facts, including relations such asisToTheRightOf(Fork1, Fork2)andlaneFromTo(Lane, Fork, Exit). - Log events as atoms. As vehicles drive, the trigger callbacks
OnArrival,OnEntrance,OnEnterLane,OnExitLaneandOnExitMonitoreach append a ground atom to a log:arrivesAtForkAtTime(Vehicle, Fork, Time),entersLaneAtTime(Vehicle, Lane, Time), and so on. - Solve.
LogicSolver/monitor.clincludes the generated geometry and event facts together with the hand-written rule program, and Clingo derives the yield obligations that hold at that moment. - Act or record. The derived obligations drive the vehicles' right-of-way behavior during the run, and the log remains as an auditable record afterward.
The rule layer is small and readable. Predicates such as atTheIntersection/1,
insideTheIntersection/1, arrivedEarlierThan/2, arrivedSameTime/2 and
isToTheRightOf/2 are defined from the raw events, and the right-of-way rules are
written on top of those rather than on top of raw geometry.
Simulating autonomous vehicles at four-way and three-way uncontrolled intersections, vehicles governed by this reasoning behave more realistically than under CARLA's default FIFO intersection controller, and traffic throughput through the intersection improves. Right-of-way is resolved in real time.
Source/TrafficMonitor/
Public/, Private/
IntersectionMonitor the monitor actor: triggers, event logging, solver invocation
Fork, Lane, Exit the intersection's topology
DistanceTimeCurve vehicle motion along a lane over time
LogWriter emits ASP atoms
LogicSolver/
all-way-stop_new.cl the traffic-rule program (the current one)
all-way-stop.cl the earlier version
monitor.cl entry point; includes the generated geometry and event facts
Content/Intersection/ Unreal assets: entrance and exit triggers, lane markers,
the events logger blueprint, turn-signal enum
TrafficMonitor.uplugin
This is an Unreal Engine plugin, so it builds as part of a CARLA Unreal project: place
it under the project's Plugins/ directory and rebuild. Clingo must be available for the
solver step, and the generated fact files are written under the project's Saved/
directory, which is where monitor.cl expects to include them from.
@inproceedings{Karimi.2020,
title={Formalizing traffic rules for uncontrolled intersections},
author={Karimi, Abolfazl and Duggirala, Parasara Sridhar},
booktitle={2020 ACM/IEEE 11th International Conference on Cyber-Physical Systems (ICCPS)},
pages={41--50},
year={2020},
organization={IEEE}
}- ScenarioComplexity — generating test cases of increasing complexity by constraint solving, with these rules among the constraints (ICCPS 2022).
- ScenarioGeneration — using predicates derived from these rules as the coverage criterion driving a fuzzer (ICCPS 2026).