Skip to content

This project uses Agent.py and Unity to model and simulate an agent capable of resolving Distrito Tec roundabout traffic problem.

License

Notifications You must be signed in to change notification settings

Axel3246/Smart-TrafficAgent-TEC

Repository files navigation


Logo

Smart Traffic Agent for Distrito Tec Roundabout

This project uses Agent.py and Unity to model and simulate
an agent capable of resolving Distrito Tec roundabout traffic problem.

Explore the docs »
View Live Demo

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. The Team
  5. License

About The Project

Garza Sada and Av. del Estado Roundabout

Currently, one of the main problems in any city and metropolis is traffic. The exponential increase of habitants has allowed this to become more frequent and increasingly common on the streets, avenues, intersections, and crossroads of cities. Various infrastructure, such as bridges or roundabouts, has been installed with the aim of avoiding this, but they do not always have the necessary efficiency to solve the problem.

The roundabout located at Garza Sada and Av. del Estado is one of the busiest in Distrito Tec. It was remodeled back in 2017 due to the high incidence of car accidents recorded in 2015 (86). This allowed pedestrians and drivers to enjoy various improvements. There was synchronization between traffic lights, which theoretically would allow for better vehicle and pedestrian flow. However this feature cannot be seen during the busiest hours of the roundabout and its avenues allowing traffic accumulation, thus slowing the flow.

That leads us to the purpose of this project, which is to carry out a simulation with agent and computational graphics that allows to improve the vehicle flow in the Garza Sada and Av. del Estado roundabout. The simulation consists of two solutions described below:

  • Roundabout Remodeling: It is expected that by removing or disabling some elements that make up the roundabout, such as, for example, a pair of traffic lights, the flow of traffic can greatly improve during highly traveled hours.

  • Use of Smart Traffic Lights: Due to the new restructuring of the roundabout, it is expected that by introducing a new artificial intelligence system of smart traffic lights, it will be possible to maintain the privileges and benefits of pedestrians and drivers, as well as better traffic flow due to fast decision making depending on the amount of vehicles coming from Av. Garza Sada and Av. del Estado.

(Take me up!)

Built With

The technologies that made possible this project are shown below.

  • C#
  • Unity
  • Python
  • Jupyter Notebook

(Take me up!)

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

  1. Be sure to have the lastest version of Python available in your computer. Download Python from the official website if you do not currently possess the lastest version.

  2. Verify you have pip installed in your computer. You can check by running the following command in your terminal.

  • Check pip version
    pip3 --version.

Installation

  1. Install Unity Hub and set the editor version to 2021.3.8.

  2. Install any IDE of your choice. For this project we recommend Visual Studio Code.

  3. Clone the repo.

    git clone https://github.com/Axel3246/Smart-TrafficAgent-TEC
  4. Once you clone the repo, open the Simulation-DataServer folder and go to tc2008B_server.py file. Change the port in the following line to any unused localhost port in your computer.

    def run(server_class=HTTPServer, handler_class=Server, port=YOURPORT):
  5. Unzip Unity-TSTEC.zip and move the folder to Unity Hub. Open it and go to Scripts > v3.1.2022 > clon.cs. Change the port in the following line to any unused port in your computer. This needs to match tc2008B_server.py port.

    string url = "http://localhost:YOURPORT";

(Take me up!)

Usage

There is a three step process to use this project and see the simulation in Unity. Before these steps , this agent is based on a grid enviroment which can be seen in the next picture.

Delimited Grid Enviroment For The Agents

Step One: Generating The JSON Objects

  1. Open the Simulation-DataServer folder and go to SPWN_v3.1.2022.ipynb file. By default, the ipynb file will generate 10 agents with 50 steps. If you want to change this, you may go to the parameters section and change the steps and agents values.

    parameters = {
     '''
      REMEMBER: steps are the "movements" an agent 
      will make, which means more agents need more steps 
      to finish the simulation.
     '''
     'size': 13,  # Height and length of the grid
     'steps': YOUR VALUE,
     'agents': YOUR VALUE,  # Number of 'car' agents
     }
  2. Once the parameters are set, click Run All. If done correctly, you should see at the bottom of the ipynb file an animation like the following.

Matplotlib's Agent Animation

  1. At the same time, two archives will pop up in your folder: data.json and dataSems.json. These folders contain a JSON object with data generated from the ipynb simulation. The JSON objects will be deserialized in Unity to start the visualization of the data in the engine.

Step Two: Starting The Python Server

  1. Once you've done step one, go to tc2008B_server.py and click run. This step is taking in consideration that the user has already established their free localhost port in the file.

  2. Now the server is running and it's actively listening for Unity's POST request.

Step Three: Running The Simulation In Unity!

  1. Now that we have the server running, the only thing left is to open Unity Hub and run the file Reto Multiagentes v23-11-135, which is inside the Unity-TSTEC.zip file. This step is taking in consideration that the user has already established their free localhost port in the clon.cs file.

  2. If everything is in order, Unity will generate a POST request to tc2008B_server.py and will recieve the JSON object from the data.json and dataSems.json files in return, starting the simulation. It should look similar to this, depending on the parameters that had been previously set in step one.

Unity Engine Simulation of the Smart Agents

What If I Want A New Set Of Data?

Simple! Just repeat step one, run Unity again and you're good to go!

(Take me up!)

That's a Wrap!

Congratulations! You have correctly setup a local copy of the project. Start experimenting!

If you found this repository interesting, don't forget to star it, it's highly appreciated :)!

For more examples, images, and models please refer to the project's Documentation

(Take me up!)

The Team

Here you'll find the team that made possible this project. Feel free to check out their GitHub profiles too!

(Take me up!)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(Take me up!)

About

This project uses Agent.py and Unity to model and simulate an agent capable of resolving Distrito Tec roundabout traffic problem.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published