LpVariable dictionary function

Supply Chain Analytics in Python

Aaren Stubberfield

Supply Chain Analytics Mgr.

Moving from simple to complex

Complex Bakery Example

# Define Decision Variables
A = LpVariable('A', lowBound=0, cat='Integer')
B = LpVariable('B', lowBound=0, cat='Integer')
C = LpVariable('C', lowBound=0, cat='Integer')
D = LpVariable('D', lowBound=0, cat='Integer')
E = LpVariable('E', lowBound=0, cat='Integer')
F = LpVariable('F', lowBound=0, cat='Integer')
# Define Objective Function
var_dict = {"A":A, "B":B, "C":C, "D":D, "E":E, "F":F}

# Define Objective Function
model += lpSum([profit_by_cake[type] * var_dict[type] for type in cake_types])
Supply Chain Analytics in Python

Using LpVariable.dicts()

LpVariable(name, indexs, lowBound=None, upBound=None, cat='Continuous')
  • name = The prefix to the name of each LP variable created
  • indexs = A list of strings of the keys to the dictionary of LP variables
  • lowBound = Lower bound
  • upBound = Upper bound
  • cat = The type of variable this is
    • Integer
    • Binary
    • Continuous (default)
Supply Chain Analytics in Python

LpVariable.dicts() with list comprehension

  • LpVariable.dicts() often used with Python's list comprehension

Transportation Optimization

# Define Decision Variables
customers = ['East','South','Midwest','West']
warehouse = ['New York','Atlanta']
transport = LpVariable.dicts("route", [(w,c) for w in warehouse for c in customers],
                              lowBound=0, cat='Integer')

# Define Objective model += lpSum([cost[(w,c)]*transport[(w,c)] for w in warehouse for c in customers])
Supply Chain Analytics in Python

Summary

  • Creating many LP variables for complex problems
  • LpVariable.dicts()
  • Used with list comprehension
Supply Chain Analytics in Python

Now you try it out

Supply Chain Analytics in Python

Preparing Video For Download...