kerigard/lpsolve

LPSolve extension as simple PHP library

v1.1.2 2024-11-22 10:39 UTC

This package is auto-updated.

Last update: 2024-11-22 10:42:30 UTC


README

Build Status Total Downloads Latest Stable Version License

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

License

MIT