@@ -141,27 +141,32 @@ def choose_parking_location(
141141 model_settings ,
142142 want_sample_table ,
143143 skims ,
144- chunk_size , trace_hh_id ,
144+ chunk_size ,
145+ trace_hh_id ,
145146 trace_label ):
146147
147148 logger .info ("choose_parking_location %s with %d trips" , trace_label , trips .shape [0 ])
148149
149150 t0 = print_elapsed_time ()
150151
151152 alt_dest_col_name = model_settings ['ALT_DEST_COL_NAME' ]
152- destination_sample = logit .interaction_dataset (trips , alternatives , alt_index_id = alt_dest_col_name )
153- destination_sample .index = np .repeat (trips .index .values , len (alternatives ))
154- destination_sample .index .name = trips .index .name
155- destination_sample = destination_sample [[alt_dest_col_name ]].copy ()
156153
154+ numchoosers = len (trips )
155+ numalts = len (alternatives )
156+ sample = np .tile (np .arange (numalts ), numchoosers )
157+ destination_sample = alternatives .take (sample ).copy ()
158+ destination_sample .index = np .repeat (trips .index .values , numalts )
159+ destination_sample .index .name = trips .index .name
160+
157161 # # - trip_destination_simulate
158162 destinations = parking_destination_simulate (
159163 segment_name = segment_name ,
160164 trips = trips ,
161165 destination_sample = destination_sample ,
162166 model_settings = model_settings ,
163167 skims = skims ,
164- chunk_size = chunk_size , trace_hh_id = trace_hh_id ,
168+ chunk_size = chunk_size ,
169+ trace_hh_id = trace_hh_id ,
165170 trace_label = trace_label )
166171
167172 if want_sample_table :
@@ -177,10 +182,11 @@ def choose_parking_location(
177182
178183def run_parking_destination (
179184 model_settings ,
180- trips , land_use ,
181- chunk_size , trace_hh_id ,
182- trace_label ,
183- fail_some_trips_for_testing = False ):
185+ trips ,
186+ alternatives ,
187+ chunk_size ,
188+ trace_hh_id ,
189+ trace_label ):
184190
185191 chooser_filter_column = model_settings .get ('CHOOSER_FILTER_COLUMN_NAME' )
186192 chooser_segment_column = model_settings .get ('CHOOSER_SEGMENT_COLUMN_NAME' )
@@ -197,13 +203,6 @@ def run_parking_destination(
197203
198204 skims = wrap_skims (model_settings )
199205
200- alt_column_filter_name = model_settings .get ('ALTERNATIVE_FILTER_COLUMN_NAME' )
201- alternatives = land_use [land_use [alt_column_filter_name ]]
202-
203- # don't need size terms in alternatives, just TAZ index
204- alternatives = alternatives .drop (alternatives .columns , axis = 1 )
205- alternatives .index .name = parking_location_column_name
206-
207206 choices_list = []
208207 sample_list = []
209208 for segment_name , chooser_segment in choosers .groupby (chooser_segment_column ):
@@ -218,7 +217,8 @@ def run_parking_destination(
218217 model_settings ,
219218 want_sample_table ,
220219 skims ,
221- chunk_size , trace_hh_id ,
220+ chunk_size ,
221+ trace_hh_id ,
222222 trace_label = tracing .extend_trace_label (trace_label , segment_name ))
223223
224224 choices_list .append (choices )
@@ -228,10 +228,6 @@ def run_parking_destination(
228228
229229 if len (choices_list ) > 0 :
230230 parking_df = pd .concat (choices_list )
231-
232- if fail_some_trips_for_testing :
233- parking_df = parking_df .drop (parking_df .index [0 ])
234-
235231 assign_in_place (trips , parking_df .to_frame (parking_location_column_name ))
236232 trips [parking_location_column_name ] = trips [parking_location_column_name ].fillna (- 1 )
237233 else :
@@ -259,18 +255,33 @@ def parking_location(
259255 model_settings = config .read_model_settings ('parking_location_choice.yaml' )
260256 alt_destination_col_name = model_settings ['ALT_DEST_COL_NAME' ]
261257
262- preprocessor_settings = model_settings .get ('PREPROCESSOR' , None )
263-
264258 trips_df = trips .to_frame ()
265259 trips_merged_df = trips_merged .to_frame ()
260+
266261 land_use_df = land_use .to_frame ()
267262
268- locals_dict = {
269- 'network_los' : network_los
270- }
271- locals_dict .update (config .get_model_constants (model_settings ))
263+ alt_column_filter_name = model_settings .get ('ALTERNATIVE_FILTER_COLUMN_NAME' )
264+ alt_tdd = land_use_df [land_use_df [alt_column_filter_name ]]
265+ alt_tdd [alt_destination_col_name ] = alt_tdd .index
266+
267+ # alt preprocessor
268+ alt_preprocessor_settings = model_settings .get ('ALTS_PREPROCESSOR' , None )
269+ if alt_preprocessor_settings :
270+ locals_dict = {}
272271
272+ alt_tdd = alt_tdd .copy ()
273+
274+ expressions .assign_columns (
275+ df = alt_tdd ,
276+ model_settings = alt_preprocessor_settings ,
277+ locals_dict = locals_dict ,
278+ trace_label = trace_label )
279+
280+ # trips preprocessor
281+ preprocessor_settings = model_settings .get ('PREPROCESSOR' , None )
273282 if preprocessor_settings :
283+ locals_dict = {}
284+
274285 expressions .assign_columns (
275286 df = trips_merged_df ,
276287 model_settings = preprocessor_settings ,
@@ -279,7 +290,8 @@ def parking_location(
279290
280291 parking_locations , save_sample_df = run_parking_destination (
281292 model_settings ,
282- trips_merged_df , land_use_df ,
293+ trips_merged_df ,
294+ alt_tdd ,
283295 chunk_size = chunk_size ,
284296 trace_hh_id = trace_hh_id ,
285297 trace_label = trace_label ,
0 commit comments