This project is an AI simulation of a smart traffic light system built in Clojure. It demonstrates the decision-making processes of the four foundational AI agent architectures (as defined in standard Artificial Intelligence textbooks like Russell & Norvig's AIMA).
The simulation models an intersection where cars arrive randomly, and the traffic light agent must decide whether to switch the light to keep traffic flowing efficiently.
This simulation runs the same environment through four different agent types to observe how their complexity changes their behavior:
- How it works: Makes decisions based only on the current environment state, ignoring history.
- Logic:
IFcars waiting > 5,THENswitch the light. Otherwise, do nothing. - Flaw: It has no memory. If 4 cars are waiting, it will let them sit at a red light forever because the rule hasn't been triggered.
- How it works: Maintains an internal state (memory) to track how the world evolves.
- Logic: Looks at cars waiting and how long the light has been in its current state.
- Advantage: Prevents "starvation." If the light has been red for more than 5 ticks, it forces a switch, even if there are only a few cars waiting.
- How it works: Acts to achieve a specific, defined goal by projecting into the future.
- Logic: Goal: Keep the number of waiting cars strictly below 4. It asks, "If I do nothing and more cars arrive, will I violate my goal?" If yes, it switches the light preemptively.
- Advantage: Proactive rather than reactive.
- How it works: Uses a numerical utility function to weigh the "costs" and "benefits" of its actions to maximize overall efficiency.
- Logic: Calculates a mathematical score. It weighs the penalty of making cars wait against the penalty of switching the light too quickly (which causes wear-and-tear or disrupts flow). It chooses the action with the highest utility score.
- Advantage: Can handle conflicting goals by finding the best possible compromise.
- Java Development Kit (JDK 11+)
- Leiningen (The Clojure build tool)
- Open your terminal (or PowerShell).
- Navigate to the root directory of this project.
- Run the following command:
lein run
The application will run the traffic simulation loop 4 times—once for each agent. Watch the terminal output to see how each agent reacts to the randomly generated traffic!
src/smart_traffic_light/core.clj- Contains the environment state, the simulation loop, and the logic for all four AI agents.project.clj- The Leiningen project configuration file.