Rustplex
Rustplex is a fast, type-safe, and ergonomic Linear Programming (LP) Solver written in pure Rust.
It uses the Two-Phase Simplex Algorithm to solve optimization problems, featuring a clean builder API that allows you to write mathematical constraints using standard Rust operators.
β οΈ Status: Early Development
This library is currently in version
0.x. The API is subject to breaking changes as we refine the solver core and introduce new features. We recommend pinning the version in yourCargo.toml.
β¨ Key Features
- Ergonomic Modeling: Use standard operators (
+,-,*) to build constraints naturally (e.g.,3*x + y <= 10). - Type Safety: Strongly typed keys (
VariableKey,ConstraintKey) prevent common mistakes, like mixing up variables from different models. - Performance Optimized: Internally uses sparse sorted vectors and an efficient
slotmaparena for memory management, ensuring fast iteration and low allocation overhead. - Robust Solver: Implements the Two-Phase Simplex method to automatically detect and handle infeasible or unbounded problems.
- Standard Form Conversion: Automatically handles complex variable bounds (e.g., free variables, ranges like
[-5, 10]) by compiling them into standard form (x >= 0) behind the scenes.
π Installation
Add rustplex to your project via Cargo:
Or add it manually to your Cargo.toml:
[]
= "0.3.0"
π» Usage
Rustplex separates the Model (your problem definition) from the Solver (the math). Here is a complete example:
use *;
Output:
Objective Value: 5
x1 = 5
x2 = 5
Solver Status: Optimal
Objective Value: 5.00
Variable Values: [
Variable(x1:cont β [2, 5]): 5.00
Variable(x2:cont β [0, inf]): 5.00
Variable(x3:cont β [-inf, 1]): 0.00
Variable(x4:cont β [-inf, inf]): 5.00
]
Iterations: 8
Solve Time: 30.90Β΅s
βοΈ Configuration
You can tune the solver's behavior (tolerances, iteration limits) via SolverConfig:
use *;
let mut model = new
.with_config;
πΊοΈ Roadmap
We are actively working on the following features:
- Comprehensive Documentation: Add detailed API references, architectural explanations, and practical examples to improve usability and understanding.
- Integer Programming (IP): Branch-and-bound support for integer variables.
- Mixed-Integer Programming (MIP): Hybrid models with both continuous and integer variables.
- Parallel Solving: Multi-threaded pivoting for massive problems.
π€ Contributing
Contributions are welcome! Whether it's reporting a bug, improving documentation, or adding a new feature, feel free to open an issue or pull request.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/amazing-feature). - Commit your changes (
git commit -m 'Add some amazing feature'). - Push to the branch (
git push origin feature/amazing-feature). - Open a Pull Request.
π License
This project is licensed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-MIT and LICENSE-APACHE for details.
Developed with β€οΈ in Rust.