Symmetry of solutions to optimization problems related to partial differential equations