Optimal Control of Hybrid Systems