Beispiel #1
0
void TransitAccess::Read_Link (void)
{
	int anode, bnode, dist, zone, type;
	double len;
	String text;
	Zone_Map_Itr zone_itr;
	Node_Map_Itr node_itr;

	//---- walk link data ----

	Show_Message (String ("Reading %s -- Record") % link_data_file.File_Type ());
	Set_Progress ();

	while (link_data_file.Read ()) {
		Show_Progress ();

		anode = link_data_file.Get_Integer (link_anode_fld);
		bnode = link_data_file.Get_Integer (link_bnode_fld);

		if (skip_links.find (Int2_Key (anode, bnode)) != skip_links.end ()) continue;
		if (skip_links.find (Int2_Key (bnode, anode)) != skip_links.end ()) continue;

		len = link_data_file.Get_Double (link_len_fld);
		zone = link_data_file.Get_Integer (link_zone_fld);
		type = link_data_file.Get_Integer (link_type_fld);

		if (!type_range.In_Range (type)) continue;

		zone_itr = zone_map.find (zone);
		if (zone_itr == zone_map.end ()) continue;
		if (zone_itr->second.walk == 0) continue;

		dist = DTOI (len * 100.0 * zone_itr->second.weight);

		node_itr = node_map.find (anode);
		if (node_itr != node_map.end ()) {
			node_itr->second.use = 1;
		}
		node_itr = node_map.find (bnode);
		if (node_itr != node_map.end ()) {
			node_itr->second.use = 1;
		}
	
		text (" N=%d-%d MODE=13 SPEED=3 ONEWAY=T DIST=%d") % anode % bnode % dist;

		sidewalk_file.File () << "SUPPORT" << text << endl;

		walk_link_file.File () << "SUPPLINK" << text << endl;
	}
	End_Progress ();
	link_data_file.Close ();

	Print (2, "Number of Link Data Records = ") << Progress_Count ();
}
Beispiel #2
0
void LineSum::Read_Shapes (void)
{
	int anode, bnode;

	//---- read the arcview shape file ----

	Show_Message (String ("Reading %s -- Record") % link_shape.File_Type ());
	Set_Progress ();

	//---- read each record ----

	while (link_shape.Read_Record ()) {
		Show_Progress ();

		anode = link_shape.Get_Integer (anode_field);
		bnode = link_shape.Get_Integer (bnode_field);

		points_map.insert (I2_Points_Map_Data (Int2_Key (anode, bnode), link_shape));
	}
	End_Progress ();

	Print (2, String ("Number of %s Records = %d") % link_shape.File_Type () % points_map.size ());
	
	link_shape.Close ();
}
Beispiel #3
0
void RoutePrep::Route_Links (Route_Link_Data *route_link_ptr, Stop_Offset_Map *stop_offset_ptr)
{
	int link, anode, bnode;
	double offset1, offset2, length;

	Points points;
	Points_Itr pt_itr;
	Stop_Offset_Map_Itr stop_offset_itr;
	Route_Stop_Map_Itr route_stop_itr;
	Int2_Map_Itr ab_itr;

	Int_Map_Itr map_itr;

	offset1 = 0.0;
	anode = -1;

	for (stop_offset_itr = stop_offset_ptr->begin (); stop_offset_itr != stop_offset_ptr->end (); stop_offset_itr++) {
		bnode = stop_offset_itr->second.stop;
		offset2 = stop_offset_itr->second.offset;

		if (anode == bnode) continue;

		//---- create a node at the beginning of the link ----

		if (anode < 0 && offset2 > 300) {
			anode = new_node++;
		}

		if (anode >= 0) {

			//---- get the shape points for the link ----

			length = offset2 - offset1;
			points.assign (route_shape_file.begin (), route_shape_file.end ());

			Sub_Shape (points, offset1, length);

			link = Insert_Link (points); 
			if (link < 0) continue;

			route_link_ptr->links.insert (Int2_Key (stop_offset_itr->first, link));
		}
		offset1 = offset2;
		anode = bnode;
	}
}
Beispiel #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);
}
Beispiel #5
0
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 ();
}
bool LinkSum::Get_Location_Data (Location_File &file, Location_Data &data)
{
	int i, field, link, lvalue1, lvalue2, zone;
	double dvalue1, dvalue2;
	String buffer;

	Db_Field *fld;
	Link_Location loc_rec;
	Int_Itr int_itr;
	Int_Map_Itr map_itr;

	//---- get the link number ----

	link = file.Link ();
	if (link == 0) return (false);
	data.Link (link);

	//---- sum the activities on links ----

	if (activity_flag) {
		if (!link_db.Read_Record (link)) {
			Error (String ("Reading Link Database Record %d") % link);
		}

		//---- sum the data fields ----

		for (i=1, int_itr = field_list.begin (); int_itr != field_list.end (); int_itr++, i++) {
			field = *int_itr;

			fld = file.Field (field);

			if (fld->Type () == DB_INTEGER) {
				lvalue1 = file.Get_Integer (field);
				lvalue2 = link_db.Get_Integer (i);

				lvalue2 += lvalue1;
				link_db.Put_Field (i, lvalue2);
			} else if (fld->Type () == DB_DOUBLE) {
				dvalue1 = file.Get_Double (field);
				dvalue2 = link_db.Get_Double (i);

				dvalue2 += dvalue1;
				link_db.Put_Field (i, dvalue2);
			} else if (fld->Type () == DB_STRING) {
				link_db.Put_Field (i, file.Get_String (field));
			}
		}

		//---- save the changes ----

		if (!link_db.Write_Record (link)) {
			Error (String ("Writing Link Database Record %d") % link);
		}
	}

	//---- add a link location record ----

	if (zone_flag || group_flag) {
		zone = file.Zone ();

		if (zone > 0) {
			map_itr = link_map.find (link);
			if (map_itr == link_map.end ()) return (false);
			link = map_itr->second;

			loc_rec.link = link;
			loc_rec.location = i = file.Location ();
			loc_rec.zone = zone;
			loc_rec.count = 0;

			link_location.insert (Link_Loc_Map_Data (Int2_Key (link, i), loc_rec));
		}
	}

	//---- don't save the location data ----

	return (false);
}
Beispiel #7
0
void ModeChoice::Segment_Map (void)
{
	int org, des, segment, max_org, max_des, count, org_field, des_field, seg_field;
	bool first;
	Int2_Map_Stat map_stat;

	Show_Message (String ("Reading %s -- Record") % segment_file.File_Type ());
	Set_Progress ();

	max_org = max_des = num_market = 0;
	org_field = segment_file.Optional_Field ("ORIGIN", "ORG", "O", "I");
	des_field = segment_file.Optional_Field ("DESTINATION", "DES", "D", "J");
	seg_field = segment_file.Optional_Field ("SEGMENT", "SEG", "MARKET", "S");

	if (org_field < 0) org_field = 0;
	if (des_field < 0) des_field = 1;
	if (seg_field < 0) seg_field = 2;

	while (segment_file.Read ()) {
		Show_Progress ();

		org = segment_file.Get_Integer (org_field);
		if (org <= 0) continue;
		if (org > max_org) max_org = org;

		des = segment_file.Get_Integer (des_field);
		if (des <= 0) continue;
		if (des > max_des) max_des = des;

		segment = segment_file.Get_Integer (seg_field);
		if (segment <= 0) continue;
		if (segment > num_market) num_market = segment;

		map_stat = segment_map.insert (Int2_Map_Data (Int2_Key (org, des), segment));

		if (!map_stat.second) {
			Warning ("Duplicate Segment Map between ") << org << " and " << des;
		}
	}
	End_Progress ();
	segment_file.Close ();

	Print (1);
	Write (1, "Number of Market Segments = ") << num_market;
	Show_Message (1);

	//---- scan for missing interchanges ----

	first = true;
	count = 0;

	for (org=1; org <= max_org; org++) {
		for (des=1; des <= max_des; des++) {
			if (segment_map.find (Int2_Key (org, des)) == segment_map.end ()) {
				if (first) {
					first = false;
					Warning ("Missing Segment Interchanges:");
				}
				if ((++count % 10) == 1) {
					Write (1, "\t") << org << "-" << des;
				} else {
					Write (0, ", ") << org << "-" << des;
				}
			}
		}
	}
	if (count > 0) {
		Write (2, "\tNumber of Missing Interchanges = ") << count;
		Show_Message (1);
	}
}
Beispiel #8
0
bool Data_Service::Get_Connect_Data (Connect_File &file, Connect_Data &connect_rec)
{
	int link, dir, node, dir_index, to_index, lanes, low, high;

	Link_Data *link_ptr;
	Int_Map_Itr map_itr;

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

	link_ptr = Set_Link_Direction (file, link, dir);

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

	if (dir) {
		dir_index = link_ptr->BA_Dir ();
		node = link_ptr->Anode ();
	} else {
		dir_index = link_ptr->AB_Dir ();
		node = link_ptr->Bnode ();
	}
	if (dir_index < 0) {
		Warning (String ("Connection %d Link %d Direction %s was Not Found") % Progress_Count () % 
			link_ptr->Link () % ((dir) ? "BA" : "AB"));
		return (false);
	}
	connect_rec.Dir_Index (dir_index);

	//---- convert the to-link number ----

	link = file.To_Link ();

	map_itr = link_map.find (link);
	if (map_itr == link_map.end ()) {
		Warning (String ("Connection %d Link %d was Not Found") % Progress_Count () % link);
		return (false);
	}
	link = map_itr->second;

	link_ptr = &link_array [link];

	if (link_ptr->Anode () == node) {
		to_index = link_ptr->AB_Dir ();
	} else if (link_ptr->Bnode () == node) {
		to_index = link_ptr->BA_Dir ();
	} else {
		Node_Data *ptr = &node_array [node];
		Warning (String ("Connection %d Node %d is Not on Link %d") % Progress_Count () % 
			ptr->Node () % link_ptr->Link ());
		return (false);
	}
	connect_rec.To_Index (to_index);

	//---- lane numbers ----

	lanes = file.Lanes ();

	if (file.Version () <= 40 && lanes > 0) {
		low = lanes - 1;
		high = file.In_High () - 1;
		if (high < low) high = low;
	} else {
		Convert_Lane_Range (dir_index, lanes, low, high);
	}
	connect_rec.Low_Lane (low);
	connect_rec.High_Lane (high);

	lanes = file.To_Lanes ();

	if (file.Version () <= 40 && lanes > 0) {
		low = lanes - 1;
		high = file.Out_High () - 1;
		if (high < low) high = low;
	} else {
		Convert_Lane_Range (to_index, lanes, low, high);
	}
	connect_rec.To_Low_Lane (low);
	connect_rec.To_High_Lane (high);

	//---- optional fields ----
	
	connect_rec.Type (file.Type ());
	connect_rec.Penalty (file.Penalty ());
	connect_rec.Speed (file.Speed ());
	connect_rec.Capacity (file.Capacity ());
	connect_rec.Notes (file.Notes ());

	//---- check for duplicate records ----

	if (file.Version () <= 40) {
		Int2_Map_Itr map2_itr;

		//max_in = dir_ptr->Thru () + dir_ptr->Left () + dir_ptr->Right ();
		//in_bear = dir_ptr->Out_Bearing ();

		//max_out = dir_ptr->Thru () + dir_ptr->Left () + dir_ptr->Right ();
		//out_bear = dir_ptr->In_Bearing ();

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

		//int num, node_num, link, dir, in_link, out_link, max_in, max_out, in_bear, out_bear;
		//int in_low, in_high, out_low, out_high, type, penalty, speed, capacity, change;
		//if (type == 0 && compass.Num_Points () > 0) {
		//	change = compass.Change (in_bear, out_bear) * 360 / compass.Num_Points ();

		//	if (change >= -45 && change <= 45) {
		//		type = THRU;
		//	} else if (change < -165 || change > 165) {
		//		type = UTURN;
		//	} else if (change < 0) {
		//		type = LEFT;
		//	} else {
		//		type = RIGHT;
		//	}
		//}

		map2_itr = connect_map.find (Int2_Key (connect_rec.Dir_Index (), connect_rec.To_Index ()));

		if (map2_itr != connect_map.end ()) {
			Connect_Data *connect_ptr;

			//---- update optional fields ----

			connect_ptr = &connect_array [map2_itr->second];

			//---- merge the entry lane codes ----

			if (connect_rec.Low_Lane () < connect_ptr->Low_Lane ()) {
				connect_ptr->Low_Lane (connect_rec.Low_Lane ());
			}
			if (connect_rec.High_Lane () > connect_ptr->High_Lane ()) {
				connect_ptr->High_Lane (connect_rec.High_Lane ());
			}

			//---- merge the exit lane codes ----
			
			if (connect_rec.To_Low_Lane () < connect_ptr->To_Low_Lane ()) {
				connect_ptr->To_Low_Lane (connect_rec.To_Low_Lane ());
			}
			if (connect_rec.To_High_Lane () > connect_ptr->To_High_Lane ()) {
				connect_ptr->To_High_Lane (connect_rec.To_High_Lane ());
			}

			//---- merge the optional data ----

			if (connect_rec.Type () > connect_ptr->Type ()) {
				connect_ptr->Type (connect_rec.Type ());
			}
			if (connect_rec.Penalty () > connect_ptr->Penalty ()) {
				connect_ptr->Penalty (connect_rec.Penalty ());
			}
			if (connect_rec.Speed () > connect_ptr->Speed ()) {
				connect_ptr->Speed (connect_rec.Speed ());
			}
			connect_ptr->Capacity (connect_ptr->Capacity () + connect_rec.Capacity ());
			return (false);
		}
	}
	return (true);
}
Beispiel #9
0
void Data_Service::Read_Connections (void)
{
	Connect_File *file = (Connect_File *) System_File_Handle (CONNECTION);

	int num, in, out;
	Int2_Map_Stat map_stat;
	Connect_Data connect_rec;

	//---- store the lane connectivity data ----

	Show_Message (String ("Reading %s -- Record") % file->File_Type ());
	Set_Progress ();
	
	Initialize_Connects (*file);
	
	num = 0;

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

		connect_rec.Clear ();

		if (Get_Connect_Data (*file, connect_rec)) {
			in = connect_rec.Dir_Index ();
			out = connect_rec.To_Index ();

			map_stat = connect_map.insert (Int2_Map_Data (Int2_Key (in, out), (int) connect_array.size ()));

			if (!map_stat.second) {
				Dir_Data *dir_ptr;
				Link_Data *link_ptr;

				dir_ptr = &dir_array [in];
			
				link_ptr = &link_array [dir_ptr->Link ()];
				in = link_ptr->Link ();

				dir_ptr = &dir_array [out];

				link_ptr = &link_array [dir_ptr->Link ()];
				out = link_ptr->Link ();

				Warning (String ("Duplicate Link Connection = %d to %d") % in % out);
				continue;
			} else {
				connect_array.push_back (connect_rec);
			}
		}
	}
	End_Progress ();
	file->Close ();

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

	num = (int) connect_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 (CONNECTION);

		Connect_Data *connect_ptr;
		Dir_Data *dir_ptr;

		//---- create directional link list ---- 

		while (num--) {
			connect_ptr = &connect_array [num];

			dir_ptr = &dir_array [connect_ptr->Dir_Index ()];
			connect_ptr->Next_To (dir_ptr->First_Connect_To ());
			dir_ptr->First_Connect_To (num);

			dir_ptr = &dir_array [connect_ptr->To_Index ()];
			connect_ptr->Next_From (dir_ptr->First_Connect_From ());
			dir_ptr->First_Connect_From (num);
		}
	}
}
Beispiel #10
0
int Path_Builder::Trace_Path (Trip_End *org, Path_End_Array *from, Path_End *to)
{
	int type, index, dir, in_index, out_index, use_index;
	int imped, len, cost, mode, path, tot_len, prev_len, prev_imp, wait_imp;
	int from_index, from_type, from_path, from_dir, to_index, to_type, to_path, to_dir;
	bool ab_flag, park_flag;
	Dtime time, duration, prev_time, wait_time, tod;
	double len_factor;

	Trip_End *parking_end;
	Path_End *from_end;
	Path_Data *from_ptr, *to_ptr;
	Path_Itr path_itr;
	Path_RItr path_ritr;
	Link_Data *link_ptr;
	Dir_Data *dir_ptr;
	Turn_Period *turn_period_ptr;
	Turn_Data *turn_ptr;
	Int2_Map_Itr map2_itr;
	Plan_Leg_RItr leg_itr;
	Plan_Leg *prev_leg;
	Stop_Data *stop_ptr;
	Access_Data *access_ptr;

	mode = path_param.mode;
	park_flag = (mode == PNR_OUT_MODE || mode == PNR_IN_MODE || mode == KNR_OUT_MODE || mode == KNR_IN_MODE);
	flow_flag = (path_param.flow_flag && mode != WAIT_MODE && mode != WALK_MODE && mode != BIKE_MODE && 
				mode != TRANSIT_MODE && mode != RIDE_MODE && mode != OTHER_MODE && to->Index () >= 0);

	path_itr = to->begin ();

	from_end = &from->at (0);

	if (reroute_flag) {
		tot_len = plan_ptr->Length ();
	} else {
		tot_len = 0;
	}
	if (path_itr->Status () == 0) {
		plan_ptr->Clear_Plan ();
		return (0);
	}

	//---- save the path skim data ----

	plan_ptr->Activity (plan_ptr->Duration ());
	
	if (forward_flag) {
		if (!reroute_flag) plan_ptr->Depart (org->Time ().Round_Seconds ());
		plan_ptr->Arrive (path_itr->Time ().Round_Seconds ());

		if (plan_ptr->Arrive () > plan_ptr->End () && plan_ptr->Duration () > 0 &&
			plan_ptr->Constraint () != FIXED_TIME && plan_ptr->Constraint () != DURATION) {

			duration = DTOI (plan_ptr->Duration () * path_param.duration_factor [plan_ptr->Priority ()]);
			time = plan_ptr->End () + plan_ptr->Duration ();
			if (time > plan_ptr->Arrive () + duration.Round_Seconds ()) {
				plan_ptr->Activity (time - plan_ptr->Arrive ());
			} else {
				plan_ptr->Activity (duration.Round_Seconds ());
			}
		}
	} else {
		plan_ptr->Depart (path_itr->Time ().Round_Seconds ());
		plan_ptr->Arrive (org->Time ().Round_Seconds ());
	}
	plan_ptr->Impedance (Resolve (path_itr->Imped ()));
	plan_ptr->Length (path_itr->Length ());
	plan_ptr->Cost (path_itr->Cost ());

	//---- magic moves ----

	if (mode == RIDE_MODE || mode == OTHER_MODE) {
		plan_ptr->Other (plan_ptr->Arrive () - plan_ptr->Depart ());
		return (0);
	}

	//---- all walk path with no detail ----

	if (mode == WALK_MODE && !path_param.walk_detail) {
		plan_ptr->Walk (plan_ptr->Arrive () - plan_ptr->Depart ());
		return (0);
	}

	//---- add legs to the plan record ----

	if (forward_flag) {
		leg_ptr = &leg_array;
	} else {
		leg_ptr = plan_ptr;
	}
	if (!path_param.skim_only) leg_ptr->clear ();

	prev_time = wait_time = 0;
	prev_imp = prev_len = wait_imp = 0;

next_mode:
	from_ptr = to_ptr = &(*path_itr);
	
	//---- insert the destination access legs ----

	for (++path_itr; path_itr != to->end (); path_itr++) {

		from_ptr = &(*path_itr);
		type = to_ptr->Type ();

		//---- don't write parking ID twice ----

		if (to->End_Type () == PARKING_ID && type == PARKING_ID && 
			(((path_param.mode == PNR_IN_MODE || path_param.mode == KNR_IN_MODE) && forward_flag) || 
			((path_param.mode == PNR_OUT_MODE || path_param.mode == KNR_OUT_MODE) && !forward_flag))) {
			to_ptr = from_ptr;
			continue;
		}
		
		//---- get leg attributes ----

		if (forward_flag) {
			time = to_ptr->Time () - from_ptr->Time ();
		} else {
			time = from_ptr->Time () - to_ptr->Time ();
		}
		len = to_ptr->Length () - from_ptr->Length ();
		imped = Resolve (to_ptr->Imped () - from_ptr->Imped ());
		cost = to_ptr->Cost () - from_ptr->Cost ();

		if (to_ptr->Mode () == WAIT_MODE && !forward_flag) {
			wait_time = time;
			wait_imp = imped;
		} else {
			Add_Leg (to_ptr->Mode (), type, to_ptr->From (), to_ptr->Dir (), imped, time, len, cost);
		}
		tot_len += len;
		to_ptr = from_ptr;
	}
	to_index = from_index = to->Index ();
	to_type = from_type = to->Type ();	//TO_ID;
	to_path = from_path = to_ptr->Path ();
	to_dir = from_dir = to_ptr->Dir ();
	out_index = in_index = -1;

	//----- trace the path ----

	for (; from_type != FROM_ID; to_ptr = from_ptr) {
		if ((int) leg_ptr->size () > path_param.leg_check) {
			plan_ptr->Problem (TRACE_PROBLEM);
			return (0);
		}
		to_index = from_index;
		to_type = from_type;
		to_path = from_path;
		to_dir = from_dir;
		out_index = in_index;

		//---- retrieve the from record ----

		from_index = to_ptr->From ();
		from_type = to_ptr->Type ();
		from_path = to_ptr->Path ();
		from_dir = to_ptr->Dir ();
		mode = to_ptr->Mode ();

		if (from_type == DIR_ID) {
#ifdef CHECK
			if (from_index < 0 || from_index >= (int) link_path.size ()) exe->Error ("Path_Builder::Trace: link_path from_index");
#endif
			from_ptr = &link_path [from_index];	
		} else if (from_type == FROM_ID) {
			if (park_flag) {
#ifdef CHECK
				if (from_index < 0 || from_index >= (int) from_parking.size ()) exe->Error ("Path_Builder::Trace: parking from_index");
#endif
				from_end = &from_parking [from_index];
				park_flag = false;
			} else {
#ifdef CHECK
				if (from_index < 0 || from_index >= (int) from->size ()) exe->Error ("Path_Builder::Trace: from from_index");
#endif
				from_end = &from->at (from_index);
			}
			path_ritr = from_end->rbegin ();
			from_ptr = &(*path_ritr);
		} else if (from_type == NODE_ID) {
#ifdef CHECK
			if (from_path < 0 || from_path > MAX_PATHS) exe->Error ("Path_Builder::Trace: node_path max_paths");
			if (from_index < 0 || from_index >= (int) node_path [from_path].size ()) exe->Error ("Path_Builder::Trace: node_path from_index");
#endif
			from_ptr = &node_path [from_path] [from_index];
		} else if (from_type == STOP_ID) {
			if (mode == WAIT_MODE) {
#ifdef CHECK
				if (from_path < 0 || from_path >= MAX_PATHS) exe->Error ("Path_Builder::Trace: board_path max_paths");
				if (from_index < 0 || from_index >= (int) board_path [from_path].size ()) exe->Error ("Path_Builder::Trace: board_path from_index");
#endif
				from_ptr = &board_path [from_path] [from_index];
			} else {
#ifdef CHECK
				if (from_path < 0 || from_path >= MAX_PATHS) exe->Error ("Path_Builder::Trace: alight_path max_paths");
				if (from_index < 0 || from_index >= (int) alight_path [from_path].size ()) exe->Error ("Path_Builder::Trace: alight_path from_index");
#endif
				from_ptr = &alight_path [from_path] [from_index];
			}
		} else if (from_type == ROUTE_ID) {
#ifdef CHECK
			if (from_path < 0 || from_path >= MAX_PATHS) exe->Error ("Path_Builder::Trace: wait_path max_paths");
			if (from_index < 0 || from_index >= (int) wait_path [from_path].size ()) exe->Error ("Path_Builder::Trace: wait_path from_index");
#endif
			from_ptr = &wait_path [from_path] [to_index];
		} else if (from_type == ACCESS_ID) {
#ifdef CHECK
			if (from_index < 0 || from_index >= (int) exe->access_array.size ()) exe->Error ("Path_Builder::Trace: access_array from_index");
#endif
			access_ptr = &exe->access_array [from_index];

			if (path_param.walk_detail) {
				if (forward_flag || to_type == NODE_ID) {
					Add_Leg (mode, to_type, to_index, to_dir);
				} else {
					Add_Leg (TRANSIT_MODE, to_type, to_index, 0, prev_imp, prev_time, prev_len);
				}
				to_type = from_type;
				to_index = from_index;
				to_path = from_path;
				to_dir = from_dir;
			} else if (!forward_flag && to_type == STOP_ID) {
				Add_Leg (TRANSIT_MODE, to_type, to_index, 0, prev_imp, prev_time, prev_len);

				to_type = from_type;
				to_index = from_index;
				to_path = from_path;
				to_dir = from_dir;
			}
			from_type = access_ptr->Type ((from_dir == 0));
			from_index = access_ptr->ID ((from_dir == 0));

			if (!forward_flag) to_dir = (from_dir == 0) ? 1 : 0;

			if (from_type == NODE_ID) {
#ifdef CHECK
				if (from_path < 0 || from_path > MAX_PATHS) exe->Error ("Path_Builder::Trace: node_path max_paths");
				if (from_index < 0 || from_index >= (int) node_path [from_path].size ()) exe->Error ("Path_Builder::Trace: node_path from_index");
#endif
				from_ptr = &node_path [from_path] [from_index];
			} else if (from_type == STOP_ID) {
#ifdef CHECK
				if (from_path < 0 || from_path >= MAX_PATHS) exe->Error ("Path_Builder::Trace: alight_path max_paths");
				if (from_index < 0 || from_index >= (int) alight_path [from_path].size ()) exe->Error ("Path_Builder::Trace: alight_path from_index");
#endif
				from_ptr = &alight_path [from_path] [from_index];
			}
		} else {
			exe->Write (1, "From Type=") << from_type << "-" << from_index << " not implemented to=" << to_type << "-" << to_index;
			return (0);
		}

		//---- accumulate mode-specific travel time ---

		if (forward_flag) {
			time = to_ptr->Time () - from_ptr->Time ();
		} else {
			time = from_ptr->Time () - to_ptr->Time ();
		}
		len = to_ptr->Length () - from_ptr->Length ();
		imped = Resolve (to_ptr->Imped () - from_ptr->Imped ());
		cost = to_ptr->Cost () - from_ptr->Cost ();

		//---- save the plan leg or flow data ----

		if (!path_param.skim_only || (flow_flag && mode == DRIVE_MODE)) {
			if (forward_flag) {
				type = to_type;
				index = in_index = to_index;
				path = from_path;
				dir = to_dir;
			} else if (from_type == FROM_ID) {
				index = from_end->Index ();
				type = from_end->Type ();
				path = to_path;
				dir = from_dir;
			} else {
				index = to_index;
				type = to_type;
				path = to_path;
				dir = to_dir;
			}

			if (type == DIR_ID) {
				in_index = index;
			} else if (type == LINK_ID) {
				if (mode == DRIVE_MODE) {
					if (index < 0 || index >= (int) exe->link_array.size ()) return (0);
					link_ptr = &exe->link_array [index];
					if (dir == 0) {
						in_index = link_ptr->AB_Dir ();
					} else {
						in_index = link_ptr->BA_Dir ();
					}
					if (!forward_flag) {
						if (from_end->End_Type () == PARKING_ID) {
							Add_Leg (mode, type, index, dir, imped, time, len, cost, path);
							Add_Leg (OTHER_MODE, PARKING_ID, from_ptr->From (), from_ptr->Dir ());
							continue;
						}
					}
				} else if (path_param.walk_detail && (from_type == NODE_ID || from_type == FROM_ID)) {
#ifdef CHECK
					if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
#ifdef CHECK
					if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
					prev_leg = &leg_ptr->back ();

					if (prev_leg->Access_Type ()) {
						Add_Leg (WALK_MODE, NODE_ID, to_index, to_dir);
					}
				}
			} else if (type == NODE_ID) {
				if (from_type == NODE_ID) {
					if (path_param.walk_detail) {
#ifdef CHECK
						if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
#ifdef CHECK
						if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
						prev_leg = &leg_ptr->back ();

						if (prev_leg->Access_Type ()) {
							Add_Leg (WALK_MODE, NODE_ID, index);
						}
					}
					int anode, bnode;

					if (index > from_index) {
						anode = from_index;
						bnode = index;
						ab_flag = forward_flag;
					} else {
						anode = index;
						bnode = from_index;
						ab_flag = !forward_flag;
					}
					Int2_Map_Itr itr = exe->ab_link.find (Int2_Key (anode, bnode));

					if (itr != exe->ab_link.end ()) {
						type = LINK_ID;
						index = itr->second;
						dir = (ab_flag) ? 0 : 1;
					} else {
						exe->Error (String ("Node Path Error %d-%d") % anode % bnode);
					}
				} else if (from_type == FROM_ID) {
					if (from_end->Type () == NODE_ID) {
						continue;	//---- ignore the extra node record ----
					} else if (from_end->Type () == LINK_ID) {
						if (from_end->Index () < 0) return (0);
#ifdef CHECK
						if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
						prev_leg = &leg_ptr->back ();

						if (prev_leg->Access_Type ()) {
							Add_Leg (WALK_MODE, NODE_ID, index);
						}
#ifdef CHECK
						if (from_end->Index () < 0 || from_end->Index () >= (int) exe->link_array.size ()) exe->Error ("Path_Builder::Trace: link_array index");
#endif
						link_ptr = &exe->link_array [from_end->Index ()];
						ab_flag = (link_ptr->Bnode () == index) ? forward_flag : !forward_flag;

						type = LINK_ID;
						index = from_end->Index ();
						dir = (ab_flag) ? 0 : 1;
						in_index = (ab_flag) ? link_ptr->AB_Dir () : link_ptr->BA_Dir ();
					}
				} else if (from_type == STOP_ID) {
					if (from_index < 0) return (0);
					if (path_param.walk_detail) {
#ifdef CHECK
						if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
#ifdef CHECK
						if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
						prev_leg = &leg_ptr->back ();

						if (prev_leg->Access_Type ()) {
							Add_Leg (WALK_MODE, NODE_ID, index);
						}
#ifdef CHECK
						if (from_index < 0 || from_index >= (int) exe->stop_array.size ()) exe->Error ("Path_Builder::Trace: stop_array index");
#endif
						stop_ptr = &exe->stop_array [from_index];
#ifdef CHECK
						if (stop_ptr->Link () < 0 || stop_ptr->Link () >= (int) exe->link_array.size ()) exe->Error ("Path_Builder::Trace: link_array index");
#endif
						link_ptr = &exe->link_array [stop_ptr->Link ()];

						ab_flag = (link_ptr->Bnode () == index) ? forward_flag : !forward_flag;

						type = LINK_ID;
						index = stop_ptr->Link ();
						dir = (ab_flag) ? 0 : 1;
					}
				} else {
					exe->Warning ("File_Type=") << from_type;
				}

			} else if (type == STOP_ID) {

				if (forward_flag) {
					if (path_param.walk_detail && (from_type == NODE_ID || from_type == FROM_ID)) {


						Add_Leg (mode, type, index, dir);
						if (from_type == FROM_ID && time == 0) continue;
#ifdef CHECK
						if (index < 0 || index >= (int) exe->stop_array.size ()) exe->Error ("Path_Builder::Trace: stop_array index");
#endif
						stop_ptr = &exe->stop_array [index];

						type = LINK_ID;
						index = stop_ptr->Link ();
						dir = from_dir;
					} else {
						if (time == 0 && from_type == to_type && from_index == to_index) continue;

						if (path_param.walk_detail && time > 0 && from_type == STOP_ID && to_type == STOP_ID) {
							Add_Leg (mode, type, index, dir);
#ifdef CHECK
							if (index < 0 || index >= (int) exe->stop_array.size ()) exe->Error ("Path_Builder::Trace: stop_array index");
#endif
							stop_ptr = &exe->stop_array [index];

							type = LINK_ID;
							index = stop_ptr->Link ();
							dir = from_dir;
						}
					}
				} else {
					if (mode == WAIT_MODE) {
						Add_Leg (TRANSIT_MODE, type, index, dir, prev_imp, prev_time, prev_len);
						prev_imp = imped;
						prev_time = time;
						prev_len = len;
						continue;
					}
					if (from_type == FROM_ID && time == 0) continue;
					if (time == 0 && from_type == to_type && from_index == to_index) continue;

					if (mode == WALK_MODE) {
						Add_Leg (TRANSIT_MODE, type, index, 0, prev_imp, prev_time, prev_len);
#ifdef CHECK
						if (index < 0 || index >= (int) exe->stop_array.size ()) exe->Error ("Path_Builder::Trace: stop_array index");
#endif
						stop_ptr = &exe->stop_array [index];

						type = LINK_ID;
						index = stop_ptr->Link ();
						dir = from_dir;
					} else if (mode == TRANSIT_MODE) {
#ifdef CHECK
						if (leg_ptr->size () == 0) exe->Error ("Path_Builder::Trace: prev_leg");
#endif
						prev_leg = &leg_ptr->back ();

						if (prev_leg->Type () == ROUTE_ID) {
							Add_Leg (TRANSIT_MODE, type, index);
						} else {
							Add_Leg (WALK_MODE, type, index);
						}
						prev_imp = imped;
						prev_time = time;
						prev_len = len;
						continue;
					}
				}
			} else if (type == ROUTE_ID && !forward_flag) {
				Add_Leg (WAIT_MODE, type, index, 0, wait_imp, wait_time);
				wait_imp = imped;
				wait_time = time;
				continue;
			}

			//---- save the leg ----

			Add_Leg (mode, type, index, dir, imped, time, len, cost, path);

			//---- accumulate flow and turning movement data ----

			if (flow_flag && mode == DRIVE_MODE) {
				if (path == 0) {
					use_index = in_index;
				} else {
#ifdef CHECK
					if (in_index < 0 || in_index >= (int) exe->dir_array.size ()) exe->Error ("Path_Builder::Trace: dir_array index");
#endif
					dir_ptr = &exe->dir_array [in_index];
					use_index = dir_ptr->Use_Index ();
					if (use_index < 0) use_index = in_index;
				}
				if (type == DIR_ID) {
#ifdef CHECK
					if (index < 0 || index >= (int) exe->dir_array.size ()) exe->Error ("Path_Builder::Trace: dir_array index");
#endif
					dir_ptr = &exe->dir_array [index];
#ifdef CHECK
					if (dir_ptr->Link () < 0 || dir_ptr->Link () >= (int) exe->link_array.size ()) exe->Error ("Path_Builder::Trace: link_array index");
#endif
					link_ptr = &exe->link_array [dir_ptr->Link ()];
				} else {
#ifdef CHECK
					if (abs (index) >= (int) exe->link_array.size ()) exe->Error ("Path_Builder::Trace: link_array index");
#endif
					link_ptr = &exe->link_array [abs (index)];
				}
				if (len >= link_ptr->Length ()) {
					len_factor = 1.0;
				} else {
					len_factor = (double) len / link_ptr->Length ();
				}
				perf_period_array_ptr->Flow_Time (use_index, to_ptr->Time (), len_factor, link_ptr->Length (), path_param.pce, path_param.occupancy, forward_flag);

				if (out_index >= 0 && path_param.turn_flow_flag) {
					if (forward_flag) {
						map2_itr = exe->connect_map.find (Int2_Key (in_index, out_index));
						tod = to_ptr->Time ();
					} else {
						map2_itr = exe->connect_map.find (Int2_Key (out_index, in_index));
						tod = from_ptr->Time ();
					}
					if (map2_itr != exe->connect_map.end ()) {
						turn_period_ptr = turn_period_array_ptr->Period_Ptr (tod);

						if (turn_period_ptr != 0) {
							turn_ptr = turn_period_ptr->Data_Ptr (map2_itr->second);
							turn_ptr->Add_Turn (path_param.pce);
						}
					}
				}
			}
		}
		tot_len += len;
		dir = to_dir;
	}

	//---- end node ----

	for (++path_ritr; path_ritr != from_end->rend (); path_ritr++) {
		from_ptr = &(*path_ritr);
		mode = to_ptr->Mode ();

		if (forward_flag) {
			time = to_ptr->Time () - from_ptr->Time ();
		} else {
			time = from_ptr->Time () - to_ptr->Time ();
		}
		len = to_ptr->Length () - from_ptr->Length ();
		imped = Resolve (to_ptr->Imped () - from_ptr->Imped ());
		cost = to_ptr->Cost () - from_ptr->Cost ();

		Add_Leg (mode, to_ptr->Type (), to_ptr->From (), to_ptr->Dir (), imped, time, len, cost, to_ptr->Path ());

		tot_len += len;
		to_ptr = from_ptr;
	}
	if (from_end->End_Type () == PARKING_ID) {
#ifdef CHECK
		if (from_end->Trip_End () < 0 || from_end->Trip_End () >= (int) parking_lots.size ()) exe->Error ("Path_Builder::Trace: parking_lots index");
#endif
		parking_end = &parking_lots [from_end->Trip_End ()];
		if (parking_end->Best () < 0) return (0);
#ifdef CHECK
		if (parking_end->Best () < 0 || parking_end->Best () >= (int) to_parking.size ()) exe->Error ("Path_Builder::Trace: to_parking index");
#endif
		to = &to_parking [parking_end->Best ()];
		path_itr = to->begin ();

		if (to_ptr->Type () == PARKING_ID && (path_param.mode == PNR_OUT_MODE || path_param.mode == KNR_OUT_MODE)) goto next_mode;

		if (forward_flag) {
			time = to_ptr->Time () - path_itr->Time ();
		} else {
			time = path_itr->Time () - to_ptr->Time ();
		}
		len = to_ptr->Length () - path_itr->Length ();
		imped = Resolve (to_ptr->Imped () - path_itr->Imped ());
		cost = to_ptr->Cost () - path_itr->Cost ();
	} else {
		if (forward_flag) {
			time = to_ptr->Time () - org->Time ();
		} else {
			time = org->Time () - to_ptr->Time ();
		}
		len = to_ptr->Length ();
		imped = Resolve (to_ptr->Imped ());
		cost = to_ptr->Cost ();
	}
	if (!reroute_flag || to_ptr->Mode () > 0 || time > 0) {
		Add_Leg (to_ptr->Mode (), to_ptr->Type (), to_ptr->From (), to_ptr->Dir (), imped, time, len, cost, to_ptr->Path ());
	}
	if (from_end->End_Type () == PARKING_ID) goto next_mode;

	//---- check for early arrivals ----

	if (!forward_flag && prev_time > 0) {
		Add_Leg (WAIT_MODE, LOCATION_ID, -plan_ptr->Destination (), 0, wait_imp, wait_time);
	}
	plan_ptr->Length (tot_len);

	//---- reverse the legs and add to the plan record ----

	if (!path_param.skim_only && forward_flag) {
		if (reroute_flag) {
			leg_itr = leg_ptr->rbegin ();
			if (leg_itr != leg_ptr->rend ()) {
				Plan_Leg *leg = &plan_ptr->back ();

				if (leg->Type () == leg_itr->Type () && leg->ID () == leg_itr->ID ()) {
					leg->Time (leg->Time () + leg_itr->Time ());
					leg->Length (leg->Length () + leg_itr->Length ());
					leg->Cost (leg->Cost () + leg_itr->Cost ());
					leg->Impedance (leg->Impedance () + leg_itr->Impedance ());
				} else {
					plan_ptr->push_back (*leg_itr);
				}
				for (++leg_itr; leg_itr != leg_ptr->rend (); leg_itr++) {
					plan_ptr->push_back (*leg_itr);
				}
			}
		} else {
			for (leg_itr = leg_ptr->rbegin (); leg_itr != leg_ptr->rend (); leg_itr++) {
				plan_ptr->push_back (*leg_itr);
			}
		}
	}
	return (0);
}
Beispiel #11
0
bool TransimsNet::Get_Phasing_Data (Phasing_File &file, Phasing_Record &phasing_rec)
{
	int link, dir, node, dir_index, to_index, num, detector, signal;
	String svalue;
	
	Int_Map_Itr map_itr;
	Int2_Map_Itr map2_itr;
	Link_Data *link_ptr;
	Dir_Data *dir_ptr;

	Phasing_Data *phasing_ptr = &(phasing_rec.phasing_data);

	//---- process the header record ----
	
	if (!file.Nested ()) {
		signal = file.Signal ();
		if (signal == 0) return (false);

		map_itr = signal_map.find (signal);
		if (map_itr == signal_map.end ()) {
			Warning (String ("Phasing Signal %d was Not Found") % signal);
			return (false);
		}
		phasing_rec.Signal (map_itr->second);

		phasing_ptr->Phasing (file.Phasing ());
		phasing_ptr->Phase (file.Phase ());

		//---- process the detectors ----

		svalue = file.Detectors ();

		if (!svalue.empty ()) {
			Strings detect;
			Str_Itr itr;

			num = svalue.Parse (detect, "|+/");

			for (itr = detect.begin (); itr != detect.end (); itr++) {
				detector = itr->Integer ();
				if (detector <= 0) break;

				map_itr = detector_map.find (detector);
				if (map_itr == detector_map.end ()) {
					Warning (String ("Signal %d Detector %d was Not Found") % file.Signal () % detector);
					break;
				}
				phasing_ptr->detectors.push_back (map_itr->second);
			}
		}
		if (file.Version () > 40) return (phasing_rec.Signal () >= 0);
	}
	Movement_Data move_rec;

	move_rec.Movement (file.Movement ());

	//---- convert the link direction ----
	
	link = file.Link ();
	dir = file.Dir ();

	link_ptr = Set_Link_Direction (file, link, dir);

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

	if (dir) {
		dir_index = link_ptr->BA_Dir ();
		node = link_ptr->Anode ();
	} else {
		dir_index = link_ptr->AB_Dir ();
		node = link_ptr->Bnode ();
	}
	if (dir_index < 0) {
		Warning (String ("Phasing Plan %d Link %d Direction %s was Not Found") % Progress_Count () % 
			link_ptr->Link () % ((dir) ? "BA" : "AB"));
		return (false);
	}

	//---- convert the to-link number ----

	link = file.To_Link ();

	map_itr = link_map.find (link);
	if (map_itr == link_map.end ()) {
		Warning (String ("Phasing Plan %d Link %d was Not Found") % Progress_Count () % link);
		return (false);
	}
	link = map_itr->second;

	link_ptr = &link_array [link];

	if (link_ptr->Anode () == node) {
		to_index = link_ptr->AB_Dir ();
	} else if (link_ptr->Bnode () == node) {
		to_index = link_ptr->BA_Dir ();
	} else {
		Node_Data *ptr = &node_array [node];
		Warning (String ("Phasing Plan %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ());
		return (false);
	}

	//---- check the link connection ----

	map2_itr = connect_map.find (Int2_Key (dir_index, to_index));

	if (map2_itr == connect_map.end ()) {
		to_index = link_ptr->Link ();

		dir_ptr = &dir_array [dir_index];
		link_ptr = &link_array [dir_ptr->Link ()];
		dir_index = link_ptr->Link ();

		if (file.Version () > 40) {
			Warning (String ("No Link Connection between %d and %d") % dir_index % to_index);
		}
		return (false);
	}

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

	move_rec.Connection (map2_itr->second);

	move_rec.Protection (file.Protection ());

	if (file.Version () <= 40 && move_rec.Movement () == 0) {
		Connect_Data *connect_ptr;
		const char *direction;

		dir_ptr = &dir_array [dir_index];
		direction = compass.Point_Text (dir_ptr->In_Bearing (), 4);

		if (*direction == 'N') {
			dir = NB_TH;
		} else if (*direction == 'S') {
			dir = SB_TH;
		} else if (*direction == 'E') {
			dir = EB_TH;
		} else {
			dir = WB_TH;
		}
		connect_ptr = &connect_array [map2_itr->second];
		num = connect_ptr->Type ();
		
		if (num == RIGHT || num == R_SPLIT) {
			dir += NB_RT - NB_TH;
		} else if (num == LEFT || num == L_SPLIT) {
			dir += NB_LT - NB_TH;
		} else if (num == UTURN) {
			dir += NB_UT - NB_TH;
		}
		move_rec.Movement (dir);
	}
	phasing_ptr->push_back (move_rec);

	return (phasing_rec.Signal () >= 0);
}