Input
Decide what data the model receives. For the DJ problem, raw song features such as tempo, genre, and mood are possible inputs, but they do not directly say how awkward one transition is.
The chapter chooses a more direct input: for every ordered pair of songs i,j, ask for a transition difficulty d(i,j).
Output
The DJ does not need a complicated timing schedule. A concise output is an order in which to play the songs.
This is a permutation: every song appears exactly once.
Goal
The model measures playlist quality by adding the transition difficulties between consecutive songs.
The mathematical goal is to minimize this sum.
DJ playlist problem
Input
- n, the number of songs;
- d(i,j), the transition difficulty from song i to song j, for all ordered pairs.
Output
- A permutation π of 1,2,…,n.
Goal
- Minimize d(π1,π2)+d(π2,π3)+⋯+d(πn−1,πn).
What is not included?
The chapter points out that a real DJ might care about additional requirements: grouping several songs in a style, spreading out songs by the same artist, or controlling the energy arc over the night.
The first model ignores those features. That is not a mistake; it is a modeling choice. The interactive lab below lets you turn some of those choices into extra terms or hard constraints and see how the mathematical problem changes.
Build and solve a DJ playlist model
Edit song features, generate directed transition difficulties, rearrange the playlist, and compare your order with a brute-force optimum for small instances.
Current playlist
Model controls
Songs as raw features
Transition difficulty matrix d(i,j)
The matrix is directed: the difficulty from song i to song j need not equal the difficulty from j to i. Edit a cell directly to override the generated value.
The current mathematical model
Changing the controls in the lab changes this statement. This is the central modeling move in the chapter: before solving anything, make the computational task precise.
Why the last transition matters
The playlist model has a first song and a last song. The transition from the last song back to the first is not part of the objective.
If you include that final transition, the model becomes cycle-like. This is the key difference between the playlist problem here and the Traveling Salesman Problem in the next chapter.
What does it mean to solve the model?
An algorithm is a prescribed method that takes an input and produces an output. An optimal solution is a feasible output with the best possible objective value.
The brute-force button in the lab checks every permutation, so it is correct for small instances. It is included as a teaching tool; it quickly becomes impractical because the number of permutations is n!.
Model first, solve second
Once the input, output, and goal are fixed, the original DJ story has become a mathematical optimization problem. That exact problem may then be attacked with algorithms, compared against lower bounds, or reduced to a classical model.
