A question on Mathematics Stack Exchange asks how to solve an optimization problem related to a game apparently called "speedrunner". The problem boils down to selecting integer values for variables and () so as to minimize elapsed time
where , and are parameters with specified values. The sole constraint specified is that winnings, defined by
(where is another parameter), must be at least billion. We can infer from the requirement of positive earnings that and for For modeling purposes, we will allow the index to exceed and require that for An integer linear programming model would be a no-brainer were it not for two things: the product form of the expression for winnings is nonlinear; and it involves the product of a variable number of variables.
The approach I chose was to express the original variables in terms of binary variables. To do that, we first need upper bounds on the original variables. We get those by guessing an upper bound on (If we guess too low, we will either get a solution that exceeds that upper bound or the model will become infeasible, either of which will tip us off to try a larger guess.) Once we have that upper bound, we get an upper bound for each variable by setting the other two variables as small as possible. That leads to the following upper bounds:
and
The denominator in the third equation arises from the fact that adding 1 to not only directly costs units of time but also adds another variable with minimum value 1, costing units of time.
Armed with those upper bounds, we can introduce binary variables and and along with constraints making them type 1 special ordered sets (i.e., each set contains exactly one variable with value 1) and expanding the original variables in terms of them. Specifically:
- with constraint
with constraint and
- for
with the following constraints for all
- (the value of is uniquely defined); and
- (the value of is uniquely defined); and
- ( if and only if ).
Armed with all that, the original objective function can be expressed as minimizingwhere the only tweak is that we now sum over a constant number of terms rather than a variable number relying on the fact that for
That brings us to the nonlinear formula for winnings. The original constraint is which we can rewrite as using whatever flavor logarithm you like. Expanding the logs of and in terms of the binary variables, we getSo the constraint that log winnings equal or exceed the log of is linear in the binary variables.
The solution in the Math Stack Exchange post and turns out to be optimal given the parameter values in the question, and the IP model here will correctly achieve the minimum time (approximately 52.3 minutes) ... but it will not necessarily reproduce the best winnings within that time (approximately billion). That is because there are multiple feasible solutions that hit the correct time value, with and with but with the 54 cumulative units allocated differently (for instance, rather than To get the best possible solution, we can use a bicriterion model with lexicographically ordered objectives, first minimizing time and then maximizing winnings (by minimizing the negative of the log of winnings).
I tested that model using the Java API to CPLEX 22.1. My code is available from my university repository.