mipsolver


Namemipsolver JSON
Version 1.0.5 PyPI version JSON
download
home_pageNone
Summary高性能混合整数规划求解器,现代Python API
upload_time2025-07-25 02:22:52
maintainerNone
docs_urlNone
authorlytreallynb
requires_python>=3.8
licenseNone
keywords optimization linear-programming integer-programming mip solver
VCS
bugtrack_url
requirements pybind11 setuptools cmake
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MIPSolver

高性能混合整数规划求解器,提供现代化Python API。

## 安装

```bash
pip install mipsolver
```

## 快速开始

```python
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

```cpp
#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

```cpp
#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](examples/README.md)

## 构建C++示例

```bash
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](docs/PROJECT_STRUCTURE.md)

## 开发工具

- **清理项目**: `./scripts/clean.sh` - 清理所有构建产物和缓存
- **快速构建**: `./scripts/build.sh` - 完整的构建和测试流程
- **示例构建**: `cd examples && ./build_examples.sh` - 构建C++示例

## 许可证

MIT License

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mipsolver",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "optimization, linear-programming, integer-programming, mip, solver",
    "author": "lytreallynb",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/4e/80/a4c021cece19d70b251e2298a2cb12ebd12560b204f76aced368ed525f65/mipsolver-1.0.5.tar.gz",
    "platform": null,
    "description": "# MIPSolver\n\n\u9ad8\u6027\u80fd\u6df7\u5408\u6574\u6570\u89c4\u5212\u6c42\u89e3\u5668\uff0c\u63d0\u4f9b\u73b0\u4ee3\u5316Python API\u3002\n\n## \u5b89\u88c5\n\n```bash\npip install mipsolver\n```\n\n## \u5feb\u901f\u5f00\u59cb\n\n```python\nimport mipsolver as mp\n\n# \u521b\u5efa\u4f18\u5316\u6a21\u578b\nmodel = mp.Model(\"example\")\n\n# \u6dfb\u52a0\u53d8\u91cf\nx = model.add_var(vtype=mp.BINARY, name=\"x\")\ny = model.add_var(vtype=mp.BINARY, name=\"y\")\n\n# \u8bbe\u7f6e\u76ee\u6807\u51fd\u6570\nmodel.set_objective(5*x + 8*y, mp.MAXIMIZE)\n\n# \u6dfb\u52a0\u7ea6\u675f\nmodel.add_constr(2*x + 4*y <= 10, \"capacity\")\n\n# \u6c42\u89e3\nmodel.optimize()\n\n# \u83b7\u53d6\u7ed3\u679c\nprint(f\"\u6700\u4f18\u503c: {model.obj_val}\")\nprint(f\"x = {x.value}, y = {y.value}\")\n```\n\n## \u7279\u6027\n\n- \u9ad8\u6027\u80fdC++\u6c42\u89e3\u5668\u6838\u5fc3\n- \u73b0\u4ee3\u5316Python API\n- \u591a\u79cdC++ API\u63a5\u53e3\uff08\u76f4\u63a5API\u3001C API\uff09\n- \u652f\u6301\u4e8c\u8fdb\u5236\u3001\u6574\u6570\u548c\u8fde\u7eed\u53d8\u91cf\n- MPS\u6587\u4ef6\u683c\u5f0f\u652f\u6301\n- \u8de8\u5e73\u53f0\u517c\u5bb9\u6027\n- \u5b8c\u6574\u7c7b\u578b\u63d0\u793a\u652f\u6301\n\n## C++ API\n\nMIPSolver\u4e5f\u63d0\u4f9b\u4e86C++ API\u7528\u4e8e\u9ad8\u6027\u80fd\u5e94\u7528\uff1a\n\n### C++ \u76f4\u63a5API\n\n```cpp\n#include \"src/core.h\"\n#include \"src/branch_bound_solver.h\"\n\nMIPSolver::Problem problem(\"example\", MIPSolver::ObjectiveType::MAXIMIZE);\nint x = problem.addVariable(\"x\", MIPSolver::VariableType::BINARY);\nint y = problem.addVariable(\"y\", MIPSolver::VariableType::BINARY);\n\nproblem.setObjectiveCoefficient(x, 5.0);\nproblem.setObjectiveCoefficient(y, 8.0);\n\nint c = problem.addConstraint(\"capacity\", MIPSolver::ConstraintType::LESS_EQUAL, 10.0);\nproblem.getConstraint(c).addVariable(x, 2.0);\nproblem.getConstraint(c).addVariable(y, 4.0);\n\nMIPSolver::BranchBoundSolver solver;\nMIPSolver::Solution solution = solver.solve(problem);\n```\n\n### C API\n\n```cpp\n#include \"api/mipsolver_c_api.h\"\n\nMIPSolver_ProblemHandle problem = MIPSolver_CreateProblem(\"example\", MIPSOLVER_OBJ_MAXIMIZE);\nint x = MIPSolver_AddVariable(problem, \"x\", MIPSOLVER_VAR_BINARY);\nint y = MIPSolver_AddVariable(problem, \"y\", MIPSOLVER_VAR_BINARY);\n// ... \u8bbe\u7f6e\u76ee\u6807\u51fd\u6570\u548c\u7ea6\u675f\nMIPSolver_SolutionHandle solution = MIPSolver_Solve(problem);\n```\n\n\u66f4\u591aC++\u793a\u4f8b\u8bf7\u53c2\u8003 [examples/README.md](examples/README.md)\n\n## \u6784\u5efaC++\u793a\u4f8b\n\n```bash\ncd examples\n./build_examples.sh\n./build/test_cpp_direct\n```\n\n## \u9879\u76ee\u7ed3\u6784\n\n```\nMIPSolver/\n\u251c\u2500\u2500 mipsolver/          # Python\u5305\u6e90\u7801\n\u251c\u2500\u2500 src/               # C++\u6838\u5fc3\u6c42\u89e3\u5668\n\u251c\u2500\u2500 api/               # C\u8bed\u8a00\u63a5\u53e3\n\u251c\u2500\u2500 bindings/          # Python-C++\u7ed1\u5b9a\n\u251c\u2500\u2500 examples/          # \u4f7f\u7528\u793a\u4f8b\n\u251c\u2500\u2500 tests/             # \u6d4b\u8bd5\u6587\u4ef6\n\u251c\u2500\u2500 docs/              # \u9879\u76ee\u6587\u6863\n\u251c\u2500\u2500 scripts/           # \u6784\u5efa\u811a\u672c\n\u2514\u2500\u2500 temp/              # \u4e34\u65f6\u6587\u4ef6\n```\n\n\u8be6\u7ec6\u7684\u9879\u76ee\u7ed3\u6784\u8bf4\u660e\u8bf7\u53c2\u8003\uff1a[docs/PROJECT_STRUCTURE.md](docs/PROJECT_STRUCTURE.md)\n\n## \u5f00\u53d1\u5de5\u5177\n\n- **\u6e05\u7406\u9879\u76ee**: `./scripts/clean.sh` - \u6e05\u7406\u6240\u6709\u6784\u5efa\u4ea7\u7269\u548c\u7f13\u5b58\n- **\u5feb\u901f\u6784\u5efa**: `./scripts/build.sh` - \u5b8c\u6574\u7684\u6784\u5efa\u548c\u6d4b\u8bd5\u6d41\u7a0b\n- **\u793a\u4f8b\u6784\u5efa**: `cd examples && ./build_examples.sh` - \u6784\u5efaC++\u793a\u4f8b\n\n## \u8bb8\u53ef\u8bc1\n\nMIT License\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u9ad8\u6027\u80fd\u6df7\u5408\u6574\u6570\u89c4\u5212\u6c42\u89e3\u5668\uff0c\u73b0\u4ee3Python API",
    "version": "1.0.5",
    "project_urls": {
        "Bug Tracker": "https://github.com/lytreallynb/MIPSolver/issues",
        "Documentation": "https://github.com/lytreallynb/MIPSolver#readme",
        "Homepage": "https://github.com/lytreallynb/MIPSolver",
        "Repository": "https://github.com/lytreallynb/MIPSolver.git"
    },
    "split_keywords": [
        "optimization",
        " linear-programming",
        " integer-programming",
        " mip",
        " solver"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "18a6e565f23bb8ec5eba9921bab3e227f3854a8774494359d56be22c1062819c",
                "md5": "22dcaface9c36793250d0805f812856d",
                "sha256": "5641774b1199353830f89d61c497d34f5e0ffa7671cacdf1d5f0d201009a7b37"
            },
            "downloads": -1,
            "filename": "mipsolver-1.0.5-cp312-cp312-macosx_15_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "22dcaface9c36793250d0805f812856d",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 218203,
            "upload_time": "2025-07-25T02:22:50",
            "upload_time_iso_8601": "2025-07-25T02:22:50.533822Z",
            "url": "https://files.pythonhosted.org/packages/18/a6/e565f23bb8ec5eba9921bab3e227f3854a8774494359d56be22c1062819c/mipsolver-1.0.5-cp312-cp312-macosx_15_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4e80a4c021cece19d70b251e2298a2cb12ebd12560b204f76aced368ed525f65",
                "md5": "206fe0dff80fd802b945a2a81c3ebb73",
                "sha256": "38a3eaec1d674a5b93bedec15cc59059dfd9accf1c2bc63e8cb64c15d8863a49"
            },
            "downloads": -1,
            "filename": "mipsolver-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "206fe0dff80fd802b945a2a81c3ebb73",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 37848,
            "upload_time": "2025-07-25T02:22:52",
            "upload_time_iso_8601": "2025-07-25T02:22:52.108757Z",
            "url": "https://files.pythonhosted.org/packages/4e/80/a4c021cece19d70b251e2298a2cb12ebd12560b204f76aced368ed525f65/mipsolver-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-25 02:22:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lytreallynb",
    "github_project": "MIPSolver",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pybind11",
            "specs": [
                [
                    ">=",
                    "2.6"
                ]
            ]
        },
        {
            "name": "setuptools",
            "specs": []
        },
        {
            "name": "cmake",
            "specs": []
        }
    ],
    "lcname": "mipsolver"
}
        
Elapsed time: 1.60417s