Exemple #1
0
bool ArcPlan::Get_Problem_Data (Problem_File &file, Problem_Data &problem_rec, int partition)
{
	Location_Data *loc_ptr;
	Trip_Index trip_index;

	if (Data_Service::Get_Problem_Data (file, problem_rec, partition)) {
		if (select_problems && !problem_range.In_Range (problem_rec.Problem ())) return (false);
		if (select_households && !hhold_range.In_Range (problem_rec.Household ())) return (false);
		if (problem_rec.Mode () < MAX_MODE && !select_mode [problem_rec.Mode ()]) return (false);
		if (select_purposes && !purpose_range.In_Range (problem_rec.Purpose ())) return (false);
		if (select_start_times && !start_range.In_Range (problem_rec.Start ())) return (false);
		if (select_end_times && !end_range.In_Range (problem_rec.End ())) return (false);
		if (select_origins && !org_range.In_Range (file.Origin ())) return (false);
		if (select_destinations && !des_range.In_Range (file.Destination ())) return (false);

		if (select_org_zones) {
			loc_ptr = &location_array [problem_rec.Origin ()];
			if (!org_zone_range.In_Range (loc_ptr->Zone ())) return (false);
		}
		if (select_des_zones) {
			loc_ptr = &location_array [problem_rec.Destination ()];
			if (!des_zone_range.In_Range (loc_ptr->Zone ())) return (false);
		}
		if (select_travelers && !traveler_range.In_Range (problem_rec.Type ())) return (false);

		//---- check the selection records ----

		if (System_File_Flag (SELECTION)) {
			Select_Map_Itr sel_itr;

			sel_itr = select_map.Best (problem_rec.Household (), problem_rec.Person (), problem_rec.Tour (), problem_rec.Trip ());
			if (sel_itr == select_map.end ()) return (false);
		}

		//---- draw the problem record ----

		if (problem_out) {
			XYZ_Point point;

			arcview_problem.clear ();
			arcview_problem.Copy_Fields (file);

			if (problem_method == 3) {
				if (file.Link () > 0 && problem_rec.Dir_Index () >= 0) {
					int lane, center;
					double side;

					Dir_Data *dir_ptr = &dir_array [problem_rec.Dir_Index ()];
					Link_Data *link_ptr = &link_array [dir_ptr->Link ()];

					lane = problem_rec.Lane () + 1;

					if (center_flag) {
						if (link_ptr->BA_Dir () < 0) {
							center = dir_ptr->Left () + dir_ptr->Lanes () + dir_ptr->Right () + 1;
						} else if (link_ptr->AB_Dir () < 0) {
							center = dir_ptr->Left () + dir_ptr->Lanes () + dir_ptr->Right () + 1;
						} else {
							center = 1;
						}
					} else {
						center = 1;
					}
					side = (2 * lane - center) * lane_width / 2.0;

					Link_Shape (link_ptr, dir_ptr->Dir (), points, UnRound (problem_rec.Offset ()), 0.0, side);

					arcview_problem.assign (1, points [0]);
				} else {
					loc_ptr = &location_array [problem_rec.Origin ()];
					point.x = UnRound (loc_ptr->X ());
					point.y = UnRound (loc_ptr->Y ());

					arcview_problem.push_back (point);
				}
			} else if (problem_method < 2) {
				loc_ptr = &location_array [problem_rec.Origin ()];
				point.x = UnRound (loc_ptr->X ());
				point.y = UnRound (loc_ptr->Y ());

				arcview_problem.push_back (point);
			}
			if (problem_method != 1) {
				loc_ptr = &location_array [problem_rec.Destination ()];
				point.x = UnRound (loc_ptr->X ());
				point.y = UnRound (loc_ptr->Y ());

				arcview_problem.push_back (point);
			}
			if (!arcview_problem.Write_Record ()) {
				Error (String ("Writing %s") % arcview_problem.File_Type ());
			}
			num_problem++;
		}

		//---- save the problem index ----

		if (plan_flag) {
			trip_index.Set (problem_rec.Household (), problem_rec.Person (), problem_rec.Tour (), problem_rec.Trip ());

			problem_map.insert (Trip_Map_Data (trip_index, problem_rec.Problem ()));
		}
	}
	return (false);
}
Exemple #2
0
void EventSum::Read_Events (void)
{
	int hhold, type, num_rec, period, link, diff, mode;
	Dtime schedule, actual;

	Travel_Time_Data *time_ptr, time_data;
	Time_Sum_Data *sum_ptr, sum_data;
	Link_Time_Map_Stat link_map_stat;
	Link_Time_Key link_key;
	Trip_Index trip_index;
	Trip_Map_Itr time_map_itr;
	Trip_Map_Stat time_map_stat;

	Event_File *event_file = (Event_File *) System_File_Handle (EVENT);

	//----- initialize the time summary memory ----

	if (!compare_flag) {
		num_rec = event_file->Estimate_Records () / 2;
		travel_time_array.reserve (num_rec);
	}
	if (time_sum_flag) {
		time_sum_array.assign (num_inc, sum_data);
	}

	//---- read the event file ----

	Show_Message (String ("Reading %s -- Record") % event_file->File_Type ());
	Set_Progress ();

	num_rec = 0;

	while (event_file->Read ()) {
		Show_Progress ();

		//---- check the event type ----

		type = event_file->Event ();
		if (type != TRIP_START_EVENT && type != TRIP_END_EVENT) continue;

		//---- check the household id ----

		hhold = event_file->Household ();
		if (hhold <= 0) continue;

		if (select_households && !hhold_range.In_Range (hhold)) continue;

		mode = event_file->Mode ();
		if (mode > 0 && mode < MAX_MODE && !select_mode [mode]) continue;

		//---- check the selection records ----
		
		time_data.Household (hhold);
		time_data.Person (event_file->Person ());
		time_data.Tour (event_file->Tour ());
		time_data.Trip (event_file->Trip ());

		time_data.Get_Trip_Index (trip_index);

		if (select_flag && select_map.Best (trip_index) == select_map.end ()) continue;

		//---- get the event times ----

		schedule = event_file->Schedule ();
		actual = event_file->Actual ();

		link = abs (event_file->Link ());

		//---- save the trip data ----

		if (compare_flag || type == TRIP_END_EVENT) {
			time_map_itr = travel_time_map.find (trip_index);
			if (time_map_itr == travel_time_map.end ()) continue;

			time_ptr = &travel_time_array [time_map_itr->second];

			if (link == 0) {
				link = (type == TRIP_START_EVENT) ? time_ptr->Start_Link () : time_ptr->End_Link ();
			}
		} else {
			time_data.Mode (mode);
			time_data.Purpose (0);
			time_data.Constraint (FIXED_TIME);

			num_rec = (int) travel_time_array.size ();

			time_map_stat = travel_time_map.insert (Trip_Map_Data (trip_index, num_rec));
			if (!time_map_stat.second) {
				Warning (String ("Duplicate Travel Time Index %d-%d-%d-%d") % 
					trip_index.Household () % trip_index.Person () % trip_index.Tour () % trip_index.Trip ());
			} else {
				travel_time_array.push_back (time_data);
			}
			time_ptr = &travel_time_array [time_map_stat.first->second];
		}

		//---- save the trip start time ----

		if (type == TRIP_START_EVENT) {
			if (!compare_flag || link == time_ptr->Start_Link ()) {
				if (!trip_file_flag) {
					time_ptr->Trip_Start (schedule);
				}
				if (!time_in_flag) {
					time_ptr->Base_Start (schedule);
				}
				time_ptr->Started (actual);
				time_ptr->Start_Link (link);
			}
		} else {
			if (!compare_flag || link == time_ptr->End_Link ()) {

				//---- complete the trip ----

				if (!trip_file_flag) {
					time_ptr->Trip_End (schedule);
				}
				if (!time_in_flag) {
					time_ptr->Base_End (schedule);
				}
				time_ptr->Ended (actual);
				time_ptr->End_Link (link);
			}

			//---- process complete trips ----

			if (time_ptr->Ended () > time_ptr->Started ()) {

				//---- add to the time summary ----

				if (time_sum_flag) {

					//---- process the start time ----

					schedule = time_ptr->Trip_Start ();
					actual = time_ptr->Started ();

					period = sum_periods.Period (schedule);

					if (period >= 0 && period < num_inc) {

						sum_ptr = &time_sum_array [period];
						sum_ptr->Period (period);
						sum_ptr->Add_Trip_Start ();
					}
					period = sum_periods.Period (actual);

					if (period >= 0 && period < num_inc) {
						diff = actual - schedule;

						sum_ptr = &time_sum_array [period];
						sum_ptr->Period (period);
						sum_ptr->Add_Start_Diff (diff);
					}

					//---- process the end time ----

					schedule = time_ptr->Trip_End ();
					actual = time_ptr->Ended ();

					period = sum_periods.Period (schedule);

					if (period >= 0 && period < num_inc) {
						sum_ptr = &time_sum_array [period];
						sum_ptr->Period (period);
						sum_ptr->Add_Trip_End ();
					}
					period = sum_periods.Period (actual);

					if (period >= 0 && period < num_inc) {
						diff = actual - schedule;

						sum_ptr =&time_sum_array [period];
						sum_ptr->Period (period);
						sum_ptr->Add_End_Diff (diff);
					}

					//---- travel time difference ----
					
					actual = time_ptr->Mid_Trip ();

					period = sum_periods.Period (actual);

					if (period >= 0 && period < num_inc) {
						sum_ptr = &time_sum_array [period];

						diff = time_ptr->Travel_Time () - time_ptr->Trip_Time ();

						sum_ptr->Add_Travel_Time (time_ptr->Travel_Time (), diff);

						diff = abs (time_ptr->Trip_Start_Diff ()) + abs (time_ptr->Trip_End_Diff ());

						if (diff >= min_variance) {
							sum_ptr->Add_Sum_Error (diff);
						}
					}
				}

				//---- add to link and period totals ----

				if (link_event_flag) {
					schedule = time_ptr->Trip_Start ();
					actual = time_ptr->Started ();
					link = time_ptr->Start_Link ();

					period = sum_periods.Period (schedule);

					if (period >= 0) {
						link_key.Key (link, period);

						link_map_stat = link_time_map.insert (Link_Time_Map_Data (link_key, sum_data));

						sum_ptr = &link_map_stat.first->second;

						sum_ptr->Period (period);
						sum_ptr->Add_Trip_Start ();
					}
					period = sum_periods.Period (actual);

					if (period >= 0) {
						diff = actual - schedule;

						link_key.Key (link, period);

						link_map_stat = link_time_map.insert (Link_Time_Map_Data (link_key, sum_data));

						sum_ptr = &link_map_stat.first->second;

						sum_ptr->Period (period);
						sum_ptr->Add_Start_Diff (diff);
					}

					//---- end time ----

					schedule = time_ptr->Trip_End ();
					actual = time_ptr->Ended ();
					link = time_ptr->End_Link ();

					period = sum_periods.Period (schedule);

					if (period >= 0) {
						link_key.Key (link, period);

						link_map_stat = link_time_map.insert (Link_Time_Map_Data (link_key, sum_data));

						sum_ptr = &link_map_stat.first->second;

						sum_ptr->Period (period);
						sum_ptr->Add_Trip_End ();
					}
					period = sum_periods.Period (actual);

					if (period >= 0) {
						diff = actual - schedule;

						link_key.Key (link, period);

						link_map_stat = link_time_map.insert (Link_Time_Map_Data (link_key, sum_data));

						sum_ptr = &link_map_stat.first->second;

						sum_ptr->Period (period);
						sum_ptr->Add_End_Diff (diff);
					}

					//---- travel time difference ----
					
					actual = time_ptr->Mid_Trip ();

					period = sum_periods.Period (actual);

					if (period >= 0 && period < num_inc) {
						link_key.Key (link, period);

						link_map_stat = link_time_map.insert (Link_Time_Map_Data (link_key, sum_data));

						sum_ptr = &link_map_stat.first->second;

						diff = time_ptr->Travel_Time () - time_ptr->Trip_Time ();

						sum_ptr->Add_Travel_Time (time_ptr->Travel_Time (), diff);

						diff = abs (time_ptr->Trip_Start_Diff ()) + abs (time_ptr->Trip_End_Diff ());

						if (diff >= min_variance) {
							sum_ptr->Add_Sum_Error (diff);
						}
					}
				}

				//---- add to the time distribution -----

				if (time_flag && time_ptr->Base_Start () < time_ptr->Base_End () &&
					time_ptr->Started () < time_ptr->Ended ()) {

					time_diff.Add_Trip (time_ptr->Mid_Trip (), time_ptr->Travel_Time (), time_ptr->Base_Time ());
				}

				//---- add to time gap data ----

				if (time_gap_flag) {
					if (sum_periods.Period_Control_Point () == MID_TRIP) {
						schedule = (time_ptr->Base_End () + time_ptr->Base_Start ()) >> 1;
					} else if (sum_periods.Period_Control_Point () == TRIP_START) {
						schedule = time_ptr->Base_Start ();
					} else {
						schedule = time_ptr->Base_End ();
					}
					time_gap.Add_Trip_Gap_Data (schedule, time_ptr->Travel_Time (), time_ptr->Base_Time ());
				}
			}
		}
Exemple #3
0
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);
}
Exemple #4
0
void EventSum::Read_Trips (void)
{
	int hhold, num_rec, mode, purpose;

	Location_Data *location_ptr;
	Trip_File *trip_file;
	Travel_Time_Data *time_ptr, time_data;
	Travel_Time_Itr time_itr;
	Trip_Index trip_index;
	Trip_Map_Stat map_stat;
	Trip_Map_Itr trip_itr;
	Int_Map_Itr map_itr;

	trip_file = System_Trip_File ();
	
	//----- initialize the summary memory ----
	
	if (travel_time_array.size () == 0) {
		num_rec = trip_file->Estimate_Records ();
		travel_time_array.reserve (num_rec);
	}
	Show_Message (String ("Reading %s -- Record") % trip_file->File_Type ());
	Set_Progress ();

	num_rec = 0;

	//---- store the trip data ----

	while (trip_file->Read ()) {
		Show_Progress ();

		//---- check the household id ----

		hhold = trip_file->Household ();
		if (hhold <= 0) continue;

		if (select_households && !hhold_range.In_Range (hhold)) continue;

		mode = trip_file->Mode ();
		if (mode > 0 && mode < MAX_MODE && !select_mode [mode]) continue;

		purpose = trip_file->Purpose ();
		if (select_purposes && !purpose_range.In_Range (purpose)) continue;

		//---- check the selection records ----
		
		time_data.Household (hhold);
		time_data.Person (trip_file->Person ());
		time_data.Tour (trip_file->Tour ());
		time_data.Trip (trip_file->Trip ());

		time_data.Get_Trip_Index (trip_index);

		if (select_flag && select_map.Best (trip_index) == select_map.end ()) continue;

		//---- save a new travel time ----

		if (time_in_flag) {
			trip_itr = travel_time_map.find (trip_index);

			if (trip_itr == travel_time_map.end ()) continue;

			time_ptr = &travel_time_array [trip_itr->second];
		} else {
			num_rec = (int) travel_time_array.size ();

			map_stat = travel_time_map.insert (Trip_Map_Data (trip_index, num_rec));
			if (!map_stat.second) {
				Warning (String ("Duplicate Travel Time Index %d-%d-%d-%d") % 
					trip_index.Household () % trip_index.Person () % trip_index.Tour () % trip_index.Trip ());
			} else {
				travel_time_array.push_back (time_data);
			}
			time_ptr = &travel_time_array [map_stat.first->second];
		}

		//---- save a new travel time ----

		time_ptr->Mode (mode);
		time_ptr->Purpose (purpose);
		time_ptr->Constraint (trip_file->Constraint ());

		time_ptr->Trip_Start (trip_file->Start ());
		time_ptr->Trip_End (trip_file->End ());

		//---- find the origin and destination links ----

		map_itr = location_map.find (trip_file->Origin ());

		if (map_itr == location_map.end ()) {
			Warning (String ("Trip Origin %d was Not Found in the Location File") % trip_file->Origin ());
			time_ptr->Start_Link (0);
		} else {
			location_ptr = &location_array [map_itr->second];
			time_ptr->Start_Link (link_array [location_ptr->Link ()].Link ());
		}

		map_itr = location_map.find (trip_file->Destination ());

		if (map_itr == location_map.end ()) {
			Warning (String ("Trip Destination %d was Not Found in the Location File") % trip_file->Destination ());
			time_ptr->End_Link (0);
		} else {
			location_ptr = &location_array [map_itr->second];
			time_ptr->End_Link (link_array [location_ptr->Link ()].Link ());
		}
		num_rec++;
	}
	End_Progress ();

	trip_file->Close ();
	
	Print (2, String ("Number of %s Records = %d") % trip_file->File_Type () % Progress_Count ());
	if (num_rec != Progress_Count ()) Print (1, "Number of Records Saved = ") << num_rec;
}