kerigard / lpsolve
LPSolve extension as simple PHP library
v1.1.1
2024-10-11 12:51 UTC
Requires
- php: >=5.6
- ext-lpsolve: >=5.5.0.8
Requires (Dev)
- phpunit/phpunit: >=5.0
This package is auto-updated.
Last update: 2024-10-11 12:55:19 UTC
README
LPSolve is a PHP extension for solving linear programming problems. This library provides a wrapper for standard lpsolve() function.
Installation
Run composer
composer require kerigard/lpsolve
Require autoloader
require 'vendor/autoload.php'
Usage
use Kerigard\LPSolve\Constraint; use Kerigard\LPSolve\Problem; use Kerigard\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('x + y + z <= 75') // ]; // Define problem $problem = new Problem([143, 60, 195], $constraints); // Solve it! $solver = new Solver(Solver::MAX); // Can be either Solver::MIN for minimization $solution = $solver->solve($problem); var_dump($solution);
Note
Do not omit coefficients when create constraint from string.
For more information please visit: https://lpsolve.sourceforge.net