liveBook · Manning

Optimization

As explained in Statistics Slam Dunk

Constrained optimization is the process of finding the best value of an objective function subject to specified restrictions.

Constrained optimization finds the best value of an objective while obeying nonnegotiable limits. The objective may be to maximize profit, performance, or win shares, or to minimize costs, time, or resource use. Constraints define the boundaries: a solution that breaks a budget, capacity, staffing, or eligibility rule is not acceptable, even if its objective value looks better. section 4.1 section 4.9

A practical problem has three parts: available choices, an objective function, and explicit constraints. For a roster decision, each candidate player is a choice, projected win shares are the objective, and roster size, positions, salary, and age are constraints. The goal is not simply to pick the strongest individuals; it is to select the strongest feasible combination. section 4.0 section 4.6

Set up a constrained optimization problem by turning the decision into data and rules:

  • Define the candidate choices and retain only fields needed for the decision, such as player, age, position, salary, and win shares. section 4.6 section 4.7
  • Choose the quantity to minimize or maximize. Here, the objective is total win shares. section 4.8
  • Translate every requirement into a numeric constraint: exactly one player at each position, five players total, salary at most $90 million, and total age at most 150. section 4.6 section 4.8
  • Encode category membership with 1s and 0s, then combine those vectors with salary and age into a constraint matrix. section 4.7
  • Solve the model, inspect the selected choices, and verify the objective and each constraint from the returned results. section 4.8

For the position rules, binary encoding marks whether each candidate belongs to a position. A center vector, for example, contains 1 for centers and 0 for everyone else. Requiring that vector’s selected values to total exactly 1 ensures one center is chosen. Repeating that pattern for all five positions, then adding rows for total selections, salary, and age, creates a matrix that expresses the full decision policy. section 4.7 section 4.8

Five-player NBA roster

From 24 free agents, maximize total win shares while selecting five players: one center, power forward, point guard, small forward, and shooting guard. Keep combined annual salaries at or below $90 million and average age at or below 30. The solved selection contains Serge Ibaka, Marvin Bagley III, Marcus Smart, Kawhi Leonard, and Zach LaVine. It produces 25.5 win shares, costs $89.5 million, and has an average age of 28.4, satisfying every stated limit. section 4.6 section 4.8 section 20.5

co_object <-
 lp(const.mat = constraint_matrix,
    objective = free_agents_sort$win_shares,
    direction = "max",
    const.rhs = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 90000000, 150), 
    const.dir = c("<=", ">=","<=", ">=", "<=", ">=", 
                  "<=", ">=", "<=", ">=", "<=", "<=", "<="), 
    int.vec = 1:24, all.bin = TRUE)

This lpSolve call makes the model concrete: win shares are maximized, the constraint matrix supplies coefficients, comparison directions define the rules, and binary decision variables indicate whether each player is selected. section 4.8

The same structure transfers to other decisions. Replace win shares with a different linear objective, such as costs, profit margins, delivery time, shelf space, or schedule adherence, then replace the roster rules with the limits that matter. Optimization removes guesswork only after the objective and hard constraints have been stated clearly. section 4.9 section 20.5

How Statistics Slam Dunk covers it

How deep it goes
Walks through data sorting, binary constraint encoding, matrix construction, lpSolve execution, and verification of a solved roster.
Examples
Uses 24 NBA free agents, position requirements, a $90 million salary cap, and an average-age limit to select five players.
What it assumes
Introduces the method through plain-language requirements while using R data preparation, matrices, and package loading.
What you can do after
Apply it via lpSolve to maximize or minimize a linear objective while checking hard constraints against the returned solution.
How it connects
Connects linear programming with objective functions, constraint matrices, binary encoding, win shares, and operations research.

Also explained in

Compare how 30 books explain optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.