Linear-quadratic optimal control under non-Markovian switching