Logische Nebenbedingungen

Supply Chain Analytics mit Python

Aaren Stubberfield

Supply Chain Analytics Mgr.

Beispielproblem

Maximalgewicht 20.000 lbs

Product Weight (lbs) Profitability ($US)
A 12,800 77,878
B 10,900 82,713
C 11,400 82,728
D 2,100 68,423
E 11,300 84,119
F 2,300 77,765
  • Wähle das profitabelste Produktset, ohne das Gewichtslimit zu überschreiten
  • Entscheidungsvariablen:
    • X$_{i}$ = 1, wenn Produkt _i_ ausgewählt ist, sonst 0
  • Ziel:
    • Maximiere z = $\sum$ Profitability$_{i}$X$_{i}$
  • Nebenbedingung:
    • $\sum$ Weight$_{i}$X$_{i}$ < 20,0000
Supply Chain Analytics mit Python
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 mit Python

Beispielergebnis

Maximalgewicht 20.000 lbs

Product Ship or Not
A No
B No
C No
D Yes
E Yes
F Yes

Ergebnis

  • Profitability: $230,307
  • Weight of Products: 15,700 lbs
Supply Chain Analytics mit Python

Beispiel logische Nebenbedingung 1

Entweder Produkt E wird gewählt oder Produkt D, aber nicht beide.

  • X$_{E}$ = 1, wenn Produkt _i_ ausgewählt ist, sonst 0
  • X$_{D}$ = 1, wenn Produkt _i_ ausgewählt ist, sonst 0
  • Nebenbedingung
    • X$_{E}$ + X$_{D}$ ≤ 1
Supply Chain Analytics mit Python

Codebeispiel – logische Nebenbedingung 1

model += x['E'] + x['D'] <= 1
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
model += x['E'] + x['D'] <= 1

# Solve Model
model.solve()
for i in prod:
  print("{} status {}".format(i, x[i].varValue))
Supply Chain Analytics mit Python

Ergebnis logische Nebenbedingung 1

Maximalgewicht 20.000 lbs

Product Ship or Not
A No
B No
C Yes
D Yes
E No
F Yes

Ergebnis

  • Profitability: $228,916
  • Weight of Products: 15,800 lbs
Supply Chain Analytics mit Python

Beispiel logische Nebenbedingung 2

Wenn Produkt D gewählt wird, muss auch Produkt B gewählt werden.

  • X$_{D}$ = 1, wenn Produkt _i_ ausgewählt ist, sonst 0
  • X$_{B}$ = 1, wenn Produkt _i_ ausgewählt ist, sonst 0
  • Nebenbedingung
    • X$_{D}$ ≤ X$_{B}$
Supply Chain Analytics mit Python

Codebeispiel – logische Nebenbedingung 2

model += x['D'] <= x['B']

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
model += x['D'] <= x['B']

# Solve Model
model.solve()
for i in prod:
  print("{} status {}".format(i, x[i].varValue))
Supply Chain Analytics mit Python

Ergebnis logische Nebenbedingung 2

Maximalgewicht 20.000 lbs

Product Ship or Not
A No
B Yes
C No
D Yes
E No
F Yes

Ergebnis

  • Profitability: $228,901
  • Weight of Products: 15,300 lbs
Supply Chain Analytics mit Python

Weitere logische Nebenbedingungen

Logical Constraint Constraint
Wenn Element _i_ gewählt wird, wird auch Element _j_ gewählt. x$_{i}$ - x$_{j}$ ≤ 0
Entweder Element _i_ oder Element _j_ wird gewählt, aber nicht beide. x$_{i}$ + x$_{j}$ = 1
Wenn Element _i_ gewählt wird, wird Element _j_ nicht gewählt. x$_{i}$ - x$_{j}$ ≤ 1
Wenn Element _i_ nicht gewählt wird, wird Element _j_ nicht gewählt. -x$_{i}$ + x$_{j}$ ≤ 0
Höchstens eines der Elemente _i_, _j_ und _k_ wird gewählt. x$_{i}$ + x$_{j}$ + x$_{k}$ ≤ 1
1 James Orlin und Ebrahim Nasrabadi. 15.053 Optimization Methods in Management Science. Frühjahr 2013. Massachusetts Institute of Technology: MIT OpenCourseWare. Lizenz: Creative Commons BY-NC-SA.
Supply Chain Analytics mit Python

Zusammenfassung

  • Beispiele für logische Nebenbedingungen wiederholt
  • Eine Tabelle weiterer logischer Nebenbedingungen aufgeführt
Supply Chain Analytics mit Python

Du bist dran!

Supply Chain Analytics mit Python

Preparing Video For Download...