I was recently watching a video game "speedrunner", who was trying to earn $1 billion of in-game currency in the shortest possible time.
He identified 3 different actions ($a$, $b$ and $c$) he could perform to generate money. The total $ value generated by (repeatedly) performing these actions was:
$$ x_{total}=n_{a}x_{0}\prod_{i=1}^{n_{c}}n_{b}[i] $$
where:
- $x_0=\$25000$ is a known constant.
- $n_a$ is the number of repetitions of action $a$.
- $n_c$ is the number of repetitions of action $c$.
- $n_b[i]$ is the number of repetitions of action $b$ associated with the $i^{th}$ repetition of action $c$.
The corresponding time cost was:
$$ t_{total}=n_{a}t_{a}+\left( \sum_{i=1}^{n_{c}}n_{b}[i]\right)t_{b}+n_{c}t_{c} $$
where $t_a = 52\text{ secs}$, $t_b = 18\text{ secs}$ and $t_c = 600\text{ secs}$ were the known times consumed (per repetition) by actions $a$, $b$ and $c$.
So, the goal was to find the integers $n_a$, $\{n_b\}$ and $n_c$ that minimize $t_{total}$, subject to the requirement that $x_{total} \geq \$1,000,000,000$.
After several minutes of trial and error, the "speedrunner" and his viewers found that $n_a = 7$, $\{n_b\} = \{18, 18, 18\}$ and $n_c = 3$ yielded $x_{total} \approx \$1.02 \text{ billion}$ and $t_{total} \approx 52.3 \text{ minutes}$. This seemed to be difficult to beat, but how can I find the optimal solution?
Some googling led me to a topic called "integer programming", but I couldn't figure out if it was applicable to this problem.
If a numerical/programmatic method is required, then:
- I would prefer to avoid brute force, if possible.
- I would like to understand how the method works, not just feed my parameters into a software package.
Suppose for now that we loosen the obvious restriction on $n_a, n_c, n_b[i]$ necessarily being positive integers, and allow them to take on positive real values instead.
A key observation that simplifies the problem dramatically is that $n_b[i]$ should be fixed for all $i$. This follows from AM-GM: we're given $$\prod_i n_b[i] = \frac{x_{tot}}{n_a x_0}.$$ If we have already found the ideal value of $n_a$, then $$\left(\frac{1}{n_a}\sum_i n_b[i]\right)^{n_a} \ge \prod_i n_b[i] = \frac{x_{tot}}{n_a x_0}$$ with equality only occurring when $n_b[1]=n_b[2]= \dots = n_b[n_c]$. For fixed $n_a$, the left-hand side increases with the value of $\sum_i n_b[i]$, hence this sum is minimized when we have equality of the terms.
Let $n_b$ be the value of all of the $n_b[i]$. Then, after substituting known constants, we have the constraint function $$40000 = n_a \cdot n_b^{n_c}$$ and the objective $$t_{tot} = 52n_a + 18n_bn_c + 600n_c.$$ Conveniently, we may substitute the constraint function into the objective function and reduce the number of variables: $$t_{tot} = 2080000n_b^{-n_c} + 18n_bn_c + 600n_c.$$ Minimizing this value is a multivariable calculus problem, and numerical methods will give you a minimum at $n_b \approx 17.76$ and $n_c \approx 3.05$. This then gives $n_a \approx 6.18$.
Notice how similar these values are to the values that the speedrunner found. You would expect the positive integer values minimizing the time cost to be close to these three values. This is usually true, but it's not an easy problem so solve in general: that's where different integer programming techniques come into play. In this case, however, it's not particularly necessary. The continuous solution gives us a very good starting guess, and that starting guess gives us a bound in which to check the remaining candidates. Any better integer solutions for the values of $n_b$ and $n_c$ would need to at least be contained in the region bounded by
$$2080000n_b^{-n_c} + 18n_bn_c + 600n_c \le 3136$$
(since $3136$ is what we get for $t_{tot}$ when $n_b = 18$, $n_c = 3$, and the actual value for $n_a$ will be larger than its real approximation $40000n_b^{-n_c}$, which satisfies the constraint perfectly). There's only one such pair in this region, and that's $n_b = 19$, $n_c = 3$. This gives $n_a=6$, and a $t_{tot}$ of $3138$, which is slightly larger.