Conditions of optimal classification for piecewise affine regression