Provides a RESTful API interface built with FastAPI for solving constraint satisfaction problems and linear programming problems, supporting JSON requests and responses with comprehensive error handling.
gurddy-mcp
This repository contains a fully functional MCP (Model Context Protocol) server, providing solutions for Constraint Satisfaction Problems (CSP) and Linear Programming (LP). It is based on the gurddy
package and supports solving a variety of classic problems.
Main Features
CSP Problem Solving
N-Queens Problem: Place N queens on an N×N chessboard so that they do not attack each other
Graph Coloring Problem: Assign colors to graph vertices so that adjacent vertices have different colors
Map Coloring Problem: Assign colors to map regions so that adjacent regions have different colors
Sudoku Solving: Solve 9×9 Sudoku puzzles
General CSP Solver: Supports custom constraint satisfaction problems
LP/Optimization Problems
Linear Programming: Solve optimization problems with linear objective functions and constraints
Production Planning: Solve production optimization problems under resource constraints
Integer Programming: Supports optimization problems with integer variables
HTTP API Service
RESTful API interface, supporting JSON requests and responses
Comprehensive error handling and performance monitoring
Supports online solving of various CSP and LP problems
Quick Start
Environment Preparation
Usage
1. HTTP API Service
Start the HTTP server:
Access the API documentation: http://127.0.0.1:8000/docs
2. Directly Calling the Demo
Run the complete CSP functionality demonstration:
Test the API functions (no server required):
3. Command Line Tools
Check/Install gurddy:
Run example:
API endpoint
CSP problem solution
N-Queens problem
Graph coloring problem
Map coloring problem
Sudoku Solver
General CSP Solver
LP/Optimization Problems
Linear Programming
Production Planning
Project Structure
8 Queen Problem
Petersen Graph Coloring
Supported Problem Types
CSP Problems
N-Queens: The classic N-Queens problem, supporting chessboards of any size
Graph Coloring: Vertex coloring of arbitrary graph structures
Map Coloring: Coloring geographic regions, verifying the Four Color Theorem
Sudoku: Solving standard 9×9 Sudoku puzzles
Logic Puzzles: Including classic logical reasoning problems such as the Zebra Puzzle
Scheduling: Course scheduling, meeting scheduling, resource allocation, etc.
Optimization Problems
Linear Programming: Linear optimization with continuous variables
Integer Programming: Optimization with discrete variables
Production Planning: Production optimization under resource constraints
Mixed Integer Programming: Optimization with a mix of continuous and discrete variables
Performance Features
Fast Solution: Typically completes in milliseconds for small to medium-sized problems (N-Queens with N ≤ 12, graph coloring with < 50 vertices)
Memory Efficient: Uses backtracking search and constraint propagation, resulting in a small memory footprint.
Extensible: Supports custom constraints and objective functions
Concurrency-Safe: The HTTP API supports concurrent request processing
Troubleshooting
Common Errors
"gurddy package not available"
: Need to install the gurddy package"No solution found"
: No solution found under the given constraints; try relaxing the constraints."Invalid input types"
: Check the data types of the input parameters."Unknown problem type"
: Use a supported problem type.
Installation Issues
License
This project is licensed under an open source license. Please see the LICENSE file for details.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables solving Constraint Satisfaction Problems (CSP) like N-Queens, graph coloring, and Sudoku, as well as Linear Programming optimization problems through both MCP tools and HTTP API endpoints.