Skip to content
DeepForgeby svx
All problems

MPC Replan Count

Problem

Count how many full-horizon plans a receding-horizon controller can run.

A plan starting at step t needs t + horizon <= episode_length, so the number of start steps is episode_length - horizon + 1. Return 0 when the horizon is non-positive or longer than the episode.

Hint

MPC executes only the first action of each plan, then plans again.

Test cases

case 1
in: [10,3]
expected: 8
case 2
in: [5,5]
expected: 1
case 3
in: [4,5]
expected: 0
case 4
in: [10,0]
expected: 0
case 5
in: [1,1]
expected: 1
Starter codePython
def mpc_replan_count(episode_length, horizon):
    # Your code here
    pass

5 test cases · run your code against them in the editor