Cbc - the mixed-integer programming solver - for PHP
First, install Cbc. For Homebrew, use:
brew install cbcAnd for Ubuntu, use:
sudo apt-get install coinor-libcbc-devThen run:
composer require ankane/cbcThe API is fairly low-level at the moment
Load a problem
$model = Cbc\Model::loadProblem(
sense: Cbc\Sense::Minimize,
start: [0, 3, 6],
index: [0, 1, 2, 0, 1, 2],
value: [2, 3, 2, 2, 4, 1],
colLower: [0, 0],
colUpper: [1e30, 1e30],
obj: [8, 10],
rowLower: [7, 12, 6],
rowUpper: [1e30, 1e30, 1e30],
colType: [Cbc\ColType::Integer, Cbc\ColType::Continuous]
);Solve
$model->solve();Write the problem to an LP or MPS file
$model->writeLp('hello.lp');
// or
$model->writeMps('hello'); // adds .mps.gzRead a problem from an LP or MPS file
$model = Cbc\Model::readLp('hello.lp');
// or
$model = Cbc\Model::readMps('hello.mps.gz');Set the log level
$model->solve(logLevel: 1); // 0 = off, 3 = maxSet the time limit in seconds
$model->solve(timeLimit: 30);View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone https://github.com/ankane/cbc-php.git
cd cbc-php
composer install
composer test