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); }
void TripPrep::MPI_Setup (void) { #ifdef MPI_EXE if (MPI_Size () == 1) return; int range [2]; if (Master ()) { int num_parts, rank; Db_File temp_file; String key, dir; Integers count; Int_Itr itr; Int_RItr ritr; dir = Get_Control_String (PROJECT_DIRECTORY); if (!dir.empty ()) { Fix_Directory (dir); } key = Get_Control_String (System_File_ID (TRIP)); temp_file.Filename (dir + key); num_parts = temp_file.Num_Parts (); if (num_parts < 2) return; Write (1, "Number of MPI Processors = ") << MPI_Size (); Write (1, "Number of Trip Partitions = ") << num_parts; Write (1); count.assign (MPI_Size (), 0); for (itr = count.begin (); itr != count.end (); itr++) { (*itr)++; if (--num_parts == 0) break; } while (num_parts > 0) { for (ritr = count.rbegin (); ritr != count.rend (); ritr++) { (*ritr)++; if (--num_parts == 0) break; } } num_parts = 0; for (rank=0, itr = count.begin (); itr != count.end (); itr++, rank++) { range [0] = num_parts; num_parts += *itr; range [1] = num_parts - 1; if (rank == 0) { First_Partition (range [0]); Last_Partition (range [1]); } else { Send_MPI_Array (range, 2, rank); } } } else { //---- slave ---- Get_MPI_Array (range, 2, 0); First_Partition (range [0]); Last_Partition (range [1]); } #endif }
void PlanCompare::MPI_Processing (void) { #ifdef MPI_EXE int i, lvalue [7], rank; if (Master ()) { Write (1); for (i=1; i < MPI_Size (); i++) { rank = Show_MPI_Message (); //---- retrieve the data buffer ---- Get_MPI_Buffer (rank); if (mpi_buffer.Size () == 0) continue; //---- retrieve the plan statistics mpi_buffer.Get_Data (lvalue, sizeof (lvalue)); plan_file->Add_Files (lvalue [0]); plan_file->Add_Records (lvalue [1]); plan_file->Add_Households (lvalue [2]); plan_file->Add_Persons (lvalue [3]); plan_file->Add_Tours (lvalue [4]); plan_file->Add_Trips (lvalue [5]); num_trips += lvalue [6]; //---- retrieve the compare statistics mpi_buffer.Get_Data (lvalue, sizeof (lvalue)); compare_file.Add_Files (lvalue [0]); compare_file.Add_Records (lvalue [1]); compare_file.Add_Households (lvalue [2]); compare_file.Add_Persons (lvalue [3]); compare_file.Add_Tours (lvalue [4]); compare_file.Add_Trips (lvalue [5]); num_compare += lvalue [6]; //---- selection map data ---- selected.UnPack (mpi_buffer); //---- time difference data ---- if (time_diff.Active_Flag ()) { Difference_Data temp; temp.Replicate (time_diff); temp.UnPack (mpi_buffer); time_diff.Merge_Data (temp); } //---- cost difference data ---- if (cost_diff.Active_Flag ()) { Difference_Data temp; temp.Replicate (cost_diff); temp.UnPack (mpi_buffer); cost_diff.Merge_Data (temp); } //---- time gap data ---- if (time_gap.Active_Flag ()) { Trip_Gap_Data temp; temp.Replicate (time_gap); temp.UnPack (mpi_buffer); time_gap.Merge_Data (temp); } //---- cost gap data ---- if (cost_gap.Active_Flag ()) { Trip_Gap_Data temp; temp.Replicate (cost_gap); temp.UnPack (mpi_buffer); cost_gap.Merge_Data (temp); } } Show_Message (1); plan_file->Close (); compare_file.Close (); } else { //---- slave ---- if (Partition_Range ()) { Send_MPI_Message (String ("Slave %d Read %ss %d..%d") % MPI_Rank () % plan_file->File_Type () % First_Partition () % Last_Partition ()); } else { Send_MPI_Message (String ("Slave %d Read %s %d") % MPI_Rank () % plan_file->File_Type () % First_Partition ()); } //---- send plan statistics ---- lvalue [0] = plan_file->Num_Files (); lvalue [1] = plan_file->Num_Records (); lvalue [2] = plan_file->Num_Households (); lvalue [3] = plan_file->Num_Persons (); lvalue [4] = plan_file->Num_Tours (); lvalue [5] = plan_file->Num_Trips (); lvalue [6] = num_trips; plan_file->Close (); mpi_buffer.Data (lvalue, sizeof (lvalue)); //---- send compare statistics ---- lvalue [0] = compare_file.Num_Files (); lvalue [1] = compare_file.Num_Records (); lvalue [2] = compare_file.Num_Households (); lvalue [3] = compare_file.Num_Persons (); lvalue [4] = compare_file.Num_Tours (); lvalue [5] = compare_file.Num_Trips (); lvalue [6] = num_compare; compare_file.Close (); mpi_buffer.Add_Data (lvalue, sizeof (lvalue)); //---- selection map data ---- selected.Pack (mpi_buffer); //---- time difference data ---- if (time_diff.Active_Flag ()) { time_diff.Pack (mpi_buffer); } //---- cost difference data ---- if (cost_diff.Active_Flag ()) { cost_diff.Pack (mpi_buffer); } //---- time gap data ---- if (time_gap.Active_Flag ()) { time_gap.Pack (mpi_buffer); } //---- cost gap data ---- if (cost_gap.Active_Flag ()) { cost_gap.Pack (mpi_buffer); } //---- send the data buffer ---- Send_MPI_Buffer (); if (!new_plan_flag && !select_parts) Exit_Stat (DONE); } #endif }
void ExportPlans::Read_Plans (void) { int part, num, first, part_num, org, des, period, link, dir, veh_type; bool start_flag, vehicle_flag; Dtime start; Plan_File *file = (Plan_File *) System_File_Handle (PLAN); Int_Map_Itr map_itr; Plan_Data plan_rec; Plan_Leg_Itr leg_itr; Location_Data *loc_ptr; Link_Data *link_ptr; Node_Data *node_ptr; Vehicle_Map_Itr vehicle_itr; Vehicle_Index veh_index; Vehicle_Data *vehicle_ptr; Veh_Type_Data *veh_type_ptr; Trip_Table_Map_Stat trip_map_stat; Trip_Table trip_table, *table_ptr; Matrix_Index trip_index; Trip_Table_Stat trip_stat; Integers volumes; num = sum_periods.Num_Periods (); volumes.assign (MAX (num, 1), 0); //---- check the partition number ---- period = first = 0; if (file->Part_Flag () && First_Partition () != file->Part_Number ()) { file->Open (0); } else if (First_Partition () >= 0) { first = First_Partition (); } veh_type = 1; vehicle_flag = System_File_Flag (VEHICLE); //---- process each partition ---- for (part=0; ; part++) { if (part > 0) { if (!file->Open (part)) break; } //---- store the plan 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_Plan (plan_rec)) { Show_Progress (); if (vehicle_flag) { if (plan_rec.Vehicle () <= 0) continue; veh_index.Household (plan_rec.Household ()); veh_index.Vehicle (plan_rec.Vehicle ()); vehicle_itr = vehicle_map.find (veh_index); if (vehicle_itr == vehicle_map.end ()) continue; vehicle_ptr = &vehicle_array [vehicle_itr->second]; veh_type_ptr = &veh_type_array [vehicle_ptr->Type ()]; veh_type = veh_type_ptr->Type (); } if (select_vehicles && !vehicle_range.In_Range (veh_type)) continue; start = plan_rec.Depart (); org = plan_rec.Origin (); des = plan_rec.Destination (); if (select_flag) { map_itr = location_map.find (org); if (map_itr != location_map.end ()) { loc_ptr = &location_array [map_itr->second]; start_flag = (loc_ptr->Zone () > 0); } else { start_flag = false; } //---- trace the path ---- for (leg_itr = plan_rec.begin (); leg_itr != plan_rec.end (); leg_itr++) { if (leg_itr->Mode () == DRIVE_MODE && leg_itr->Link_Type ()) { link = leg_itr->Link_ID (); dir = leg_itr->Link_Dir (); map_itr = link_map.find (link); if (map_itr != link_map.end ()) { link_ptr = &link_array [map_itr->second]; if (link_ptr->Divided () != 0) { if (dir == 0) { if (link_ptr->Divided () == 1) { node_ptr = &node_array [link_ptr->Bnode ()]; des = node_ptr->Control (); break; } else if (!start_flag) { node_ptr = &node_array [link_ptr->Anode ()]; org = node_ptr->Control (); } } else { if (link_ptr->Divided () == 2) { node_ptr = &node_array [link_ptr->Anode ()]; des = node_ptr->Control (); break; } else if (!start_flag) { node_ptr = &node_array [link_ptr->Bnode ()]; org = node_ptr->Control (); } } start_flag = true; } } } if (!start_flag) start += leg_itr->Time (); } if (!start_flag) continue; } if (map_flag) { map_itr = loc_zone_map.find (org); if (map_itr != loc_zone_map.end ()) { org = map_itr->second; } map_itr = loc_zone_map.find (des); if (map_itr != loc_zone_map.end ()) { des = map_itr->second; } } trip_index.Origin (org); trip_index.Destination (des); if (num > 0) { period = sum_periods.Period (start); if (period < 0) continue; } trip_map_stat = trip_tables.insert (Trip_Table_Map_Data (veh_type, trip_table)); table_ptr = &trip_map_stat.first->second; trip_stat = table_ptr->insert (Trip_Table_Data (trip_index, volumes)); trip_stat.first->second [period]++; } End_Progress (); } file->Close (); }
void PlanCompare::MPI_Close (void) { #ifdef MPI_EXE int i, lvalue [6], rank; if (Master ()) { if (new_plan_flag) { Show_Message (1); for (i=1; i < MPI_Size (); i++) { rank = Show_MPI_Message (); //---- retrieve the new plan statistics Get_MPI_Array (lvalue, 6, rank); new_plan_file->Add_Files (lvalue [0]); new_plan_file->Add_Records (lvalue [1]); new_plan_file->Add_Households (lvalue [2]); new_plan_file->Add_Persons (lvalue [3]); new_plan_file->Add_Tours (lvalue [4]); new_plan_file->Add_Trips (lvalue [5]); } new_plan_file->Close (); } //---- write the new selection file ---- if (select_parts) { Show_Message (1); select_map.swap (selected); Write_Selections (); for (i=1; i < MPI_Size (); i++) { Show_MPI_Message (); } } Show_Message (1); } else { //---- slave ---- if (new_plan_flag) { if (Partition_Range ()) { Send_MPI_Message (String ("Slave %d Wrote %ss %d..%d") % MPI_Rank () % new_plan_file->File_Type () % First_Partition () % Last_Partition ()); } else { Send_MPI_Message (String ("Slave %d Wrote %s %d") % MPI_Rank () % new_plan_file->File_Type () % First_Partition ()); } //---- send new plan statistics ---- lvalue [0] = new_plan_file->Num_Files (); lvalue [1] = new_plan_file->Num_Records (); lvalue [2] = new_plan_file->Num_Households (); lvalue [3] = new_plan_file->Num_Persons (); lvalue [4] = new_plan_file->Num_Tours (); lvalue [5] = new_plan_file->Num_Trips (); new_plan_file->Close (); Send_MPI_Array (lvalue, 6); } //---- write the new selection file ---- if (select_parts) { select_map.swap (selected); Write_Selections (); Selection_File *file = System_Selection_File (true); if (Partition_Range ()) { Send_MPI_Message (String ("Slave %d Wrote %ss %d..%d") % MPI_Rank () % file->File_Type () % First_Partition () % Last_Partition ()); } else { Send_MPI_Message (String ("Slave %d Wrote %s %d") % MPI_Rank () % file->File_Type () % First_Partition ()); } } Exit_Stat (DONE); } #endif }