Example #1
0
void RoutePrep::Read_Node_Map (void)
{
	String record;
	Strings fields;

	int node, index;
	Int_Map_Itr map_itr;
	Int_Map_Stat map_stat;
	Node_Data *node_ptr;

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

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

		record = node_map_file.Record_String ();

		record.Parse (fields);

		node = fields [0].Integer ();
		if (node <= 0) continue;

		index = fields [1].Integer ();

		if (index > 0) {
			map_itr = node_map.find (index);

			if (map_itr == node_map.end ()) {
				Warning (String ("Node Map %d to %d was Not Found in the Node File") % node % index);
				continue;
			}
			index = map_itr->second;
		}

		//---- insert the node;

		map_stat = input_map.insert (Int_Map_Data (node, index));

		if (!map_stat.second) {
			Warning (String ("Duplicate Node Map %d to %d and %d") % node % index % map_stat.first->second);
			continue;
		}
		if (index >= 0) {
			node_ptr = &node_array [index];

			node_ptr->Control (node);
		}

	}
	End_Progress ();

	node_map_file.Close ();

	Print (2, String ("Number of %s Records = %d") % node_map_file.File_Type () % Progress_Count ());
}
Example #2
0
void Data_Service::Read_Lines (Line_File &file)
{
	int i, num;
	bool keep_flag;
	Int_Map_Stat map_stat;
	Line_Data line_rec;

	//---- store the route data ----

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

	while (file.Read (false)) {
		Show_Progress ();

		line_rec.Clear ();

		keep_flag = Get_Line_Data (file, line_rec);

		num = file.Num_Nest ();
		if (num > 0) line_rec.reserve (num);

		for (i=1; i <= num; i++) {
			if (!file.Read (true)) {
				Error (String ("Number of Stop Records for Route %d") % file.Route ());
			}
			Show_Progress ();

			Get_Line_Data (file, line_rec);
		}
		if (keep_flag) {
			map_stat = line_map.insert (Int_Map_Data (line_rec.Route (), (int) line_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Route Number = ") << line_rec.Route ();
			} else {
				line_array.push_back (line_rec);

				line_array.Add_Route_Stops ((int) line_rec.size ());
			}
		}
	}
	End_Progress ();
	file.Close ();

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

	num = (int) line_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 (TRANSIT_ROUTE);
}
Example #3
0
void Data_Service::Read_Shapes (Shape_File &file)
{
	int i, num;	
	bool keep_flag;
	Shape_Data shape_rec;
	Int_Map_Stat map_stat;

	//---- store the shape point data ----

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

	Initialize_Shapes (file);

	while (file.Read (false)) {
		Show_Progress ();

		shape_rec.Clear ();

		keep_flag = Get_Shape_Data (file, shape_rec);

		num = file.Num_Nest ();
		if (num > 0) shape_rec.reserve (num);

		for (i=1; i <= num; i++) {
			if (!file.Read (true)) {
				Error (String ("Number of Nested Records for Link %d") % file.Link ());
			}
			Show_Progress ();

			Get_Shape_Data (file, shape_rec);
		}
		if (keep_flag) {
			map_stat = shape_map.insert (Int_Map_Data (shape_rec.Link (), (int) shape_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Link Number = ") << shape_rec.Link ();
			} else {
				shape_array.push_back (shape_rec);
			}
		}
	}
	End_Progress ();
	file.Close ();

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

	num = (int) shape_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of Link %s Records = %d") % file.File_ID () % num);
	}
	if (num > 0) System_Data_True (SHAPE);
}
Example #4
0
bool ConvertTrips::Get_Trip_Data (Trip_File &file, Trip_Data &data, int partition)
{
	int hhold, mode;
	
	Person_Index person_index;
	Int_Map_Itr map_itr;
	Location_Data *loc_ptr;

	hhold = file.Household ();
	if (hhold > max_hh_in) max_hh_in = hhold;

	hhold_map.insert (Int_Map_Data (hhold, 1));

	person_index.Household (hhold);
	person_index.Person (file.Person ());

	person_map.insert (Person_Map_Data (person_index, 1));

	if (select_households && !hhold_range.In_Range (hhold)) return (false);

	mode = file.Mode ();
	if (mode >= 0 && mode < MAX_MODE && !select_mode [mode]) return (false);
	if (select_purposes && !purpose_range.In_Range (file.Purpose ())) return (false);
	if (select_start_times && !start_range.In_Range (file.Start ())) return (false);
	if (select_end_times && !end_range.In_Range (file.End ())) return (false);

	if (select_org_zones) {
		map_itr = location_map.find (file.Origin ());
		if (map_itr != location_map.end ()) {
			loc_ptr = &location_array [map_itr->second];
			if (!org_zone_range.In_Range (loc_ptr->Zone ())) return (false);
		}
	}
	if (select_des_zones) {
		map_itr = location_map.find (file.Destination ());
		if (map_itr != location_map.end ()) {
			loc_ptr = &location_array [map_itr->second];
			if (!des_zone_range.In_Range (loc_ptr->Zone ())) return (false);
		}
	}
	trip_file->Copy_Fields (file);

	if (!trip_file->Write ()) {
		Error ("Writing Trip File");
	}
	trip_copy++;

	data.Household (hhold);
	hhold = partition;

	//---- don't save the record ----

	return (false);
}
Example #5
0
void Data_Service::Read_Locations (void)
{
	Location_File *file = (Location_File *) System_File_Handle (LOCATION);

	int num;
	bool zone_flag = System_Data_Flag (ZONE);

	Int_Map_Stat map_stat;
	Location_Data location_rec;

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

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

	Initialize_Locations (*file);

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

		location_rec.Clear ();

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

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

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

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

	num = (int) location_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of %s Data Records = %d") % file->File_ID () % num);
	}
	if (num > 0) System_Data_True (LOCATION);
}
Example #6
0
void Data_Service::Read_Zones (void)
{
	Zone_File *file = (Zone_File *) System_File_Handle (ZONE);
	
	Zone_Data zone_rec;
	Int_Map_Stat map_stat;

	//---- store the zone data ----

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

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

		zone_rec.Clear ();

		if (Get_Zone_Data (*file, zone_rec)) {
			map_stat = zone_map.insert (Int_Map_Data (zone_rec.Zone (), (int) zone_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Zone Number = ") << zone_rec.Zone ();
				continue;
			} else {
				zone_array.push_back (zone_rec);

				if (zone_rec.Zone () > Max_Zone_Number ()) {
					Max_Zone_Number (zone_rec.Zone ());
				}
			}
		}
	}
	End_Progress ();
	file->Close ();
	
	Print (2, String ("Number of %s Records = %d") % file->File_Type () % Progress_Count ());

	int num = (int) zone_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of %s Data Records = %d") % file->File_ID () % num);
	}
	if (num != Max_Zone_Number ()) Print (1, "Highest Zone Number = ") << Max_Zone_Number ();

	if (num > 0) System_Data_True (ZONE);
}
Example #7
0
void TransimsNet::Add_Node_Data (void)
{
	int node, count;
	Db_Sort_Itr db_itr;
	Int_Map_Stat map_stat;
	Node_Data node_rec;

	//---- read the data file ----

	Show_Message (String ("Adding %s -- Record") % node_data_file.File_Type ());
	Set_Progress ();

	count = 0;

	for (db_itr = node_data_array.begin (); db_itr != node_data_array.end (); db_itr++) {
		Show_Progress ();

		node = db_itr->first;
		if (node_map.find (node) != node_map.end ()) continue;

		update_node_range.Add_Range (node, node);

		node_data_array.Read_Record (node);

		count++;
		node_data_file.Copy_Fields (node_data_array);

		node_rec.Clear ();
		node_rec.Node (node_data_file.Node ());
		node_rec.X (node_data_file.X ());
		node_rec.Y (node_data_file.Y ());
		node_rec.Z (node_data_file.Z ());
		node_rec.Subarea (node_data_file.Subarea ());
		node_rec.Notes (node_data_file.Notes ());

		map_stat = node_map.insert (Int_Map_Data (node_rec.Node (), (int) node_array.size ()));

		if (!map_stat.second) {
			Warning ("Duplicate Node Number = ") << node_rec.Node ();
			continue;
		} else {
			node_array.push_back (node_rec);
		}
	}
	End_Progress ();

	Print (2, String ("Number of %s Records Added = %d") % node_data_file.File_Type () % count);
}
Example #8
0
void RoutePrep::Transfer_Link (void)
{
	int link_index, dir_index, length, best_len, best;
	double dx, dy, speed;

	Ints_Itr st1_itr, st2_itr;
	Int_Itr a_itr, b_itr;
	Node_Data *a_ptr, *b_ptr;
	Link_Data link_rec;
	Dir_Data dir_rec;

	if (station_nodes.size () < 2) return;

	link_rec.Use (Use_Code ("WALK"));
	link_rec.Type (WALKWAY);
	link_rec.Divided (1);

	link_rec.Name ("Transfer Link");

	dir_rec.Lanes (1);
	dir_rec.Speed (Internal_Units (3.0, MPH));
	dir_rec.Capacity (1000);
	speed = UnRound (dir_rec.Speed ());

	for (st1_itr = station_nodes.begin (); st1_itr != station_nodes.end (); st1_itr++) {
		st2_itr = st1_itr + 1;
		if (st2_itr == station_nodes.end ()) break;

		for (a_itr = st1_itr->begin (); a_itr != st1_itr->end (); a_itr++) {
			a_ptr = &node_array [*a_itr];

			best = -1; 
			best_len = MAX_INTEGER;

			for (b_itr = st2_itr->begin (); b_itr != st2_itr->end (); b_itr++) {
				b_ptr = &node_array [*b_itr];

				dx = a_ptr->X () - b_ptr->X ();
				dy = a_ptr->Y () - b_ptr->Y ();

				length = DTOI (sqrt (dx * dx + dy * dy));

				if (length < best_len) {
					best = *b_itr;
					best_len = length;
				}
			}
			if (best < 0) continue;

			link_index = (int) link_array.size ();
			dir_index = (int) dir_array.size ();
	
			link_rec.Anode (*a_itr);
			link_rec.Bnode (best);
			link_rec.Length (best_len);
			dir_rec.Time0 (UnRound (best_len) / speed);

			link_rec.AB_Dir (dir_index);

			dir_rec.Link (link_index);
			dir_map.insert (Int_Map_Data (dir_rec.Link_Dir (), dir_index));
			dir_array.push_back (dir_rec);

			link_rec.BA_Dir (++dir_index);

			dir_rec.Dir (1);

			dir_map.insert (Int_Map_Data (dir_rec.Link_Dir (), dir_index));
			dir_array.push_back (dir_rec);

			link_rec.Link (new_link++);
			link_map.insert (Int_Map_Data (link_rec.Link (), link_index));
			link_array.push_back (link_rec);
		}
	}
}
Example #9
0
bool Relocate::Get_Link_Data (Link_File &file, Link_Data &link_rec, Dir_Data &ab_rec, Dir_Data &ba_rec)
{
	if (!Data_Service::Get_Link_Data (file, link_rec, ab_rec, ba_rec)) return (false);

	if (target_flag) {
		link_rec.Divided (2);
		ab_rec.Sign (2);
		ba_rec.Sign (2);

		Int_Map_Itr map_itr = link_map.find (link_rec.Link ());

		if (map_itr != link_map.end ()) {
			Dir_Data *dir_ptr;
			Link_Data *link_ptr = &link_array [map_itr->second];

			if (link_ptr->Anode () == link_rec.Anode () && link_ptr->Bnode () == link_rec.Bnode ()) {
				link_ptr->Divided (1);
				if (shape_flag) {
					Int_Map_Itr map_itr = target_shape_map.find (link_rec.Link ());
					if (map_itr != target_shape_map.end ()) {
						link_ptr->Shape (map_itr->second);
					}
				}
				if (link_ptr->AB_Dir () >= 0) {
					dir_ptr = &dir_array [link_ptr->AB_Dir ()];
					dir_ptr->Sign (1);
				}
				if (link_ptr->BA_Dir () >= 0) {
					dir_ptr = &dir_array [link_ptr->BA_Dir ()];
					dir_ptr->Sign (1);
				}
				return (false);
			} else if (link_ptr->Anode () == link_rec.Anode () || link_ptr->Bnode () == link_rec.Bnode ()) {
				link_ptr->Divided (3);
				if (shape_flag) {
					Int_Map_Itr map_itr = target_shape_map.find (link_rec.Link ());
					if (map_itr != target_shape_map.end ()) {
						link_ptr->Shape (map_itr->second);
					}
				}
			}
			if (link_rec.AB_Dir () >= 0) {
				link_rec.AB_Dir ((int) dir_array.size ());

				target_dir_map.insert (Int_Map_Data (ab_rec.Link_Dir (), link_rec.AB_Dir ()));
				dir_array.push_back (ab_rec);
			}
			if (link_rec.BA_Dir () >= 0) {
				link_rec.BA_Dir ((int) dir_array.size ());

				target_dir_map.insert (Int_Map_Data (ba_rec.Link_Dir (), link_rec.BA_Dir ()));
				dir_array.push_back (ba_rec);
			}
			target_link_map.insert (Int_Map_Data (link_rec.Link (), (int) link_array.size ()));
			link_array.push_back (link_rec);
			return (false);
		}
	} else {
		link_rec.Divided (0);
		ab_rec.Sign (0);
		ba_rec.Sign (0);
	}
	return (true);
}
Example #10
0
void NewFormat::Read_Routes (void)
{
	String field;
	int i, node, route, route_fld, mode_fld, ttime_fld, name_fld, note_fld, node_fld, dwell_fld, time_fld, spd_fld;
	int head_fld [24], offset_fld [24], ttim_fld [24];

	Int_Map_Stat map_stat;
	Int_Map_Itr map_itr;
	Route_Header route_rec, *route_ptr;

	//---- process the route header file ----

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

	route_fld = route_header.Required_Field ("ROUTE", "LINE");
	mode_fld = route_header.Required_Field ("MODE", "TYPE");
	ttime_fld = route_header.Optional_Field ("TTIME", "TIME", "MIN_TIME");
	name_fld = route_header.Optional_Field ("NAME", "ROUTE_NAME", "RTNAME", "DESCRIPTION");
	note_fld = route_header.Optional_Field (NOTES_FIELD_NAMES);
	
	for (i=1; i <= route_periods; i++) {
		field ("HEADWAY_%d") % i;
		head_fld [i-1] = route_header.Required_Field (field.c_str ());

		field ("OFFSET_%d") % i;
		offset_fld [i-1] = route_header.Optional_Field (field.c_str ());

		field ("TTIME_%d") % i;
		ttim_fld [i-1] = route_header.Optional_Field (field.c_str ());
		if (ttim_fld [i-1] < 0) ttim_fld [i-1] = ttime_fld;
	}

	while (route_header.Read ()) {
		Show_Progress ();
		route_rec.Clear ();

		route_rec.Route (route_header.Get_Integer (route_fld));
		if (route_rec.Route () == 0) continue;

		//---- set the parking type ----
		
		route_rec.Mode (Transit_Code (route_header.Get_String (mode_fld)));
		route_rec.Name (route_header.Get_String (name_fld));
		route_rec.Notes (route_header.Get_String (note_fld));

		switch (route_rec.Mode ()) {
			case LOCAL_BUS:
				route_rec.Veh_Type (4);
				break;
			case EXPRESS_BUS:
				route_rec.Veh_Type (5);
				break;
			case BRT:
				route_rec.Veh_Type (6);
				break;
			case STREETCAR:
				route_rec.Veh_Type (7);
				break;
			case LRT:
				route_rec.Veh_Type (8);
				break;
			case RAPIDRAIL:
				route_rec.Veh_Type (9);
				break;
			case REGIONRAIL:
				route_rec.Veh_Type (10);
				break;
		}
		if (veh_type_array.size () > 0) {
			route_rec.Veh_Type (VehType40_Map (route_rec.Veh_Type (), 0));

			if (route_rec.Veh_Type () > 0) {
				Int_Map_Itr map_itr = veh_type_map.find (route_rec.Veh_Type ());
				if (map_itr == veh_type_map.end ()) {
					Warning (String ("Transit Vehicle Type %d was Not Found") % route_rec.Veh_Type ());
					route_rec.Veh_Type (0);
				} else {
					route_rec.Veh_Type (map_itr->second);
				}
			} else {
				route_rec.Veh_Type (0);
			}
		}

		for (i=0; i < route_periods; i++) {
			Route_Period period_rec;

			period_rec.Headway (route_header.Get_Time (head_fld [i]));
			period_rec.Offset (route_header.Get_Time (offset_fld [i]));
			period_rec.TTime (route_header.Get_Integer (ttim_fld [i]));

			route_rec.periods.push_back (period_rec);
		}
		map_stat = route_map.insert (Int_Map_Data (route_rec.Route (), (int) route_nodes_array.size ()));

		if (!map_stat.second) {
			Warning ("Duplicate Route Number = ") << route_rec.Route ();
		} else {
			route_nodes_array.push_back (route_rec);
		}
	}
	End_Progress ();

	Print (2, String ("Number of %s Records = %d") % route_header.File_Type () % Progress_Count ());

	//---- process the route nodes file ----

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

	route_fld = route_nodes.Required_Field ("ROUTE", "LINE");
	node_fld = route_nodes.Required_Field ("NODE", "STOP");
	dwell_fld = route_nodes.Optional_Field ("DWELL", "DWELL_TIME", "STOP_TIME", "STOPTIME");
	time_fld = route_nodes.Optional_Field ("TIME", "TTIME", "RUNTIME", "RUN_TIME");
	spd_fld = route_nodes.Optional_Field ("SPEED", "SPD", "RUNSPD", "RUN_SPD", "RUN_SPEED");

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

		route = route_nodes.Get_Integer (route_fld);

		map_itr = route_map.find (route);
		if (map_itr == route_map.end ()) {
			Warning (String ("Route Nodes Route %d was Not Found in the Route Header File") % route);
			continue;
		}
		route_ptr = &route_nodes_array [map_itr->second];

		Route_Node node_rec;

		node = route_nodes.Get_Integer (node_fld);
		if (node < 0) {
			node_rec.Type (NO_STOP);
			node = -node;
		} else {
			node_rec.Type (STOP);
		}
		map_itr = node_map.find (node);
		if (map_itr == node_map.end ()) {
			Warning (String ("Route %d Node %d was Not Found") % route % node);
			continue;
		}
		node_rec.Node (map_itr->second);
		node_rec.Dwell (Dtime (route_nodes.Get_Integer (dwell_fld), SECONDS));
		node_rec.Time (Dtime (route_nodes.Get_Integer (time_fld), SECONDS));
		node_rec.Speed (Internal_Units (route_nodes.Get_Double (spd_fld), MPS));

		route_ptr->nodes.push_back (node_rec);
	}
	End_Progress ();

	Print (2, String ("Number of %s Records = %d") % route_nodes.File_Type () % Progress_Count ());
}
Example #11
0
void NetPrep::Split_Loops (void)
{
	int num_splits = 0;
	int index, x1, y1, x2, y2, id, node;
	double dx, dy, len, length, dist;

	Node_Data node_rec, *node_ptr;
	Link_Itr link_itr;
	Link_Data link_rec;
	Dir_Data *dir_ptr, dir_rec;
	Shape_Data *shape_ptr, shape_rec;
	XYZ xyz;
	XYZ_Itr xyz_itr, mid_itr;
	Int_Map_Itr map_itr;
	Int_Map_Stat map_stat;

	Show_Message ("Splitting Large Loops -- Record");
	Set_Progress ();
	
	for (id=0, link_itr = link_array.begin (); link_itr != link_array.end (); link_itr++, id++) {
		Show_Progress ();

		if (link_itr->Anode () != link_itr->Bnode ()) continue;

		//---- update the shape records ----

		map_itr = shape_map.find (link_itr->Link ());

		if (map_itr == shape_map.end ()) continue;

		shape_ptr = &shape_array [map_itr->second];

		shape_rec.Clear ();
		shape_rec.Link (new_link);

		length = link_itr->Length () / 2.0;
		node_ptr = &node_array [link_itr->Anode ()];

		x1 = node_ptr->X ();
		y1 = node_ptr->Y ();
		len = 0;

		//---- find the mid-point ----

		for (xyz_itr = mid_itr = shape_ptr->begin (); ; xyz_itr++) {
			if (xyz_itr != shape_ptr->end ()) {
				x2 = xyz_itr->x;
				y2 = xyz_itr->y;
			} else {
				node_ptr = &node_array [link_itr->Bnode ()];
				x2 = node_ptr->X ();
				y2 = node_ptr->Y ();
			}
			dx = x2 - x1;
			dy = y2 - y1;

			dist = sqrt (dx * dx + dy * dy);

			len += dist;
			if (len >= length || xyz_itr == shape_ptr->end ()) {
				mid_itr = xyz_itr;

				if (dist > 0) {
					node_rec.X (x1);
					node_rec.Y (y1);
				} else if (len == length) {
					node_rec.X (x2);
					node_rec.Y (y2);
				} else {
					dist = (len - length) / dist;
					node_rec.X ((int) (x1 + dist * dx + 0.5));
					node_rec.Y ((int) (y1 + dist * dy + 0.5));	
				}
				break;
			}
			x1 = x2;
			y1 = y2;
		}

		if (mid_itr != shape_ptr->end ()) {
			shape_rec.assign (mid_itr, shape_ptr->end ());

			shape_map.insert (Int_Map_Data (shape_rec.Link (), (int) shape_array.size ()));
			shape_array.push_back (shape_rec);

			shape_ptr->erase (mid_itr);
		}

		//---- add the new node ----

		node_rec.Node (new_node);
		node_rec.Z (0);
		node_rec.Count (2);
		node = (int) node_array.size ();

		map_stat = node_map.insert (Int_Map_Data (new_node, node));
		if (!map_stat.second) {
			Warning ("Duplicate Node Number = ") << new_node;
		} else {
			node_array.push_back (node_rec);
		}

		//---- split the link record ----

		link_itr->Length (link_itr->Length () / 2);

		link_rec = *link_itr;

		link_itr->Bnode (node);

		link_rec.Link (new_link);
		link_rec.Anode (node);

		index = (int) link_array.size ();

		//---- get the ab link ----

		if (link_itr->AB_Dir () >= 0) {
			dir_ptr = &dir_array [link_itr->AB_Dir ()];

			dir_ptr->Time0 (dir_ptr->Time0 () / 2);

			dir_rec = *dir_ptr;
			dir_rec.Link (index);

			link_rec.AB_Dir ((int) dir_array.size ());

			dir_array.push_back (dir_rec);
		}

		//---- get the ba link ----

		if (link_itr->BA_Dir () >= 0) {
			dir_ptr = &dir_array [link_itr->BA_Dir ()];

			dir_ptr->Time0 (dir_ptr->Time0 () / 2);

			dir_rec = *dir_ptr;
			dir_rec.Link (index);

			link_rec.BA_Dir ((int) dir_array.size ());

			dir_array.push_back (dir_rec);
		}
		map_stat = link_map.insert (Int_Map_Data (link_rec.Link (), index));

		if (!map_stat.second) {
			Warning ("Duplicate Link Number = ") << link_rec.Link ();
		} else {
			link_array.push_back (link_rec);
			link_itr = link_array.begin () + id;

			if (link_node_flag) {
				Link_Nodes rec;
				rec.link = link_rec.Link ();
				link_node_array.push_back (rec);
			}
		}
		new_node++;
		new_link++;
		num_splits++;
	}
	End_Progress ();

	Print (2, "Number of Large Loop Splits = ") << num_splits;
}
Example #12
0
void TransimsNet::Zone_Access (void)
{
	int j, link, min_len, area_type, zone, zone_num, location, parking;
	bool ab_flag, dir_flag;

	Link_Itr link_itr;
	Node_Data *node_ptr;
	Location_Data loc_rec;
	Parking_Data park_rec;
	Int_Map_Stat map_stat;
	Int_Map_Itr map_itr;
	Park_Detail_Itr detail_itr;
	Parking_Nest park_nest;
	Zone_Itr zone_itr;
	Access_Data access_rec;

	naccess = (int) access_map.size ();

	naccess = (int) access_array.size ();
	if (naccess > 0) {
		Int_Map_Itr map_itr = --access_map.end ();
		naccess = ((map_itr->first / 10) + 1) * 10 - 1;
	}

	Show_Message (String ("Creating Zone Access Points -- Record"));
	Set_Progress ();

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

		if (link_itr->Type () != EXTERNAL) continue;
		area_type = link_itr->Area_Type ();

		loc_rec.Link (link);
		loc_rec.Setback (loc_setback);

		park_rec.Link (link);

		min_len = external_offset;
		if (link_itr->Length () < external_offset * 2) min_len = link_itr->Length () / 2;

		node_ptr = &node_array [link_itr->Anode ()];
		zone = node_ptr->Node ();

		node_ptr = &node_array [link_itr->Bnode ()];

		if (zone < node_ptr->Node ()) {
			ab_flag = true;
		} else {
			ab_flag = false;
			zone = node_ptr->Node ();
		}
		map_itr = zone_map.find (zone);
		if (map_itr == zone_map.end ()) {
			Warning (String ("External Link %d Zone %d is Out of Range") % link_itr->Link () % zone);
			zone_num = -1;
		} else {
			zone_num = map_itr->second;
		}
		park_rec.Type (BOUNDARY);
		park_rec.Notes ("External Station");
		dir_flag = true;

		//---- insert activity locations ----

		map_itr = zone_centroid.find (zone);

		if (map_itr == zone_centroid.end ()) {
			loc_rec.Location (++location_id);

			location = (int) location_array.size ();

			zone_centroid.insert (Int_Map_Data (zone, location));

			if (ab_flag) {
				loc_rec.Dir (0);
			} else {
				loc_rec.Dir (1);
			}
			loc_rec.Offset (min_len);
			loc_rec.Notes ("External");
			loc_rec.Zone (zone_num);

			//---- insert the location record ----

			map_stat = location_map.insert (Int_Map_Data (location_id, location));

			if (!map_stat.second) continue;

			location_array.push_back (loc_rec);

		} else {
			location = map_itr->second;
		}

		for (j=0; j < 2; j++) {
			if (j == 0) {
				if (dir_flag && link_itr->AB_Dir () < 0) continue;

				if (ab_flag) {
					park_rec.Offset (min_len);
				} else {
					park_rec.Offset (link_itr->Length () - min_len);
				}
			} else {
				if (dir_flag && link_itr->BA_Dir () < 0) continue;

				if (ab_flag) {
					park_rec.Offset (link_itr->Length () - min_len);
				} else {
					park_rec.Offset (min_len);
				}
			}

			//---- add a parking lot ----

			park_rec.Parking (++parking_id);

			parking = (int) parking_array.size ();

			park_rec.Dir (j);

			map_stat = parking_map.insert (Int_Map_Data (parking_id, parking));

			if (!map_stat.second) continue;

			if (details_flag) {
				park_rec.clear ();

				for (detail_itr = parking_details.begin (); detail_itr != parking_details.end (); detail_itr++) {
					if (detail_itr->Area_Type1 () <= area_type && area_type <= detail_itr->Area_Type2 ()) {
						park_nest.Start (detail_itr->Start ());
						park_nest.End (detail_itr->End ());
						park_nest.Use (detail_itr->Use ());
						park_nest.Time_In (detail_itr->Time_In ());
						park_nest.Time_Out (detail_itr->Time_Out ());
						park_nest.Hourly (detail_itr->Hourly ());
						park_nest.Daily (detail_itr->Daily ());

						park_rec.push_back (park_nest);
					}
				}
			}
			parking_array.push_back (park_rec);

			//---- add the access link ----

			access_rec.Link (++naccess);
			access_rec.From_Type (LOCATION_ID);
			access_rec.From_ID (location);
			access_rec.To_Type (PARKING_ID);
			access_rec.To_ID (parking);
			access_rec.Dir (2);
			access_rec.Time (10);
			access_rec.Cost (0);
			access_rec.Notes ("Zone Access");

			access_map.insert (Int_Map_Data (access_rec.Link (), (int) access_array.size ()));
			access_array.push_back (access_rec);
		}
	}
	End_Progress ();
}
Example #13
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);
}
Example #14
0
bool Path_Builder::Best_Lane_Use (int index, Dtime time, double len_factor, Dtime &ttime, Dtime &delay, int &cost, int &group)
{
	int i, num, tt, cst, imp, lanes, type, grp, use_type [2], costs [2], best [2];
	Dtime ttimes [2], delays [2];
	double factor;

	Dir_Data *dir_ptr;
	Lane_Use_Data *use_ptr;
	Int_Map_Stat map_stat;
	Lane_Use_Period *period_ptr;
	Link_Dir_Data *use_index;

	dir_ptr = &exe->dir_array [index];

	if (path_param.delay_flag) {
		ttimes [0] = exe->perf_period_array.Travel_Time (index, time, len_factor, forward_flag);
		if (dir_ptr->Use_Index () >= 0) {
			ttimes [1] = exe->perf_period_array.Travel_Time (dir_ptr->Use_Index (), time, len_factor, forward_flag);
		}
	}
	if (ttimes [0] < 0 && ttimes [1] <= 0) return (false);

	if (ttimes [0] == 0) ttimes [0] = dir_ptr->Time0 ();
	if (ttimes [1] == 0) ttimes [1] = dir_ptr->Time0 ();

	ttime = ttimes [0];
	delay = 0;
	cost = group = 0;

	//---- find the time period ----

	index = dir_ptr->First_Lane_Use ();
	if (index < 0) return (true);

	for (period_ptr = &exe->use_period_array [index]; ; period_ptr = &exe->use_period_array [++index]) {
		if (period_ptr->Start () <= time && time < period_ptr->End ()) break;
		if (period_ptr->Periods () == 0) return (true);
	}

	//---- set the lane group data ----

	best [0] = best [1] = 0;
	delays [0] = delays [1] = 0;
	costs [0] = costs [1] = 0;

	use_type [0] = (period_ptr->Lanes (0) == 0) ? PROHIBIT : APPLY;
	use_type [1] = (period_ptr->Lanes (1) == 0) ? PROHIBIT : APPLY;

	type = path_param.traveler_type;

	num = period_ptr->Records ();
	index = period_ptr->Index ();

	for (i=0; i < num; i++, index++) {
		use_index = &exe->use_period_index [index];
		use_ptr = &exe->lane_use_array [use_index->Link ()];

		grp = use_index->Dir ();
		if (use_type [grp] == PROHIBIT) continue;

		lanes = use_ptr->High_Lane () - use_ptr->Low_Lane () + 1;

		if (lanes >= period_ptr->Lanes (grp)) {
			if (path_param.veh_type < 0 || use_ptr->Min_Veh_Type () < 0 || 
				(use_ptr->Min_Veh_Type () <= path_param.veh_type && path_param.veh_type <= use_ptr->Max_Veh_Type ())) {

				if (type == 0 || use_ptr->Min_Traveler () < 0 || 
					(use_ptr->Min_Traveler () <= type && type <= use_ptr->Max_Traveler ())) {

					if (Use_Permission (use_ptr->Use (), path_param.use)) {
						if (use_ptr->Type () == APPLY) {
							cst = use_ptr->Toll ();
							tt = use_ptr->Min_Delay ();
							if (use_ptr->Max_Delay () > use_ptr->Min_Delay ()) {
								map_stat = lane_use_delay.insert (Int_Map_Data (use_index->Link_Dir (), 0));
								if (map_stat.second) {
									map_stat.first->second = DTOI ((use_ptr->Max_Delay () - use_ptr->Min_Delay ()) * path_param.random.Probability ());
								}
								tt += map_stat.first->second;
							}
							imp = Resolve (tt * path_param.value_time + cst * path_param.value_cost);
							if (imp < best [grp] || best [grp] == 0) {
								delays [grp] = tt;
								costs [grp] = cst;
								best [grp] = imp;
							}
							use_type [grp] = APPLY;
						} else if (use_ptr->Type () == PROHIBIT) {
							use_type [grp] = PROHIBIT;
						} else if (use_ptr->Type () == REQUIRE) {
							use_type [1-grp] = PROHIBIT;
						}
						continue;
					}
				}
			}
			if (use_ptr->Type () == LIMIT) {
				use_type [grp] = PROHIBIT;
			}
		}
	}

	//---- select the best lane group ----

	if (use_type [0] == PROHIBIT && use_type [1] == PROHIBIT) return (false);

	if (use_type [0] == APPLY && use_type [1] == APPLY) {
		best [0] += Resolve (ttimes [0] * path_param.value_time);
		best [1] += Resolve (ttimes [1] * path_param.value_time);

		if (random_flag) {
			factor = 1.0 + path_param.random_imped * (path_param.random.Probability () - 0.5) / 100.0;
			best [1] = DTOI (best [1] * factor);
		}
		if (best [1] > 0 && best [0] > 0) {
			group = (best [1] < best [0]) ? 1 : 0;
		} else {
			group = 0;
		}
	} else if (use_type [0] == APPLY) {
		group = 0;
	} else {
		group = 1;
	}
	delay = delays [group];
	cost = costs [group];
	ttime = ttimes [group];
	return ((ttime > 0));
}
Example #15
0
void IntControl::Read_Signal (void)
{
	int signal, node, num;
	String buffer;
	Strings nodes;

	Signal_Data signal_rec;
	Int_Map_Itr map_itr;
	Int_Map_Stat map_stat;
	Int_Set_Stat set_stat;
	Str_Itr str_itr;
	Int_Itr node_itr;
	Node_Data *node_ptr;

	//---- store the signal data ----

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

	num_new = num_update = 0;

	while (signal_file.Read (false)) {
		Show_Progress ();

		//---- check the signal number ----

		signal = signal_file.Signal ();
		if (signal == 0) continue;
		
		map_itr = signal_map.find (signal);
		if (map_itr != signal_map.end ()) {
			if (update_flag) {
				set_stat = update_signal.insert (signal);
				if (!set_stat.second) {
					Warning ("Duplicate Signal Number = ") << signal;
				}
				num_update++;
				nsignal++;
			} else {
				Warning (String ("Signal %d Already Exists") % signal);
			}
			goto read_nest;
		}

		//---- gather the warrant signal data ----

		signal_rec.Clear ();

		signal_rec.Signal (signal);
		signal_rec.Group (signal_file.Group ());

		buffer = signal_file.Nodes ();
		if (buffer.empty ()) goto read_nest;

		num = buffer.Parse (nodes, "|+/");
		if (num == 0) goto read_nest;

		signal_rec.nodes.reserve (num);

		for (str_itr = nodes.begin (); str_itr != nodes.end (); str_itr++) {
			node = str_itr->Integer ();
			if (node <= 0) break;

			map_itr = node_map.find (node);
			if (map_itr == node_map.end ()) {
				Warning (String ("Signal %d Node %d was Not Found") % signal_rec.Signal () % node);
				continue;
			}
			node_ptr = &node_array [map_itr->second];

			if (node_ptr->Control () >= 0 && signal_file.Version () > 40) {
				Warning (String ("Node %d is assigned to multiple signals") % node);
				continue;
			} else if (node_ptr->Control () < -1) {
				Warning (String ("Node %d has a Sign/Signal control conflict") % node);
				continue;
			}
			signal_rec.nodes.push_back (map_itr->second);
		}
		if (signal_rec.nodes.size () == 0) goto read_nest;

		//---- insert the signal warrant ----

		num = (int) signal_array.size ();

		map_stat = signal_map.insert (Int_Map_Data (signal, num));

		if (!map_stat.second) {
			Warning ("Duplicate Signal Number = ") << signal_rec.Signal ();
			goto read_nest;
		}

		//---- set the node controls ----

		for (node_itr = signal_rec.nodes.begin (); node_itr != signal_rec.nodes.end (); node_itr++) {
			node_ptr = &node_array [*node_itr];
			node_ptr->Control (num);
		}
		signal_array.push_back (signal_rec);
		num_new++;
		nsignal++;

read_nest:
		for (num = signal_file.Times (); num > 0; num--) {
			if (!signal_file.Read (true)) {
				Error (String ("Number of Time Records for Signal %d") % signal);
			}
			Show_Progress ();
		}
	}
	End_Progress ();

	signal_file.Close ();

	Print (2, String ("Number of %s Records = %d") % signal_file.File_Type () % Progress_Count ());
	if (num_new > 0) {
		Print (1, "Number of New Signal Records = ") << num_new;
	}
	if (num_update > 0) {
		Print (1, "Number of Signal Updates = ") << num_update;
	}
}
Example #16
0
void LinkSum::Zone_Summary (void)
{
	int i, j, z, count, link, nrec, nzone, index, flow_index;
	double factor, vmt, vht, flow;
	Dtime time;

	Link_Data *link_ptr;
	Link_Perf_Period_Itr period_itr;
	Flow_Time_Data flow_data;

	Link_Loc_Map_Itr loc_itr, first_itr;
	Doubles dbl;
	Doubles_Itr itr;
	Int_Map_Itr map_itr;

	Show_Message ("Summarize Activity Locations on Links -- Record");
	Set_Progress ();

	link = count = nrec = 0;
	link_ptr = 0;

	for (loc_itr = first_itr = link_location.begin (); loc_itr != link_location.end (); loc_itr++) {
		Show_Progress ();

		if (loc_itr->second.link == link) {
			count++;
		} else {
			if (link > 0) {
				link_ptr = &link_array [link];

				if (!select_flag || link_ptr->Use () != 0) {
					first_itr->second.count = count;
				}
			}
			first_itr = loc_itr;
			link = loc_itr->second.link;
			count = 1;
		}
	}
	Set_Progress ();

	//---- set the count data for all records ----

	link = 0;

	for (loc_itr = link_location.begin (); loc_itr != link_location.end (); loc_itr++) {
		Show_Progress ();

		if (loc_itr->second.link == link) {
			loc_itr->second.count = count;
		} else {
			link = loc_itr->second.link;
			count = loc_itr->second.count;
		}
		if (count > 0) {
			nrec += count;
			zone_list.insert (Int_Map_Data (loc_itr->second.zone, (int) zone_list.size ()));
		}
	}
	nzone = (int) zone_list.size ();

	Break_Check (4);

	Print (2, "Number of Link Locations = ") << nrec;
	Print (1, "Number of Selected Zones = ") << nzone;

	//---- allocate space for zone summaries ----

	zone_vmt.assign (num_inc, dbl);
	zone_vht.assign (num_inc, dbl);

	for (itr = zone_vmt.begin (); itr != zone_vmt.end (); itr++) {
		itr->assign (nzone, 0.0);
	}
	for (itr = zone_vht.begin (); itr != zone_vht.end (); itr++) {
		itr->assign (nzone, 0.0);
	}

	//---- summarizes link data by zone ----

	link = 0;

	for (loc_itr = link_location.begin (); loc_itr != link_location.end (); loc_itr++) {
		Show_Progress ();

		if (loc_itr->second.count == 0) continue;
		
		if (loc_itr->second.link != link) {
			link = loc_itr->second.link;
			link_ptr = &link_array [link];
		}
		map_itr = zone_list.find (loc_itr->second.zone);
		if (map_itr == zone_list.end ()) continue;

		z = map_itr->second;

		factor = UnRound (link_ptr->Length ()) / loc_itr->second.count; 

		//---- process each direction ----

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

			for (j=0, period_itr = link_perf_array.begin (); period_itr != link_perf_array.end (); period_itr++, j++) {
				flow_data = period_itr->Total_Flow_Time (index, flow_index);

				flow = flow_data.Flow ();
				time = flow_data.Time ();

				if (flow > 0) {
					vmt = flow * factor;
					vht = flow * time / loc_itr->second.count;

					zone_vmt [j] [z] += vmt;
					zone_vht [j] [z] += vht;
				}
			}
		}
	}
	End_Progress ();
}
Example #17
0
void TransitDiff::Read_Line (void)
{
	int i, num, route;
	bool keep_flag;
	Int_Map_Stat map_stat;
	Int_Map_Itr map_itr;
	Line_Data line_rec;

	//---- store the route data ----

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

	while (compare_line_file.Read (false)) {
		Show_Progress ();

		line_rec.Clear ();
		keep_flag = true;

		route = compare_line_file.Route ();
		if (route == 0) keep_flag = false;
		line_rec.Route (route);

		if (compare_line_file.Stops () < 2) keep_flag = false;

		line_rec.Mode (compare_line_file.Mode ());
		line_rec.Type (compare_line_file.Type ());
		line_rec.Name (compare_line_file.Name ());

		map_itr = veh_type_map.find (line_rec.Type ());
		if (map_itr == veh_type_map.end ()) {
			Warning (String ("Transit Route %d Vehicle Type %d was Not Found") % route % line_rec.Type ());
		} else {
			line_rec.Type (map_itr->second);
		}

		num = compare_line_file.Num_Nest ();
		if (num > 0) line_rec.reserve (num);

		for (i=1; i <= num; i++) {
			if (!compare_line_file.Read (true)) {
				Error (String ("Number of Stop Records for Route %d") % compare_line_file.Route ());
			}
			Show_Progress ();

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

			int zone, stop;
			Line_Stop line_stop;
			Int_Map_Itr itr;

			stop = compare_line_file.Stop ();

			itr = compare_stop_map.find (stop);
			if (itr == compare_stop_map.end ()) {
				Warning (String ("Transit Stop %d on Route %d was Not Found") % stop % route);
				continue;
			}
			line_stop.Stop (itr->second);
			zone = compare_line_file.Zone ();

			line_stop.Zone (zone);
			line_stop.Time_Flag ((compare_line_file.Time_Flag () > 0));
			
			line_rec.push_back (line_stop);
		}
		if (keep_flag) {
			map_stat = compare_line_map.insert (Int_Map_Data (line_rec.Route (), (int) compare_line_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Route Number = ") << line_rec.Route ();
			} else {
				compare_line_array.push_back (line_rec);
			}
		}
	}
	End_Progress ();
	compare_line_file.Close ();

	Print (2, String ("Number of %s Records = %d") % compare_line_file.File_Type () % Progress_Count ());

	num = (int) compare_line_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of %s Data Records = %d") % compare_line_file.File_ID () % num);
	}
}
Example #18
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 ();
}
Example #19
0
void Data_Service::Read_Veh_Types (Veh_Type_File &file)
{
	int num, cell_size;
	double length, min_len;
	Veh_Type_Data veh_type_rec;
	Int_Map_Stat map_stat;
	Veh_Type_Itr veh_type_itr;

	//---- store the vehicle type data ----

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

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

		veh_type_rec.Clear ();

		if (Get_Veh_Type_Data (file, veh_type_rec)) {
			map_stat = veh_type_map.insert (Int_Map_Data (veh_type_rec.Type (), (int) veh_type_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Vehicle Type Number = ") << veh_type_rec.Type ();
				continue;
			} else {
				veh_type_array.push_back (veh_type_rec);
			}
		}
	}
	End_Progress ();
	file.Close ();
	
	Print (2, String ("Number of %s Records = %d") % file.File_Type () % Progress_Count ());

	num = (int) veh_type_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of %d Data Records = %d") % file.File_ID () % num);
	}
	if (num > 0) System_Data_True (VEHICLE_TYPE);

	//---- set the PCE factor ----

	num = Use_Code ("CAR");
	length = 0.0;
	min_len = MAX_INTEGER;

	for (veh_type_itr = veh_type_array.begin (); veh_type_itr != veh_type_array.end (); veh_type_itr++) {
		if ((veh_type_itr->Use () & num) != 0) {
			length = veh_type_itr->Length ();
			break;
		}
		if (veh_type_itr->Length () < min_len) min_len = veh_type_itr->Length ();
	}
	if (length <= 0.0) length = min_len;
	if (length <= 0.0) return;
	cell_size = DTOI (min_len);

	for (veh_type_itr = veh_type_array.begin (); veh_type_itr != veh_type_array.end (); veh_type_itr++) {
		veh_type_itr->PCE (Round (veh_type_itr->Length () / length));
		veh_type_itr->Cells (MAX (((veh_type_itr->Length () + cell_size / 2) / cell_size), 1));
	}
}
Example #20
0
void ExportNet::New_Links (void)
{
	int i, node, link, new_link, count, length, index, park_len, speed, time, dir;
	double offset, len, factor;

	Int_Map_Itr map_itr;
	Link_Data link_data, link_rec;
	Split_Itr split_itr, split2_itr;
	Link_Split_Itr link_itr;
	Points points;
	Dir_Data dir_ab, dir_ba, dir_rec;
	Shape_Data shape_rec;
	Points_Itr pt_itr;
	XYZ xyz;
	
	park_len = Round (Internal_Units (20, METERS)); 
	speed = Round (Internal_Units (5, MPS));
	time = Round (Internal_Units (20/5, SECONDS));

	map_itr = --link_map.end ();
	link = map_itr->first;
	new_link = ((link + 1) / 100 + 1) * 100;
	count = 0;

	//---- split links ----

	Set_Progress ();

	for (link=0, link_itr = link_splits.begin (); link_itr != link_splits.end (); link_itr++, link++) {
		if (link_itr->size () == 0) continue;
		Show_Progress ();

		link_data = link_array [link];

		if (link_data.AB_Dir () >= 0) {
			dir_ab = dir_array [link_data.AB_Dir ()];
		}
		if (link_data.BA_Dir () >= 0) {
			dir_ba = dir_array [link_data.BA_Dir ()];
		}
		offset = 0.0;

		for (split_itr = split2_itr = link_itr->begin (); split_itr != link_itr->end (); split2_itr = split_itr++) {
			link_rec = link_data;
			link_rec.Name (link_data.Name ());

			index = (int) link_array.size ();
			link_rec.Divided (3);

			split_itr->link = index;
			link_rec.Link (new_link++);

			if ((split_itr + 1) != link_itr->end ()) {
				link_rec.Bnode (split_itr->node);
				length = split_itr->offset;
				link_rec.Boffset (0);
			} else {
				length = link_rec.Length ();
			}
			if (split_itr != split2_itr) {
				link_rec.Anode (split2_itr->node);
				length -= split2_itr->offset;
				link_rec.Aoffset (0);
				offset = UnRound (split2_itr->offset);
			}
			len = UnRound (length);
			link_rec.Length (length);
			factor = (double) length / link_data.Length ();

			//---- split the link shape ----

			if (link_data.Shape () >= 0) {
				Link_Shape (&link_data, 0, points, offset, len);

				if (points.size () > 2) {
					shape_rec.Clear ();
					shape_rec.Link (link_rec.Link ());

					for (pt_itr = points.begin () + 1; pt_itr != points.end (); pt_itr++) {
						xyz.x = Round (pt_itr->x);
						xyz.y = Round (pt_itr->y);
						xyz.z = Round (pt_itr->z);

						shape_rec.push_back (xyz);
					}
					link_rec.Shape ((int) shape_array.size ());
					shape_map.insert (Int_Map_Data (shape_rec.Link (), link_rec.Shape ()));
					shape_array.push_back (shape_rec);
				} else {
					link_rec.Shape (-1);
				}
			}

			//---- process each direction ----

			if (link_data.AB_Dir () >= 0) {
				dir_rec = dir_ab;
				dir_rec.Link (index);
				dir_rec.First_Connect_From (-1);
				dir_rec.First_Connect_To (-1);

				if ((split_itr + 1) != link_itr->end ()) {
					dir_rec.First_Pocket (-1);
				}
				dir_rec.Time0 ((int) (dir_rec.Time0 () * factor + 0.5));

				dir = (int) dir_array.size ();
				link_rec.AB_Dir (dir);

				dir_map.insert (Int_Map_Data (dir_rec.Link_Dir (), dir));
				dir_array.push_back (dir_rec);
			} else {
				link_rec.AB_Dir (-1);
			}

			if (link_data.BA_Dir () >= 0) {
				dir_rec = dir_ba;
				dir_rec.Link (index);
				dir_rec.First_Connect_From (-1);
				dir_rec.First_Connect_To (-1);
			
				if (split_itr != split2_itr) {
					dir_rec.First_Pocket (-1);
				}
				dir_rec.Time0 ((int) (dir_rec.Time0 () * factor + 0.5));
				
				dir = (int) dir_array.size ();
				link_rec.BA_Dir (dir);

				dir_map.insert (Int_Map_Data (dir_rec.Link_Dir (), dir));
				dir_array.push_back (dir_rec);
			} else {
				link_rec.BA_Dir (-1);
			}

			//---- insert the link ----

			link_map.insert (Int_Map_Data (link_rec.Link (), index));
			link_array.push_back (link_rec);
			count++;
		}
	}

	//---- add parking connection links ----

	Set_Progress ();

	for (link=0, link_itr = link_splits.begin (); link_itr != link_splits.end (); link_itr++, link++) {
		if (link_itr->size () == 0) continue;
		Show_Progress ();

		for (split_itr = split2_itr = link_itr->begin (); split_itr != link_itr->end (); split2_itr = split_itr++) {

			for (i=0; i < 2; i++) {
				index = (int) link_array.size ();

				if (i == 0) {
					node = split_itr->park_ab;
					if (node < 0) continue;
					split_itr->link_ab = index;
				} else {
					node = split_itr->park_ba;
					if (node < 0) continue;
					split_itr->link_ba = index;
				}
				link_rec.Clear ();
				link_rec.Divided (3);

				link_rec.Link (new_link++);
				link_rec.Anode (split_itr->node);
				link_rec.Bnode (node);
				link_rec.Length (park_len);
				link_rec.Use (ANY);
				link_rec.Type (LOCAL);
				link_rec.Name ("Parking");
				
				//---- insert directional data ----

				dir_rec.Clear ();
				dir_rec.Link (index);
				dir_rec.Dir (0);
				dir_rec.Lanes (1);
				dir_rec.Speed (speed);
				dir_rec.Capacity (300);
				dir_rec.Time0 (time);
				dir_rec.Sign (YIELD_SIGN);

				dir = (int) dir_array.size ();
				link_rec.AB_Dir (dir);

				dir_map.insert (Int_Map_Data (dir_rec.Link_Dir (), dir));
				dir_array.push_back (dir_rec);

				dir_rec.Dir (1);
				dir_rec.Sign (NO_CONTROL);
			
				dir = (int) dir_array.size ();
				link_rec.BA_Dir (dir);

				dir_map.insert (Int_Map_Data (dir_rec.Link_Dir (), dir));
				dir_array.push_back (dir_rec);

				//---- insert the link ----

				link_map.insert (Int_Map_Data (link_rec.Link (), index));
				link_array.push_back (link_rec);
				count++;
			}
		}
	}
	Print (2, "Number of New Link Records = ") << count;
}