Skip to content

PASINDU151/Senate-Bus-Problem---Parallel-and-Concurrent-Programming-

Repository files navigation

🚌 Bus-Rider Synchronization Simulation

This project simulates the classic Bus Problem from concurrent programming, implemented in Java using semaphores.
The simulation models a bus that arrives at a bus stop with multiple riders waiting. Only up to 50 riders can board at once, and the synchronization ensures safe concurrent access and communication between bus and riders.


💻 How to Run

You can use the provided Makefile for easy compilation and execution.

🧱 Compile and Run

make

Compiles all .java files and runs the simulation.


🏗️ Compile Only

make compile

Compiles all .java files into .class files without running the program.


▶️ Run Only

make run

Runs the most recently compiled simulation.


🧹 Clean Build Files

make clean

Deletes all compiled .class files.


🧩 Problem Overview

  • Buses and riders continue to arrive throughout the day.
  • The inter-arrival times of buses and riders are exponentially distributed with means of 20 minutes and 30 seconds, respectively.
  • Each bus allows up to 50 riders to board.
  • Riders who arrive while boarding is in progress must wait for the next bus.
  • Each rider signals after boarding, and the bus departs only after all selected riders are on board.

This problem demonstrates:

  • Semaphores for synchronization
  • Critical section protection using mutex
  • Rendezvous pattern between bus and riders

⚙️ Project Structure

.
├── Makefile
├── BusProblem.java
├── Rider.java
├── BusSimulation.java   # Main simulation class
└── README.md

📜 Output Example

Rider 1 arrived.
Rider 2 arrived.
Bus arrived with 5 riders waiting.
Rider 1 boarded.
Rider 2 boarded.
Bus departing with 2 riders.
Rider 3 arrived.
...

These print statements visualize how riders and buses interact in real time, demonstrating synchronization correctness.


🧠 Concepts Demonstrated

  • Mutual exclusion using semaphores (mutex)
  • Bounded waiting (max 50 riders per bus)
  • Rendezvous synchronization (bus, boarded)
  • Randomized exponential event simulation

🧹 Cleanup and Re-run

If you wish to recompile or reset the simulation environment:

make clean
make

👨‍💻 Authors

Pasindu Dulmith & Adeesha Dissanayake
University of Moratuwa – Department of Computer Science & Engineering
4th Year Undergraduates | Data Science & Main Stream Specializations

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published