コード例 #1
0
ファイル: Line_Sum_Report.cpp プロジェクト: qingswu/Transim
void RiderSum::Line_Sum_Report (void)
{
	int riders, max_load, board, alight, run, runs;

	Int_Map_Itr map_itr;
	Line_Data *line_ptr;
	Line_Stop_Itr stop_itr;
	Line_Run_Itr run_itr;

	Show_Message ("Line Summary Report -- Record");
	Set_Progress ();

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

	Header_Number (LINE_SUM);

	if (!Break_Check ((int) line_map.size () + 5)) {
		Print (1);
		Line_Sum_Header ();
	}

	//---- get the route data ----

	for (map_itr = line_map.begin (); map_itr != line_map.end (); map_itr++) {
		Show_Progress ();

		if (select_routes && !route_range.In_Range (map_itr->first)) continue;

		line_ptr = &line_array [map_itr->second];

		if (select_modes && !select_mode [line_ptr->Mode ()]) continue;

		//---- check the link criteria ----

		if (!Link_Selection (line_ptr)) continue;

		//---- set the run flags ----

		if (!Run_Selection (line_ptr)) continue;

		//---- save the route ridership data ----

		riders = board = alight = max_load = runs = 0;

		for (stop_itr = line_ptr->begin (); stop_itr != line_ptr->end (); stop_itr++) {
			for (run=0, run_itr = stop_itr->begin (); run_itr != stop_itr->end (); run_itr++, run++) {
				if (run_flag [run] == 0) continue;
				if (run_period [run] < 0) continue;
				if (select_time_of_day && !time_range.In_Range (run_itr->Schedule ())) continue;

				if (run_itr->Board () > board) board = run_itr->Board ();
				if (run_itr->Alight () > alight) alight = run_itr->Alight ();
				if (run_itr->Load () > max_load)  max_load = run_itr->Load ();
				riders += run_itr->Board ();

				if (run_flag [run] == 1) {
					runs++;
					run_flag [run] = 2;
				}
			}
		}
		if (riders == 0) continue;
		
		Print (1, String ("%8d  %10.10s  %5d  %5d  %8d  %8d %8d %8d") % line_ptr->Route () %
			Transit_Code ((Transit_Type) line_ptr->Mode ()) % line_ptr->size () % runs %
			riders % max_load % board % alight);

		if (!line_ptr->Name ().empty ()) {
			Print (0, String ("  %s") % line_ptr->Name ());
		}
		if (Notes_Name_Flag ()) {
			if (!line_ptr->Notes ().empty ()) {
				Print (0, String ("  %s") % line_ptr->Notes ());
			}
		}
	}
	End_Progress ();

	Header_Number (0);
}
コード例 #2
0
ファイル: Line_Rider_Report.cpp プロジェクト: qingswu/Transim
void RiderSum::Line_Rider_Report (void)
{
	int riders, board, alight, run, runs, num, length, tot_len, period, num_periods;
	int max_riders, max_board, max_alight, max_runs, total, capacity, max_cap;
	double factor, max_fac, sum_time, tot_time, time, capfac, max_capfac;
	double vmt, vht, pmt, pht;
	Dtime low, high;

	Int_Map_Itr map_itr;
	Line_Data *line_ptr;
	Stop_Data *stop_ptr;
	Line_Stop_Itr stop_itr, next_itr;
	Line_Run_Itr run_itr;
	Veh_Type_Data *veh_type_ptr, *run_type_ptr;

	Show_Message ("Line Rider Profile -- Record");
	Set_Progress ();

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

	Header_Number (LINE_RIDERS);

	num_periods = sum_periods.Num_Periods ();
	if (num_periods == 0) num_periods = 1;

	num = (int) (line_map.size () * stop_map.size ());

	if (!Break_Check (num + 5)) {
		Print (1);
		Line_Rider_Header ();
	}

	//---- process each route ----

	for (map_itr = line_map.begin (); map_itr != line_map.end (); map_itr++) {
		Show_Progress ();

		if (select_routes && !route_range.In_Range (map_itr->first)) continue;

		line_ptr = &line_array [map_itr->second];

		if (select_modes && !select_mode [line_ptr->Mode ()]) continue;

		//---- check the link criteria ----

		if (!Link_Selection (line_ptr)) continue;

		//---- set the run flags ----

		if (!Run_Selection (line_ptr)) continue;

		//---- save the route ridership data ----
		
		veh_type_ptr = &veh_type_array [line_ptr->Type ()];

		for (period = 0; period < num_periods; period++) {
			if (period_flag [period] == 0) continue;

			if (!Break_Check ((int) line_ptr->size () + 15)) {
				Print (1);
				Line_Rider_Header ();
			}
			veh_type_ptr = &veh_type_array [line_ptr->Type ()];

			Print (1, "   Route    Mode     Type   Time Period  Name");

			Print (2, String ("%8d  %10.10s %4d  %12.12s") % line_ptr->Route () %
				Transit_Code ((Transit_Type) line_ptr->Mode ()) % veh_type_ptr->Type () % 
				sum_periods.Range_Format (period));

			if (!line_ptr->Name ().empty ()) {
				Print (0, String ("  %s") % line_ptr->Name ());
			}
			if (Notes_Name_Flag ()) {
				if (!line_ptr->Notes ().empty ()) {
					Print (0, String (" -- %s") % line_ptr->Notes ());
				}
			}
			Print (2, "    Stop  Length   TTime   Alight    Board   Riders  Runs  LoadFac Capacity CapFac");
			Print (1);

			time = tot_time = 0.0;
			max_alight = max_board = max_riders = max_runs = total = length = tot_len = max_cap = 0;
			max_fac = vmt = vht = pmt = pht = max_capfac = 0.0;

			sum_periods.Period_Range (period, low, high);

			for (stop_itr = line_ptr->begin (); stop_itr != line_ptr->end (); stop_itr++) {
				riders = board = alight = runs = capacity = 0;

				stop_ptr = &stop_array [stop_itr->Stop ()];

				next_itr = stop_itr + 1;

				if (next_itr != line_ptr->end ()) {
					length = next_itr->Length () - stop_itr->Length ();
				} else {
					length = 0;
				}
				sum_time = 0.0;
				num = 0;

				for (run=0, run_itr = stop_itr->begin (); run_itr != stop_itr->end (); run_itr++, run++) {
					if (run_flag [run] == 0) continue;
					if (run_period [run] != period) continue;

					board += run_itr->Board ();
					alight += run_itr->Alight ();
					riders += run_itr->Load ();
					runs++;

					if (line_ptr->run_types.size () > 0) {
						run_type_ptr = &veh_type_array [line_ptr->Run_Type (run)];
						capacity += run_type_ptr->Capacity ();
					} else {
						capacity += veh_type_ptr->Capacity ();
					}
					if (next_itr != line_ptr->end ()) {
						time = next_itr->at (run).Schedule ().Seconds () - run_itr->Schedule ().Seconds ();

						vmt += length;
						vht += time;
						pmt += length * run_itr->Load ();
						pht += time * run_itr->Load ();

						sum_time += time;
						num++;
					}
				}
				if (runs == 0) continue;
				if (capacity == 0) capacity = runs;

				factor = (double) riders / runs;
				capfac = DTOI (riders * 10.0 / capacity) / 10.0;

				if (next_itr == line_ptr->end ()) runs = 0;

				if (num > 0) {
					time = sum_time / num;
				} else {
					time = 0;
				}
				Print (1, String ("%8d %7.0lf %7.0lf %8d %8d %8d %5d %8.1lf %6d %8.1lf") % stop_ptr->Stop () % 
					UnRound (length) % time % alight % board % riders % runs % factor % capacity % capfac);

				if (Notes_Name_Flag ()) {
					if (!stop_ptr->Name ().empty ()) {
						Print (0, String ("  %s") % stop_ptr->Name ());
					}
					if (!stop_ptr->Notes ().empty ()) {
						Print (0, " -- ") << stop_ptr->Notes ();
					}
				}
				if (alight > max_alight) max_alight = alight;
				if (board > max_board) max_board = board;
				if (riders > max_riders) max_riders = riders;
				if (runs > max_runs) max_runs = runs;
				if (factor > max_fac) max_fac = factor;
				if (capacity > max_cap) max_cap = capacity;
				if (capfac > max_capfac) max_capfac = capfac;

				tot_len += length;
				tot_time += time;
				total += board;
			}
			if (max_runs == 0) continue;

			Print (2, String (" Maximum                 %8ld %8ld %8ld %5ld %8.1lf %6lf %8.1lf") %
				max_alight % max_board % max_riders % max_runs % max_fac % max_cap % max_capfac);

			Print (2, "Total Boardings = ") << total;

			if (total == 0 || tot_time == 0) continue;

			factor = UnRound (tot_len);
			vmt = UnRound (vmt) / 5280.0;
			vht = vht / 3600.0;
			pmt = UnRound (pmt) / 5280.0;
			pht = pht / 3600.0;


			Print (1, String ("Route Length = %.1lf miles, %.1lf minutes  Average Speed = %.1lf mph") %
				External_Units (factor, MILES) % (tot_time / 60.0) % External_Units ((factor / tot_time), MPH));
			Print (1, String ("Vehicle Miles = %.1lf  Vehicle Hours = %.1lf") % vmt % vht);
			Print (1, String ("Passenger Miles = %.1lf  Passenger Hours = %.1lf") %	pmt % pht);
			Print (1, String ("Passengers per Vehicle Mile = %.1lf  Passengers per Vehicle Hour = %.1lf") %	
				(pmt / vht) % (pht / vht));

			vmt = pmt / total;
			vht = pht * 60.0 / total;

			Print (1, String ("Average Trip Length = %.1lf miles, %.1lf minutes") % vmt % vht);
		}
	}
	End_Progress ();

	Header_Number (0);
}
コード例 #3
0
ファイル: Network_Control.cpp プロジェクト: kravitz/transims4
void Network_Service::Program_Control (void)
{
	bool first, new_flag, notes_flag;
	char *str_ptr, *format_ptr;
	Format_Type default_format, file_format, network_format;
	Access_Type access;

	first = true;
	new_flag = false;
	network_format = default_format = Network_Format ();

	if (Get_Control_String (CREATE_NOTES_AND_NAME_FIELDS) != NULL) {
		Notes_Name_Flag (Get_Control_Flag (CREATE_NOTES_AND_NAME_FIELDS));
	}
	notes_flag = Notes_Name_Flag ();

	File_Data *file = network_file;

	//---- open the files ----

	for (int i=0; i < END_NETWORK; i++, file++) {
		if (file->flag || file->option) {
			if (i == DIRECTORY) {
				first = true;

				//---- get the network format ----

				format_ptr = Get_Control_String (file->format);

				if (format_ptr != NULL) {
					network_format = Format_Code (format_ptr);
					if (network_format != default_format) {
						Print (2, "Default Network Format = %s", format_ptr);
						first = false;
					}
				} else {
					network_format = default_format;
				}
				Network_Format (network_format);
			} else if (i == NEW_DIRECTORY) {
				first = true;

				//---- get the new network format ----

				format_ptr = Get_Control_String (file->format);

				if (format_ptr != NULL) {
					network_format = Format_Code (format_ptr);
					if (network_format != default_format) {
						Print (2, "Default New Network Format = %s", format_ptr);
						first = false;
					}
				} else {
					network_format = default_format;
				}
				Network_Format (network_format);
			}

			//---- get the filename ----

			str_ptr = Get_Control_String (file->key);

			if (str_ptr == NULL) {
				if (file->flag) goto control_error;
			} else {
				if (first) {
					Print (1);
					first = false;
				}
				file->flag = true;

				if (i == DIRECTORY) {
					Print_Filename (1, "Network Directory", str_ptr);
					Network_Directory (str_ptr);

				} else if (i == NEW_DIRECTORY) {
					Print_Filename (1, "New Network Directory", str_ptr);
					New_Directory (str_ptr);

				} else {
					format_ptr = Get_Control_String (file->format);

					if (format_ptr != NULL) {
						file_format = Format_Code (format_ptr);
						//if (file_format != network_format) Print (1);
					} else {
						file_format = network_format;
					}
					access = file->access;

					if (i > NEW_DIRECTORY) {
						new_flag = true;
						str_ptr = New_Filename (str_ptr);
					} else {
						str_ptr = Network_Filename (str_ptr);
					}

					switch (i) {
						case NODE:
						case NEW_NODE:
							file->file = new Node_File (str_ptr, access, file_format, notes_flag);
							break;
						case ZONE:
						case NEW_ZONE:
							file->file = new Zone_File (str_ptr, access, file_format, notes_flag);
							break;
						case SHAPE:
						case NEW_SHAPE:
							file->file = new Shape_File (str_ptr, access, file_format, notes_flag);
							break;
						case LINK:
						case NEW_LINK:
							file->file = new Link_File (str_ptr, access, file_format, notes_flag);
							break;
						case POCKET_LANE:
						case NEW_POCKET_LANE:
							file->file = new Pocket_File (str_ptr, access, file_format, notes_flag);
							break;
						case LANE_USE:
						case NEW_LANE_USE:
							file->file = new Lane_Use_File (str_ptr, access, file_format, notes_flag);
							break;
						case TOLL:
						case NEW_TOLL:
							file->file = new Toll_File (str_ptr, access, file_format, notes_flag);
							break;
						case LANE_CONNECTIVITY:
						case NEW_LANE_CONNECTIVITY:
							file->file = new Connect_File (str_ptr, access, file_format, notes_flag);
							break;
						case TURN_PROHIBITION:
						case NEW_TURN_PROHIBITION:
							file->file = new Turn_File (str_ptr, access, file_format, notes_flag);
							if (((Turn_File *) (file->file))->Node_Based ()) AB_Key_Flag (true);
							break;
						case PARKING:
						case NEW_PARKING:
							file->file = new Parking_File (str_ptr, access, file_format, notes_flag);
							break;
						case ACTIVITY_LOCATION:
						case NEW_ACTIVITY_LOCATION:
							file->file = new Location_File (str_ptr, access, file_format, notes_flag);
							break;
						case PROCESS_LINK:
						case NEW_PROCESS_LINK:
							file->file = new Access_File (str_ptr, access, file_format, notes_flag);
							break;
						case UNSIGNALIZED_NODE:
						case NEW_UNSIGNALIZED_NODE:
							file->file = new Sign_File (str_ptr, access, file_format, notes_flag);
							break;
						case SIGNALIZED_NODE:
						case NEW_SIGNALIZED_NODE:
							file->file = new Signal_File (str_ptr, access, file_format, notes_flag);
							break;
						case TIMING_PLAN:
						case NEW_TIMING_PLAN:
							file->file = new Timing_File (str_ptr, access, file_format, notes_flag);
							break;
						case PHASING_PLAN:
						case NEW_PHASING_PLAN:
							file->file = new Phasing_File (str_ptr, access, file_format, notes_flag);
							break;
						case DETECTOR:
						case NEW_DETECTOR:
							file->file = new Detector_File (str_ptr, access, file_format, notes_flag);
							break;
						case SIGNAL_COORDINATOR:
						case NEW_SIGNAL_COORDINATOR:
							file->file = new Coordinator_File (str_ptr, access, file_format, notes_flag);
							break;
						case TRANSIT_STOP:
						case NEW_TRANSIT_STOP:
							file->file = new Stop_File (str_ptr, access, file_format, notes_flag);
							break;
						case TRANSIT_FARE:
						case NEW_TRANSIT_FARE:
							file->file = new Fare_File (str_ptr, access, file_format, notes_flag);
							break;
						case TRANSIT_ROUTE:
						case NEW_TRANSIT_ROUTE:
							file->file = new Line_File (str_ptr, access, file_format, notes_flag);
							break;
						case TRANSIT_SCHEDULE:
						case NEW_TRANSIT_SCHEDULE:
							file->file = new Schedule_File (str_ptr, access, file_format, notes_flag);
							break;
						case TRANSIT_DRIVER:
						case NEW_TRANSIT_DRIVER:
							file->file = new Driver_File (str_ptr, access, file_format, notes_flag);
							break;
						case ROUTE_HEADER:
						case NEW_ROUTE_HEADER:
							file->file = new Route_Header_File (str_ptr, access, file_format, notes_flag);
							break;
						case ROUTE_NODES:
						case NEW_ROUTE_NODES:
							file->file = new Route_Nodes_File (str_ptr, access, file_format, notes_flag);
							break;
						default:
							file->file = new Db_Header (Project_Filename (str_ptr));
							break;
					}
				}
			}
		}
	}
	if (new_flag && notes_flag) {
		Print (2, "Notes and Name Fields will be Created");
	}
	Network_Format (default_format);
	control_flag = true;
	return;
	
control_error:
	Error ("Missing Control Key = %s", Current_Key ());
}
コード例 #4
0
void RiderSum::Group_Rider_Report (void)
{
	int n, run, runs, num, length, tot_len, period, num_periods, routes, index, stop, to, link;
	int max_riders, max_board, max_alight, max_runs, total;
	double factor, max_fac, sum_time, tot_time, time;
	double vmt, vht, pmt, pht;
	Dtime low, high;
	String label;
	bool flag;

	Int_Set *group;
	Int_Set_Itr itr;
	Int_Map_Itr map_itr, to_itr;
	Line_Data *line_ptr;
	Stop_Data *stop_ptr;
	Line_Stop_Itr stop_itr, next_itr;
	Line_Run_Itr run_itr;
	Int_Map stop_index;
	Int2_Map link_index;
	Int2_Map_Itr map2_itr;
	Int2_Key int2_key;
	Int2_Map_Stat map2_stat;
	Int_Map_Stat map_stat;
	Stop_Group_Data data, *data_ptr, *link_ptr;
	Stop_Group_Itr data_itr;

	Show_Message ("Line Group Profile -- Record");
	Set_Progress ();

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

	Header_Number (GROUP_RIDERS);

	num_periods = sum_periods.Num_Periods ();
	if (num_periods == 0) num_periods = 1;

	num = (int) (line_map.size () * stop_map.size ());

	if (!Break_Check (num + 5)) {
		Print (1);
		Group_Rider_Header ();
	}

	routes = 0;
	memset (&data, '\0', sizeof (data));
	
	for (n = line_equiv.First_Group (); n > 0; n = line_equiv.Next_Group ()) {

		group = line_equiv.Group_List (n);
		if (group == 0) continue;

		label = line_equiv.Group_Label (n);

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

		for (period = 0; period < num_periods; period++) {

			//---- initialize stop data ----

			stop_index.clear ();
			link_index.clear ();
			stop_group_array.clear ();
			routes = 0;
			vmt = vht = pmt = pht = 0.0;

			//---- process each line in the line group ----

			for (itr = group->begin (); itr != group->end (); itr++) {

				map_itr = line_map.find (*itr);
				if (map_itr == line_map.end ()) continue;

				Show_Progress ();

				line_ptr = &line_array [map_itr->second];

				//---- set the run flags ----

				if (!Run_Selection (line_ptr)) continue;

				if (period_flag [period] == 0) continue;

				time = 0.0;
				total = length = 0;
				flag = false;

				sum_periods.Period_Range (period, low, high);

				for (stop_itr = line_ptr->begin (); stop_itr != line_ptr->end (); stop_itr++) {

					stop_ptr = &stop_array [stop_itr->Stop ()];
					stop = stop_ptr->Stop ();

					map_itr = stop_index.find (stop);

					next_itr = stop_itr + 1;

					if (next_itr != line_ptr->end ()) {
						stop_ptr = &stop_array [next_itr->Stop ()];

						to = stop_ptr->Stop ();
					} else {
						to = 0;
					}

					//---- create the link ----

					int2_key = Int2_Key (stop, to);

					map2_itr = link_index.find (int2_key);

					if (map2_itr == link_index.end ()) {
						if (to == 0 && map_itr != stop_index.end ()) {
							link = map_itr->second;
						} else {
							link = (int) stop_group_array.size ();

							link_index.insert (Int2_Map_Data (int2_key, link));

							data.stop = stop;
							data.to = to;
							stop_group_array.push_back (data);

							//---- check for a merge ----

							if (to != 0) {
								to_itr = stop_index.find (to);

								if (to_itr != stop_index.end ()) {
									index = (int) stop_group_array.size ();

									int2_key = Int2_Key (to, 0);

									map2_stat = link_index.insert (Int2_Map_Data (int2_key, index));

									if (map2_stat.second) {
										data.stop = to;
										data.to = 0;
										stop_group_array.push_back (data);
									}
								}
							}
						}
					} else {
						link = map2_itr->second;
					}
					link_ptr = &stop_group_array [link];

					//---- crete the stop index ----

					if (map_itr == stop_index.end ()) {
						map_stat = stop_index.insert (Int_Map_Data (stop, link));
						index = link;
					} else {
						index = map_itr->second;
					}
					data_ptr = &stop_group_array [index];

					if (next_itr != line_ptr->end ()) {
						length = next_itr->Length () - stop_itr->Length ();
					} else {
						length = 0;
					}
					sum_time = 0.0;
					num = runs = 0;

					for (run=0, run_itr = stop_itr->begin (); run_itr != stop_itr->end (); run_itr++, run++) {
						if (run_flag [run] == 0) continue;
						if (run_period [run] != period) continue;

						data_ptr->board += run_itr->Board ();
						data_ptr->alight += run_itr->Alight ();
						link_ptr->riders += run_itr->Load ();
						runs++;
						flag = true;

						if (next_itr != line_ptr->end ()) {
							link_ptr->runs++;
							time = next_itr->at (run).Schedule ().Seconds () - run_itr->Schedule ().Seconds ();
							sum_time += time;
							num++;

							vmt += length;
							vht += time;
							pmt += length * run_itr->Load ();
							pht += time * run_itr->Load ();
						}
					}
					if (runs == 0) continue;

					if (link_ptr->length == 0.0) {
						link_ptr->length = length;
					}
					if (num > 0) {
						time = sum_time / num;
					} else {
						time = 0;
					}
					if (link_ptr->time > 0) {
						link_ptr->time = (link_ptr->time + time) / 2.0;
					} else {
						link_ptr->time = time;
					}
				}
				if (flag) routes++;
			}

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

			if (!Break_Check ((int) stop_index.size () + 15)) {
				Print (1);
				Group_Rider_Header ();
			}
			Print (1, "Group   Time Period  Routes  Description");

			Print (2, String ("%5d  %12.12s  %6d  %s") % n %	sum_periods.Range_Format (period) %
				routes % label);

			Print (2, "    Stop  Length   TTime   Alight    Board   Riders  Runs  LoadFac");
			Print (1);

			tot_time = 0.0;
			max_alight = max_board = max_riders = max_runs = total = tot_len = 0;
			max_fac = 0.0;

			for (data_itr = stop_group_array.begin (); data_itr != stop_group_array.end (); data_itr++) {

				map_itr = stop_map.find (data_itr->stop);
					
				stop_ptr = &stop_array [map_itr->second];
				
				if (data_itr->runs > 0) {
					factor = DTOI (data_itr->riders * 10.0 / data_itr->runs) / 10.0;
				} else {
					factor = 0.0;
				}
				Print (1, String ("%8d %7.0lf %7.0lf %8d %8d %8d %5d %8.1lf") % data_itr->stop  % 
					UnRound (data_itr->length) % data_itr->time % data_itr->alight % data_itr->board % 
					data_itr->riders % data_itr->runs % factor);

				if (Notes_Name_Flag ()) {
					if (!stop_ptr->Name ().empty ()) {
						Print (0, String ("  %s") % stop_ptr->Name ());
					}
					if (!stop_ptr->Notes ().empty ()) {
						Print (0, " -- ") << stop_ptr->Notes ();
					}
				}
				if (data_itr->alight > max_alight) max_alight = data_itr->alight;
				if (data_itr->board > max_board) max_board = data_itr->board;
				if (data_itr->riders > max_riders) max_riders = data_itr->riders;
				if (data_itr->runs > max_runs) max_runs = data_itr->runs;
				if (factor > max_fac) max_fac = factor;

				tot_len += data_itr->length;
				tot_time += data_itr->time;
				total += data_itr->board;
			}
			if (max_runs == 0) continue;

			Print (2, String (" Maximum                 %8ld %8ld %8ld %5ld %8.1lf") %
				max_alight % max_board % max_riders % max_runs % max_fac);

			Print (2, "Total Boardings = ") << total;

			if (total == 0 || tot_time == 0) continue;

			factor = UnRound (tot_len);
			vmt = UnRound (vmt) / 5280.0;
			vht = vht / 3600.0;
			pmt = UnRound (pmt) / 5280.0;
			pht = pht / 3600.0;


			Print (1, String ("Route Length = %.1lf miles, %.1lf minutes  Average Speed = %.1lf mph") %
				External_Units (factor, MILES) % (tot_time / 60.0) % External_Units ((factor / tot_time), MPH));
			Print (1, String ("Vehicle Miles = %.1lf  Vehicle Hours = %.1lf") % vmt % vht);
			Print (1, String ("Passenger Miles = %.1lf  Passenger Hours = %.1lf") %	pmt % pht);
			Print (1, String ("Passengers per Vehicle Mile = %.1lf  Passengers per Vehicle Hour = %.1lf") %	
				(pmt / vht) % (pht / vht));

			vmt = pmt / total;
			vht = pht * 60.0 / total;

			Print (1, String ("Average Trip Length = %.1lf miles, %.1lf minutes") % vmt % vht);
		}
	}
	End_Progress ();

	Header_Number (0);
}
コード例 #5
0
ファイル: Write_Group_Rider.cpp プロジェクト: qingswu/Transim
void RiderSum::Write_Group_Rider (void)
{
	int n, run, runs, num, length, period, num_periods, routes, index, stop, to, link, capacity;
	double factor, sum_time, time, capfac;
	Dtime low, high;
	String label;
	bool flag;
	
	Int_Set *group;
	Int_Set_Itr itr;
	Int_Map_Itr map_itr, to_itr;
	Line_Data *line_ptr;
	Stop_Data *stop_ptr;
	Line_Stop_Itr stop_itr, next_itr;
	Line_Run_Itr run_itr;
	Int_Map stop_index;
	Int2_Map link_index;
	Int2_Map_Itr map2_itr;
	Int2_Key int2_key;
	Int2_Map_Stat map2_stat;
	Int_Map_Stat map_stat;
	Stop_Group_Data data, *data_ptr, *link_ptr;
	Stop_Group_Itr data_itr;
	Veh_Type_Data *veh_type_ptr, *run_type_ptr;

	fstream &file = line_group_file.File ();
	
	num_periods = sum_periods.Num_Periods ();
	if (num_periods == 0) num_periods = 1;

	Show_Message (String ("Writing % -- Record") % line_group_file.File_Type ());
	Set_Progress ();

	file << "Group\tPeriod\tRoutes\tStops\tDescription\n";
	file << "Stop\tLength\tTTime\tAlight\tBoard\tRiders\tRuns\tLoadFac\tCapacity\tCapFac\tStopName\n";

	//---- process each line group ----

	routes = 0;
	memset (&data, '\0', sizeof (data));
	
	for (n = line_equiv.First_Group (); n > 0; n = line_equiv.Next_Group ()) {

		group = line_equiv.Group_List (n);
		if (group == 0) continue;

		label = line_equiv.Group_Label (n);

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

		for (period = 0; period < num_periods; period++) {

			//---- initialize stop data ----

			stop_index.clear ();
			link_index.clear ();
			stop_group_array.clear ();
			routes = 0;

			//---- process each line in the line group ----

			for (itr = group->begin (); itr != group->end (); itr++) {

				map_itr = line_map.find (*itr);
				if (map_itr == line_map.end ()) continue;

				Show_Progress ();

				line_ptr = &line_array [map_itr->second];

				//---- set the run flags ----

				if (!Run_Selection (line_ptr)) continue;

				//---- check the period flag ----

				if (period_flag [period] == 0) continue;

				time = 0.0;
				length = 0;
				flag = false;
				veh_type_ptr = &veh_type_array [line_ptr->Type ()];

				sum_periods.Period_Range (period, low, high);

				for (stop_itr = line_ptr->begin (); stop_itr != line_ptr->end (); stop_itr++) {
					
					stop_ptr = &stop_array [stop_itr->Stop ()];
					stop = stop_ptr->Stop ();

					map_itr = stop_index.find (stop);

					next_itr = stop_itr + 1;

					if (next_itr != line_ptr->end ()) {
						stop_ptr = &stop_array [next_itr->Stop ()];

						to = stop_ptr->Stop ();
					} else {
						to = 0;
					}

					//---- create the link ----

					int2_key = Int2_Key (stop, to);

					map2_itr = link_index.find (int2_key);

					if (map2_itr == link_index.end ()) {
						if (to == 0 && map_itr != stop_index.end ()) {
							link = map_itr->second;
						} else {
							link = (int) stop_group_array.size ();

							link_index.insert (Int2_Map_Data (int2_key, link));

							data.stop = stop;
							data.to = to;
							stop_group_array.push_back (data);

							//---- check for a merge ----

							if (to != 0) {
								to_itr = stop_index.find (to);

								if (to_itr != stop_index.end ()) {
									index = (int) stop_group_array.size ();

									int2_key = Int2_Key (to, 0);

									map2_stat = link_index.insert (Int2_Map_Data (int2_key, index));

									if (map2_stat.second) {
										data.stop = to;
										data.to = 0;
										stop_group_array.push_back (data);
									}
								}
							}
						}
					} else {
						link = map2_itr->second;
					}
					link_ptr = &stop_group_array [link];

					//---- crete the stop index ----

					if (map_itr == stop_index.end ()) {
						map_stat = stop_index.insert (Int_Map_Data (stop, link));
						index = link;
					} else {
						index = map_itr->second;
					}
					data_ptr = &stop_group_array [index];

					if (next_itr != line_ptr->end ()) {
						length = next_itr->Length () - stop_itr->Length ();
					} else {
						length = 0;
					}
					sum_time = 0.0;
					num = runs = 0;

					for (run=0, run_itr = stop_itr->begin (); run_itr != stop_itr->end (); run_itr++, run++) {
						if (run_flag [run] == 0) continue;
						if (run_period [run] != period) continue;

						data_ptr->board += run_itr->Board ();
						data_ptr->alight += run_itr->Alight ();
						link_ptr->riders += run_itr->Load ();
						runs++;
						flag = true;

						if (next_itr != line_ptr->end ()) {
							if (line_ptr->run_types.size () > 0) {
								run_type_ptr = &veh_type_array [line_ptr->Run_Type (run)];
								capacity = run_type_ptr->Capacity ();
							} else {
								capacity = veh_type_ptr->Capacity ();
							}
							link_ptr->runs++;
							link_ptr->capacity += capacity;
							time = next_itr->at (run).Schedule ().Seconds () - run_itr->Schedule ().Seconds ();
							sum_time += time;
							num++;
						}
					}
					if (runs == 0) continue;
						
					if (link_ptr->length == 0.0) {
						link_ptr->length = length;
					}
					if (num > 0) {
						time = sum_time / num;
					} else {
						time = 0;
					}
					if (link_ptr->time > 0) {
						link_ptr->time = (link_ptr->time + time) / 2.0;
					} else {
						link_ptr->time = time;
					}
				}
				if (flag) routes++;
			}
			file << n << "\t" << sum_periods.Range_Format (period) << "\t" << routes << "\t" << stop_index.size () << "\t" << label << "\n";

			for (data_itr = stop_group_array.begin (); data_itr != stop_group_array.end (); data_itr++) {

				map_itr = stop_map.find (data_itr->stop);
					
				stop_ptr = &stop_array [map_itr->second];
				
				if (data_itr->runs > 0) {
					factor = DTOI (data_itr->riders * 10.0 / data_itr->runs) / 10.0;
				} else {
					factor = 0;
				}
				if (data_itr->capacity > 0) {
					capfac = DTOI (data_itr->riders * 10.0 / data_itr->capacity) / 10.0;
				} else {
					capfac = 0;
				}
				file << data_itr->stop << "\t" << UnRound (data_itr->length) << "\t" << data_itr->time << "\t" <<
					data_itr->alight << "\t" << data_itr->board << "\t" << data_itr->riders << "\t" << 
					data_itr->runs << "\t" << factor << "\t" << data_itr->capacity << "\t" << capfac << "\t";

				if (Notes_Name_Flag ()) {
					file << stop_ptr->Name ();

					if (!stop_ptr->Notes ().empty ()) {
						file << " -- " << stop_ptr->Notes ();
					}
				}
				file << "\n";
			}
		}
	}
	End_Progress ();
	line_group_file.Close ();
}
コード例 #6
0
ファイル: Write_Square.cpp プロジェクト: qingswu/Transim
void MatrixData::Write_Square_Table (void)
{
	int i, j, period, num_periods, org, des, tab, num_tables;
	double total, value;
	Doubles des_tot;
	Int_Map *org_map, *des_map;
	Int_Map_Itr org_itr, des_itr;
	String period_format;
	Str_Map_Itr map_itr;

	fstream *file = &square_file.File();

	Show_Message ("Writing Square Table File -- Record");
	Set_Progress ();

	num_periods = new_matrix->Num_Periods ();
	if (num_periods == 0) {
		num_periods = 1;
	}
	org_map = new_matrix->Org_Map ();
	des_map = new_matrix->Des_Map ();
	num_tables = new_matrix->Tables ();

	for (tab=0; tab < num_tables; tab++) {
		*file << "Table=\t" << new_matrix->Table_Field (tab)->Name () << endl;

		for (period=0; period < num_periods; period++) {
			if (period_flag) {
				if (new_matrix->Merge_Flag ()) {
					*file << "Period=\t" << new_matrix->Range_String () << endl;
				} else {
					*file << "Period=\t" << new_matrix->Range_Format (period) << endl;
				}
			}
			if (Notes_Name_Flag ()) {
				*file << "\t";

				for (des_itr = des_map->begin (); des_itr != des_map->end (); des_itr++) {
					des = des_itr->first;
					*file << "\t";

					if (Zone_Equiv_Flag ()) {
						*file << zone_equiv.Group_Label (des);
					} else if (label_flag) {
						map_itr = label_map.find (des);
						if (map_itr != label_map.end ()) {
							*file << map_itr->second;
						}
					}
				}
				*file << endl << "\t";
			}
			*file << "Group";

			for (des_itr = des_map->begin (); des_itr != des_map->end (); des_itr++) {
				*file << (String ("\t%d") % des_itr->first);
			}
			*file << "\tTotal" << endl;

			des_tot.assign (des_map->size (), 0);

			for (org_itr = org_map->begin (); org_itr != org_map->end (); org_itr++) {
				Show_Progress ();

				org = org_itr->first;
				i = org_itr->second;
				total = 0;

				if (Notes_Name_Flag ()) {
					if (Zone_Equiv_Flag ()) {
						*file << zone_equiv.Group_Label (org);
					} else if (label_flag) {
						map_itr = label_map.find (org);
						if (map_itr != label_map.end ()) {
							*file << map_itr->second;
						}
					}
					*file << "\t";
				}
				*file << org_itr->first;

				for (des_itr = des_map->begin (); des_itr != des_map->end (); des_itr++) {
					j = des_itr->second;

					new_matrix->Get_Cell_Index (period, i, j, tab, value);

					*file << "\t" << value;
					total += value;
					des_tot [j] += value;
				}
				*file << "\t" << total;

				if (Zone_Equiv_Flag ()) {
					*file << "\t" << zone_equiv.Group_Label (org);
				} else if (label_flag) {
					map_itr = label_map.find (org);
					if (map_itr != label_map.end ()) {
						*file << "\t" << map_itr->second;
					}
				}
				*file << endl;
			}
			if (Notes_Name_Flag ()) {
				*file << "\t";
			}
			*file << "Total";
			total = 0;

			for (des_itr = des_map->begin (); des_itr != des_map->end (); des_itr++) {
				j = des_itr->second;

				value = des_tot [j];
				*file << "\t" << value;
				total += value;
			}
			*file << "\t" << total << endl;
		}
	}
	End_Progress ();
	square_file.Close ();
}
コード例 #7
0
ファイル: Read_Line.cpp プロジェクト: kravitz/transims4
bool Network_Service::Line_Processing (Db_File *fh)
{
	static int id, nstops, stop_num; 
	int zone;

	bool stop_flag;
	
	Line_Data *line_ptr = NULL;

	Line_File *file = (Line_File *) fh;

	stop_flag = Network_Data_Flag (TRANSIT_STOP);

	//---- process a header line ----

	if (!file->Nest ()) {	
		id = file->Route ();

		if (id == 0) return (false);

		if (id < 1) {
			return (Check_Message ("Transit Route ID %d is Out of Range", id));
		}
		line_ptr = line_data.New_Record (true);
		if (line_ptr == NULL) goto mem_error;

		line_ptr->Route (id);

		stop_num = 1;
		nstops = file->Stops ();

		if (nstops < 2) {
			return (Check_Message ("Number of Stops %d on Route %d is Out of Range", nstops, id));
		}
		if (!line_ptr->Stops (nstops)) {
			Error ("Insufficient Memory for %d Stops on Router %d", nstops, id);
		}
		line_ptr->Mode (Transit_Code (file->Mode ()));
		line_ptr->Null_Name ();
		line_ptr->Null_Notes ();

		if (Notes_Name_Flag ()) {
			char *str_ptr = file->Name ();

			if (str_ptr != NULL && *str_ptr != '\0') {
				line_ptr->Name (str_ptr);
			}
			str_ptr = file->Notes ();

			if (str_ptr != NULL && *str_ptr != '\0') {
				line_ptr->Notes (str_ptr);
			}
		}
	} else {
		line_ptr = line_data.New_Record (false);
		if (line_ptr == NULL) goto mem_error;

		//---- process a stop record ----

		int stop = file->Stop ();

		if (stop_flag) {
			int index = stop_data.Get_Index (stop);

			if (index == 0) {
				return (Check_Message ("Transit Stop %d on Route %d was Not Found in the Stop File", stop, id));
			}
			if (Renumber ()) stop = index;
		}
		line_ptr->Stop (stop_num, stop);

		zone = file->Zone ();

		if (Num_Fare_Zones () > 0 && (zone < 1 || zone > Num_Fare_Zones ())) {
			if (zone != 0 || !Zero_Fare_Zone ()) {
				Warning ("Transit Zone %d on Route %d is Out of Range (1..%d)", zone, id, Num_Fare_Zones ());
				if (zone == 0) Zero_Fare_Zone (true);
			}
		}
		line_ptr->Zone (stop_num, zone);
		line_ptr->Time_Flag (stop_num, file->Time_Flag ());

		if (stop_num == nstops) {
			return (true);
		} else {
			stop_num++;
			return (false);
		}
	}
	return (false);

mem_error:
	Error ("Insuffienct Memory for Transit Line Data");
	return (false);
}
コード例 #8
0
ファイル: Control.cpp プロジェクト: kravitz/transims4
void TPPlusNet::Program_Control (void)
{
	int len;
	char *str_ptr, *format_ptr;

	//---- create the network files ----

	Network_Service::Program_Control ();

	//---- get the projection data ----

	proj_service.Read_Control ();

	projection.Set_Projection (proj_service.Input_Projection (), proj_service.Output_Projection ());

	//---- open the TP+ link file ----
	
	str_ptr = Get_Control_String (TPPLUS_LINK_FILE);

	if (str_ptr == NULL) goto control_error;

	len = (int) strlen (str_ptr);
	len = (len > 4) ? len - 4 : 0;

	if ((format_ptr = strchr (str_ptr + len, '.')) != NULL) {
		link_shape_flag = (str_cmp (format_ptr, ".shp") == 0);
	}

	if (link_shape_flag) {

		//---- set the projection data ----

		link_shape_file.Set_Projection (proj_service.Input_Projection (), proj_service.Output_Projection ());

		link_shape_file.File_Type ("TPPlus Link File");
		link_shape_file.File_ID ("TPPLUS");

		Print (1);
		link_shape_file.Open (Project_Filename (str_ptr));

		link_shape_file.File_Access (MODIFY);
	} else {
		link_file.File_Type ("TPPlus Link File");
		link_file.File_ID ("TPPLUS");

		format_ptr = Get_Control_String (TPPLUS_LINK_FORMAT);

		if (format_ptr != NULL) {
			link_file.Dbase_Format (format_ptr);
		}
		Print (1);
		link_file.Open (Project_Filename (str_ptr));

		link_file.File_Access (MODIFY);
	}

	//---- open the TP+ node file ----
	
	str_ptr = Get_Control_String (TPPLUS_NODE_FILE);

	if (str_ptr == NULL) goto control_error;

	len = (int) strlen (str_ptr);
	len = (len > 4) ? len - 4 : 0;

	if ((format_ptr = strchr (str_ptr + len, '.')) != NULL) {
		node_shape_flag = (str_cmp (format_ptr, ".shp") == 0);
	}

	if (node_shape_flag) {

		//---- set the projection data ----

		node_shape_file.Set_Projection (proj_service.Input_Projection (), proj_service.Output_Projection ());

		node_shape_file.File_Type ("TPPlus Node File");
		node_shape_file.File_ID ("TPPLUS");

		Print (1);
		node_shape_file.Open (Project_Filename (str_ptr));
	} else {
		node_file.File_Type ("TPPlus Node File");
		node_file.File_ID ("TPPLUS");

		format_ptr = Get_Control_String (TPPLUS_NODE_FORMAT);

		if (format_ptr != NULL) {
			node_file.Dbase_Format (format_ptr);
		}
		Print (1);
		node_file.Open (Project_Filename (str_ptr));
	}

	//---- open the speed capacity table ----
	
	str_ptr = Get_Control_String (TPPLUS_SPDCAP_FILE);

	if (str_ptr != NULL) {
		spdcap_file.File_Type ("TPPlus Speed-Capacity File");
		spdcap_file.File_ID ("TPPLUS");

		format_ptr = Get_Control_String (TPPLUS_SPDCAP_FORMAT);

		if (format_ptr != NULL) {
			spdcap_file.Dbase_Format (format_ptr);
		} else {
			spdcap_file.Dbase_Format (FIXED_COLUMN);
		}
		Print (1);
		spdcap_file.Open (Project_Filename (str_ptr));
		spdcap_flag = true;

		//---- convert units ----

		str_ptr = Get_Control_String (CONVERT_MPH_TO_MPS);

		if (str_ptr != NULL) {
			Print (1, "Convert MPH to MPS = %s", str_ptr);

			units_flag = Get_Control_Flag (CONVERT_MPH_TO_MPS);
		}

		//---- facility index field ----

		str_ptr = Get_Control_String (FACILITY_INDEX_FIELD);

		if (str_ptr != NULL) {
			Print (1, "Facility Index Field = %s", str_ptr);

			if (link_shape_flag) {
				fac_fld = link_shape_file.Required_Field (str_ptr);
			} else {
				fac_fld = link_file.Required_Field (str_ptr);
			}
			Print (0, " (Number = %d)", fac_fld);
		}

		//---- area type index field ----

		str_ptr = Get_Control_String (AREA_TYPE_INDEX_FIELD);

		if (str_ptr != NULL) {
			Print (1, "Area Type Index Field = %s", str_ptr);

			if (link_shape_flag) {
				at_fld = link_shape_file.Required_Field (str_ptr);
			} else {
				at_fld = link_file.Required_Field (str_ptr);
			}
			Print (0, " (Number = %d)", at_fld);
		}
		if ((fac_fld == 0 && at_fld > 0) || (fac_fld > 0 && at_fld == 0)) {
			Error ("Facility and Area Types Index Fields are Required");
		}
	}

	//---- open the conversion script ----

	str_ptr = Get_Control_String (CONVERSION_SCRIPT);

	if (str_ptr != NULL) {
		Print (1);
		script_file.File_Type ("Conversion Script");

		script_file.Open (Project_Filename (str_ptr));
		convert_flag = true;
	}

	//---- external zone number ----

	str_ptr = Get_Control_String (EXTERNAL_ZONE_NUMBER);

	if (str_ptr != NULL) {
		ext_zone = atoi (str_ptr);

		if (ext_zone < 0 || ext_zone > 10000) {
			Error ("External Zone Number %d is Out of Range (0..10000)", ext_zone);
		}
		Print (2, "First External Zone Number = %d", ext_zone);
	}

	//---- open the link detail file ----

	str_ptr = Get_Control_String (NEW_LINK_DETAIL_FILE);

	if (str_ptr != NULL) {
		Print (1);
		detail_file.Notes_Flag (Notes_Name_Flag ());

		detail_file.Create (Project_Filename (str_ptr));
		detail_flag = true;
	}

	if (link_shape_flag) {
		shape_file = (Shape_File *) Network_Db_Base (NEW_SHAPE);

		if (link_shape_file.Z_Flag () && shape_file != NULL) {
			shape_file->Z_Flag (true);

			shape_file->Clear_Fields ();
			shape_file->Create_Fields ();
			shape_file->Write_Header ();
		}
	}
	return;

control_error:
	Error ("Missing Control Key = %s", Current_Key ());
} 
コード例 #9
0
ファイル: Stop_Report.cpp プロジェクト: kravitz/transims5
void PlanSum::Stop_Report (void)
{
	int stop, total_board, total_alight;
	int walk_board, bus_board, rail_board, drive_board;
	int walk_alight, bus_alight, rail_alight, drive_alight;
	char *name;

	Int_Map_Itr map_itr;
	Transfer_Data *transfer_ptr;

	Show_Message ("Transit Stop Report -- Stop");
	Set_Progress ();

	Header_Number (SUM_STOPS);

	if (!Break_Check ((int) transfer_array.size () + 8)) {
		Print (1);
		Stop_Header ();
	}

	walk_board = bus_board = rail_board = drive_board = 0;
	walk_alight = bus_alight = rail_alight = drive_alight = 0;

	//---- process each transit stop ----

	for (map_itr = stop_map.begin (); map_itr != stop_map.end (); map_itr++) {
		Show_Progress ();

		stop = map_itr->first;
		if (select_stops && !stop_range.In_Range (stop)) continue;

		transfer_ptr = &transfer_array [map_itr->second];

		total_board = transfer_ptr->Walk_Board () + transfer_ptr->Bus_Board () + 
						transfer_ptr->Rail_Board () + transfer_ptr->Drive_Board ();

		total_alight = transfer_ptr->Walk_Alight () + transfer_ptr->Bus_Alight () + 
						transfer_ptr->Rail_Alight () + transfer_ptr->Drive_Alight ();

		if (total_board == 0 && total_alight == 0) continue;

		if (total_board > 0) {
			walk_board += transfer_ptr->Walk_Board ();
			bus_board += transfer_ptr->Bus_Board ();
			rail_board += transfer_ptr->Rail_Board ();
			drive_board += transfer_ptr->Drive_Board ();
		}
		if (total_alight > 0) {
			walk_alight += transfer_ptr->Walk_Alight ();
			bus_alight += transfer_ptr->Bus_Alight ();
			rail_alight += transfer_ptr->Rail_Alight ();
			drive_alight += transfer_ptr->Drive_Alight ();
		}

		Print (1, String ("%-8d %7d %7d %7d %7d %7d %7d %7d %7d %7d %7d") % 
			stop % transfer_ptr->Walk_Board () % transfer_ptr->Bus_Board () %
			transfer_ptr->Rail_Board () % transfer_ptr->Drive_Board () % total_board %
			transfer_ptr->Walk_Alight () % transfer_ptr->Bus_Alight () %
			transfer_ptr->Rail_Alight () % transfer_ptr->Drive_Alight () % total_alight);

		if (Notes_Name_Flag ()) {
			name = stop_array [stop].Name ();
			if (name != 0) {
				Print (0, "  ") << name;
			}
		}
	}
	End_Progress ();

	total_board = walk_board + bus_board + rail_board + drive_board;
	total_alight = walk_alight + bus_alight + rail_alight + drive_alight;

	Print (2, String ("Total    %7d %7d %7d %7d %7d %7d %7d %7d %7d %7d") % 
		walk_board % bus_board % rail_board % drive_board % total_board %
		walk_alight % bus_alight % rail_alight % drive_alight % total_alight);

	Header_Number (0);
}