Algorithm for generate schedule with constraints