A crucial part of segmented or multiple-aperture systems is control of the optical path difference between the segments or subapertures. In order to achieve optimal performance we have to phase subapertures to within a fraction of the wavelength, and this requires high accuracy of positioning for each subaperture. We present simulations and hardware realization of a simulated annealing algorithm in an active optical system with sparse segments. In order to align the optical system we applied the optimization algorithm to the image itself. The main advantage of this method over traditional correction methods is that wave-front-sensing hardware and software are no longer required, making the optical and mechanical system much simpler. The results of simulations and laboratory experiments demonstrate the ability of this optimization algorithm to correct both piston and tip-tilt errors.