makao / lpsolve
LPSolve 扩展,作为简单的 PHP 库
dev-master
2016-03-20 12:45 UTC
Requires
- php: >=5.6
- ext-lpsolve: >=5.5.0.8
This package is auto-updated.
Last update: 2024-08-29 04:36:55 UTC
README
LPSolve 是一个用于解决线性规划问题的 PHP 扩展。此库为标准 lpsolve() 函数提供了一个包装器。
安装
运行 composer
composer require makao/lpsolve
需要自动加载器
require 'vendor/autoload.php'
使用方法
use makao\LPSolve\Constraint; use makao\LPSolve\Problem; use makao\LPSolve\Solver; // Define constraints $constraints = [ new Constraint([120, 210, 150.75], LE, 15000), new Constraint([110, 30, 125], LE, 4000), new Constraint([1, 1, 1], LE, 75) ]; // Or initialize them from string // $constraints = [ // Constraint::fromString('120x + 210y + 150.75z <= 15000'), // Constraint::fromString('110x + 30y + 125z <= 4000'), // Constraint::fromString('1x + 1y + 1z <= 75') // ]; // Define problem $problem = new Problem([143, 60, 195], $constraints); // Solve it! $solver = new Solver(Solver::MAX); // Can be either Solver::MIN for minimalization $solution = $solver->solve($problem); var_dump($solution);
注意:从字符串创建约束时,不要省略系数值。
example.php 中提供了 3 个示例。
更多信息请访问:http://lpsolve.sourceforge.net
许可证
MIT