Three distinct optimization problems — binary integer programming for a DraftKings NHL lineup under a $50k salary cap, mixed-integer production planning for ice cream flavor profitability, and Manhattan-distance facility location minimization using IPOPT.
Binary integer programming · Exam 1 grade: 100%
Select 9 NHL players that maximize total fantasy points scored on a given game night, subject to DraftKings position requirements and a strict $50,000 salary cap. Each player is either on the roster (1) or not (0) — a classic binary integer program solved with the GLPK solver.
model = pe.ConcreteModel()
model.x = pe.Var(PSActual.index, domain=pe.Binary) # 1 = selected, 0 = not
## Objective: maximize total fantasy points
model.obj = pe.Objective(
expr = sum([PSActual.p.loc[i] * model.x[i] for i in PSActual.index]),
sense = pe.maximize)
## Constraints
model.salary = pe.Constraint(expr=sum([PSActual.Salary.loc[i] * model.x[i] for i in PSActual.index]) <= 50000)
model.roster = pe.Constraint(expr=sum([model.x[i] for i in PSActual.index]) == 9)
model.C = pe.Constraint(expr=sum([PSActual.C.loc[i] * model.x[i] for i in PSActual.index]) >= 2)
model.W = pe.Constraint(expr=sum([PSActual.W.loc[i] * model.x[i] for i in PSActual.index]) >= 3)
model.D = pe.Constraint(expr=sum([PSActual.D.loc[i] * model.x[i] for i in PSActual.index]) >= 2)
model.G = pe.Constraint(expr=sum([PSActual.G.loc[i] * model.x[i] for i in PSActual.index]) == 1)
opt = pe.SolverFactory('glpk')
opt.solve(model)
| # | Player | Team | Position | Fantasy Pts | Salary |
|---|---|---|---|---|---|
| 1 | Michael McLeod | NJ | C/UTIL | 2 | $2,500 |
| 2 | Kyle Connor | WPG | W/UTIL | 2 | $8,600 |
| 3 | William Karlsson | VGK | C/UTIL | 2 | $4,500 |
| 4 | Patrik Laine | CLS | W/UTIL | 3 | $4,800 |
| 5 | Elvis Merzlikins | CLS | G | 0 | $7,100 |
| 6 | Adam Boqvist | CLS | D/UTIL | 2 | $4,000 |
| 7 | Nic Dowd | WAS | C/UTIL | 2 | $2,500 |
| 8 | Jake Guentzel | PIT | W/UTIL | 2 | $7,500 |
| 9 | Oliver Ekman-Larsson | VAN | D/UTIL | 3 | $3,100 |
Mixed-integer programming with binary activation variables · Exam 2 grade: 100%
Determine optimal production quantities for five ice cream flavors (Apple, Banana, Chocolate, Elderberry, Fig) to maximize profit — accounting for fixed setup costs triggered by binary activation variables, production capacity across four resource lines, and demand ceilings per flavor.
model.x = pe.Var(DV_indexes, domain=pe.NonNegativeReals) # quantity produced
model.y = pe.Var(DV_indexes, domain=pe.Binary) # 1 = flavor is produced
## Objective: revenue - variable costs - fixed setup costs
model.obj = pe.Objective(
expr = (sum([cost.loc['Price', i] * model.x[i] for i in DV_indexes])
- sum([cost.loc['Cost', i] * model.x[i] for i in DV_indexes])
- sum([cost.loc['Fixed Setup Cost',i] * model.y[i] for i in DV_indexes])),
sense=pe.maximize)
## Resource capacity constraints
model.mixing = pe.Constraint(expr=sum([coef.loc['Mixing', i]*model.x[i] for i in DV_indexes]) <= rhs.loc['Mixing', 'rhs'])
model.preparation = pe.Constraint(expr=sum([coef.loc['Preparation', i]*model.x[i] for i in DV_indexes]) <= rhs.loc['Preparation', 'rhs'])
model.blending = pe.Constraint(expr=sum([coef.loc['Blending', i]*model.x[i] for i in DV_indexes]) <= rhs.loc['Blending', 'rhs'])
model.packaging = pe.Constraint(expr=sum([coef.loc['Packaging', i]*model.x[i] for i in DV_indexes]) <= rhs.loc['Packaging', 'rhs'])
## Link quantity to activation binary (can only produce if y=1)
model.LinkA = pe.Constraint(expr=model.x['Apple'] <= demand.loc['Apple', 'demand'] * model.y['Apple'])
model.LinkB = pe.Constraint(expr=model.x['Banana'] <= demand.loc['Banana', 'demand'] * model.y['Banana'])
model.LinkC = pe.Constraint(expr=model.x['Chocolate'] <= demand.loc['Chocolate', 'demand'] * model.y['Chocolate'])
model.LinkE = pe.Constraint(expr=model.x['Elderberry'] <= demand.loc['Elderberry', 'demand'] * model.y['Elderberry'])
model.LinkF = pe.Constraint(expr=model.x['Fig'] <= demand.loc['Fig', 'demand'] * model.y['Fig'])
| Apple | Banana | Chocolate | Elderberry | Fig | |
|---|---|---|---|---|---|
| Part A — Quantity | 200 | 150 | 0 | 0 | 200 |
| Part A — Produce? | ✓ | ✓ | ✗ | ✗ | ✓ |
| Part B — Quantity | 200 | 149.5 | 0 | 1 | 200 |
| Part B — Produce? | ✓ | ✓ | ✗ | ✓ | ✓ |
Nonlinear optimization via IPOPT solver · Exam 2 grade: 100%
Given 15 existing coffee shop locations on a 2D coordinate grid, find the (x, y) location that minimizes the total Manhattan (absolute value) distance to all shops. The absolute-value objective is nonlinear and non-differentiable at the optimum, requiring the IPOPT nonlinear solver rather than GLPK.
model.x = pe.Var(['x', 'y'], domain=pe.NonNegativeReals)
## Minimize sum of Manhattan distances to all 15 shops
model.obj = pe.Objective(
expr = sum([abs(model.x['x'] - dfloc.loc[i, 'x']) for i in dfloc.index]
+ [abs(model.x['y'] - dfloc.loc[i, 'y']) for i in dfloc.index]),
sense=pe.minimize)
opt = pe.SolverFactory('ipopt') # nonlinear solver required
opt.solve(model)
Both optimization exams scored 100%. Problems spanned binary integer programming, mixed-integer production planning, and nonlinear facility location — covering three major optimization paradigms within one course.