Skip to content

Commit

Permalink
cdap choose backfill persons randomly like ctramp
Browse files Browse the repository at this point in the history
  • Loading branch information
toliwaga committed Apr 23, 2019
1 parent e97148b commit 103fdd5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
16 changes: 13 additions & 3 deletions activitysim/abm/models/util/cdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from zbox import toolz as tz, gen

from activitysim.core import simulate
from activitysim.core import pipeline

from activitysim.core import chunk
from activitysim.core import logit
Expand Down Expand Up @@ -90,7 +91,7 @@ def assign_cdap_rank(persons, trace_hh_id=None, trace_label=None):
than 5 people, the cdapPersonArray is the same as the person array."
We diverge from the above description in that a cdap_rank is assigned to all persons,
including 'extra' householld members, whose activity is assigned subsequently.
including 'extra' household members, whose activity is assigned subsequently.
The pair _hh_id_, cdap_rank will uniquely identify each household member.
Parameters
Expand Down Expand Up @@ -130,10 +131,19 @@ def assign_cdap_rank(persons, trace_hh_id=None, trace_label=None):
del children

# choose up to MAX_HHSIZE, preferring anyone already chosen
# others = \
# persons[[_hh_id_, 'cdap_rank']]\
# .sort_values(by=[_hh_id_, 'cdap_rank'], ascending=[True, True])\
# .groupby(_hh_id_).head(MAX_HHSIZE)

# choose up to MAX_HHSIZE, choosing randomly
others = persons[[_hh_id_, 'cdap_rank']].copy()
others['random_order'] = pipeline.get_rn_generator().random_for_df(persons)
others = \
persons[[_hh_id_, 'cdap_rank']]\
.sort_values(by=[_hh_id_, 'cdap_rank'], ascending=[True, True])\
others\
.sort_values(by=[_hh_id_, 'random_order'], ascending=[True, True])\
.groupby(_hh_id_).head(MAX_HHSIZE)

# tag the backfilled persons
persons.loc[others[others.cdap_rank == RANK_UNASSIGNED].index, 'cdap_rank'] \
= RANK_BACKFILL
Expand Down
6 changes: 2 additions & 4 deletions activitysim/abm/test/configs/cdap_indiv_and_hhsize1.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ Pre-driving-age child who is in school alternative-specific constants,ptype == 7
Pre-driving-age child who is in school interaction with age 6 to 9,(ptype == 7) & (age >= 6) & (age <= 9),-0.2943,,
Pre-driving-age child who is in school interaction with age 13 to 15,(ptype == 7) & (age >= 13) & (age <= 15),-0.7141,-0.672,
Pre-driving-age child who is too young for school alternative-specific constants,ptype == 8,1.052531189,-0.837567776,
# tm1 age bug,,,,
Pre-driving-age child who is too young for school interaction with age 0 to 1,(ptype == 8) * age,-0.4515,,
# asim corrected age bug,,,,
# Pre-driving-age child who is too young for school interaction with age 0 to 1,(ptype == 8) & (age >= 0) & (age <= 1),-0.4515,,
# corrected tm1 age bug,,,,
Pre-driving-age child who is too young for school interaction with age 0 to 1,(ptype == 8) & (age >= 0) & (age <= 1),-0.4515,,
Pre-driving-age child who is too young for school interaction with age 4 to 5,(ptype == 8) & (age >= 4) & (age <= 5),0.6107,,
#,,,,
Full-time worker interaction with age less than 40,(ptype == 1) & (age < 40),0.2091,,
Expand Down
60 changes: 26 additions & 34 deletions activitysim/abm/test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
HOUSEHOLDS_SAMPLE_SIZE = 100

# household with mandatory, non mandatory, atwork_subtours, and joint tours
HH_ID = 1396417
HH_ID = 1402945

# [1081630 1396417 1511245 1594943 1747572 1931915 2222690 2366390 2727112]
# [1402945 1511245 1931827 1931908 2224336 2307195 2366390 2408855 2727112 1196229 932096 932412]

# SKIP_FULL_RUN = True
SKIP_FULL_RUN = False
Expand Down Expand Up @@ -318,7 +318,7 @@ def get_trace_csv(file_name):
return df


EXPECT_TOUR_COUNT = 210
EXPECT_TOUR_COUNT = 205


def regress_tour_modes(tours_df):
Expand All @@ -334,54 +334,46 @@ def regress_tour_modes(tours_df):
"""
tour_mode person_id tour_type tour_num tour_category
tour_id
91533592 WALK 3156330 othmaint 1 non_mandatory
91533620 WALK_LOC 3156331 othdiscr 1 non_mandatory
91533647 SHARED2FREE 3156332 maint 1 atwork
91533655 WALK 3156332 work 1 mandatory
91533650 WALK_LOC 3156332 othmaint 1 non_mandatory
91533583 SHARED2FREE 3156333 othmaint 1 joint
91533680 WALK 3156333 school 1 mandatory
91533683 SHARED2FREE 3156333 social 1 non_mandatory
91533709 WALK 3156334 school 1 mandatory
91533738 WALK 3156335 school 1 mandatory
92466005 WALK 3188482 work 1 mandatory
92465999 WALK 3188482 othdiscr 1 non_mandatory
92466034 WALK_LOC 3188483 work 1 mandatory
92466040 WALK 3188484 eat 1 atwork
92465989 SHARED2FREE 3188484 othdiscr 1 joint
92466063 WALK_LOC 3188484 work 1 mandatory
92466059 WALK_LOC 3188484 school 2 mandatory
92466092 WALK 3188485 work 1 mandatory
"""

EXPECT_PERSON_IDS = [
3156330,
3156331,
3156332,
3156332,
3156332,
3156333,
3156333,
3156333,
3156334,
3156335,
3188482,
3188482,
3188483,
3188484,
3188484,
3188484,
3188484,
3188485,
]

EXPECT_TOUR_TYPES = [
'othmaint',
'work',
'othdiscr',
'work',
'eat',
'othdiscr',
'maint',
'work',
'othmaint',
'othmaint',
'school',
'social',
'school',
'school',
'work',
]

EXPECT_MODES = [
'WALK',
'WALK_LOC',
'SHARED2FREE',
'WALK',
'WALK_LOC',
'SHARED2FREE',
'WALK',
'SHARED2FREE',
'WALK',
'WALK_LOC',
'WALK_LOC',
'WALK',
]

Expand Down

1 comment on commit 103fdd5

@bstabler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.