doing the new optimization based on the actual graph