https://github.com/freewheel/flipy
A Python linear programming interface library
https://github.com/freewheel/flipy
cbc gurobi linear-programming pulp python solver
Last synced: 9 months ago
JSON representation
A Python linear programming interface library
- Host: GitHub
- URL: https://github.com/freewheel/flipy
- Owner: freewheel
- License: apache-2.0
- Created: 2020-01-29T22:21:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-18T04:30:07.000Z (almost 4 years ago)
- Last Synced: 2025-01-10T03:19:27.577Z (about 1 year ago)
- Topics: cbc, gurobi, linear-programming, pulp, python, solver
- Language: Python
- Homepage: https://freewheel.github.io/flipy
- Size: 12.5 MB
- Stars: 25
- Watchers: 7
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Flipy

[](https://pypi.python.org/pypi/flipy/)
[](https://travis-ci.com/freewheel/flipy)
[](https://coveralls.io/github/freewheel/flipy)
Flipy is a Python linear programming interface library, originally developed by [FreeWheel](https://freewheel.com). It currently supports Gurobi and CBC as the backend solver.
To use Gurobi, make sure you have a Gurobi license file, and gurobipy is installed in your Python environment. You can find details from [Gurobi’s documentation](https://www.gurobi.com/documentation/8.1/quickstart_mac/the_gurobi_python_interfac.html).
Flipy requires Python 3.6 or newer.
## Installation
The latest offical version of Flipy can be installed with `pip`:
```
pip install flipy
```
The latest development version can be get with Git:
```
git clone https://github.com/freewheel/flipy.git
cd flipy
python setup.py install
```
## Quickstart
Here is a simple example for Flipy:
```python
import flipy
# 1 <= x <= 3.5
x = flipy.LpVariable('x', low_bound=1, up_bound=3.5)
# 2 <= y <= 4
y = flipy.LpVariable('y', low_bound=2, up_bound=4)
# 5x + y <= 12
lhs = flipy.LpExpression('lhs', {x: 2.5, y: 1})
rhs = flipy.LpExpression('rhs', constant=12)
constraint = flipy.LpConstraint(lhs, 'leq', rhs)
# maximize: 3x + 2y
objective = flipy.LpObjective('test_obj', {x: 3, y: 2}, sense=flipy.Maximize)
problem = flipy.LpProblem('test', objective, [constraint])
solver = flipy.CBCSolver()
status = solver.solve(problem)
```
## Get the solution
After solving, a status is returned to indicate whether the solver has found a optimal solution for the problem:
```python
print(status)
#
```
The objective value can be retrieved with `objective.evaluate()`:
```python
print(objective.evaluate())
# 17.6
```
The value of variables can be retrieved with `.evaluate()` as well:
```python
print(x.evaluate())
# 3.2
print(y.evaluate())
# 4.0
```