citrus


Namecitrus JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/bgschiller/citrus
SummaryA more convenient interface to doing Binary Linear Programming with PuLP
upload_time2023-02-08 05:47:45
maintainer
docs_urlNone
authorBrian Schiller
requires_python>=3.6,<4.0
licenseMIT
keywords pulp linear optimization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # Citrus

Intended to work like [PuLP](https://github.com/coin-or/pulp), but with a few convenience functions thrown in.

```bash
pip install citrus
```

# Comparisons

## ANDing two variables

```python
# without citrus
import pulp
p = pulp.LpProblem('and example', pulp.LpMinimize)

x = pulp.LpVariable('x', cat=pulp.LpBinary)
y = pulp.LpVariable('y', cat=pulp.LpBinary)
x_and_y = pulp.LpVariable('x_and_y', cat=pulp.LpBinary)
model.addConstraint(x_and_y >= x + y - 1)
model.addConstraint(x_and_y <= x)
model.addConstraint(x_and_y <= y)
```

```python
# with citrus
import citrus
p = citrus.Problem('and example', pulp.LpMinimize)

x = p.make_var('x', cat=pulp.LpBinary)
y = p.make_var('y', cat=pulp.LpBinary)
x_and_y = x & y
# alternatively, x_and_y = citrus.logical_and(x, y)
```

## ORing two variables

```python
# without citrus
import pulp
p = pulp.LpProblem('or example', pulp.LpMinimize)

x = pulp.LpVariable('x', cat=pulp.LpBinary)
y = pulp.LpVariable('y', cat=pulp.LpBinary)
x_or_y = pulp.LpVariable('x_or_y', cat=pulp.LpBinary)
model.addConstraint(x_or_y <= x + y)
model.addConstraint(x_or_y >= x)
model.addConstraint(x_or_y >= y)
```

```python
# with citrus
import citrus
p = citrus.Problem('or example', pulp.LpMinimize)

x = p.make_var('x', cat=pulp.LpBinary)
y = p.make_var('y', cat=pulp.LpBinary)
x_or_y = x | y
# alternatively, x_or_y = citrus.logical_or(x, y)
```

## Negating a variable

```python
# without citrus
p = pulp.LpProblem('negation test', pulp.LpMinimize)

x = pulp.LpVariable('x', cat=pulp.LpBinary)
not_x = pulp.LpVariable('not_x', cat=pulp.LpBinary)
p.addConstraint(not_x == 1 - x)
```

```python
# With citrus
import citrus
p = citrus.Problem('negation test', pulp.LpMinimize)

x = p.make_var('x', cat=pulp.LpBinary)
not_x = citrus.negate(x)
```

# Tips & Tricks

Sometimes, you'll have many variables that you want to AND or OR together:

```python
p = citrus.Problem('vacation at some point', pulp.Maximize)

vacation_in_x_month = [
  p.make_var('vacation in ' + month, cat=pulp.LpBinary)
  for month in MONTHS
]

take_a_vacation = reduce(citrus.logical_or, vacation_in_x_month)
p.addConstraint(take_a_vacation)
```

# API

## Classes

- `Variable` is a subclass of `pulp.LpVariable`. It adds the following methods:

  - (classmethod) `from_lp_var`. Upgrade a `pulp.LpVariable` to a Variable.
  - `__or__(self, other)` Compute the `logical_or` of two binary `Variable`s
  - `__and__(self, other)` Compute the `logical_and` of two binary `Variable`s
  - `__and__(self, other)` Compute the `logical_and` of two binary `Variable`s
  - `__abs__(self)` Create a new Variable restricted to the absolute value of this one.

- `Problem` A subclass of `pulp.LpProblem`. It adds the following method
  - `make_var()` accepts the same arguments as `pulp.LpVariable`, but produces a `Variable`

## Functions

- `negate(x: Variable)` Produce a new `Variable` with the opposite value of `x`.
- `logical_and(x: Variable, y: Variable)` Produce a new `Variable` constrained to take on the AND of `x` and `y`.
- `logical_or(x: Variable, y: Variable)` Produce a new `Variable` constrained to take on the OR of `x` and `y`.
- `logical_xor(x: Variable, y: Variable)` Produce a new `Variable` constrained to take on the XOR of `x` and `y`.
- `implies(x: Variable, y: Variable)` Produce a new variable constrained to take on the value of `x => y`
- `minimum(*xs)` Produce a new `Variable` that can be no larger than the smallest in `xs`
- `maximum(*xy)` Produce a new `Variable` that can be no smaller than the largest in `xs`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bgschiller/citrus",
    "name": "citrus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6,<4.0",
    "maintainer_email": "",
    "keywords": "pulp,linear,optimization",
    "author": "Brian Schiller",
    "author_email": "bgschiller@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3b/40/e6024d3d28e86e097f6c90ecbd914326365fd6584ba3b80d5dd3e9d6bbf2/citrus-0.0.5.tar.gz",
    "platform": null,
    "description": "# Citrus\n\nIntended to work like [PuLP](https://github.com/coin-or/pulp), but with a few convenience functions thrown in.\n\n```bash\npip install citrus\n```\n\n# Comparisons\n\n## ANDing two variables\n\n```python\n# without citrus\nimport pulp\np = pulp.LpProblem('and example', pulp.LpMinimize)\n\nx = pulp.LpVariable('x', cat=pulp.LpBinary)\ny = pulp.LpVariable('y', cat=pulp.LpBinary)\nx_and_y = pulp.LpVariable('x_and_y', cat=pulp.LpBinary)\nmodel.addConstraint(x_and_y >= x + y - 1)\nmodel.addConstraint(x_and_y <= x)\nmodel.addConstraint(x_and_y <= y)\n```\n\n```python\n# with citrus\nimport citrus\np = citrus.Problem('and example', pulp.LpMinimize)\n\nx = p.make_var('x', cat=pulp.LpBinary)\ny = p.make_var('y', cat=pulp.LpBinary)\nx_and_y = x & y\n# alternatively, x_and_y = citrus.logical_and(x, y)\n```\n\n## ORing two variables\n\n```python\n# without citrus\nimport pulp\np = pulp.LpProblem('or example', pulp.LpMinimize)\n\nx = pulp.LpVariable('x', cat=pulp.LpBinary)\ny = pulp.LpVariable('y', cat=pulp.LpBinary)\nx_or_y = pulp.LpVariable('x_or_y', cat=pulp.LpBinary)\nmodel.addConstraint(x_or_y <= x + y)\nmodel.addConstraint(x_or_y >= x)\nmodel.addConstraint(x_or_y >= y)\n```\n\n```python\n# with citrus\nimport citrus\np = citrus.Problem('or example', pulp.LpMinimize)\n\nx = p.make_var('x', cat=pulp.LpBinary)\ny = p.make_var('y', cat=pulp.LpBinary)\nx_or_y = x | y\n# alternatively, x_or_y = citrus.logical_or(x, y)\n```\n\n## Negating a variable\n\n```python\n# without citrus\np = pulp.LpProblem('negation test', pulp.LpMinimize)\n\nx = pulp.LpVariable('x', cat=pulp.LpBinary)\nnot_x = pulp.LpVariable('not_x', cat=pulp.LpBinary)\np.addConstraint(not_x == 1 - x)\n```\n\n```python\n# With citrus\nimport citrus\np = citrus.Problem('negation test', pulp.LpMinimize)\n\nx = p.make_var('x', cat=pulp.LpBinary)\nnot_x = citrus.negate(x)\n```\n\n# Tips & Tricks\n\nSometimes, you'll have many variables that you want to AND or OR together:\n\n```python\np = citrus.Problem('vacation at some point', pulp.Maximize)\n\nvacation_in_x_month = [\n  p.make_var('vacation in ' + month, cat=pulp.LpBinary)\n  for month in MONTHS\n]\n\ntake_a_vacation = reduce(citrus.logical_or, vacation_in_x_month)\np.addConstraint(take_a_vacation)\n```\n\n# API\n\n## Classes\n\n- `Variable` is a subclass of `pulp.LpVariable`. It adds the following methods:\n\n  - (classmethod) `from_lp_var`. Upgrade a `pulp.LpVariable` to a Variable.\n  - `__or__(self, other)` Compute the `logical_or` of two binary `Variable`s\n  - `__and__(self, other)` Compute the `logical_and` of two binary `Variable`s\n  - `__and__(self, other)` Compute the `logical_and` of two binary `Variable`s\n  - `__abs__(self)` Create a new Variable restricted to the absolute value of this one.\n\n- `Problem` A subclass of `pulp.LpProblem`. It adds the following method\n  - `make_var()` accepts the same arguments as `pulp.LpVariable`, but produces a `Variable`\n\n## Functions\n\n- `negate(x: Variable)` Produce a new `Variable` with the opposite value of `x`.\n- `logical_and(x: Variable, y: Variable)` Produce a new `Variable` constrained to take on the AND of `x` and `y`.\n- `logical_or(x: Variable, y: Variable)` Produce a new `Variable` constrained to take on the OR of `x` and `y`.\n- `logical_xor(x: Variable, y: Variable)` Produce a new `Variable` constrained to take on the XOR of `x` and `y`.\n- `implies(x: Variable, y: Variable)` Produce a new variable constrained to take on the value of `x => y`\n- `minimum(*xs)` Produce a new `Variable` that can be no larger than the smallest in `xs`\n- `maximum(*xy)` Produce a new `Variable` that can be no smaller than the largest in `xs`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A more convenient interface to doing Binary Linear Programming with PuLP",
    "version": "0.0.5",
    "split_keywords": [
        "pulp",
        "linear",
        "optimization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0540533d025f68c2f24983fbc443daa7ee157ba9ac949333b9b567efac4da452",
                "md5": "bf3f0dba259e101e1ce406a4103f1d7d",
                "sha256": "dc256328bfa6dcc939f70b143e3d25b5ce8ced9bad1d9f2f9adc56ee7fbece80"
            },
            "downloads": -1,
            "filename": "citrus-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bf3f0dba259e101e1ce406a4103f1d7d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6,<4.0",
            "size": 7487,
            "upload_time": "2023-02-08T05:47:42",
            "upload_time_iso_8601": "2023-02-08T05:47:42.726206Z",
            "url": "https://files.pythonhosted.org/packages/05/40/533d025f68c2f24983fbc443daa7ee157ba9ac949333b9b567efac4da452/citrus-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3b40e6024d3d28e86e097f6c90ecbd914326365fd6584ba3b80d5dd3e9d6bbf2",
                "md5": "22bbc8c8d18cf39a4fe4b66e5cc19467",
                "sha256": "4d53ea7564f2c37a713f83156a1647389a33d0b772a51599626ce272f2dd7dab"
            },
            "downloads": -1,
            "filename": "citrus-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "22bbc8c8d18cf39a4fe4b66e5cc19467",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6,<4.0",
            "size": 6512,
            "upload_time": "2023-02-08T05:47:45",
            "upload_time_iso_8601": "2023-02-08T05:47:45.086009Z",
            "url": "https://files.pythonhosted.org/packages/3b/40/e6024d3d28e86e097f6c90ecbd914326365fd6584ba3b80d5dd3e9d6bbf2/citrus-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-08 05:47:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "bgschiller",
    "github_project": "citrus",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "citrus"
}
        
Elapsed time: 0.04411s