About Skills Projects Resume Contact
← Back to Projects
03 — Optimization & Operations Research

Optimization Modeling
with Pyomo

Python Pyomo GLPK IPOPT Integer Programming Both Exams: 100%

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.

Problem 1 — DraftKings NHL Lineup

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)
#PlayerTeamPositionFantasy PtsSalary
1Michael McLeodNJC/UTIL2$2,500
2Kyle ConnorWPGW/UTIL2$8,600
3William KarlssonVGKC/UTIL2$4,500
4Patrik LaineCLSW/UTIL3$4,800
5Elvis MerzlikinsCLSG0$7,100
6Adam BoqvistCLSD/UTIL2$4,000
7Nic DowdWASC/UTIL2$2,500
8Jake GuentzelPITW/UTIL2$7,500
9Oliver Ekman-LarssonVAND/UTIL3$3,100
Total Salary Used
$44,600
$5,400 under cap
Total Fantasy Points
18.00
Optimal given actual game data

Problem 2 — Flavor Production Planning

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'])
AppleBananaChocolateElderberryFig
Part A — Quantity20015000200
Part A — Produce?
Part B — Quantity200149.501200
Part B — Produce?
Part A — Max Profit
$1,217.20
Apple, Banana & Fig only
Part B — Max Profit (constrained)
$1,212.05
Force Choc or Elderberry: −$5.15

Problem 3 — Optimal Facility Location

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)
Optimal Location
(43.4, 59.0)
Minimizes total travel distance
Total Distance
665 units
Sum of Manhattan distances to all 15 shops

Technology Stack

Python 3.x Pyomo GLPK (MIP solver) IPOPT (NLP solver) Pandas NumPy Matplotlib Seaborn SciPy Excel Solver

Results

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.

Interested in this project or want to connect?

[email protected] LinkedIn ← All Projects