Stellar Grove · Research

Stellar Grove · Concrete Mathematical Modelling

When to replace a machine

Running costs rise as a machine wears. When is it worth paying for a new one?

Chapter 7 · Optimal decision and reward. A worked example rebuilt from the chapter's topic in Mike Mesterton-Gibbons, *A Concrete Approach to Mathematical Modelling*; the scenario and numbers are our own illustration, not the book's text.

Headline: Replace the machine once it reaches condition 4 of 9. That rule cuts the discounted cost of a new machine by 65% compared with running it into the ground, and averages 8.88 per period in the long run.

The problem

A machine's condition runs from 0 (new) to 9 (worn out). Each period it wears one step with probability 0.6, and its running cost rises with wear (2.0 when new, 35.8 when worn out). Replacing it costs 25 and gives a new machine. Costs are discounted by γ=0.95 a period. What replacement rule minimises total expected cost?

The model

This is a Markov decision process: states s, actions a (keep or replace), costs c(s,a) and transition probabilities P(s′∣s,a). Bellman's principle of optimality says the minimum expected discounted cost V satisfies

V(s)=mina∈{keep,replace}[c(s,a)+γ∑s′P(s′∣s,a)V(s′)]

Value iteration applies this equation repeatedly from V=0 until it stops changing (it is a contraction, so it converges); policy iteration alternates exact evaluation of a rule, V=(I−γPπ)−1cπ, with greedy improvement. Both give the same answer here (identical policies, values within 9.2e-11).

The optimal rule is a threshold: keep while the machine is in good condition, replace once wear passes a critical state, because the cost of keeping rises with s while the cost of replacing does not.

Expected discounted cost of each action by condition: replace where the lines cross
Expected discounted cost of each action by condition: replace where the lines cross

Try it

Replacement policy explorer

The chart re-solves the Bellman equation (value iteration) each time you move a slider.

Key findings

import numpy as np
from books.concrete_mathematics import decision as de
n, wear, gamma = 10, 0.6, 0.95
run = 2 + 1.5 * np.arange(n) + 0.25 * np.arange(n) ** 2
keep = np.zeros((n, n))
for s in range(n):
    keep[s, min(s + 1, n - 1)] += wear
    keep[s, s] += 1 - wear
P = np.stack([keep, np.tile(keep[0], (n, 1))])              # a = 0 keep, 1 replace
R = np.stack([run, np.full(n, 25.0 + run[0])])
V, policy = de.policy_iteration(P, R, gamma, minimize=True)
print(policy, np.round(V[:3], 1))

# → [0 0 0 0 1 1 1 1 1 1] [160.3 170.9 179.3]

Assumptions and extensions