Skip to content

Commit

Permalink
cache a couple more things in cdap.initial_household_utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jiffyclub committed May 5, 2015
1 parent 528c2ce commit 579927c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions activitysim/cdap/cdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ def initial_household_utilities(utilities, people, hh_id_col):
utils = utilities.loc[df.index].as_matrix()

if hh_size in combo_cache:
combos, flat_combos = combo_cache[hh_size]
ncombos, combos, flat_combos, tiled = combo_cache[hh_size]
else:
combos = list(itertools.product(alts, repeat=hh_size))
flat_combos = [alts_map[a] for a in tz.concat(combos)]
combo_cache[hh_size] = (combos, flat_combos)
ncombos = len(combos)
tiled = np.tile(np.arange(hh_size), ncombos)
combo_cache[hh_size] = (ncombos, combos, flat_combos, tiled)

ncombos = len(combos)
u = (utils[np.tile(np.arange(hh_size), ncombos), flat_combos]
.reshape((ncombos, hh_size)).sum(axis=1))
u = utils[tiled, flat_combos].reshape((ncombos, hh_size)).sum(axis=1)

hh_util[hh_id] = pd.Series(u, index=combos)

Expand Down

0 comments on commit 579927c

Please sign in to comment.