This project simulates a tourist attraction in a salt mine, implementing concurrent programming principles to manage visitor movement and resource allocation. The simulation recreates a real-world scenario where multiple tourists navigate through a complex mine structure with specific constraints and rules.
The project is part of a larger repository containing different laboratory works. The main simulation project is located in the simulation
folder, while other directories contain labs from different classes.
.
βββ .idea
βββ demo
βββ lab_src
β βββ .idea
β βββ src
β βββ lab3_4
β βββ lab5_6
β βββ lab7_8
β βββ lab9_10
β βββ simulation
β βββ Connector.java
β βββ Controllable.java
β βββ Elevator.java
β βββ Paintable.java
β βββ Plan.java
β βββ Room.java
β βββ Simulation.java
β βββ Visitable.java
β βββ Visitor.java
β βββ config.properties
β βββ .gitignore
β βββ lab3_4.iml
βββ .gitignore
βββ LICENSE.md
βββ README.md
βββ lab3_4.iml
The mine consists of four main chambers interconnected by passages:
- 3 standard rooms (R1, R3, R4) with capacity X visitors
- 1 larger room (R2) with capacity 2X visitors
- 2 elevators (E1, E2) for vertical transportation
- Single-person bidirectional passages connecting the rooms
- Visitors cannot stop in passages between rooms
- Passages are bidirectional
- Passages allow only one person at a time
- Visitors can pass through rooms without visiting them
- Rooms cannot be divided into restricted access zones
- Each room displays a counter showing the current number of visitors
- Green paths indicate visitor routes
- Visitors can move either randomly (when visiting) or directly (when passing through)
- The Pause button changes to Resume when simulation is paused
- Multiple rapid clicks on the Restart button should be avoided to prevent unstable behavior
The simulation supports two distinct visiting routes:
- Plan A: E1 β R1 β R2 β R3 β R4 β E2
- Plan B: E2 β R4 β R3 β R2 β R1 β E1
The project utilizes modern Java concurrency features:
- Virtual threads for efficient visitor simulation
- Semaphores for room capacity management
- Synchronized blocks for critical sections
- Blocking queues for elevator management
- Event-driven GUI updates
classDiagram
class Paintable {
<<abstract>>
#Color color
+paint(Graphics g)*
}
class Visitable {
<<abstract>>
#String name
#Rectangle area
#int capacity
#int visitorCount
+onEntry(Visitor v)
+onExit(Visitor v)
}
class Room {
+Room(name, area, capacity)
}
class Elevator {
-Queue upQueue
-Queue downQueue
-Queue insideQueue
-Direction direction
+move()
+notifyUp()
+notifyDown()
}
class Visitor {
-String name
-Plan plan
-boolean visiting
+move()
+moveRandom()
+detectGoal()
}
class Plan {
-List~Visitable~ visitables
-Point startPosition
-Point endPosition
+addVisitable()
+resolveNextVisitable()
}
class Simulation {
-List~Plan~ plans
-List~Visitor~ visitors
+startSimulation()
+pauseSimulation()
+resumeSimulation()
}
Paintable <|-- Visitable
Visitable <|-- Room
Visitable <|-- Elevator
Paintable <|-- Visitor
Simulation --> Plan
Plan --> Visitable
Visitor --> Plan
sequenceDiagram
participant V as Visitor
participant R as Room
participant E as Elevator
participant P as Plan
V->>P: resolveNextVisitable()
P-->>V: nextLocation
V->>V: detectGoal()
V->>R: onEntry()
R-->>V: acquire semaphore
V->>V: moveRandom()/moveStraight()
V->>R: onExit()
R-->>V: release semaphore
V->>E: onEntry()
E-->>V: add to queue
E->>E: move()
E->>V: notify movement complete
V->>E: onExit()
flowchart TD
A[Start Simulation] --> B{Create Plans}
B --> C[Plan A]
B --> D[Plan B]
C --> E[Initialize Visitors]
D --> E
E --> F[Start Threads]
F --> G{Movement Loop}
G --> H[Check Goal]
H --> I[Move Visitor]
I --> J{Room Available?}
J -->|Yes| K[Enter Room]
J -->|No| L[Wait]
K --> M[Process Visit]
M --> N[Exit Room]
N --> G
L --> G
- Intelligent Pathfinding: Visitors can navigate between rooms using the shortest available path
- Dynamic Speed Adjustment: Movement speed adapts based on congestion and room availability
- Random/Direct Movement: Visitors can either explore rooms randomly or move directly to exits
- Thread-Safe Room Access: Synchronized access to prevent overcrowding
- Smart Elevator Scheduling: Efficient elevator algorithms to minimize wait times
- Queue Management: Fair queuing system for rooms and elevators
- Real-time Statistics: Displays current visitor count and room occupancy
- Visual Feedback: Color-coded paths and visitor states
- Interactive Controls: Dynamic adjustment of simulation parameters
- Java 21 or higher (for virtual threads support)
- 4GB RAM
- 1920x1080 display resolution (recommended)
- IDE: IntelliJ IDEA, Eclipse, or NetBeans
- Build System: Java Build Path
- Required Libraries: Java Swing (included in JDK)
-
Thread Pool Management
- Uses virtual threads for efficient concurrency
- Automatic thread lifecycle management
-
Resource Utilization
- Minimized synchronization overhead
- Efficient memory usage through object pooling
-
GUI Performance
- Optimized rendering pipeline
- Double buffering for smooth animations
This project was completed on 06/10/2024 as part of the Concurrent Programming course (PW-12/2024) under the supervision of dr inΕΌ. JarosΕaw Rulka.