flopt


Nameflopt JSON
Version 0.5.6 PyPI version JSON
download
home_pagehttps://flopt.readthedocs.io/en/latest/index.html
SummaryA python Non-Linear Programming API with Heuristic approach
upload_time2023-06-03 02:03:23
maintainer
docs_urlNone
authornariaki tateiwa
requires_python
licenseMIT
keywords optimization nonliear search heuristics algorithm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flopt

A Python Flexible Modeler for Optimization Problems.<br><br>

flopt is a modeling tool for optimization problems such as LP, QP, Ising, QUBO, etc.
flopt provides various functions for flexible and easy modeling.
Users can also solve modeled problems with several solvers to obtain optimal or good solutions.

[![Documentation Status](https://readthedocs.org/projects/flopt/badge/?version=latest)](https://flopt.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/flopt.svg)](https://badge.fury.io/py/flopt) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flopt) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](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

# 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

# Solve
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, args=[a, b])

prob = Problem(name='CustomExpression')
prob += custom_obj

# Solve
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, 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, args=[x])

# Problem
prob = Problem(name='TSP')
prob += tsp_obj

# Solve
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




            

Raw data

            {
    "_id": null,
    "home_page": "https://flopt.readthedocs.io/en/latest/index.html",
    "name": "flopt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "optimization nonliear search heuristics algorithm",
    "author": "nariaki tateiwa",
    "author_email": "nariaki3551@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/b2/bfac1e099727669ac061391b03e89cfcc853c77f3cbb2a61710af299093a/flopt-0.5.6.tar.gz",
    "platform": null,
    "description": "# flopt\n\nA Python Flexible Modeler for Optimization Problems.<br><br>\n\nflopt is a modeling tool for optimization problems such as LP, QP, Ising, QUBO, etc.\nflopt provides various functions for flexible and easy modeling.\nUsers can also solve modeled problems with several solvers to obtain optimal or good solutions.\n\n[![Documentation Status](https://readthedocs.org/projects/flopt/badge/?version=latest)](https://flopt.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/flopt.svg)](https://badge.fury.io/py/flopt) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flopt) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n[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)\n\n<br>\n\n## Install\n\n**PyPI**\n\n```\npip install flopt\n```\n\n**GitHub**\n\n```\ngit clone https://github.com/flab-coder/flopt.git\ncd flopt && python -m pip install .\n```\n\n<br>\n\n## Formulatable problems in flopt\n\n- Linear Programming (LP)\n- Quadratic Programming (QP)\n- Ising\n- Quadratic Unconstrainted Binary Programming  (QUBO)\n- Non-Linear problem\n  ```\n  minimize  2*(3*a+b)*c**2 + 3\n  s.t       a + b * c <= 3\n            0 <= a <= 1\n            1 <= b <= 2\n                 c <= 3\n  ```\n- BlackBox problem\n  ```\n  minimize  simulator(a, b, c)\n  s.t       0 <= a <= 1\n            1 <= b <= 2\n            1 <= c <= 3\n  ```\n- Finding the best permutation problem (including TSP)\n- Satisfiability problem (including MAX-SAT)\n\n<br>\n\n## Available Solvers and Heuristic Algorithms\n\n- CBC, CVXOPT, scipy.optimize(minimize, linprog, milp), Optuna\n- Random Search, 2-Opt, Swarm Intelligence Search\n\n<br>\n\n## Simple Example\n\nYou  can write codes like PuLP application.\n\n```python\nfrom flopt import Variable, Problem\n\n# Variables\na = Variable('a', lowBound=0, upBound=1, cat='Continuous')\nb = Variable('b', lowBound=1, upBound=2, cat='Continuous')\nc = Variable('c', upBound=3, cat='Continuous')\n\n# Problem\nprob = Problem()\nprob += 2 * (3*a+b) * c**2 + 3 # set the objective function\nprob += a + b * c <= 3         # set the constraint\n\n# Solve\nprob.solve(timelimit=0.5, msg=True) # run solver to solve the problem\n\n# display the result, incumbent solution\nprint('obj value', prob.getObjectiveValue())\nprint('a', a.value())\nprint('b', b.value())\nprint('c', c.value())\n```\n\n<br>\n\nIn addition, you can represent any objective function by *CustomExpression*\n\n```python\nfrom flopt import Variable, Problem, CustomExpression\n\n# Variables\na = Variable('a', lowBound=0, upBound=1, cat='Integer')\nb = Variable('b', lowBound=1, upBound=2, cat='Continuous')\n\ndef user_func(a, b):\n    from math import sin, cos\n    return (0.7*a + 0.3*cos(b)**2 + 0.1*sin(b))*abs(a)\n\ncustom_obj = CustomExpression(func=user_func, args=[a, b])\n\nprob = Problem(name='CustomExpression')\nprob += custom_obj\n\n# Solve\nprob.solve(timelimit=1, msg=True)  # run solver to solve the problem\n\n# display the result, incumbent solution\nprint('obj value', prob.getObjectiveValue())\n```\n\n<br>\n\nIn the case you solve TSP, *Permutation Variable* is useful.\n\n```python\nfrom flopt import Variable, Problem, CustomExpression\n\nN = 4  # Number of city\nD = [[0,1,2,3],  # Distance matrix\n     [3,0,2,1],\n     [1,2,0,3],\n     [2,3,1,0]]\n\n# Variables\nx = Variable('x', lowBound=0, upBound=N-1, cat='Permutation')\n\n# Object\ndef tsp_dist(x):\n    distance = 0\n    for head, tail in zip(x, x[1:]+[x[0]]):\n        distance += D[head][tail]  # D is the distance matrix\n    return distance\ntsp_obj = CustomExpression(func=tsp_dist, args=[x])\n\n# Problem\nprob = Problem(name='TSP')\nprob += tsp_obj\n\n# Solve\nprob.solve(timelimit=10, msg=True)    # run solver to solve the problem\n\n# display the result, incumbent solution\nprint('obj value', prob.getObjectiveValue())\nprint('x', x.value())\n```\n\n## Learning more\n\n- document: https://flopt.readthedocs.io/en/latest/\n- tutorials: https://flopt.readthedocs.io/en/latest/tutorial/index.html\n- case studies: https://flopt.readthedocs.io/en/latest/case_studies/index.html\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A python Non-Linear Programming API with Heuristic approach",
    "version": "0.5.6",
    "project_urls": {
        "Homepage": "https://flopt.readthedocs.io/en/latest/index.html"
    },
    "split_keywords": [
        "optimization",
        "nonliear",
        "search",
        "heuristics",
        "algorithm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0ea57dbab6084b9b9b38817f1f1a44920825a56c337f29bd56bb52d4c0a1782",
                "md5": "6c200e001af2069e8139c7637c047675",
                "sha256": "3383a692b0c4f471b789249c4145b22519aab8d95841f9f46a12ae6a93f84e90"
            },
            "downloads": -1,
            "filename": "flopt-0.5.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6c200e001af2069e8139c7637c047675",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 114357,
            "upload_time": "2023-06-03T02:03:21",
            "upload_time_iso_8601": "2023-06-03T02:03:21.262299Z",
            "url": "https://files.pythonhosted.org/packages/c0/ea/57dbab6084b9b9b38817f1f1a44920825a56c337f29bd56bb52d4c0a1782/flopt-0.5.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4eb2bfac1e099727669ac061391b03e89cfcc853c77f3cbb2a61710af299093a",
                "md5": "ec8afec6ff5ebe163006a1187eeb56d0",
                "sha256": "b701fa9f54a83f32f678d316869827e43df2c779d1eec0032fa73c5fe07a9c36"
            },
            "downloads": -1,
            "filename": "flopt-0.5.6.tar.gz",
            "has_sig": false,
            "md5_digest": "ec8afec6ff5ebe163006a1187eeb56d0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 79740,
            "upload_time": "2023-06-03T02:03:23",
            "upload_time_iso_8601": "2023-06-03T02:03:23.134419Z",
            "url": "https://files.pythonhosted.org/packages/4e/b2/bfac1e099727669ac061391b03e89cfcc853c77f3cbb2a61710af299093a/flopt-0.5.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-03 02:03:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "flopt"
}
        
Elapsed time: 0.07427s