Emergence Via Constrained Optimization: Analysis and Experiments with Constraint-Driven Flocking