Logische restricties

Supply Chain Analytics in Python

Aaren Stubberfield

Supply Chain Analytics Mgr.

Voorbeeldprobleem

Maximaal gewicht 20.000 lb

Product Gewicht (lb) Winst ($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
  • Kies de meest winstgevende producten binnen de gewichtslimiet
  • Beslissingsvariabelen:
    • X$_{i}$ = 1 als product _i_ is gekozen, anders 0
  • Doelfunctie:
    • Maximaliseer z = $\sum$ Winst$_{i}$X$_{i}$
  • Restrictie:
    • $\sum$ Gewicht$_{i}$X$_{i}$ < 20.0000
Supply Chain Analytics in 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 in Python

Voorbeeldresultaat

Maximaal gewicht 20.000 lb

Product Verzenden of niet
A Nee
B Nee
C Nee
D Ja
E Ja
F Ja

Resultaat

  • Winstgevendheid: $230.307
  • Totaalgewicht: 15.700 lb
Supply Chain Analytics in Python

Voorbeeld 1 van logische restrictie

Of product E wordt gekozen of product D, maar niet allebei.

  • X$_{E}$ = 1 als product _i_ is gekozen, anders 0
  • X$_{D}$ = 1 als product _i_ is gekozen, anders 0
  • Restrictie
    • X$_{E}$ + X$_{D}$ ≤ 1
Supply Chain Analytics in Python

Codevoorbeeld - logisch restrictievoorbeeld 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 in Python

Logische restrictie 1: voorbeeldresultaat

Maximaal gewicht 20.000 lb

Product Verzenden of niet
A Nee
B Nee
C Ja
D Ja
E Nee
F Ja

Resultaat

  • Winstgevendheid: $228.916
  • Totaalgewicht: 15.800 lb
Supply Chain Analytics in Python

Voorbeeld 2 van logische restrictie

Als product D is gekozen, moet product B ook worden gekozen.

  • X$_{D}$ = 1 als product _i_ is gekozen, anders 0
  • X$_{B}$ = 1 als product _i_ is gekozen, anders 0
  • Restrictie
    • X$_{D}$ ≤ X$_{B}$
Supply Chain Analytics in Python

Codevoorbeeld - logisch restrictievoorbeeld 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 in Python

Logische restrictie 2: voorbeeldresultaat

Maximaal gewicht 20.000 lb

Product Verzenden of niet
A Nee
B Ja
C Nee
D Ja
E Nee
F Ja

Resultaat

  • Winstgevendheid: $228.901
  • Totaalgewicht: 15.300 lb
Supply Chain Analytics in Python

Andere logische restricties

Logische restrictie Restrictie
Als item _i_ is gekozen, wordt item _j_ ook gekozen. x$_{i}$ - x$_{j}$ ≤ 0
Of item _i_ of item _j_ wordt gekozen, maar niet allebei. x$_{i}$ + x$_{j}$ = 1
Als item _i_ is gekozen, wordt item _j_ niet gekozen. x$_{i}$ - x$_{j}$ ≤ 1
Als item _i_ niet is gekozen, wordt item _j_ niet gekozen. -x$_{i}$ + x$_{j}$ ≤ 0
Uiterlijk één van items _i_, _j_ en _k_ wordt gekozen. x$_{i}$ + x$_{j}$ + x$_{k}$ ≤ 1
1 James Orlin, and Ebrahim Nasrabadi. 15.053 Optimization Methods in Management Science. Spring 2013. Massachusetts Institute of Technology: MIT OpenCourseWare. License: Creative Commons BY-NC-SA.
Supply Chain Analytics in Python

Samenvatting

  • Voorbeelden van logische restricties herhaald
  • Tabel met andere logische restricties getoond
Supply Chain Analytics in Python

Jij bent aan de beurt!

Supply Chain Analytics in Python

Preparing Video For Download...