private static void normalizeTransferTime(ref Time timeDeparture, ref Time timeArrival, Time minimalTransferTime, int onPeriod, int offPeriod) { // if departure is before arrival, we need to find closest time departure // that satisfied the condition(departure>arrival) if (timeDeparture < timeArrival + minimalTransferTime) { while (timeDeparture < timeArrival + minimalTransferTime) { // addConstraint new period of train timeDeparture += Time.ToTime(onPeriod); } } else { // if arrival is before departure, we need to find closest time arrival // that satisfied the cond(departure>arrival) but not the cond(departure>arrival+nextPeriod) while (timeDeparture > timeArrival + Time.ToTime(offPeriod) + minimalTransferTime) { timeArrival += Time.ToTime(offPeriod); } } }