Solving constrained mean-field linear quadratic and other stochastic optimal control problems