lpvariable dictionar y f u nction
play

LpVariable dictionar y f u nction SU P P LY C H AIN AN ALYTIC S IN - PowerPoint PPT Presentation

LpVariable dictionar y f u nction SU P P LY C H AIN AN ALYTIC S IN P YTH ON Aaren St u bber eld S u ppl y Chain Anal y tics Mgr . Mo v ing from simple to comple x Comple x Baker y E x ample # Define Decision Variables A = LpVariable('A',


  1. LpVariable dictionar y f u nction SU P P LY C H AIN AN ALYTIC S IN P YTH ON Aaren St u bber � eld S u ppl y Chain Anal y tics Mgr .

  2. Mo v ing from simple to comple x Comple x Baker y E x ample # 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

  3. Using LpVariable . dicts () LpVariable(name, indexs, lowBound=None, upBound=None, cat='Continuous') name = The pre �x to the name of each LP v ariable created indexs = A list of strings of the ke y s to the dictionar y of LP v ariables lowBound = Lo w er bo u nd upBound = Upper bo u nd cat = The t y pe of v ariable this is Integer Binar y Contin u o u s ( defa u lt ) SUPPLY CHAIN ANALYTICS IN PYTHON

  4. LpVariable . dicts () w ith list comprehension LpVariable.dicts() o � en u sed w ith P y thon ' s list comprehension Transportation Optimi z ation # 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

  5. S u mmar y Creating man y LP v ariables for comple x problems LpVariable.dicts() Used w ith list comprehension SUPPLY CHAIN ANALYTICS IN PYTHON

  6. No w y o u tr y it o u t SU P P LY C H AIN AN ALYTIC S IN P YTH ON

  7. E x ample of a sched u ling problem SU P P LY C H AIN AN ALYTIC S IN P YTH ON Aaren St u bber � eld S u ppl y Chain Anal y tics Mgr .

  8. E x pected Demand Q u estion : Ho w man y dri v ers , in total , do w e need to Da y of Week Dri v ers Needed hire ? 0 = Monda y 11 Constraint : 1= T u esda y 14 Each dri v er w orks for 5 consec u ti v e da y s , 2 = Wednesda y 23 follo w ed b y 2 da y s o �, repeated w eekl y 3 = Th u rsda y 21 4 = Frida y 20 5 = Sat u rda y 15 6 = S u nda y 8 SUPPLY CHAIN ANALYTICS IN PYTHON

  9. Step De � nition i Decision Var X = the n u mber of dri v ers w orking on da y _ i _ 0 1 2 3 4 5 6 Objecti v e minimi z e z = X + X + X + X + X + X + X 0 S u bject to X ≥ 11 1 X ≥ 14 2 X ≥ 23 3 X ≥ 21 4 X ≥ 20 i X ≥ 0 ( i = 0, ..., 6) SUPPLY CHAIN ANALYTICS IN PYTHON

  10. Step De � nition i Decision Var X = the n u mber of dri v ers w orking on da y _ i _ 0 1 2 3 4 5 6 Objecti v e minimi z e z = X + X + X + X + X + X + X 0 3 4 5 6 S u bject to X + X + X + X + X ≥ 11 0 1 4 5 6 X + X + X + X + X ≥ 14 0 1 2 3 6 X + X + X + X + X ≥ 23 0 1 2 3 4 X + X + X + X + X ≥ 21 1 2 3 4 5 X + X + X + X + X ≥ 15 i X ? 0 ( i = 0, ..., 6) SUPPLY CHAIN ANALYTICS IN PYTHON

  11. Coding e x ample # Initialize Class # Define Constraints model = LpProblem("Minimize Staffing", model += x[0] + x[3] + x[4] + x[5] + x[6] >= 11 LpMinimize) model += x[0] + x[1] + x[4] + x[5] + x[6] >= 14 days = list(range(7)) model += x[0] + x[1] + x[2] + x[5] + x[6] >= 23 model += x[0] + x[1] + x[2] + x[3] + x[6] >= 21 # Define Decision Variables model += x[0] + x[1] + x[2] + x[3] + x[4] >= 20 x = LpVariable.dicts('staff_', days, model += x[1] + x[2] + x[3] + x[4] + x[5] >= 15 lowBound=0, cat='Integer') model += x[2] + x[3] + x[4] + x[5] + x[6] >= 8 # Define Objective # Solve Model model += lpSum([x[i] for i in days]) model.solve() SUPPLY CHAIN ANALYTICS IN PYTHON

  12. S u mmar y O u r initial v ariables did not w ork Decision v ariables to incorporate some of the constraints SUPPLY CHAIN ANALYTICS IN PYTHON

  13. Practice time ! SU P P LY C H AIN AN ALYTIC S IN P YTH ON

  14. Capacitated plant location - case st u d y P 1 SU P P LY C H AIN AN ALYTIC S IN P YTH ON Aaren St u bber � eld S u ppl y Chain Anal y tics Mgr .

  15. Conte x t M u ltiple options to meet regional prod u ct demand Option Pro Con Lo w transportation O v erall net w ork ma y ha v e e x cess Small man u fact u ring costs , fe w to no tari � s capacit y, cannot take ad v antage facilities w ithin region or d u ties economies of scale A fe w large man u fact u ring Higher transportation , higher tari � s plants and ship prod u ct to Economies of scale and d u ties region SUPPLY CHAIN ANALYTICS IN PYTHON

  16. Capacitated plant location model 1 Capacitated Plant Location Model The goal is to optimi z e global S u ppl y Chain net w ork Meet regional demand at the lo w est cost Determine regional prod u ction of a prod u ct 1 Chopra , S u nil , and Peter Meindl . _ S u ppl y Chain Management : Strateg y, Planning , and Operations ._ Pearson Prentice - Hall , 2007. SUPPLY CHAIN ANALYTICS IN PYTHON

  17. Capacitated plant location model Modeling Prod u ction at regional facilities T w o plant si z es ( lo w / high ) E x porting prod u ction to other regions Prod u ction facilities open / close SUPPLY CHAIN ANALYTICS IN PYTHON

  18. Decision v ariables What w e can control : x = q u antit y prod u ced at location _ i _ and shipped to _ j _ ij y = 1 if the plant at location _ i _ of capacit y _ s _ is open , 0 if closed is s = lo w or high capacit y plant SUPPLY CHAIN ANALYTICS IN PYTHON

  19. Objecti v e f u nction Minimi z e z = ( f y ) + ( c x ) ∑ i =1 n ∑ i =1 n ∑ i =1 m is is ij ij c = cost of prod u cing and shipping from plant _ i _ to region _ j _ ij f = �x ed cost of keeping plant _ i _ of capacit y _ s _ open is n = n u mber of prod u ction facilities m = n u mber of markets or regional demand points SUPPLY CHAIN ANALYTICS IN PYTHON

  20. from pulp import * # Initialize Class model = LpProblem("Capacitated Plant Location Model", LpMinimize) # Define Decision Variables loc = ['A', 'B', 'C', 'D', 'E'] size = ['Low_Cap','High_Cap'] x = LpVariable.dicts("production",[(i,j) for i in loc for j in loc], lowBound=0, upBound=None, cat='Continous') y = LpVariable.dicts("plant",[(i,s) for s in size for i in loc], cat='Binary') # Define objective function model += (lpSum([fix_cost.loc[i,s]*y[(i,s)] for s in size for i in loc]) + lpSum([var_cost.loc[i,j]*x[(i,j)] for i in loc for j in loc])) SUPPLY CHAIN ANALYTICS IN PYTHON

  21. S u mmar y Capacitated Plant Location Model : Finds a balance bet w een the n u mber of prod u ction facilities Model decision v ariables : Q u antit y of prod u ction in a region and e x ported High or lo w capacit y facilities open or closed Re v ie w ed objecti v e f u nction S u ms v ariable and �x ed prod u ction costs Re v ie w ed code e x ample SUPPLY CHAIN ANALYTICS IN PYTHON

  22. Re v ie w time SU P P LY C H AIN AN ALYTIC S IN P YTH ON

  23. Logical constraints SU P P LY C H AIN AN ALYTIC S IN P YTH ON Aaren St u bber � eld S u ppl y Chain Anal y tics Mgr .

  24. E x ample problem Ma x im u m Weight 20,000 lbs Select most pro � table prod u ct to ship w itho u t e x ceeding w eight limit Prod u ct Weight ( lbs ) Pro � tabilit y ($ US ) Decision Variables : i X = 1 if prod u ct _ i _ is selected else 0 A 12,800 77,878 Objecti v e : ∑ B 10,900 82,713 i i Ma x imi z e z = Pro � tabilit y X C 11,400 82,728 Constraint : ∑ i i Weight X < 20,0000 D 2,100 68,423 E 11,300 84,119 F 2,300 77,765 SUPPLY CHAIN ANALYTICS IN PYTHON

  25. prod = ['A', 'B', 'C', 'D', 'E', 'F'] weight = {'A':12800, 'B':10900, 'C':11400, 'D':2100, 'E':11300, 'F':2300} prof = {'A':77878, 'B':82713, 'C':82728, 'D':68423, 'E':84119, 'F':77765} # Initialize Class model = LpProblem("Loading Truck Problem", LpMaximize) # Define Decision Variables x = LpVariable.dicts('ship_', prod, cat='Binary') # Define Objective model += lpSum([prof[i]*x[i] for i in prod]) # Define Constraint model += lpSum([weight[i]*x[i] for i in prod]) <= 20000 # Solve Model model.solve() for i in prod: print("{} status {}".format(i, x[i].varValue)) SUPPLY CHAIN ANALYTICS IN PYTHON

  26. E x ample res u lt Ma x im u m Weight 20,000 lbs Res u lt Pro � tabilit y: $230,307 Prod u ct Ship or Not Weight of Prod u cts : 15,700 lbs A No B No C No D Yes E Yes F Yes SUPPLY CHAIN ANALYTICS IN PYTHON

  27. Logical constraint e x ample 1 Either prod u ct E is selected or prod u ct D is selected , b u t not both . E X = 1 if prod u ct _ i _ is selected else 0 D X = 1 if prod u ct _ i _ is selected else 0 Constraint E D X + X ≤ 1 SUPPLY CHAIN ANALYTICS IN PYTHON

Recommend


More recommend