The use of optimization in the reconstruction of obstacles from acoustic or eletromagnetic scattering data