Evolution of body size: an optimization model