An algorithm for calculating consistent itinerary flows