Optimal Control And Analysis For Constrained Piecewise Affine Systems