  We present a general technique to compute how the energy of a configuration
varies as a function of its overlap with the ground state in the case of
optimization problems. Our approach is based on a generalization of the cavity
method to a system interacting with its ground state. With this technique we
study the random matching problem as well as the mean field diluted spin glass.
As a byproduct of this approach we calculate the de Almeida-Thouless transition
line of the spin glass on a fixed connectivity random graph.
