An efficient algorithm for computing the state feedback optimal control law for discrete time hybrid systems