common constraint mistakes
play

Common constraint mistakes SU P P LY C H AIN AN ALYTIC S IN P YTH - PowerPoint PPT Presentation

Common constraint mistakes 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 . Dependent demand constraint Conte x t Prod u ction Plan Planning for 2 prod u cts ( A , and B ) Planning for prod u


  1. Common constraint mistakes 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. Dependent demand constraint Conte x t Prod u ction Plan Planning for 2 prod u cts ( A , and B ) Planning for prod u ction o v er 3 months ( Jan - Mar ) Prod u ct A is u sed as an inp u t for prod u ction of prod u ct B Constraint Problem For each u nit of B , w e m u st also ha v e at least 3 u nits of A SUPPLY CHAIN ANALYTICS IN PYTHON

  3. Dependent demand constraint For each u nit of B , w e m u st also ha v e at least 3 u nits of A 3 B ≤ A 3(2) ≤ A 6 ≤ A Common Mistake : B ≤ 3 A 3 B = A SUPPLY CHAIN ANALYTICS IN PYTHON

  4. Code e x ample from pulp import * # Define Objective demand = {'A':[0,0,0],'B':[8,7,6]} model += lpSum([costs[p][t] * X[(p, t)] costs = {'A':[20,17,18],'B':[15,16,15]} for p in prod for t in time]) # Initialize Model # Define Constraint So Production is >= Demand model = LpProblem("Aggregate Production Planning", for p in prod: LpMinimize) for t in time: model += X[(p, t)] >= demand[p][t] # Define Variables time = [0, 1, 2] prod = ['A', 'B'] X = LpVariable.dicts( "prod", [(p, t) for p in prod for t in time], lowBound=0, cat="Integer") SUPPLY CHAIN ANALYTICS IN PYTHON

  5. Code e x ample contin u ed for t in time: model += 3*X[('B',t)] <= X[('A',t)] SUPPLY CHAIN ANALYTICS IN PYTHON

  6. E x tended constraint For each u nit of B , w e m u st also ha v e at least 3 u nits of A and acco u nt for direct to c u stomer sells of A . A 3 B + Demand ≤ A SUPPLY CHAIN ANALYTICS IN PYTHON

  7. Combination constraint Conte x t Wareho u se distrib u tion plan 2 w areho u ses ( WH 1, and WH 2) We ship 2 prod u cts ( A , and B ) from each w areho u se Wareho u se WH 1 is small and can either ship 12 A prod u cts per a w eek or 15 B prod u cts per a w eek Constraint Problem What combinations of A , or B can be shipped in 4 w eeks ? SUPPLY CHAIN ANALYTICS IN PYTHON

  8. 1 w eek onl y: (1/12) A + (1/15) B ≤ 1 Correct Form (1/12) A + (1/15) B ? ≤ (1/12)(32) + (1/15)(20) ≤ 4 (32/12) + (20/15) ≤ 4 4 ≤ 4 Common Mistakes 12 A + 15 B ≤ 4 (1/12) A + (1/15) B = 4 SUPPLY CHAIN ANALYTICS IN PYTHON

  9. from pulp import * import pandas as pd demand = pd.read_csv("Warehouse_Constraint_Demand.csv", index_col=['Product']) costs = pd.read_csv("Warehouse_Constraint_Cost.csv", index_col=['WH','Product']) # Initialize Model model = LpProblem("Distribution Planning", LpMinimize) # Define Variables wh = ['W1','W2'] prod = ['A', 'B'] cust = ['C1', 'C2', 'C3', 'C4'] X = LpVariable.dicts("ship", [(w, p, c) for c in cust for p in prod for w in wh], lowBound=0, cat="Integer") SUPPLY CHAIN ANALYTICS IN PYTHON

  10. Code e x ample contin u ed # Define Objective model += lpSum([X[(w, p, c)]*costs.loc[(w, p), c] for c in cust for p in prod for w in wh]) # Define Constraint So Demand Equals Total Shipments for c in cust: for p in prod: model += lpSum([X[(w, p, c)] for w in wh]) == demand.loc[p, c] SUPPLY CHAIN ANALYTICS IN PYTHON

  11. Code e x ample contin u ed Constraint model += ((1/12) * lpSum([X['W1', 'A', c] for c in cust]) + (1/15) * lpSum([X['W1', 'B', c] for c in cust])) <= 4 SUPPLY CHAIN ANALYTICS IN PYTHON

  12. E x tend constraint Wareho u se WH 1 is small and either ship 12 A prod u cts per a w eek , 15 B prod u cts per a w eek , or 5 C prod u cts per a w eek . What combinations of A , B , or C can be shipped in 4 w eeks ? (1/12) A + (1/15) B + (1/5) C ≤ 4 SUPPLY CHAIN ANALYTICS IN PYTHON

  13. S u mmar y Common Mistakes Dependent constraint Combination selection constraint Ho w to e x tend constraints Check constraint b y pl u gging in a v al u e SUPPLY CHAIN ANALYTICS IN PYTHON

  14. Let ' s practice SU P P LY C H AIN AN ALYTIC S IN P YTH ON

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

  16. 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

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

  18. Constraints Total Prod u ction = Total Demand x = D for j = 1,..., m ∑ i =1 n j ij n = n u mber of prod u ction facilities m = n u mber of markets or regional demand points SUPPLY CHAIN ANALYTICS IN PYTHON

  19. Constraints Total Prod u ction ? Total Prod u ction Capacit y ∑ j =1 m ∑ s =1 ij is is x ? K y is K = potential prod u ction capacit y of plant _ i _ of si z e _ s _ 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='Continuous') 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. Code e x ample contin u ed # Define the Constraints for j in loc: model += lpSum([x[(i, j)] for i in loc]) == demand.loc[j,'Dmd'] for i in loc: model += lpSum([x[(i, j)] for j in loc]) <= lpSum([cap.loc[i,s]*y[(i,s)] for s in size]) SUPPLY CHAIN ANALYTICS IN PYTHON

  22. S u mmar y Capacitated Plant Location Model : Constraints Total Prod u ction = Total Demand Total Prod u ction ≤ Total Prod u ction Capacit y SUPPLY CHAIN ANALYTICS IN PYTHON

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

  24. Sol v e the P u LP model 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 .

  25. Common modeling process for P u LP 1. Initiali z e Model 2. De � ne Decision Variables 3. De � ne the Objecti v e F u nction 4. De � ne the Constraints 5. Sol v e Model call the solve() method check the stat u s of the sol u tion print optimi z ed decision v ariables print optimi z ed objecti v e f u nction SUPPLY CHAIN ANALYTICS IN PYTHON

  26. Sol v e model - sol v e method .solve(solver=None) solver = Optional : the speci � c sol v er to be u sed , defa u lts to the defa u lt sol v er . SUPPLY CHAIN ANALYTICS IN PYTHON

  27. # Initialize, Define Decision Vars., Objective Function, and Constraints from pulp import * import pandas as pd model = LpProblem("Minimize Transportation Costs", LpMinimize) cust = ['A','B','C'] warehouse = ['W1','W2'] demand = {'A': 1500, 'B': 900, 'C': 800} costs = {('W1','A'): 232, ('W1','B'): 255, ('W1','C'): 264, ('W2','A'): 255, ('W2','B'): 233, ('W2','C'): 250} ship = LpVariable.dicts("s_", [(w,c) for w in warehouse for c in cust], lowBound=0, cat='Integer') model += lpSum([costs[(w, c)] * ship[(w, c)] for w in warehouse for c in cust]) for c in cust: model += lpSum([ship[(w, c)] for w in warehouse]) == demand[c] # Solve Model model.solve() SUPPLY CHAIN ANALYTICS IN PYTHON

  28. Sol v e model - stat u s of the sol u tion LpStatus[model.status] Not Sol v ed : The stat u s prior to sol v ing the problem . Optimal : An optimal sol u tion has been fo u nd . Infeasible : There are no feasible sol u tions ( e . g . if y o u set the constraints x ≤ 1 and x ≥ 2). Unbo u nded : The object f u nction is not bo u nded , ma x imi z ing or minimi z ing the objecti v e w ill tend to w ards in � nit y ( e . g . if the onl y constraint w as x ≥ 3). Unde � ned : The optimal sol u tion ma y e x ist b u t ma y not ha v e been fo u nd . 1 2 Keen , Ben Ale x. “ Linear Programming w ith P y thon and P u LP Part 2.” _ Ben Ale x Keen _, 1 Apr . 2016, benale x keen . com / linear - programming -w ith - p y thon - and - p u lp - part -2/._{{5}} SUPPLY CHAIN ANALYTICS IN PYTHON

  29. # Initialize, Define Decision Vars., Objective Function, and Constraints from pulp import * import pandas as pd model = LpProblem("Minimize Transportation Costs", LpMinimize) cust = ['A','B','C'] warehouse = ['W1','W2'] demand = {'A': 1500, 'B': 900, 'C': 800} costs = {('W1','A'): 232, ('W1','B'): 255, ('W1','C'): 264, ('W2','A'): 255, ('W2','B'): 233, ('W2','C'): 250} ship = LpVariable.dicts("s_", [(w,c) for w in warehouse for c in cust], lowBound=0, cat='Integer') model += lpSum([costs[(w, c)] * ship[(w, c)] for w in warehouse for c in cust]) for c in cust: model += lpSum([ship[(w, c)] for w in warehouse]) == demand[c] # Solve Model model.solve() print("Status:", LpStatus[model.status]) Status: Optimal SUPPLY CHAIN ANALYTICS IN PYTHON

  30. Print v ariables to standard o u tp u t : for v in model.variables(): print(v.name, "=", v.varValue) Pandas data str u ct u re : o = [{A:ship[(w,'A')].varValue, B:ship[(w,'B')].varValue, C:ship[(w,'C')].varValue} for w in warehouse] print(pd.DataFrame(o, index=warehouse)) loop model v ariables store v al u es in a pandas DataFrame SUPPLY CHAIN ANALYTICS IN PYTHON

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend