File size: 3,451 Bytes
aaf7a0b
 
 
 
 
 
 
 
 
 
 
f804bd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: Gale Shapely
emoji: 🏠
colorFrom: blue
colorTo: purple
sdk: streamlit
sdk_version: "1.30.0"
app_file: app.py
pinned: false
---

# 🏠 Roommate Allocation System β€” Python & Streamlit Edition

[![Python](https://img.shields.io/badge/Python-3.9+-3776AB?logo=python&logoColor=white)](https://python.org)
[![Streamlit](https://img.shields.io/badge/Streamlit-1.30+-FF4B4B?logo=streamlit&logoColor=white)](https://streamlit.io)
[![Algorithm](https://img.shields.io/badge/Algorithm-Gale--Shapley-6C63FF)](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm)

A modern **Streamlit UI** for the Gale-Shapley Roommate Allocation algorithm.  
This version uses **Python** for the algorithm and **file-system storage** (JSON) instead of MySQL.

> πŸ”— **For the original C + MySQL version**, see:  
> [https://github.com/Harshwardhan-Deshmukh03/Roommate-allocation-using-Gale-Shapley-Algorithm.git](https://github.com/Harshwardhan-Deshmukh03/Roommate-allocation-using-Gale-Shapley-Algorithm.git)

---

## ✨ Features

- **Stable Matching** via the Nobel Prize-winning Gale-Shapley algorithm
- **Two-Stage Allocation**: Roommate matching β†’ CGPA-ranked room assignment
- **CSV Import**: Bulk-upload students & rooms via CSV files
- **File-System Storage**: No database needed β€” data stored as JSON
- **Interactive Charts**: Plotly visualizations of CGPA distributions
- **Premium UI**: Dark theme with glassmorphism, gradients, and animations

---

## πŸš€ Quick Start

```bash
# 1. Create virtual environment
python -m venv venv
venv\Scripts\activate        # Windows
# source venv/bin/activate   # macOS/Linux

# 2. Install dependencies
pip install -r requirements.txt

# 3. Run the app
streamlit run app.py
```

---

## πŸ“ Project Structure

```
streamlit_gale_shapely/
β”œβ”€β”€ app.py                  # Main Streamlit UI application
β”œβ”€β”€ gale_shapley.py         # Gale-Shapley algorithm (Python port)
β”œβ”€β”€ db.py                   # File-system database layer (JSON)
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ .streamlit/
β”‚   └── config.toml         # Streamlit theme configuration
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ students.json       # Student records (replaces MySQL 'main' table)
β”‚   β”œβ”€β”€ rooms.json          # Room records (replaces MySQL 'RoomNum' table)
β”‚   └── allocations.json    # Allocation results
└── sample_csv/
    β”œβ”€β”€ sample_students_10.csv   # 10 students (5 pairs)
    β”œβ”€β”€ sample_rooms_5.csv       # 5 rooms for 10 students
    β”œβ”€β”€ sample_students_26.csv   # 26 students (13 pairs)
    └── sample_rooms_13.csv      # 13 rooms for 26 students
```

---

## πŸ“Š CSV Format

### Students CSV
| Column | Type | Description |
|--------|------|-------------|
| id | int | Unique student ID (0-indexed) |
| name | str | Student name |
| cgpa | float | CGPA (0.0–10.0) |
| pref_roommate | str | Space-separated preferred roommate IDs |
| pref_room | str | Space-separated preferred room IDs |

### Rooms CSV
| Column | Type | Description |
|--------|------|-------------|
| room_id | int | Unique room ID (0-indexed) |
| room_number | str | Room label (e.g., "A101") |

---

## 🧠 Algorithm

1. **Stage 1 β€” Roommate Matching**: Gale-Shapley pairs students into stable roommate matches.
2. **Stage 2 β€” Room Allocation**: Pairs ranked by max CGPA select rooms via Gale-Shapley.

Higher CGPA pairs get priority in room selection.