Citrus
Intended to work like PuLP, but with a few convenience functions thrown in.
pip install citrus
Comparisons
ANDing two variables
# 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)
# 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
# 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)
# 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
# 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)
# 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:
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
-
Variableis a subclass ofpulp.LpVariable. It adds the following methods:- (classmethod)
from_lp_var. Upgrade apulp.LpVariableto a Variable. __or__(self, other)Compute thelogical_orof two binaryVariables__and__(self, other)Compute thelogical_andof two binaryVariables__and__(self, other)Compute thelogical_andof two binaryVariables__abs__(self)Create a new Variable restricted to the absolute value of this one.
- (classmethod)
-
ProblemA subclass ofpulp.LpProblem. It adds the following methodmake_var()accepts the same arguments aspulp.LpVariable, but produces aVariable
Functions
negate(x: Variable)Produce a newVariablewith the opposite value ofx.logical_and(x: Variable, y: Variable)Produce a newVariableconstrained to take on the AND ofxandy.logical_or(x: Variable, y: Variable)Produce a newVariableconstrained to take on the OR ofxandy.logical_xor(x: Variable, y: Variable)Produce a newVariableconstrained to take on the XOR ofxandy.implies(x: Variable, y: Variable)Produce a new variable constrained to take on the value ofx => yminimum(*xs)Produce a newVariablethat can be no larger than the smallest inxsmaximum(*xy)Produce a newVariablethat can be no smaller than the largest inxs
Metadata
Release files for citrus 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| citrus-0.0.5.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| citrus-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / citrus-0.0.5.tar.gz
| Download URL | citrus-0.0.5.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d53ea7564f2c37a713f83156a1647389a33d0b772a51599626ce272f2dd7dab
|
|
BLAKE2b-256 checksum How to use checksums |
3b40e6024d3d28e86e097f6c90ecbd914326365fd6584ba3b80d5dd3e9d6bbf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.9 Darwin/21.6.0
|
Release files / citrus-0.0.5-py3-none-any.whl
| Download URL | citrus-0.0.5-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc256328bfa6dcc939f70b143e3d25b5ce8ced9bad1d9f2f9adc56ee7fbece80
|
|
BLAKE2b-256 checksum How to use checksums |
0540533d025f68c2f24983fbc443daa7ee157ba9ac949333b9b567efac4da452
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.9 Darwin/21.6.0
|