MPSolver 接口
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
用于优化的 Google 开源软件套件,
OR-Tools,提供 MPSolver 封装容器
用于求解线性规划和
混合整数编程问题。
要解决纯整数编程问题,您还可以使用
CP-SAT 求解器。
示例
以下页面举例说明了 MPSolver 的用法:
常见任务
以下部分介绍了与求解相关的常见任务
LP 和 MIP。
时间限制
以下示例展示了如何将搜索时间限制设置为 15 毫秒,
(使用 Glop 实现)。
Python
solver.set_time_limit(15)
C++
solver->set_time_limit(15);
Java
solver.setTimeLimit(15)
C#
solver.SetTimeLimit(15);
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-29。
[null,null,["最后更新时间 (UTC):2024-08-29。"],[[["\u003cp\u003eGoogle's OR-Tools provides the MPSolver for solving linear programming (LP) and mixed integer programming (MIP) problems.\u003c/p\u003e\n"],["\u003cp\u003eThe CP-SAT solver can be used for pure integer programming problems.\u003c/p\u003e\n"],["\u003cp\u003eOR-Tools offers various examples demonstrating MPSolver usage with different solvers like Glop and SCIP for LP, MIP, bin packing, and assignment problems.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can control the search time limit for solvers using the \u003ccode\u003eset_time_limit\u003c/code\u003e function across different programming languages like Python, C++, Java, and C#.\u003c/p\u003e\n"]]],["OR-Tools offers MPSolver for linear and mixed integer programming, and CP-SAT for pure integer programming. It provides examples for solving problems like the Stigler diet, LP and MIP problems, bin packing, and assignment. Common tasks include setting search time limits, demonstrated with `set_time_limit` methods in Python, C++, Java, and C#; the example shows how to set the limit to 15 milliseconds. MPSolver can be used with Glop or SCIP.\n"],null,["# MPSolver Interface\n\nGoogle's open source software suite for optimization,\n[OR-Tools](https://github.com/google/or-tools), provides the MPSolver wrapper\nfor solving [linear programming](/optimization/lp) and\n[mixed integer programming](/optimization/mip) problems.\n\nTo solve pure integer programming problems you can also use the\n[CP-SAT](/optimization/cp/cp_solver) solver.\n\nExamples\n--------\n\nThe following pages provide examples that illustrate MPSolver usage:\n\n- [Solving the Stigler diet problem](/optimization/lp/stigler_diet) using Glop\n- [Solving an LP problem](/optimization/lp/lp_example) using Glop\n- [Solving a MIP problem](/optimization/mip/mip_example) using SCIP\n- [Solving a bin packing problem](/optimization/pack/bin_packing) using SCIP\n- [Solving an assignment problem](/optimization/assignment/assignment_example) using CP-SAT\n- [Using arrays to define a model](/optimization/mip/mip_var_array)\n\nCommon tasks\n------------\n\nThe following section demonstrates common tasks related to solving\nand .\n\n### Time limits\n\nThe example below shows how to set a search time limit of 15 milliseconds when\nusing . \n\n### Python\n\n```python\nsolver.set_time_limit(15)\n```\n\n### C++\n\n```c++\nsolver-\u003eset_time_limit(15);\n```\n\n### Java\n\n```java\nsolver.setTimeLimit(15)\n```\n\n### C#\n\n```c#\nsolver.SetTimeLimit(15);\n```\n\n*[Glop]: Google Linear Optimization\n*[MIPs]: Mixed Integer Programming\n*[LPs]: Linear Programming"]]