A computational method for optimal structural design. I. Piecewise uniform structures