bool ConvertTrips::Get_Trip_Data (Trip_File &file, Trip_Data &data, int partition) { int hhold, mode; Person_Index person_index; Int_Map_Itr map_itr; Location_Data *loc_ptr; hhold = file.Household (); if (hhold > max_hh_in) max_hh_in = hhold; hhold_map.insert (Int_Map_Data (hhold, 1)); person_index.Household (hhold); person_index.Person (file.Person ()); person_map.insert (Person_Map_Data (person_index, 1)); if (select_households && !hhold_range.In_Range (hhold)) return (false); mode = file.Mode (); if (mode >= 0 && mode < MAX_MODE && !select_mode [mode]) return (false); if (select_purposes && !purpose_range.In_Range (file.Purpose ())) return (false); if (select_start_times && !start_range.In_Range (file.Start ())) return (false); if (select_end_times && !end_range.In_Range (file.End ())) return (false); if (select_org_zones) { map_itr = location_map.find (file.Origin ()); if (map_itr != location_map.end ()) { loc_ptr = &location_array [map_itr->second]; if (!org_zone_range.In_Range (loc_ptr->Zone ())) return (false); } } if (select_des_zones) { map_itr = location_map.find (file.Destination ()); if (map_itr != location_map.end ()) { loc_ptr = &location_array [map_itr->second]; if (!des_zone_range.In_Range (loc_ptr->Zone ())) return (false); } } trip_file->Copy_Fields (file); if (!trip_file->Write ()) { Error ("Writing Trip File"); } trip_copy++; data.Household (hhold); hhold = partition; //---- don't save the record ---- return (false); }
void Data_Service::Initialize_Trips (Trip_File &file) { Required_File_Check (file, LOCATION); Required_File_Check (file, VEHICLE_TYPE); int percent = System_Data_Reserve (TRIP); if (trip_array.capacity () == 0 && percent > 0) { int num = file.Estimate_Records (); if (percent != 100) { num = (int) ((double) num * percent / 100.0); } if (num > 1) { trip_array.reserve (num); if (num > (int) trip_array.capacity ()) Mem_Error (file.File_ID ()); } } }
bool Data_Service::Get_Trip_Data (Trip_File &file, Trip_Data &trip_rec, int partition) { file.Get_Data (trip_rec); //---- check the household id ---- if (trip_rec.Household () < 1) return (false); if (trip_rec.Partition () < partition) trip_rec.Partition (partition); return (true); }
void Data_Service::Read_Trips (Trip_File &file) { int part, num, num_rec, part_num, first; Trip_Data trip_rec; Trip_Index trip_index; Trip_Map_Stat map_stat; Initialize_Trips (file); num_rec = first = 0; //---- check the partition number ---- if (file.Part_Flag () && First_Partition () != file.Part_Number ()) { file.Open (0); } else if (First_Partition () >= 0) { first = First_Partition (); } //---- process each partition ---- for (part=0; ; part++) { if (part > 0) { if (!file.Open (part)) break; } //---- store the trip data ---- if (file.Part_Flag ()) { part_num = file.Part_Number (); Show_Message (String ("Reading %s %d -- Record") % file.File_Type () % part_num); } else { part_num = part + first; Show_Message (String ("Reading %s -- Record") % file.File_Type ()); } Set_Progress (); while (file.Read ()) { Show_Progress (); trip_rec.Clear (); if (Get_Trip_Data (file, trip_rec, part_num)) { trip_rec.Internal_IDs (); trip_rec.Get_Index (trip_index); trip_rec.Index ((int) trip_array.size ()); //---- process the record ---- map_stat = trip_map.insert (Trip_Map_Data (trip_index, trip_rec.Index ())); if (!map_stat.second) { Warning (String ("Duplicate Trip Record = %d-%d-%d-%d") % trip_index.Household () % trip_index.Person () % trip_index.Tour () % trip_index.Trip ()); } else { trip_array.push_back (trip_rec); trip_array.Max_Partition (trip_rec); file.Add_Trip (trip_index.Household (), trip_index.Person (), trip_index.Tour ()); } } } End_Progress (); num_rec += Progress_Count (); } file.Close (); Print (2, String ("Number of %s Records = %d") % file.File_Type () % num_rec); if (part > 1) Print (0, String (" (%d files)") % part); num = (int) trip_array.size (); if (num && num != num_rec) { Print (1, String ("Number of %s Data Records = %d") % file.File_ID () % num); } if (num > 0) System_Data_True (TRIP); }
bool NewFormat::Get_Trip_Data (Trip_File &file, Trip_Data &trip_rec, int partition) { static int part_num = -1; static Trip_File *out_file = 0; if (part_num != partition) { part_num = partition; if (new_trip_flag) { out_file = System_Trip_File (true); if (out_file != 0 && out_file->Part_Flag () && part_num > 1) { if (!out_file->Open (part_num)) { Error (String ("Opening %s") % out_file->Filename ()); } if (part_num > max_trip_part) max_trip_part = part_num; } else { max_trip_part = 1; } } else { max_trip_part = 1; } } if (file.Version () < 60) { trip_rec.Household (file.Household ()); if (trip_rec.Household () < 1) return (false); trip_rec.Person (file.Person ()); trip_rec.Tour (file.Tour ()); if (trip_rec.Tour () < 1) trip_rec.Tour (1); trip_rec.Trip (file.Trip ()); trip_rec.Start (file.Start ()); trip_rec.End (file.End ()); trip_rec.Duration (file.Duration ()); trip_rec.Origin (file.Origin ()); trip_rec.Destination (file.Destination ()); trip_rec.Purpose (file.Purpose ()); trip_rec.Constraint (file.Constraint ()); trip_rec.Priority (file.Priority ()); int vehicle = file.Vehicle (); int veh_type = file.Veh_Type (); if (file.Version () <= 40) { trip_rec.Mode (Trip_Mode_Map (file.Mode ())); if (vehicle > 0) { Veh_ID_Map_Itr itr = vehicle40_map.find (vehicle); if (itr == vehicle40_map.end () || itr->second.Household () != trip_rec.Household ()) return (false); vehicle = itr->second.Vehicle (); } } else { trip_rec.Mode (file.Mode ()); } if (vehicle > 0) { Vehicle_Index veh_index (trip_rec.Household (), vehicle); Vehicle_Map_Itr itr = vehicle_type.find (veh_index); if (itr != vehicle_type.end ()) { Veh_Type_Data *ptr = &veh_type_array [itr->second]; veh_type = ptr->Type (); } else if (file.Version () < 50 || veh_type == 0) { return (false); } } else { veh_type = 0; } trip_rec.Vehicle (vehicle); trip_rec.Veh_Type (veh_type); trip_rec.Type (file.Type ()); trip_rec.Partition (file.Partition ()); if (trip_rec.Partition () < partition) trip_rec.Partition (partition); } else { if (!Data_Service::Get_Trip_Data (file, trip_rec, partition)) return (false); } if (select_households && !hhold_range.In_Range (trip_rec.Household ())) return (false); if (trip_rec.Mode () >= 0 && trip_rec.Mode () < MAX_MODE && !select_mode [trip_rec.Mode ()]) return (false); if (select_purposes && !purpose_range.In_Range (trip_rec.Purpose ())) return (false); if (select_vehicles && !vehicle_range.In_Range (trip_rec.Veh_Type ())) return (false); if (select_travelers && !traveler_range.In_Range (trip_rec.Type ())) return (false); if (select_start_times && !start_range.In_Range (trip_rec.Start ())) return (false); if (select_end_times && !end_range.In_Range (trip_rec.End ())) return (false); if (select_origins && !org_range.In_Range (trip_rec.Origin ())) return (false); if (select_destinations && !des_range.In_Range (trip_rec.Destination ())) return (false); if (new_trip_flag) { num_new_trip += Put_Trip_Data (*out_file, trip_rec); } if (new_plan_flag) return (true); return (false); }
bool Data_Service::Get_Trip_Data (Trip_File &file, Trip_Data &trip_rec, int partition) { int hhold, lvalue; Int_Map_Itr map_itr; Vehicle_Index veh_index; Vehicle_Map_Itr veh_itr; //---- check the household id ---- hhold = file.Household (); if (hhold < 1) return (false); trip_rec.Household (hhold); trip_rec.Person (file.Person ()); trip_rec.Tour (MAX (file.Tour (), 1)); trip_rec.Trip (file.Trip ()); trip_rec.Start (file.Start ()); trip_rec.End (file.End ()); //---- convert the origin ---- lvalue = file.Origin (); map_itr = location_map.find (lvalue); if (map_itr == location_map.end ()) { Warning (String ("Trip %d Origin %d was Not Found") % Progress_Count () % lvalue); return (false); } trip_rec.Origin (map_itr->second); //---- convert the destination ---- lvalue = file.Destination (); map_itr = location_map.find (lvalue); if (map_itr == location_map.end ()) { Warning (String ("Trip %d Destination %d was Not Found") % Progress_Count () % lvalue); return (false); } trip_rec.Destination (map_itr->second); lvalue = file.Vehicle (); if (file.Version () <= 40) { lvalue = Fix_Vehicle_ID (lvalue); } if (lvalue > 0) { veh_index.Household (hhold); veh_index.Vehicle (lvalue); veh_itr = vehicle_map.find (veh_index); if (veh_itr == vehicle_map.end ()) { Warning (String ("Trip %d Vehicle %d was Not Found") % Progress_Count () % lvalue); return (false); } lvalue = veh_itr->second; } else { lvalue = -1; } trip_rec.Vehicle (lvalue); if (file.Version () <= 40) { trip_rec.Mode (Trip_Mode_Map (file.Mode ())); } else { trip_rec.Mode (file.Mode ()); } trip_rec.Purpose (file.Purpose ()); trip_rec.Constraint (file.Constraint ()); trip_rec.Passengers (file.Passengers ()); trip_rec.Type (file.Type ()); if (file.Partition_Flag ()) { trip_rec.Partition (file.Partition ()); } else { trip_rec.Partition (partition); } //trip_rec.Notes (file.Notes ()); return (true); }
void NewFormat::Program_Control (void) { bool type_flag, flat_flag, time_flag; String key; //---- open the support files ---- Data_Service::Program_Control (); if (Check_Control_Key (VERSION4_PLAN_FILE) && Check_Control_Key (TRIP_SORT_TYPE)) { Warning ("Plan Sorting is Limited to Version 5 Plan files"); Show_Message (1); } Print (2, String ("%s Control Keys:") % Program ()); //---- copy existing fields ---- copy_flag = Get_Control_Flag (COPY_EXISTING_FIELDS); if (copy_flag) { if (System_File_Flag (LOCATION) && System_File_Flag (NEW_LOCATION)) { Location_File *file = (Location_File *) System_File_Handle (LOCATION); new_loc_file = (Location_File *) System_File_Handle (NEW_LOCATION); new_loc_file->Add_User_Fields (file); } if (System_File_Flag (ZONE) && System_File_Flag (NEW_ZONE)) { Zone_File *file = (Zone_File *) System_File_Handle (ZONE); new_zone_file = (Zone_File *) System_File_Handle (NEW_ZONE); new_zone_file->Add_User_Fields (file); } } //---- copy existing configuration ---- if (System_File_Flag (LINK_DELAY) && System_File_Flag (NEW_LINK_DELAY)) { Link_Delay_File *file = (Link_Delay_File *) System_File_Header (LINK_DELAY); if (file->Turn_Flag ()) { file = (Link_Delay_File *) System_File_Header (NEW_LINK_DELAY); file->Clear_Fields (); file->Turn_Flag (true); file->Set_Nesting (true); file->Create_Fields (); file->Write_Header (); } } if (System_File_Flag (PERFORMANCE) && System_File_Flag (NEW_PERFORMANCE)) { Performance_File *file = (Performance_File *) System_File_Header (PERFORMANCE); if (file->Turn_Flag ()) { file = (Performance_File *) System_File_Header (NEW_PERFORMANCE); file->Clear_Fields (); file->Turn_Flag (true); file->Set_Nesting (true); file->Create_Fields (); file->Write_Header (); } } //---- flatten output flag ---- flat_flag = Get_Control_Flag (FLATTEN_OUTPUT_FLAG); if (flat_flag) { if (System_File_Flag (NEW_SHAPE)) { System_File_Header (NEW_SHAPE)->Flatten_File (); } if (System_File_Flag (NEW_PARKING)) { System_File_Header (NEW_PARKING)->Flatten_File (); } if (System_File_Flag (NEW_SIGNAL)) { System_File_Header (NEW_SIGNAL)->Flatten_File (); } if (System_File_Flag (NEW_TIMING_PLAN)) { System_File_Header (NEW_TIMING_PLAN)->Flatten_File (); } if (System_File_Flag (NEW_PHASING_PLAN)) { System_File_Header (NEW_PHASING_PLAN)->Flatten_File (); } if (System_File_Flag (NEW_TRANSIT_ROUTE)) { System_File_Header (NEW_TRANSIT_ROUTE)->Flatten_File (); } if (System_File_Flag (NEW_TRANSIT_SCHEDULE)) { System_File_Header (NEW_TRANSIT_SCHEDULE)->Flatten_File (); } if (System_File_Flag (NEW_TRANSIT_DRIVER)) { System_File_Header (NEW_TRANSIT_DRIVER)->Flatten_File (); } if (System_File_Flag (NEW_ROUTE_NODES)) { System_File_Header (NEW_ROUTE_NODES)->Flatten_File (); } if (System_File_Flag (NEW_HOUSEHOLD)) { System_File_Header (NEW_HOUSEHOLD)->Flatten_File (); } if (System_File_Flag (NEW_LINK_DELAY)) { System_File_Header (NEW_LINK_DELAY)->Flatten_File (); } if (System_File_Flag (NEW_PERFORMANCE)) { System_File_Header (NEW_PERFORMANCE)->Flatten_File (); } if (System_File_Flag (NEW_PLAN)) { System_File_Header (NEW_PLAN)->Flatten_File (); } } //---- toll file ---- key = Get_Control_String (TOLL_FILE); if (!key.empty ()) { toll_file.Open (Project_Filename (key)); toll_flag = true; } //---- activity file ---- key = Get_Control_String (ACTIVITY_FILE); if (!key.empty ()) { activity_file.Open (Project_Filename (key)); activity_flag = true; if (!System_File_Flag (NEW_TRIP)) { Error ("A New Trip file is required to convert an Activity File"); } if (!System_File_Flag (VEHICLE)) { Error ("A Vehicle file is required to convert an Activity File"); } } //---- person file ---- key = Get_Control_String (PERSON_FILE); if (!key.empty ()) { person_file.Open (Project_Filename (key)); person_flag = true; } //---- snapshot file ---- key = Get_Control_String (SNAPSHOT_FILE); if (!key.empty ()) { Print (1); snap_file.Open (Project_Filename (key)); snap_flag = true; } //---- new snapshot file ---- key = Get_Control_String (NEW_SNAPSHOT_FILE); if (!key.empty ()) { new_snap_file.Compress_Flag (Set_Control_Flag (NEW_SNAPSHOT_COMPRESSION)); if (new_snap_file.Compress_Flag ()) { new_snap_file.Dbase_Format (BINARY); } else { if (Check_Control_Key (NEW_SNAPSHOT_FORMAT)) { new_snap_file.Dbase_Format (Get_Control_String (NEW_SNAPSHOT_FORMAT)); } new_snap_file.Location_Flag (snap_file.Location_Flag ()); new_snap_file.Cell_Flag (snap_file.Cell_Flag ()); new_snap_file.Status_Flag (snap_file.Status_Flag ()); } new_snap_file.Create (Project_Filename (key)); Get_Control_Flag (NEW_SNAPSHOT_COMPRESSION); } else if (snap_flag) { Error ("A New Snapshot File is required for Output"); } //---- version 4 time format ---- time_units = Units_Code (Get_Control_Text (VERSION4_TIME_FORMAT)); time_flag = Check_Control_Key (VERSION4_TIME_FORMAT); if (time_flag) { int num; Field_Ptr fld_ptr; if (System_File_Flag (TRIP)) { Trip_File *file = (Trip_File *) System_File_Base (TRIP); if (file->Version () <= 40) { num = file->Optional_Field (START_FIELD_NAMES); if (num >= 0) { fld_ptr = file->Field (num); fld_ptr->Units (time_units); } num = file->Optional_Field (END_FIELD_NAMES); if (num >= 0) { fld_ptr = file->Field (num); fld_ptr->Units (time_units); } num = file->Optional_Field (DURATION_FIELD_NAMES); if (num >= 0) { fld_ptr = file->Field (num); fld_ptr->Units (time_units); } } } if (activity_flag) { num = activity_file.Optional_Field ("START_MIN", "START", "START_TIME", "STARTTIME"); if (num >= 0) { fld_ptr = activity_file.Field (num); fld_ptr->Units (time_units); } num = activity_file.Optional_Field ("START_MAX", "START", "START_TIME", "STARTTIME"); if (num >= 0) { fld_ptr = activity_file.Field (num); fld_ptr->Units (time_units); } num = activity_file.Optional_Field ("END_MIN", "END", "END_TIME", "ENDTIME"); if (num >= 0) { fld_ptr = activity_file.Field (num); fld_ptr->Units (time_units); } num = activity_file.Optional_Field ("END_MAX", "END", "END_TIME", "ENDTIME"); if (num >= 0) { fld_ptr = activity_file.Field (num); fld_ptr->Units (time_units); } num = activity_file.Optional_Field ("TIME_MIN", "DURATION"); if (num >= 0) { fld_ptr = activity_file.Field (num); fld_ptr->Units (time_units); } num = activity_file.Optional_Field ("TIME_MAX", "DURATION"); if (num >= 0) { fld_ptr = activity_file.Field (num); fld_ptr->Units (time_units); } } } //---- plan file ---- if (Check_Control_Key (VERSION4_PLAN_FILE)) { if (System_File_Flag (PLAN)) { Error ("A plan file and Version 4 plan file must be processed separateley"); } if (!System_File_Flag (NEW_PLAN)) { Error ("A new plan file is required to convert a Version 4 plan file"); } Print (1); plan_flag = true; old_plan.File_Type ("Version4 Plan File"); //---- get the list type ---- key = Get_Control_String (NODE_LIST_PATHS); if (!key.empty ()) { type_flag = key.Bool (); } else { type_flag = true; } old_plan.Node_Based_Flag (type_flag); //---- get the traveler scale ---- key = Get_Control_String (TRAVELER_SCALING_FACTOR); if (!key.empty ()) { scale = key.Integer (); if (scale < 2 || scale > 100) { Control_Key_Error (TRAVELER_SCALING_FACTOR, "(2..100)"); } old_plan.Traveler_Scale (scale); } //---- get the file format ---- if (Check_Control_Key (VERSION4_PLAN_FORMAT)) { old_plan.File_Format (Get_Control_String (VERSION4_PLAN_FORMAT)); } //---- open the file and print the parameters ---- if (!old_plan.Open (Project_Filename (Get_Control_String (VERSION4_PLAN_FILE)))) { File_Error ("Opening Version4 Plan File", old_plan.Filename ()); } Get_Control_Text (VERSION4_PLAN_FORMAT); type_flag = old_plan.Node_Based_Flag (); if (type_flag) { Print (1, "Plan File contains Node List Paths"); if (!System_File_Flag (NODE) || !System_File_Flag (LINK) || !System_File_Flag (PARKING)) { Error ("A Node, Link and Parking Files are Required for Node-Based Plan Files"); } AB_Map_Flag (true); } else { Print (1, "Plan File contains Link List Paths"); } Get_Control_Integer (TRAVELER_SCALING_FACTOR); } else if (snap_flag && snap_file.Version () <= 40) { //---- get the traveler scale ---- scale= Get_Control_Integer (TRAVELER_SCALING_FACTOR); if (scale < 2 || scale > 100) { Control_Key_Error (TRAVELER_SCALING_FACTOR, "(2..100)"); } } //---- Version 4 Route Header and Node files ---- if (Check_Control_Key (VERSION4_ROUTE_HEADER)) { if (!System_File_Flag (NEW_ROUTE_NODES)) { Error ("A New Route Nodes File is Required"); } int i, num; String field; Field_Ptr fld_ptr; if (!time_flag) time_units = MINUTES; Print (1); route_flag = true; Route_Nodes_File *file = (Route_Nodes_File *) System_File_Base (NEW_ROUTE_NODES); key = Get_Control_String (VERSION4_ROUTE_HEADER); route_header.File_Type ("Version4 Route Header"); route_header.File_ID ("Header"); route_header.Open (Project_Filename (key)); for (i=1; i <= 24; i++) { field ("HEADWAY_%d") % i; num = route_header.Optional_Field (field.c_str ()); if (num < 0) break; fld_ptr = route_header.Field (num); fld_ptr->Units (time_units); field ("OFFSET_%d") % i; num = route_header.Optional_Field (field.c_str ()); if (num >= 0) { fld_ptr = route_header.Field (num); fld_ptr->Units (time_units); } field ("TTIME_%d") % i; num = route_header.Optional_Field (field.c_str ()); if (num >= 0) { fld_ptr = route_header.Field (num); fld_ptr->Units (time_units); } } route_periods = i - 1; if (route_periods != file->Num_Periods ()) { file->Num_Periods (route_periods); file->Clear_Fields (); file->Create_Fields (); file->Write_Header (); } key = Get_Control_String (VERSION4_ROUTE_NODES); if (key.empty ()) { Error ("A Version4 Route Nodes file is Required"); } route_nodes.File_Type ("Version4 Route Nodes"); route_nodes.File_ID ("Nodes"); route_nodes.Open (Project_Filename (key)); } }