Schedule optimization algorithm