高性能混合整数规划求解器,现代Python API
Project description
MIPSolver
高性能混合整数规划求解器,提供现代化Python API。
安装
pip install mipsolver
快速开始
import mipsolver as mp
# 创建优化模型
model = mp.Model("example")
# 添加变量
x = model.add_var(vtype=mp.BINARY, name="x")
y = model.add_var(vtype=mp.BINARY, name="y")
# 设置目标函数
model.set_objective(5*x + 8*y, mp.MAXIMIZE)
# 添加约束
model.add_constr(2*x + 4*y <= 10, "capacity")
# 求解
model.optimize()
# 获取结果
print(f"最优值: {model.obj_val}")
print(f"x = {x.value}, y = {y.value}")
特性
- 高性能C++求解器核心
- 现代化Python API
- 多种C++ API接口(直接API、C API)
- 支持二进制、整数和连续变量
- MPS文件格式支持
- 跨平台兼容性
- 完整类型提示支持
C++ API
MIPSolver也提供了C++ API用于高性能应用:
C++ 直接API
#include "src/core.h"
#include "src/branch_bound_solver.h"
MIPSolver::Problem problem("example", MIPSolver::ObjectiveType::MAXIMIZE);
int x = problem.addVariable("x", MIPSolver::VariableType::BINARY);
int y = problem.addVariable("y", MIPSolver::VariableType::BINARY);
problem.setObjectiveCoefficient(x, 5.0);
problem.setObjectiveCoefficient(y, 8.0);
int c = problem.addConstraint("capacity", MIPSolver::ConstraintType::LESS_EQUAL, 10.0);
problem.getConstraint(c).addVariable(x, 2.0);
problem.getConstraint(c).addVariable(y, 4.0);
MIPSolver::BranchBoundSolver solver;
MIPSolver::Solution solution = solver.solve(problem);
C API
#include "api/mipsolver_c_api.h"
MIPSolver_ProblemHandle problem = MIPSolver_CreateProblem("example", MIPSOLVER_OBJ_MAXIMIZE);
int x = MIPSolver_AddVariable(problem, "x", MIPSOLVER_VAR_BINARY);
int y = MIPSolver_AddVariable(problem, "y", MIPSOLVER_VAR_BINARY);
// ... 设置目标函数和约束
MIPSolver_SolutionHandle solution = MIPSolver_Solve(problem);
更多C++示例请参考 examples/README.md
构建C++示例
cd examples
./build_examples.sh
./build/test_cpp_direct
项目结构
MIPSolver/
├── mipsolver/ # Python包源码
├── src/ # C++核心求解器
├── api/ # C语言接口
├── bindings/ # Python-C++绑定
├── examples/ # 使用示例
├── tests/ # 测试文件
├── docs/ # 项目文档
├── scripts/ # 构建脚本
└── temp/ # 临时文件
详细的项目结构说明请参考:docs/PROJECT_STRUCTURE.md
开发工具
- 清理项目:
./scripts/clean.sh- 清理所有构建产物和缓存 - 快速构建:
./scripts/build.sh- 完整的构建和测试流程 - 示例构建:
cd examples && ./build_examples.sh- 构建C++示例
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mipsolver-1.0.4.tar.gz
(37.0 kB
view details)
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mipsolver-1.0.4.tar.gz.
File metadata
- Download URL: mipsolver-1.0.4.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b48b57da43a5654ff5680188ab1690d5d9ae0682a43fdd8708ffed90da191a6f
|
|
| MD5 |
d9603a8c86fe38a336992b37417f8081
|
|
| BLAKE2b-256 |
7e697d5908c1b5b6c478f44e62e79b4ecaaeb80093e0b267320bad8ea6faba7f
|
File details
Details for the file mipsolver-1.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: mipsolver-1.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c770e96e07ea9eb4132ca9f68f345f0996a44308419faf5e9fae7a77618b76cd
|
|
| MD5 |
d8eff68f1c223f453f08b91eec7ea668
|
|
| BLAKE2b-256 |
ecf4398f8b04b6ea7221b6b338018ae0e9136152c4c4af590adf7d21963ac973
|
File details
Details for the file mipsolver-1.0.4-cp312-cp312-macosx_15_0_arm64.whl.
File metadata
- Download URL: mipsolver-1.0.4-cp312-cp312-macosx_15_0_arm64.whl
- Upload date:
- Size: 217.3 kB
- Tags: CPython 3.12, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39781148204df42f719c6b19108183869b418e6043c38c4008e106ea74d3c9c2
|
|
| MD5 |
218d9f96f692c2659b2233137e17be70
|
|
| BLAKE2b-256 |
4f87652a602166aad820ad91425609e290305b50f9e107d815db837a0084b86c
|