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

许可证

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.3.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

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

mipsolver-1.0.3-cp312-cp312-macosx_15_0_arm64.whl (217.0 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

File details

Details for the file mipsolver-1.0.3.tar.gz.

File metadata

  • Download URL: mipsolver-1.0.3.tar.gz
  • Upload date:
  • Size: 46.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.3.tar.gz
Algorithm Hash digest
SHA256 d0f68308b8b8f1a1f946e4c5f3d633c2f00b20f1754e9ed34728494cfcce3d88
MD5 b53a9906bdcb8b272609c5d1fbeb4e9e
BLAKE2b-256 fe2e023aca1931f8828639cb2725a88ca86c4db16b4cdb569eb899723c54c603

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mipsolver-1.0.3-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e98a3554d608d47ede917c7340f0143c402e76082083bd7c02963c138e07dea3
MD5 6fa6b18ccae5c06ee66cfcc8258db93f
BLAKE2b-256 eccb012c2437defe5bd00921ed712ecc06d80cc3301818e5c98bb78385ad83c8

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