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"}) –

linearize()[source]

linearize objective and constraints function

solve(*args, **kwargs)[source]

solve this problem.

We can use arguments same as PULP_CBC_CMD of pulp. https://coin-or.github.io/pulp/technical/solvers.html#pulp.apis.PULP_CBC_CMD shows the details of the arguments.

writeLP(*args, **kwargs)[source]

overwarp of pulp.LpProblem.writeLP

writeMPS(*args, **kwargs)[source]

overwarp of pulp.LpProblem.writeMPS

Utilities

maxValue(exp)

Calculate max value of expression

minValue(exp)

Calculate max value of expression

PiecewiseLinear(f, xl, xu[, num])

Non linear function approximator

Abs(x)

Absolute variable

And(x, y)

x & y

Or(x, y)

x | y

Xor(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) –

Return type:

VarBinaryWithConsts

ppulp.And(x, y)[source]

x & y

Parameters:
  • x (flopt.VarBinary) –

  • y (flopt.VarBinary) –

Return type:

VarBinaryWithConsts

ppulp.Or(x, y)[source]

x | y

Parameters:
  • x (flopt.VarBinary) –

  • y (flopt.VarBinary) –

Return type:

VarBinaryWithConsts

ppulp.Xor(x, y)[source]

x ^ y

Parameters:
  • x (flopt.VarBinary) –

  • y (flopt.VarBinary) –

Return type:

VarBinaryWithConsts