Skip to main content

高性能混合整数规划求解器,现代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


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)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mipsolver-1.0.4-py2.py3-none-any.whl (10.7 kB view details)

Uploaded Python 2Python 3

mipsolver-1.0.4-cp312-cp312-macosx_15_0_arm64.whl (217.3 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Hashes for mipsolver-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b48b57da43a5654ff5680188ab1690d5d9ae0682a43fdd8708ffed90da191a6f
MD5 d9603a8c86fe38a336992b37417f8081
BLAKE2b-256 7e697d5908c1b5b6c478f44e62e79b4ecaaeb80093e0b267320bad8ea6faba7f

See more details on using hashes here.

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

Hashes for mipsolver-1.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c770e96e07ea9eb4132ca9f68f345f0996a44308419faf5e9fae7a77618b76cd
MD5 d8eff68f1c223f453f08b91eec7ea668
BLAKE2b-256 ecf4398f8b04b6ea7221b6b338018ae0e9136152c4c4af590adf7d21963ac973

See more details on using hashes here.

File details

Details for the file mipsolver-1.0.4-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for mipsolver-1.0.4-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 39781148204df42f719c6b19108183869b418e6043c38c4008e106ea74d3c9c2
MD5 218d9f96f692c2659b2233137e17be70
BLAKE2b-256 4f87652a602166aad820ad91425609e290305b50f9e107d815db837a0084b86c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page