# ReMIP Server

**ReMIP** (Remote Execution for Mixed-Integer Programming) server is a FastAPI-based web service for solving Mixed-Integer Programming (MIP) problems.

## Overview

The ReMIP server directly integrates with the SCIP Optimization Suite and solves MIP problems through a RESTful API. It provides real-time logging functionality and streaming capabilities through Server-Sent Events (SSE).

## Features

- **RESTful API**: Solve MIP problems through a clean and modern API.
- **Real-time Logging**: Stream solver logs in real-time to monitor progress.
- **PySCIPOpt Integration**: Directly integrates with the SCIP Optimization Suite through its Python API for better performance and stability.
- **Containerized**: Comes with a Docker setup for easy and consistent deployment.

## Running the Server

To run the API server locally:

```bash
uv run remip
```

The API will be available at `http://localhost:8000`.

## API Documentation

This README provides a high-level overview of the API. For a complete, interactive API specification, run the server and navigate to one of the following URLs:

-   **Swagger UI**: [`http://localhost:8000/docs`](http://localhost:8000/docs)
-   **ReDoc**: [`http://localhost:8000/redoc`](http://localhost:8000/redoc)

### `POST /solve`

Solves a Mixed-Integer Programming problem.

**Request Body**:

The request body must be a JSON object representing the MIP problem, conforming to the `MIPProblem` model. This structure is typically generated by a compatible client library like `remip-client` (`pulp.LpProblem.toDict()`)

**Query Parameters**:

-   `timeout` (float, optional): The maximum time in seconds that the solver is allowed to run. If the time limit is reached, the solver will be interrupted, and the best solution found so far will be returned with a `"timelimit"` status.
-   `stream` (string, optional): If set to `sse`, the server will stream solver events (logs, metrics, and results) using Server-Sent Events. This is useful for monitoring long-running tasks.

**Responses**:

-   **Default (Non-streaming)**: Returns a single JSON object representing the final `MIPSolution`.
-   **Streaming (`stream=sse`)**: Returns a `text/event-stream` response with a series of events.

**Example `curl` Request**:

```bash
# (Note: The --data payload is a simplified example)
curl -X POST "http://localhost:8000/solve?timeout=60" \
     -H "Content-Type: application/json" \
     --data '{
         "parameters": {"name": "MyProblem", "sense": 1, "status": 0, "sol_status": 0},
         "objective": {"coefficients": [{"name": "x", "value": 1}]}
         "variables": [{"name": "x", "cat": "Integer", "lowBound": 0, "upBound": 5}],
         "constraints": []
     }'
```

### `GET /health`

Checks the health of the server. Returns a simple `true` if the server is running.

**Example `curl` Request**:

```bash
curl http://localhost:8000/health
```

### `GET /solver-info`

Returns information about the underlying optimization solver being used.

**Example `curl` Request**::

```bash
curl http://localhost:8000/solver-info
# Example Response: {"solver":"SCIP","version":"x.y.z"}
```

## Prerequisites

-   **SCIP Optimization Suite**: This project uses `pyscipopt`, which requires a working installation of the SCIP Optimization Suite. You can download it from the [official SCIP website](https://scipopt.org/index.php#download).
-   Python 3.11+
-   [uv](https://github.com/astral-sh/uv): A fast Python package installer
-   [Docker](https://www.docker.com/): For running the application in a container

## Installation

1.  **Create a virtual environment:**
    ```bash
    uv venv
    ```

2.  **Install the server and its dependencies:**
    ```bash
    # This command installs the server and test dependencies
    uv pip install -e .[test]
    ```

## Testing

To run the test suite:

```bash
uv run pytest
```

## Docker

To build and run the application using Docker:

```bash
docker-compose build
docker-compose up
```

## License

This project is licensed under the Apache License 2.0. See the [LICENSE](../LICENSE) file for details.
