Optimal guidance and control of spacecraft swarms in planetary and asteroid orbits