Optimal deterministic protocols for mobile robots on a grid