Exemple #1
0
void Data_Service::Read_Locations (void)
{
	Location_File *file = (Location_File *) System_File_Handle (LOCATION);

	int num;
	bool zone_flag = System_Data_Flag (ZONE);

	Int_Map_Stat map_stat;
	Location_Data location_rec;

	//---- store the location data ----

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

	Initialize_Locations (*file);

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

		location_rec.Clear ();

		if (Get_Location_Data (*file, location_rec)) {
			map_stat = location_map.insert (Int_Map_Data (location_rec.Location (), (int) location_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Location Number = ") << location_rec.Location ();
				continue;
			} else {
				if (!file->Setback_Flag () && location_rec.Setback () == 0) {
					location_rec.Setback (Internal_Units (100.0, FEET));
				}
				location_array.push_back (location_rec);

				if (!zone_flag && location_rec.Zone () > Max_Zone_Number ()) {
					Max_Zone_Number (location_rec.Zone ());
				}
			}
		}
	}
	End_Progress ();
	file->Close ();

	Print (2, String ("Number of %s Records = %d") % file->File_Type () % Progress_Count ());

	num = (int) location_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of %s Data Records = %d") % file->File_ID () % num);
	}
	if (num > 0) System_Data_True (LOCATION);
}
Exemple #2
0
void LinkSum::Perf_Detail_Report (void)
{
	int i, j, k, k1, lanes, max_lanes, tod_list, index, flow_index;
	double base_time, loaded_time, length, len, base, diff, value, percent, flow, factor;
	Dtime low, high, tod;
	bool connect_flag;
	String units, vmt, lane_mi;

	Link_Itr link_itr;
	Dir_Data *dir_ptr;
	Link_Perf_Period_Itr period_itr;
	Link_Perf_Array *period_ptr;
	Link_Perf_Data perf_data;
	Flow_Time_Period_Itr turn_itr;
	Flow_Time_Array *compare_ptr;
	Flow_Time_Data *turn_ptr;
	Lane_Use_Period *use_ptr;
	Connect_Data *connect_ptr;
	Doubles_Itr itr;

	Show_Message ("Creating the Network Performance Details Report -- Record");
	Set_Progress ();

	//---- clear the summary bins -----

	for (j=0, itr = sum_bin.begin (); itr != sum_bin.end (); itr++, j++) {
		itr->assign (NUM_SUM_BINS, 0.0);
	}	
	connect_flag = System_Data_Flag (CONNECTION) && (turn_perf_array.size () > 0) && (compare_turn_array.size () > 0);

	//---- process each link ----

	for (link_itr = link_array.begin (); link_itr != link_array.end (); link_itr++) {
		Show_Progress ();

		if (select_flag && link_itr->Use () == 0) continue;

		length = UnRound (link_itr->Length ());
		len = 0;

		for (i=0; i < 2; i++) {
			if (i) {
				if (link_itr->Use () == -1) continue;
				index = link_itr->BA_Dir ();
			} else {
				if (link_itr->Use () == -2) continue;
				index = link_itr->AB_Dir ();
			}
			if (index < 0) continue;
			dir_ptr = &dir_array [index];
			flow_index = dir_ptr->Flow_Index ();

			base_time = dir_ptr->Time0 ();
			if (base_time <= 0.0) continue;

			tod_list = dir_ptr->First_Lane_Use ();

			max_lanes = dir_ptr->Lanes ();
			if (max_lanes < 1) max_lanes = 1;
			lanes = max_lanes;

			if (len == 0) {
				len = length;
			} else {
				len = 0;
			}

			//---- process each time period ----

			for (j=0, period_itr = link_perf_array.begin (); period_itr != link_perf_array.end (); period_itr++, j++) {
				if (tod_list >= 0) {

					//---- get the time period ----

					sum_periods.Period_Range (j, low, high);
					tod = (low + high + 1) / 2;

					lanes = max_lanes;
					k = tod_list;

					for (use_ptr = &use_period_array [k]; ; use_ptr = &use_period_array [++k]) {
						if (use_ptr->Start () <= tod && tod < use_ptr->End ()) {
							lanes = use_ptr->Lanes0 () + use_ptr->Lanes1 ();
							break;
						}
						if (use_ptr->Periods () == 0) break;
					}
				}
				perf_data = period_itr->Total_Link_Perf (index, flow_index);

				loaded_time = perf_data.Time ();
				flow = perf_data.Flow ();

				sum_bin [j] [LINKS] += 1;
				sum_bin [j] [LENGTH] += len;
				sum_bin [j] [LANES] += lanes * length;
				sum_bin [j] [VMT] += flow * length;
				sum_bin [j] [VHT] += flow * loaded_time;
				sum_bin [j] [VHD] += flow * (loaded_time - base_time);
				sum_bin [j] [TIME_RATIO] += (double) loaded_time / base_time;
				sum_bin [j] [DENSITY] += perf_data.Density ();
				sum_bin [j] [MAX_DEN] = MAX (sum_bin [j] [MAX_DEN], perf_data.Max_Density ());
				sum_bin [j] [QUEUE] += perf_data.Queue ();
				sum_bin [j] [MAX_QUEUE] = MAX (sum_bin [j] [MAX_QUEUE], perf_data.Max_Queue ());
				sum_bin [j] [FAILURE] += perf_data.Failure ();

				if (Ratio_Flag ()) {
					sum_bin [j] [CONG_VMT] += perf_data.Ratio_VMT ();
					sum_bin [j] [CONG_VHT] += perf_data.Ratio_VHT ();
					sum_bin [j] [CONG_TIME] += perf_data.Ratio_Count ();
					sum_bin [j] [COUNT] += perf_data.Occupancy ();
				}

				if (compare_flag) {
					period_ptr = &compare_link_array [j];
					perf_data = period_ptr->Total_Link_Perf (index, flow_index);

					loaded_time = perf_data.Time ();
					flow = perf_data.Flow ();

					sum_bin [j] [VMT+PREV] += flow * length;
					sum_bin [j] [VHT+PREV] += flow * loaded_time;
					sum_bin [j] [VHD+PREV] += flow * (loaded_time - base_time);
					sum_bin [j] [TIME_RATIO+PREV] += (double) loaded_time / base_time;
					sum_bin [j] [DENSITY+PREV] += perf_data.Density ();
					sum_bin [j] [MAX_DEN+PREV] = MAX (sum_bin [j] [MAX_DEN+PREV], perf_data.Max_Density ());
					sum_bin [j] [QUEUE+PREV] += perf_data.Queue ();
					sum_bin [j] [MAX_QUEUE+PREV] = MAX (sum_bin [j] [MAX_QUEUE+PREV], perf_data.Max_Queue ());
					sum_bin [j] [FAILURE+PREV] += perf_data.Failure ();

					if (Ratio_Flag ()) {
						sum_bin [j] [CONG_VMT+PREV] += perf_data.Ratio_VMT ();
						sum_bin [j] [CONG_VHT+PREV] += perf_data.Ratio_VHT ();
						sum_bin [j] [CONG_TIME+PREV] += perf_data.Ratio_Count ();
						sum_bin [j] [COUNT+PREV] += perf_data.Occupancy ();
					}
				}
			}

			//---- get the turning movements ----

			if (connect_flag) {
				for (k=dir_ptr->First_Connect (); k >= 0; k = connect_ptr->Next_Index ()) {
					connect_ptr = &connect_array [k];

					if (connect_ptr->Type () != LEFT && connect_ptr->Type () != RIGHT &&
						connect_ptr->Type () != UTURN) continue;

					for (j=0, turn_itr = turn_perf_array.begin (); turn_itr != turn_perf_array.end (); turn_itr++, j++) {
						turn_ptr = &turn_itr->at (k);

						sum_bin [j] [TURNS] += turn_ptr->Flow ();

						if (compare_flag) {
							compare_ptr = &compare_turn_array [j];
							turn_ptr = &compare_ptr->at (k);

							sum_bin [j] [TURNS+PREV] += turn_ptr->Flow ();
						}
					}
				}
			}
		}
	}
	End_Progress ();

	//---- print the report ----

	Header_Number (PERF_DETAIL);

	if (!Break_Check (num_inc * 16)) {
		Print (1);
		Perf_Detail_Header ();
	}
	if (Metric_Flag ()) {
		factor = 1.0 / 1000.0;
		units = "Kilometers";
		vmt = "VKT";
		lane_mi = "km";
	} else {
		factor = 1.0 / MILETOFEET;
		units = "Miles";
		vmt = "VMT";
		lane_mi = "mi";
	}
	tod.Hours (1);

	for (i=0; i <= num_inc; i++) {
		len = sum_bin [i] [LINKS];
		if (len == 0.0) continue;

		if (i < num_inc) {
			for (k = 0; k <= COUNT; k++) {
				k1 = k + PREV;
				if (k < VMT) {
					sum_bin [num_inc] [k] = MAX (sum_bin [i] [k], sum_bin [num_inc] [k]);

					if (compare_flag) {
						sum_bin [num_inc] [k1] = MAX (sum_bin [i] [k1], sum_bin [num_inc] [k1]);
					}
				} else {
					sum_bin [num_inc] [k] += sum_bin [i] [k];

					if (compare_flag) {
						sum_bin [num_inc] [k1] += sum_bin [i] [k1];
					}
				}
			}
		}
		if (i < num_inc && sum_bin [i] [VHT] == 0.0 && (!compare_flag || sum_bin [i] [VHT+PREV] == 0.0)) continue;
		if (i) {
			if (!Break_Check ((Ratio_Flag () ? 19 : 16))) {
				Print (1);
			}
		}
		Print (1, String ("Time Period%22c") % BLANK);
		if (i == num_inc) {
			Print (0, "       Total");
			len *= num_inc;
		} else {
			Print (0, String ("%12.12s") % sum_periods.Range_Format (i));
		}
		Print (1, String ("Number of Links                 %13.2lf") % sum_bin [i] [LINKS]);
		Print (1, String ("Number of Roadway %-10.10s    %13.2lf") % units % (sum_bin [i] [LENGTH] * factor));
		Print (1, String ("Number of Lane %-10.10s       %13.2lf") % units % (sum_bin [i] [LANES] * factor));
		Print (1, String ("Vehicle %-20.20s    %13.2lf") % (units + " of Travel") % (sum_bin [i] [VMT] * factor));
		if (compare_flag) {
			base = sum_bin [i] [VMT+PREV] * factor;
			diff = sum_bin [i] [VMT] * factor - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Vehicle Hours of Travel         %13.2lf") % (sum_bin [i] [VHT] / tod));
		if (compare_flag) {
			base = sum_bin [i] [VHT+PREV] / tod;
			diff = sum_bin [i] [VHT] / tod - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}	
		Print (1, String ("Vehicle Hours of Delay          %13.2lf") % (sum_bin [i] [VHD] / tod));
		if (compare_flag) {
			base = sum_bin [i] [VHD+PREV] / tod;
			diff = sum_bin [i] [VHD] / tod - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Number of Queued Vehicles       %13.2lf") % UnRound (sum_bin [i] [QUEUE]));
		if (compare_flag) {
			base = sum_bin [i] [QUEUE+PREV];
			diff = sum_bin [i] [QUEUE] - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Maximum Queued Vehicles         %13.2lf") % sum_bin [i] [MAX_QUEUE]);
		if (compare_flag) {
			base = sum_bin [i] [MAX_QUEUE+PREV];
			diff = sum_bin [i] [MAX_QUEUE] - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Number of Cycle Failures        %13.2lf") % sum_bin [i] [FAILURE]);
		if (compare_flag) {
			base = sum_bin [i] [FAILURE+PREV];
			diff = sum_bin [i] [FAILURE] - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Number of Turning Movements     %13.2lf") % sum_bin [i] [TURNS]);
		if (compare_flag) {
			base = sum_bin [i] [TURNS+PREV];
			diff = sum_bin [i] [TURNS] - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Average Link Time Ratio         %13.2lf") % (sum_bin [i] [TIME_RATIO] / len));
		if (compare_flag) {
			base = sum_bin [i] [TIME_RATIO+PREV] / len;
			diff = sum_bin [i] [TIME_RATIO] / len - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Average Link Density (/ln-%s)   %13.2lf") % lane_mi % UnRound (sum_bin [i] [DENSITY] / len));
		if (compare_flag) {
			base = UnRound (sum_bin [i] [DENSITY+PREV] / len);
			diff = UnRound (sum_bin [i] [DENSITY] / len) - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		Print (1, String ("Maximum Link Density (/ln-%s)   %13.2lf") % lane_mi % UnRound (sum_bin [i] [MAX_DEN]));
		if (compare_flag) {
			base = UnRound (sum_bin [i] [MAX_DEN+PREV]);
			diff = UnRound (sum_bin [i] [MAX_DEN]) - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}
		length = sum_bin [i] [VMT] * factor;
		loaded_time = sum_bin [i] [VHT] / tod;
		if (loaded_time == 0.0) {
			loaded_time = length;
		} else {
			loaded_time = length / loaded_time;
		}
		Print (1, String ("Average %-19.19s     %13.2lf") % (units + " per Hour") % loaded_time);
		if (compare_flag) {
			length = sum_bin [i] [VMT+PREV] * factor;
			base = sum_bin [i] [VHT+PREV] / tod;
			if (base == 0.0) {
				base = length;
			} else {
				base = length / base;
			}
			diff = loaded_time - base;

			Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
		}

		if (Ratio_Flag ()) {
			value = sum_bin [i] [VMT];
			if (value == 0.0) value = 1.0;
			percent = 100.0 * sum_bin [i] [CONG_VMT] / value;

			Print (1, String ("Percent %s Congested           %13.2lf") % vmt % percent);
			if (compare_flag) {
				value = sum_bin [i] [VMT+PREV];
				if (value == 0.0) value = 1.0;
				base = 100.0 * sum_bin [i] [CONG_VMT+PREV] / value;
				diff = percent - base;

				Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
			}
			value = sum_bin [i] [VHT];
			if (value == 0.0) value = 1.0;
			percent = 100.0 * sum_bin [i] [CONG_VHT] / value;

			Print (1, String ("Percent VHT Congested           %13.2lf") % percent);
			if (compare_flag) {
				value = sum_bin [i] [VHT+PREV];
				if (value == 0.0) value = 1.0;
				base = 100.0 * sum_bin [i] [CONG_VHT+PREV] / value;
				diff = percent - base;

				Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
			}
			value = sum_bin [i] [COUNT];
			if (value == 0.0) value = 1.0;
			percent = 100.0 * sum_bin [i] [CONG_TIME] / value;

			Print (1, String ("Percent Time Congested          %13.2lf") % percent);
			if (compare_flag) {
				value = sum_bin [i] [COUNT+PREV];
				if (value == 0.0) value = 1.0;
				base = 100.0 * sum_bin [i] [CONG_TIME+PREV] / value;
				diff = percent - base;

				Print (0, String (" %13.2lf %13.2lf  (%.2lf%%)") % base % diff % ((base > 0.0) ? (100.0 * diff / base) : 0.0) % FINISH);
			}
		}
	}
	Header_Number (0);
}
Exemple #3
0
bool Data_Service::Get_Location_Data (Location_File &file, Location_Data &location_rec)
{
	int link, dir, offset;
	double setback;
	Link_Data *link_ptr;

	//---- read and save the data ----

	location_rec.Location (file.Location ());

	if (location_rec.Location () == 0) return (false);

	//---- check/convert the link number and direction  ----
	
	link = file.Link ();
	dir = file.Dir ();
	offset = Round (file.Offset ());

	link_ptr = Set_Link_Direction (file, link, dir, offset);

	location_rec.Link (link);
	location_rec.Dir (dir);
	location_rec.Offset (offset);

	setback = file.Setback ();
	location_rec.Setback (setback);

	if (Location_XY_Flag ()) {
		Points points;

		Link_Shape (link_ptr, dir, points, UnRound (offset), 0.0, setback);

		if (points.size () > 0) {
			location_rec.X (points [0].x);
			location_rec.Y (points [0].y);
		} else {
			Node_Data *node_ptr = &node_array [link_ptr->Anode ()];
		
			location_rec.X (node_ptr->X ());
			location_rec.Y (node_ptr->Y ());
		}
	}
	location_rec.Zone (file.Zone ());

	if (location_rec.Zone () > 0 && System_Data_Flag (ZONE)) {
		Int_Map_Itr map_itr = zone_map.find (location_rec.Zone ());
		if (map_itr == zone_map.end ()) {
			Warning (String ("Location %d Zone %d was Not Found") % location_rec.Location () % location_rec.Zone ());
			return (false);
		}
		location_rec.Zone (map_itr->second);
	} else if (location_rec.Zone () == 0) {
		location_rec.Zone (-1);

		//---- delete extra activity location used for transit stops ----

		if (file.Version () <= 40) return (false);
	}
	location_rec.Notes (file.Notes ());

	return (true);
}
Exemple #4
0
void LinkSum::Perf_Detail_File (void)
{
	int i, j, k, k1, lanes, max_lanes, tod_list, index, flow_index;
	int text_field, value_field, compare_field;
	double base_time, loaded_time, length, len, value, percent, flow, factor;
	String buffer, units, vmt, lane_mi;
	bool connect_flag;
	Dtime low, high, tod;

	Link_Itr link_itr;
	Dir_Data *dir_ptr;
	Link_Perf_Period_Itr period_itr;
	Link_Perf_Array *period_ptr;
	Link_Perf_Data perf_data;
	Flow_Time_Period_Itr turn_itr;
	Flow_Time_Array *compare_ptr;
	Flow_Time_Data *turn_ptr;
	Lane_Use_Period *use_ptr;
	Connect_Data *connect_ptr;
	Doubles_Itr itr;

	Show_Message ("Writing Performance Data File -- Record");
	Set_Progress ();

	text_field = detail_file.Field_Number ("MEASURE");
	value_field = detail_file.Field_Number ("VALUE");
	compare_field = detail_file.Field_Number ("COMPARE");

	//---- clear the summary bins -----

	for (itr = sum_bin.begin (); itr != sum_bin.end (); itr++) {
		itr->assign (NUM_SUM_BINS, 0.0);
	}
	connect_flag = System_Data_Flag (CONNECTION) && (turn_perf_array.size () > 0) && (compare_turn_array.size () > 0);

	//---- process each link ----

	for (link_itr = link_array.begin (); link_itr != link_array.end (); link_itr++) {
		Show_Progress ();

		if (select_flag && link_itr->Use () == 0) continue;

		len = UnRound (link_itr->Length ());

		for (i=0; i < 2; i++) {
			if (i) {
				if (link_itr->Use () == -1) continue;
				index = link_itr->BA_Dir ();
			} else {
				if (link_itr->Use () == -2) continue;
				index = link_itr->AB_Dir ();
			}
			if (index < 0) continue;
			dir_ptr = &dir_array [index];
			flow_index = dir_ptr->Flow_Index ();

			base_time = dir_ptr->Time0 ().Seconds ();
			if (base_time <= 0.0) continue;

			tod_list = dir_ptr->First_Lane_Use ();

			max_lanes = dir_ptr->Lanes ();
			if (max_lanes < 1) max_lanes = 1;
			lanes = max_lanes;

			for (j=0, period_itr = link_perf_array.begin (); period_itr != link_perf_array.end (); period_itr++, j++) {
				if (tod_list >= 0) {

					//---- get the time period ----

					sum_periods.Period_Range (j, low, high);
					tod = (low + high + 1) / 2;

					lanes = max_lanes;
					k = tod_list;

					for (use_ptr = &use_period_array [k]; ; use_ptr = &use_period_array [++k]) {
						if (use_ptr->Start () <= tod && tod < use_ptr->End ()) {
							lanes = use_ptr->Lanes0 () + use_ptr->Lanes1 ();
							break;
						}
						if (use_ptr->Periods () == 0) break;
					}
				}
				perf_data = period_itr->Total_Link_Perf (index, flow_index);

				loaded_time = perf_data.Time ().Seconds ();
				flow = perf_data.Flow ();

				sum_bin [j] [LINKS] += 1;
				sum_bin [j] [LENGTH] += len;
				sum_bin [j] [LANES] += lanes * len;
				sum_bin [j] [VMT] += flow * len;
				sum_bin [j] [VHT] += flow * loaded_time;
				sum_bin [j] [VHD] += flow * (loaded_time - base_time);
				sum_bin [j] [TIME_RATIO] += (double) loaded_time / base_time;
				sum_bin [j] [DENSITY] += perf_data.Density ();
				sum_bin [j] [MAX_DEN] = MAX (sum_bin [j] [MAX_DEN], perf_data.Max_Density ());
				sum_bin [j] [QUEUE] += perf_data.Queue ();
				sum_bin [j] [MAX_QUEUE] = MAX (sum_bin [j] [MAX_QUEUE], perf_data.Max_Queue ());
				sum_bin [j] [FAILURE] += perf_data.Failure ();

				if (Ratio_Flag ()) {
					sum_bin [j] [CONG_VMT] += perf_data.Ratio_VMT ();
					sum_bin [j] [CONG_VHT] += perf_data.Ratio_VHT ();
					sum_bin [j] [CONG_TIME] += perf_data.Ratio_Count ();
					sum_bin [j] [COUNT] += perf_data.Occupancy ();
				}

				if (compare_flag) {
					period_ptr = &compare_link_array [j];

					perf_data = period_ptr->Total_Link_Perf (index, flow_index);

					loaded_time = perf_data.Time ();
					flow = perf_data.Flow ();

					sum_bin [j] [VMT+PREV] += flow * len;
					sum_bin [j] [VHT+PREV] += flow * loaded_time;
					sum_bin [j] [VHD+PREV] += flow * (loaded_time - base_time);
					sum_bin [j] [TIME_RATIO+PREV] += (double) loaded_time / base_time;
					sum_bin [j] [DENSITY+PREV] += perf_data.Density ();
					sum_bin [j] [MAX_DEN+PREV] = MAX (sum_bin [j] [MAX_DEN+PREV], perf_data.Max_Density ());
					sum_bin [j] [QUEUE+PREV] += perf_data.Queue ();
					sum_bin [j] [MAX_QUEUE+PREV] = MAX (sum_bin [j] [MAX_QUEUE+PREV], perf_data.Max_Queue ());
					sum_bin [j] [FAILURE+PREV] += perf_data.Failure ();

					if (Ratio_Flag ()) {
						sum_bin [j] [CONG_VMT+PREV] += perf_data.Ratio_VMT ();
						sum_bin [j] [CONG_VHT+PREV] += perf_data.Ratio_VHT ();
						sum_bin [j] [CONG_TIME+PREV] += perf_data.Ratio_Count ();
						sum_bin [j] [COUNT+PREV] += perf_data.Occupancy ();
					}
				}
			}

			//---- get the turning movements ----

			if (connect_flag) {
				for (k=dir_ptr->First_Connect (); k >= 0; k = connect_ptr->Next_Index ()) {
					connect_ptr = &connect_array [k];

					if (connect_ptr->Type () != LEFT && connect_ptr->Type () != RIGHT &&
						connect_ptr->Type () != UTURN) continue;

					for (j=0, turn_itr = turn_perf_array.begin (); turn_itr != turn_perf_array.end (); turn_itr++, j++) {
						turn_ptr = &turn_itr->at (k);

						sum_bin [j] [TURNS] += turn_ptr->Flow ();

						if (compare_flag) {
							compare_ptr = &compare_turn_array [j];
							turn_ptr = &compare_ptr->at (k);

							sum_bin [j] [TURNS+PREV] += turn_ptr->Flow ();
						}
					}
				}
			}
		}
	}
	End_Progress ();

	//---- write the data ----
	
	if (Metric_Flag ()) {
		factor = 1.0 / 1000.0;
		units = "Kilometers";
		vmt = "VKT";
		lane_mi = "km)";
	} else {
		factor = 1.0 / MILETOFEET;
		units = "Miles";
		vmt = "VMT";
		lane_mi = "mi)";
	}
	tod.Hours (1);

	for (j=0; j <= num_inc; j++) {
		len = sum_bin [j] [LINKS];
		if (len == 0.0) continue;

		if (j == num_inc) {
			buffer = "Time Period Total";
			len *= num_inc;
		} else {
			buffer = String ("Time Period %12.12s") % sum_periods.Range_Format (j);

			for (k = 0; k <= COUNT; k++) {
				k1 = k + PREV;
				if (k < VMT) {
					sum_bin [num_inc] [k] = MAX (sum_bin [j] [k], sum_bin [num_inc] [k]);

					if (compare_flag) {
						sum_bin [num_inc] [k1] = MAX (sum_bin [j] [k1], sum_bin [num_inc] [k1]);
					}
				} else {
					sum_bin [num_inc] [k] += sum_bin [j] [k];

					if (compare_flag) {
						sum_bin [num_inc] [k1] += sum_bin [j] [k1];
					}
				}
			}
		}
		detail_file.Put_Field (text_field, buffer);
		detail_file.Put_Field (value_field, 0.0);
		if (compare_flag) detail_file.Put_Field (compare_field, 0.0);
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Number of Links"));
		detail_file.Put_Field (value_field, sum_bin [j] [LINKS]);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [LINKS]);
		detail_file.Write ();

		buffer = "Number of Roadway " + units;
		detail_file.Put_Field (text_field, buffer);
		detail_file.Put_Field (value_field, sum_bin [j] [LENGTH] * factor);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [LENGTH] * factor);
		detail_file.Write ();

		buffer = "Number of Lane " + units;
		detail_file.Put_Field (text_field, buffer);
		detail_file.Put_Field (value_field, sum_bin [j] [LANES] * factor);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [LANES] * factor);
		detail_file.Write ();

		buffer = "Vehicle " + units + " of Travel";
		detail_file.Put_Field (text_field, buffer);
		detail_file.Put_Field (value_field, sum_bin [j] [VMT] * factor);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [VMT+PREV] * factor);
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Vehicle Hours of Travel"));
		detail_file.Put_Field (value_field, sum_bin [j] [VHT] / tod);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [VHT+PREV] / tod);
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Vehicle Hours of Delay"));
		detail_file.Put_Field (value_field, sum_bin [j] [VHD] / tod);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [VHD+PREV] / tod);
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Number of Queued Vehicles"));
		detail_file.Put_Field (value_field, UnRound (sum_bin [j] [QUEUE]));
		if (compare_flag) detail_file.Put_Field (compare_field, UnRound (sum_bin [j] [QUEUE+PREV]));
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Maximum Queued Vehicles"));
		detail_file.Put_Field (value_field, sum_bin [j] [MAX_QUEUE]);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [MAX_QUEUE+PREV]);
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Number of Cycle Failures"));
		detail_file.Put_Field (value_field, sum_bin [j] [FAILURE]);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [FAILURE+PREV]);
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Number of Turning Movements"));
		detail_file.Put_Field (value_field, sum_bin [j] [TURNS]);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [TURNS+PREV]);
		detail_file.Write ();

		detail_file.Put_Field (text_field, String ("Average Link Time Ratio"));
		detail_file.Put_Field (value_field, sum_bin [j] [TIME_RATIO] / len);
		if (compare_flag) detail_file.Put_Field (compare_field, sum_bin [j] [TIME_RATIO+PREV] / len);
		detail_file.Write ();

		buffer = "Average Link Density (/ln-" + lane_mi;
		detail_file.Put_Field (text_field, buffer);
		detail_file.Put_Field (value_field, UnRound (sum_bin [j] [DENSITY] / len));
		if (compare_flag) detail_file.Put_Field (compare_field, UnRound (sum_bin [j] [DENSITY+PREV] / len));
		detail_file.Write ();

		buffer = "Maximum Link Density (/ln-" + lane_mi;
		detail_file.Put_Field (text_field, buffer);
		detail_file.Put_Field (value_field, UnRound (sum_bin [j] [MAX_DEN]));
		if (compare_flag) detail_file.Put_Field (compare_field, UnRound (sum_bin [j] [MAX_DEN+PREV]));
		detail_file.Write ();

		length = sum_bin [j] [VMT] * factor;
		loaded_time = sum_bin [j] [VHT] / tod;
		if (loaded_time == 0.0) {
			loaded_time = length;
		} else {
			loaded_time = length / loaded_time;
		}
		buffer = "Average " + units + " Per Hour";
		detail_file.Put_Field (text_field, buffer);
		detail_file.Put_Field (value_field, loaded_time);

		if (compare_flag) {
			length = sum_bin [j] [VMT+PREV] * factor;
			loaded_time = sum_bin [j] [VHT+PREV] / tod;
			if (loaded_time == 0.0) {
				loaded_time = length;
			} else {
				loaded_time = length / loaded_time;
			}
			detail_file.Put_Field (compare_field, loaded_time);
		}
		detail_file.Write ();

		if (Ratio_Flag ()) {
			value = sum_bin [j] [VMT];
			if (value == 0.0) value = 1.0;
			percent = 100.0 * sum_bin [j] [CONG_VMT] / value;

			if (Metric_Flag ()) {
				buffer = "Percent VKT Congested";
			} else {
				buffer = "Percent VMT Congested";
			}
			detail_file.Put_Field (text_field, buffer);
			detail_file.Put_Field (value_field, percent);
			if (compare_flag) {
				value = sum_bin [j] [VMT+PREV];
				if (value == 0.0) value = 1.0;
				percent = 100.0 * sum_bin [j] [CONG_VMT+PREV] / value;

				detail_file.Put_Field (compare_field, percent);
			}
			detail_file.Write ();

			value = sum_bin [j] [VHT];
			if (value == 0.0) value = 1.0;
			percent = 100.0 * sum_bin [j] [CONG_VHT] / value;

			detail_file.Put_Field (text_field, String ("Percent VHT Congested"));
			detail_file.Put_Field (value_field, percent);
			if (compare_flag) {
				value = sum_bin [j] [VHT+PREV];
				if (value == 0.0) value = 1.0;
				percent = 100.0 * sum_bin [j] [CONG_VHT+PREV] / value;

				detail_file.Put_Field (compare_field, percent);
			}
			detail_file.Write ();

			value = sum_bin [j] [COUNT];
			if (value == 0.0) value = 1.0;
			percent = 100.0 * sum_bin [j] [CONG_TIME] / value;

			detail_file.Put_Field (text_field, String ("Percent Time Congested"));
			detail_file.Put_Field (value_field, percent);
			if (compare_flag) {
				value = sum_bin [j] [COUNT+PREV];
				if (value == 0.0) value = 1.0;
				percent = 100.0 * sum_bin [j] [CONG_TIME+PREV] / value;

				detail_file.Put_Field (compare_field, percent);
			}
			detail_file.Write ();
		}
	}
}
Exemple #5
0
int Data_Service::Put_Link_Data (Link_File &file, Link_Data &data)
{
	if (file.Model_Format () == TPPLUS) {
		int a, b, count;
		double length;
		Dir_Data *dir_ptr;

		if (data.Length () == 0) return (0);

		count = 0;
		a = data.Anode ();
		b = data.Bnode ();
		length = UnRound (data.Length ());

		if (System_Data_Flag (NODE)) {
			a = node_array [a].Node ();
			b = node_array [b].Node ();
		}
		if (data.AB_Dir () >= 0) {
			file.Node_A (a);
			file.Node_B (b);
			file.Length (length);
			file.Type (data.Type ());

			dir_ptr = &dir_array [data.AB_Dir ()];

			file.Lanes_AB (dir_ptr->Lanes ());
			file.Speed_AB (UnRound (dir_ptr->Speed ()));
			file.Cap_AB (dir_ptr->Capacity ());

			if (file.Dbase_Format () == ARCVIEW) {
				Link_Shape (&data, 0, *((Arc_Link_File *) &file));
			}
			if (!file.Write_Record ()) {
				Error (String ("Writing %s") % file.File_Type ());
			}
			count++;
		}
		if (data.BA_Dir () >= 0) {
			file.Node_A (b);
			file.Node_B (a);
			file.Length (length);
			file.Type (data.Type ());

			dir_ptr = &dir_array [data.BA_Dir ()];

			file.Lanes_AB (dir_ptr->Lanes ());
			file.Speed_AB (UnRound (dir_ptr->Speed ()));
			file.Cap_AB (dir_ptr->Capacity ());

			if (file.Dbase_Format () == ARCVIEW) {
				Link_Shape (&data, 1, *((Arc_Link_File *) &file));
			}
			if (!file.Write_Record ()) {
				Error (String ("Writing %s") % file.File_Type ());
			}
			count++;
		}
		return (count);
	}
	Dir_Data *dir_ptr;

	if (data.Length () == 0) return (0);

	file.Link (data.Link ());
	file.Name (data.Name ());
	file.Node_A (node_array [data.Anode ()].Node ());
	file.Node_B (node_array [data.Bnode ()].Node ());
	file.Length (UnRound (data.Length ()));
	file.Setback_A (UnRound (data.Aoffset ()));
	file.Setback_B (UnRound (data.Boffset ()));
	file.Type (data.Type ());
	file.Divided (data.Divided ());
	file.Area_Type (data.Area_Type ());
	file.Use (data.Use ());
	file.Grade (UnRound (data.Grade ()));
	file.Notes (data.Notes ());

	if (data.AB_Dir () >= 0) {
		dir_ptr = &dir_array [data.AB_Dir ()];

		file.Lanes_AB (dir_ptr->Lanes ());
		file.Speed_AB (UnRound (dir_ptr->Speed ()));

		if (dir_ptr->Time0 () > 0) {
			file.Fspd_AB ((double) data.Length () / dir_ptr->Time0 ());
		} else {
			file.Fspd_AB (UnRound (dir_ptr->Speed ()));
		}
		if (file.Fspd_AB () > file.Speed_AB () && file.Speed_AB () > 0) {
			if ((file.Fspd_AB () - file.Speed_AB ()) > 0.5) {
				if (Metric_Flag ()) {
					Warning (String ("Link %d Free Flow Speed %.1lf > Maximum Speed %.1lf") % data.Link () % External_Units (file.Fspd_AB (), MPH) % 
						External_Units (file.Speed_AB (), MPH));
				} else {
					Warning (String ("Link %d Free Flow Speed %.1lf > Maximum Speed %.1lf") % data.Link () % External_Units (file.Fspd_AB (), MPH) % 
						External_Units (file.Speed_AB (), MPH));
				}
			}
			file.Fspd_AB (file.Speed_AB ());
		}
		file.Cap_AB (dir_ptr->Capacity ());
		file.Bearing_A (dir_ptr->In_Bearing ());
		file.Bearing_B (dir_ptr->Out_Bearing ());
	} else {
		file.Lanes_AB (0);
		file.Speed_AB (0);
		file.Fspd_AB (0);
		file.Cap_AB (0);
	}
	if (data.BA_Dir () >= 0) {
		dir_ptr = &dir_array [data.BA_Dir ()];

		file.Lanes_BA (dir_ptr->Lanes ());
		file.Speed_BA (UnRound (dir_ptr->Speed ()));

		if (dir_ptr->Time0 () > 0) {
			file.Fspd_BA ((double) data.Length () / dir_ptr->Time0 ());
		} else {
			file.Fspd_BA (UnRound (dir_ptr->Speed ()));
		}
		if (file.Fspd_BA () > file.Speed_BA () && file.Speed_BA () > 0) {
			if ((file.Fspd_BA () - file.Speed_BA ()) > 0.5) {
				if (Metric_Flag ()) {
					Warning (String ("Link %d Free Flow Speed %.1lf > Maximum Speed %.1lf") % data.Link () % External_Units (file.Fspd_BA (), MPH) % 
						External_Units (file.Speed_BA (), MPH));
				} else {
					Warning (String ("Link %d Free Flow Speed %.1lf > Maximum Speed %.1lf") % data.Link () % External_Units (file.Fspd_BA (), MPH) % 
						External_Units (file.Speed_BA (), MPH));
				}
			}
			file.Fspd_BA (file.Speed_BA ());
		}
		file.Cap_BA (dir_ptr->Capacity ());
		if (data.AB_Dir () < 0) {
			file.Bearing_B (compass.Flip (dir_ptr->In_Bearing ()));
			file.Bearing_A (compass.Flip (dir_ptr->Out_Bearing ()));
		}
	} else {
		file.Lanes_BA (0);
		file.Speed_BA (0);
		file.Fspd_BA (0);
		file.Cap_BA (0);
	}
	if (file.Dbase_Format () == ARCVIEW) {
		Link_Shape (&data, 0, *((Arc_Link_File *) &file));
	}
	if (!file.Write_Record ()) {
		Error (String ("Writing %s") % file.File_Type ());
	}
	return (1);
}