Reference¶
LpProblem¶
-
class
ppulp.
LpProblem
(*args, **kwargs)[source]¶ Problem for linear programming
from ppulp import * prob = LpProblem(sense=Lp.Maximize) x = LpVariable("x", cat="Binary") y = LpVariable("y", cat="Binary") z = x * y prob += z
We can check the details of problem.
print(prob.show()) >>> Name: None >>> Type : Problem >>> sense : Maximize >>> objective : x*y >>> #constraints : 0 >>> #variables : 2 (Binary 2)
We solve the problem with standard output.
prob.solve(msg=True)
- Parameters
name (str) – name of problem
sense (OptimizationType or str {"Minimize", "Maximize"}) –
Utilities¶
|
Calculate max value of expression |
|
Calculate max value of expression |
|
Non linear function approximator |
|
Absolute variable |
|
x & y |
|
x | y |
|
x ^ y |
-
ppulp.
maxValue
(exp)[source]¶ Calculate max value of expression
- Parameters
exp (flopt.ExpresionElement or flopt.VarElement) –
- Returns
maximum value of this expression can take
- Return type
float or str
-
ppulp.
minValue
(exp)[source]¶ Calculate max value of expression
- Parameters
exp (flopt.ExpresionElement or flopt.VarElement) –
- Returns
minimum value of this expression can take
- Return type
float or str
-
class
ppulp.
PiecewiseLinear
(f, xl, xu, num=10)[source]¶ Non linear function approximator
from ppulp import * import math prob = LpProblem(sense="Minimize") x = LpVariable("x", lowBound=3, cat="Continuous") y = LpVariable("y", lowBound=4, cat="Continuous") f = PiecewiseLinear(math.log, xl=7, xu=100, num=3) prob += f(x + y) prob += f(x) >= 10
- Parameters
f (function) – python function return the value
xl (float) – lower bound of domain
xu (float) – upper bound of domain
num (int) – number of samples
-
ppulp.
Abs
(x)[source]¶ Absolute variable
- Parameters
x (flopt.VarElement) –
- Returns
- Return type
VarBinaryWithConsts
-
ppulp.
And
(x, y)[source]¶ x & y
- Parameters
x (flopt.VarBinary) –
y (flopt.VarBinary) –
- Returns
- Return type
VarBinaryWithConsts