flopt-0.5.5
توضیحات
A python Non-Linear Programming API with Heuristic approach
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | flopt-0.5.5 |
| نام | flopt |
| نسخه کتابخانه | 0.5.5 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | nariaki tateiwa |
| ایمیل نویسنده | nariaki3551@gmail.com |
| آدرس صفحه اصلی | https://flopt.readthedocs.io/en/latest/index.html |
| آدرس اینترنتی | https://pypi.org/project/flopt/ |
| مجوز | MIT |
# flopt
A Python Flexible Modeler for Optimization Problems.<br><br>
flopt allows modeling of various problems such as LP, QP, Ising, QUBO, etc.<br>
Users can also solve the modeled problem using some solvers and obtain the optimal or good solutions.
[](https://flopt.readthedocs.io/en/latest/?badge=latest) [](https://badge.fury.io/py/flopt)  [](https://opensource.org/licenses/MIT)
[documentation](https://flopt.readthedocs.io/en/latest/) | [tutorial](https://flopt.readthedocs.io/en/latest/tutorial/index.html) | [case studies](https://flopt.readthedocs.io/en/latest/case_studies/index.html)
<br>
## Install
**PyPI**
```
pip install flopt
```
**GitHub**
```
git clone https://github.com/flab-coder/flopt.git
cd flopt && python -m pip install .
```
<br>
## Formulatable problems in flopt
- Linear Programming (LP)
- Quadratic Programming (QP)
- Ising
- Quadratic Unconstrainted Binary Programming (QUBO)
- Non-Linear problem
```
minimize 2*(3*a+b)*c**2 + 3
s.t a + b * c <= 3
0 <= a <= 1
1 <= b <= 2
c <= 3
```
- BlackBox problem
```
minimize simulator(a, b, c)
s.t 0 <= a <= 1
1 <= b <= 2
1 <= c <= 3
```
- Finding the best permutation problem (including TSP)
- Satisfiability problem (including MAX-SAT)
<br>
## Available Solvers and Heuristic Algorithms
- CBC, CVXOPT, scipy.optimize(minimize, linprog, milp), Optuna
- Random Search, 2-Opt, Swarm Intelligence Search
<br>
## Simple Example
You can write codes like PuLP application.
```python
from flopt import Variable, Problem, Solver
# Variables
a = Variable('a', lowBound=0, upBound=1, cat='Continuous')
b = Variable('b', lowBound=1, upBound=2, cat='Continuous')
c = Variable('c', upBound=3, cat='Continuous')
# Problem
prob = Problem()
prob += 2 * (3*a+b) * c**2 + 3 # set the objective function
prob += a + b * c <= 3 # set the constraint
# Solver
prob.solve(timelimit=0.5, msg=True) # run solver to solve the problem
# display the result, incumbent solution
print('obj value', prob.getObjectiveValue())
print('a', a.value())
print('b', b.value())
print('c', c.value())
```
<br>
In addition, you can represent any objective function by *CustomExpression*
```python
from flopt import Variable, Problem, CustomExpression
# Variables
a = Variable('a', lowBound=0, upBound=1, cat='Integer')
b = Variable('b', lowBound=1, upBound=2, cat='Continuous')
def user_func(a, b):
from math import sin, cos
return (0.7*a + 0.3*cos(b)**2 + 0.1*sin(b))*abs(a)
custom_obj = CustomExpression(func=user_func, arg=[a, b])
prob = Problem(name='CustomExpression')
prob += custom_obj
# Solver
prob.solve(timelimit=1, msg=True) # run solver to solve the problem
# display the result, incumbent solution
print('obj value', prob.getObjectiveValue())
```
<br>
In the case you solve TSP, *Permutation Variable* is useful.
```python
from flopt import Variable, Problem, Solver, CustomExpression
N = 4 # Number of city
D = [[0,1,2,3], # Distance matrix
[3,0,2,1],
[1,2,0,3],
[2,3,1,0]]
# Variables
x = Variable('x', lowBound=0, upBound=N-1, cat='Permutation')
# Object
def tsp_dist(x):
distance = 0
for head, tail in zip(x, x[1:]+[x[0]]):
distance += D[head][tail] # D is the distance matrix
return distance
tsp_obj = CustomExpression(func=tsp_dist, arg=[x])
# Problem
prob = Problem(name='TSP')
prob += tsp_obj
# Solver
prob.solve(timelimit=10, msg=True) # run solver to solve the problem
# display the result, incumbent solution
print('obj value', prob.getObjectiveValue())
print('x', x.value())
```
## Learning more
- document: https://flopt.readthedocs.io/en/latest/
- tutorials: https://flopt.readthedocs.io/en/latest/tutorial/index.html
- case studies: https://flopt.readthedocs.io/en/latest/case_studies/index.html
نیازمندی
| مقدار | نام |
|---|---|
| - | numpy |
| - | sympy |
| ==3.5.2 | matplotlib |
| - | pulp |
| ==2.10.1 | optuna |
| - | hyperopt |
| - | cvxopt |
| - | amplify |
| - | pytest |
| - | scipy |
| - | scikit-learn |
| - | dill |
| - | pooch |
| - | timeout-decorator |
نحوه نصب
نصب پکیج whl flopt-0.5.5:
pip install flopt-0.5.5.whl
نصب پکیج tar.gz flopt-0.5.5:
pip install flopt-0.5.5.tar.gz