https://github.com/floressek/concurrentlab_algorythms
Codes from Concurrency Labs and a project that simulates a tourist attraction in a salt mine, implementing concurrent programming principles to manage visitor movement and resource allocation.
https://github.com/floressek/concurrentlab_algorythms
algorithms java
Last synced: 3 months ago
JSON representation
Codes from Concurrency Labs and a project that simulates a tourist attraction in a salt mine, implementing concurrent programming principles to manage visitor movement and resource allocation.
- Host: GitHub
- URL: https://github.com/floressek/concurrentlab_algorythms
- Owner: Floressek
- License: mit
- Created: 2024-03-24T22:30:02.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-13T22:08:53.000Z (8 months ago)
- Last Synced: 2025-02-10T22:48:03.660Z (5 months ago)
- Topics: algorithms, java
- Language: Java
- Homepage:
- Size: 177 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Mine Simulation Project (Concurrent Programming)
## Overview π―
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.## Project Structure ποΈ
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
```## Detailed Project Description π
### Mine Structure
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## Movement Rules π
1. Visitors cannot stop in passages between rooms
2. Passages are bidirectional
3. Passages allow only one person at a time
4. Visitors can pass through rooms without visiting them
5. Rooms cannot be divided into restricted access zones## Notes π
- 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### Visiting Plans
The simulation supports two distinct visiting routes:
- **Plan A**: E1 β R1 β R2 β R3 β R4 β E2
- **Plan B**: E2 β R4 β R3 β R2 β R1 β E1### Technical Implementation
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## Architecture Diagrams π
### Class Diagram
```mermaid
classDiagram
class Paintable {
<>
#Color color
+paint(Graphics g)*
}
class Visitable {
<>
#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
```### Sequence Diagram
```mermaid
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
```mermaid
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
```## Key Features π
### Advanced Movement System
- **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### Resource Management
- **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### Monitoring and Control
- **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## System Requirements π»
### Minimum Requirements
- Java 21 or higher (for virtual threads support)
- 4GB RAM
- 1920x1080 display resolution (recommended)### Development Environment
- IDE: IntelliJ IDEA, Eclipse, or NetBeans
- Build System: Java Build Path
- Required Libraries: Java Swing (included in JDK)## Performance Considerations β‘
### Optimization Techniques
1. **Thread Pool Management**
- Uses virtual threads for efficient concurrency
- Automatic thread lifecycle management2. **Resource Utilization**
- Minimized synchronization overhead
- Efficient memory usage through object pooling3. **GUI Performance**
- Optimized rendering pipeline
- Double buffering for smooth animations
## Project Status β
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.