Iterated function systems and optimization problems