Python CLI and web interface using OR-Tools CP-SAT to generate round-table seating across rounds with fixed hosts, balanced tables, and pair-wise constraints.
- Line 1:
a b c - Line 2:
d(number of same-once pairs) - Next
dlines:e_i f_i - Next line:
x(number of never-together pairs) - Next
xlines:y_i z_i
Interpretation:
a: participants 1..ab: tables 1..b; participants 1..b are hosts, fixed at their table number each roundc: number of rounds- Same-once pairs: each pair should be seated together in exactly one round if possible
- Never-together pairs: must never be seated together
JSON with fields:
participants,tables,roundstable_sizes: balanced per tableassignments: list per round, each a list per table of participant IDssatisfied_same_once_pairs,unsatisfied_same_once_pairsnever_together_violations(should be empty)objective_value,solver_status
make installPipe input into the program:
# example
cat <<EOF | make run
6 2 3
1
3 5
1
4 6
EOFOr directly:
cd python && python3 main.py < input.txtA modern React + Vite web interface is available for easier use. The frontend is built with React and deployed to GitHub Pages, and the backend runs in Docker on an Ubuntu workstation.
-
Install dependencies:
make install
This will install both Python backend dependencies and Node.js frontend dependencies.
Note: This project uses pnpm as the package manager. If you don't have pnpm installed, you can install it with:
npm install -g pnpm
Or follow the pnpm installation guide.
-
Configure environment variables (optional):
cp .env.example .env # Edit .env with your settings if needed -
Start the backend server:
make serve-backend
The API will be available at
http://localhost:8000(or the port specified in.env) -
Start the frontend development server:
make serve-frontend
The frontend will be available at
http://localhost:5173and will automatically reload on changes. -
Update backend URL (if needed):
- Edit
src/config.jsand setBACKEND_URLto your backend address - For production builds, update the URL before running
make build
- Edit
The FastAPI backend provides a REST API for scheduling. When the server is running, interactive API documentation is available at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
POST /api/schedule
Generate a schedule based on constraints.
Request Body:
{
"participants": 6,
"tables": 2,
"rounds": 3,
"same_once_pairs": [
{"u": 3, "v": 5}
],
"never_together_pairs": [
{"u": 4, "v": 6}
],
"time_limit_seconds": 60
}Response:
{
"participants": 6,
"tables": 2,
"rounds": 3,
"table_sizes": [3, 3],
"table_sizes_per_round": [[3, 3], [3, 3], [3, 3]],
"assignments": [
[[1, 3, 5], [2, 4, 6]],
[[1, 4, 5], [2, 3, 6]],
[[1, 3, 6], [2, 4, 5]]
],
"satisfied_same_once_pairs": [[3, 5]],
"unsatisfied_same_once_pairs": [],
"never_together_violations": [],
"objective_value": 1005,
"solver_status": "OPTIMAL"
}GET /health
Returns the health status of the API.
Response:
{
"status": "healthy"
}- Hosts (1..b) are fixed to their own table every round.
- Tables are balanced: first
a % btables have sizea//b + 1, othersa//b. - Non-hosts do not sit at the same table in consecutive rounds.
- Objective maximizes how many same-once pairs are met exactly once; never-together is enforced strictly.
This project is licensed under the MIT License - see the LICENSE file for details.