Constraint optimization and statistical mechanics