Most of the things in life are constrained optimization problems, whether it is managing a securities portfolio or how fast should you run for how long to cover a specific distance in a specific time. Former involves random variables but the latter is a simple, yet beautiful non linear programming problem. To explore this, I developed a Python application that designs a customized running plan based on user inputs. For example, you can input:
"I want to run 5 km in 25 minutes, alternating between four different paces—10 km/h, 12 km/h, 13 km/h, and 15 km/h. Ensure I don't spend more than 2 minutes running at 15 km/h and I warmup for atleast 7 minutes at 10km/h, and maximize pace variations to keep the run dynamic and engaging, as I prefer frequent speed changes to avoid monotony."
The program uses constrained optimization to compute the ideal time allocation for each pace, ensuring all constraints are met. It's a small yet elegant application of mathematics.
Find the application on: https://run-planner.streamlit.app/
Show me the code: https://github.com/piper-of-dawn/constrained_optimisation_for_running
The program uses constrained optimization to compute the ideal time allocation for each pace, ensuring all constraints are met. It's a small yet elegant application of mathematics.
So we have primary constraint functions:
Thus we are minimising subject to above constraints. Remember, the neat trick!
There will likely be multiple solutions to this optimization problem, that is, many pace variations will let you run a distance of in time . To determine the most suitable running plan, enter a third categorical variable: how frequently you want to vary your pace. Do you prefer to change speeds often, or would you rather run at a steady pace for longer periods? This can be achieved by calculating the Gini coefficient of the time allocations across the different paces in each solution vector. The Gini coefficient is a measure of inequality, and it helps us understand how "even" or "uneven" something is distributed. Here a high Gini coefficient indicates that one or more speeds dominate the running time, which corresponds to fewer pace variations and vice versa. For more details on the Gini coefficient, you can visit the Wikipedia page.