Optimal control of Rydberg lattice gases