Simulation of dislocation microstructures in two dimensions. I. Relaxed structures