Dynamics of learning and generalization in perceptrons with constraints