urbansim / urbansim_parcels

New version of urbansim_defaults for compatibility with new developer model
0 stars 1 forks source link

Add linked tables option to Simple Transition Model #36

Open cvanoli opened 3 years ago

cvanoli commented 3 years ago

Right now, the utils.simple_transition model does not allow for linked tables to be changed as the transition model changes the main table. We use this specifically when the households are transitioning, the persons table should change as well. Though we have that option in the full_transition model in a parameter called linked_tables, we don't have the same possibility when running a simple transition model with a growth rate.

cvanoli commented 3 years ago

To solve this, I created the linked_tables_addin branch, where I add a parameter called linked_tables, which default is None, so nothing would happen if you do not choose to use this. def simple_transition(tbl, rate, location_fname, linked_tables=None): Equally as in the full transition model,

    linked_tables : dict of tuple, optional
        Dictionary of table_name: (table, 'column name') pairs. The column name
        should match the index of `agents`. Indexes in `agents` that
        are copied or removed will also be copied and removed in
        linked tables.

After the transition itself, these lines are added to take care of the linked tables that should be changed:

    linked_tables = linked_tables or {}
    updated_links = {}
    for table_name, (table, col) in linked_tables.items():
        print('updating linked table {}'.format(table_name))
        updated_links[table_name] = \
            transition._update_linked_table(table, col, added, copied, removed)
    for table_name, table in updated_links.items():
        print("Total {} after transition: {:,}".format(table_name, len(table)))
        orca.add_table(table_name, table)

if linked_tables is None nothing different from the original state, happens.

This is the improved simple_transition model in the linked_tables_addin branch

smmaurer commented 3 years ago

This looks great to me! @janowicz should take a quick look as well when convenient, because I think he wrote the original code.

cvanoli commented 3 years ago

Okay thanks @smmaurer , I'll be performing some tests meanwhile.