Merit functions: a bridge between optimization and equilibria