def vectorize_tour_scheduling(tours, alts, spec):

    max_num_trips = tours.groupby('person_id').size().max()

    # because this is Python, we have to vectorize everything by doing the
    # "nth" trip for each person in a for loop (in other words, because each
    # trip is dependent on the time windows left by the previous decision) -
    # hopefully this will work out ok!

    choices = []

    # keep a series of the the most recent tours for each person
    previous_tour_by_personid = pd.Series(
        pd.Series(alts.index).iloc[0], index=tours.person_id.unique())

    for i in range(max_num_trips):

        # this reset_index / set_index stuff keeps the index as the tours
        # index rather that switching to person_id as the index which is
        # what happens when you groupby person_id
        nth_tours = tours.reset_index().\
            groupby('person_id').nth(i).reset_index().set_index('index')

        print "Running %d #%d tour choices" % (len(nth_tours), i+1)

        # tour num can be set by the user, but if it isn't we set it here
        if "tour_num" not in nth_tours:
            nth_tours["tour_num"] = i+1

        nth_tours = nth_tours.join(get_previous_tour_by_tourid(
            nth_tours.person_id,
            previous_tour_by_personid,
            alts))

        nth_choices, _ = asim.interaction_simulate(
            nth_tours,
            alts.copy(),
            spec,
            sample_size=min(len(alts), 50)
        )

        choices.append(nth_choices)

        previous_tour_by_personid.loc[nth_tours.person_id] = nth_choices.values

    # return the concatenated choices
    return pd.concat(choices)
The purpose of this method is fairly straightforward - it takes tours
dataset/ETHPy150Open UDST/activitysim/activitysim/defaults/models/util/vectorize_tour_scheduling.py/vectorize_tour_scheduling