Generalized Hopfield networks for constrained optimization