An open API service indexing awesome lists of open source software.

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.

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 management

2. **Resource Utilization**
- Minimized synchronization overhead
- Efficient memory usage through object pooling

3. **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.