32 lines
1.3 KiB
Plaintext
32 lines
1.3 KiB
Plaintext
# About
|
|
|
|
This is a program that simulates traffic on a single lane bridge. All vehicles that cross the bridge implement the abstract class Vehicle. The traffic controller class manages the Semaphores and which Vehicles get to cross at what times. There's also some code in there for adding cars to the simulation. Emergency vehicles are randomly scheduled to appear at certain times during the simulation based off of the arguments.
|
|
|
|
After the program is done running it will output some information about what happened during the run of the program and some logs. The program uses Semaphores to handle what vehicle should go next, and seeing if there is a vehicle on the bridge. The vehicle class implements the runnable class and is run in a new thread when crossing the bridge for some amount of time based on the implementations.
|
|
|
|
There is a semaphore for each direction, the bridge, and emergencies.
|
|
|
|
# Compile
|
|
|
|
To compile the program you must change your directory to `src/`. You may run the following commands to compile the program.
|
|
|
|
```sh
|
|
cd src
|
|
javac *.java
|
|
```
|
|
|
|
# Running
|
|
|
|
To run the program you may run the following commands
|
|
|
|
```sh
|
|
java BridgeSimulator
|
|
```
|
|
|
|
or
|
|
|
|
```sh
|
|
java BridgeSimulator (simulation time) (emergencies)
|
|
```
|
|
|
|
If no command line arguments are given the program will default to a simulation time of 30 seconds and 2 emergencies. |