{"id":21347128,"url":"https://github.com/yann39/highway-simulator","last_synced_at":"2025-03-16T03:44:29.623Z","repository":{"id":224230649,"uuid":"753065800","full_name":"Yann39/highway-simulator","owner":"Yann39","description":"Java Swing application that simulates car traffic on a highway","archived":false,"fork":false,"pushed_at":"2024-02-24T16:45:25.000Z","size":3454,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T00:42:00.088Z","etag":null,"topics":["graphics2d","highway","java","swing","swing-gui"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yann39.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-05T12:01:14.000Z","updated_at":"2024-02-24T16:46:55.000Z","dependencies_parsed_at":"2024-02-24T17:51:55.080Z","dependency_job_id":null,"html_url":"https://github.com/Yann39/highway-simulator","commit_stats":null,"previous_names":["yann39/highway-simulator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fhighway-simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fhighway-simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fhighway-simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yann39%2Fhighway-simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yann39","download_url":"https://codeload.github.com/Yann39/highway-simulator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822277,"owners_count":20353499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphics2d","highway","java","swing","swing-gui"],"created_at":"2024-11-22T02:12:46.351Z","updated_at":"2025-03-16T03:44:29.604Z","avatar_url":"https://github.com/Yann39.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Highway simulator\n\n**Java Swing** application that simulates car traffic on a highway.\n\n![Version](https://img.shields.io/badge/Version-1.0.0-2AAB92.svg)\n![Static Badge](https://img.shields.io/badge/Last%20update-25%20Nov%202006-blue)\n![Version](https://img.shields.io/badge/Java-1.4-red.svg)\n\n---\n\n# Table of Contents\n\n* [About the project](#about-the-project)\n* [Usage](#usage)\n* [Description](#description)\n* [Technical details](#technical-details)\n* [License](#license)\n\n# About the project\n\n\u003cimg alt=\"Java logo\" src=\"doc/logo-java.svg\" height=\"92\"/\u003e\n\nThis is a simple GUI application (in French) that simulates cars driving on a highway, one of my first school project!\n\nThe purpose of the project is the simulation of the car traffic on a highway, the program simulates\nthe evolution of speed, lanes and positions of a set of cars arriving at regular intervals, and on\nthe other hand produces information on this evolution.\n\nApplication has been built on **November 2006** using **Netbeans IDE 5.0**.\n\nIt uses **Swing** and the **Graphics2D** library, and was compiled with **Java 1.4**.\n\n![Main interface GIF](doc/main_interface.gif \"Main interface GIF\")\n\n# Usage\n\nRun the provided `.jar` file :\n\n```bash\njava -jar \"highway-simulator.jar\"\n```\n\nThen just use the UI :\n\n![Main interface picture](doc/main_interface.png?raw=true \"Main interface\")\n\nThe application allows to :\n\n- create a new **highway** with the following parameters :\n    - number of **lanes** (`2` to `4`)\n    - length (meters, from `100m` to `10000m`)\n- add a **vehicle** with the following parameters :\n    - color (`red`, `green`, `blue`, `yellow`, `purple`)\n    - cruising speed (max `200km/h`)\n    - acceleration\n    - safety distance\n    - \"control\" car or not (\"control\" car is a special car that will be tracked independently for statistics, it will be `black` and identified with a `T` as shown below)\n- visualize some parameters like :\n    - number of cars currently running\n    - number of overtakes\n    - average speeds :\n        - faster car\n        - slower car\n        - all cars\n- view **statistics** from generated text files :\n    - session statistics (`Session.txt`)\n    - control car statistics (`VehiculeTemoin.txt`)\n\nA \"control\" car identified with a `T` :\n\n![Control car](doc/car_t.png?raw=true \"Control car\")\n\n# Description\n\nCars drive by default on a 2-lane highway. They arrive at the highway in an initial position at different intervals,\nand with an initial speed of `0`. The behavior of a car is simulated until it reaches an exit position.\n\nThere are several kinds of parameters that affect the behavior of a car :\n\n- specific parameters to each car which do not vary during execution time (safety distance, cruising speed and acceleration)\n- specific values to each car which evolve during execution time (current speed, track, position)\n\nSo the input data of the simulation program will therefore consist of :\n\n- the safety distance\n- the highway length\n- the interval between each arrival of a car at the entrance\n- a list of cars specifying, for each of them, its acceleration, cruising speed, and an identification color\n\nWe consider that a lane is free for a car if there is no other vehicle on the same lane between the\npositions `P(c)` and `P(c) + D(c)`. A lane is said to be free for a car if there is no other vehicle\nbetween the positions `P(c)-200m` and `P(c) + D(c)`.\n\nThere are two modes of traffic: _overtake_ mode and _standard_ mode.\n\n1. In _standard_ mode, a car drives on the right lane. If this lane is free, the car runs at its\n   cruising speed or accelerates until it reaches its cruising speed. If the lane is not free, then\n   it takes care of the state of the left lane :\n\n- if the left lane is free, the car begin overtaking\n- otherwise the car slows down\n\n2. In _overtaking_ mode, a car changes lane to go on the left lane (it is assumed that this change of lane is instantaneous).\n   It stays on this lane as long as it is in _overtaking_ mode. It leaves the _overtaking_ mode when the following conditions are met:\n\n- its position is located after the one of the vehicle which was right in front of it at the beginning of the overtaking\n- the right lane is free\n\nDuring the entire duration of the overtaking, if the left lane is free, the car drives at its cruising speed or accelerates until it reaches cruising speed.\nIf this lane is not free, it slows down.\n\nFinally, the program allows to identify a \"control\" car, and will record in a text file the positions and other parameters of this car.\n\n# Technical details\n\nThe application consists of several classes :\n\nBase classes :\n\n- `Vehicule` : represent a car and offers all functions related to it\n- `Autoroute` : represent the highway and offers all functions related to it\n- `EcritDansFichier` : Take care of writing into the `Session.txt` statistics file\n- `EcritVehiculeTemoin` : Take care of writing the `VehiculeTemoin.txt` statistics file\n\nFrames :\n\n- `Fenetre` : Main frame of the application, it contains the `PanelRoute` and `PanelCommandes` panels (see below) to display the whole GUI\n- `FenetreFichier` : Frame representing the window displaying the \"control\" car statistics\n- `FenetreFichierSession` : Frame representing the window displaying the whole session statistics\n\nPanels :\n\n- `PanelCommandes` : This panel contains the different components allowing to change the settings that will affect the program. This class implements the `InterfaceCommande`\n  interface which allows to communicate with the `PanelRoute` class using **listeners**\n- `PanelRoute` : This Panel contains the drawing that displays the movement of vehicles on the highway. It is intended to be added in the `Fenetre` frame to be displayed on the\n  screen next to the Panel containing the commands\n\nThe `Main` class is the entry point of the application.\n\nThe `InterfaceCommande` interface describes the actions that will need to be implemented by classes that need to listen to changes like car speed, position, etc.  (\nextends `EventListener`).\n\nThe default display of **AWT** or **Swing** components uses a simple buffer (we can see the image being drawn).\nWhen building complex animations, it may cause flickering of the image (clipping).\nTo solve this issue, we can use the **double-buffering** technique. Double buffering is having 2 buffers,\na \"back\" buffer that processes the drawing stuff in memory, and a \"front\" buffer that takes care of the display.\nProblems of refresh, image jump and other disruptive visuals effects are thus eliminated.\n\n![Double buffering](doc/double_buffering.png?raw=true \"Double buffering\")\n\nUsing a double buffer is particularly recommended for displaying complex animations or large components.\n\n# License\n\n[General Public License (GPL) v3](https://www.gnu.org/licenses/gpl-3.0.en.html)\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU\nGeneral Public License as published by the Free Software Foundation, either version 3 of the\nLicense, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\neven the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nGeneral Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program. If not,\nsee \u003chttp://www.gnu.org/licenses/\u003e.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyann39%2Fhighway-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyann39%2Fhighway-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyann39%2Fhighway-simulator/lists"}