コード例 #1
0
bool SideFriction::Lane_Use_Processing (Db_File *fh)
{
	Lane_Use_Data *lane_use_ptr;

	Lane_Use_File *file = (Lane_Use_File *) fh;

	if (Network_Service::Lane_Use_Processing (file)) {
		new_file->Copy_Fields (file);

		lane_use_ptr = lane_use_data.New_Record ();

		new_file->Link (lane_use_ptr->Link ());
		new_file->Dir (lane_use_ptr->Dir ());
		new_file->Lane (lane_use_ptr->Lane ());
		new_file->Use (Use_Code (lane_use_ptr->Use ()));
		new_file->Type (Restrict_Code ((Restrict_Type) lane_use_ptr->Type ()));
		new_file->Start (time_step.Format_Step (Resolve (lane_use_ptr->Start ())));
		new_file->End (time_step.Format_Step (Resolve (lane_use_ptr->End ())));
		new_file->Offset (UnRound (lane_use_ptr->Offset ()));
		new_file->Length (UnRound (lane_use_ptr->Length ()));

		if (!new_file->Write ()) {
			Error ("Writing %s", new_file->File_Type ());
		}
		num_use++;
		return (true);
	}
	return (false);
}
コード例 #2
0
ファイル: Stop_Delay.cpp プロジェクト: kravitz/transims4
void SideFriction::Stop_Delay (void)
{
	int stop, stops, run, runs, dir, route, period, lane, ln, time;
	int stop_id, offset, low, high, length, start, link_dir, num;
	char buffer [FIELD_BUFFER];

	Stop_Data *stop_ptr;
	Line_Data *line_ptr;
	Link_Data *link_ptr;
	Dir_Data *dir_ptr;
	Offset_Data *offset_ptr;
	Link_Use_Data *use_ptr;

	Show_Message ("Estimate Transit Stop Delay -- Route");
	Set_Progress (100);

	//---- read each route ----

	for (line_ptr = line_data.First_Key (); line_ptr; line_ptr = line_data.Next_Key ()) {
		Show_Progress ();

		route = line_ptr->Route ();

		stops = line_ptr->Stops ();
		runs = line_ptr->Runs ();

		if (route_flag) {
			if (!select_routes.In_Range (route)) continue;
		}
		if (!select_modes [line_ptr->Mode ()]) continue;

		for (stop=1; stop <= stops; stop++) {

			stop_id = line_ptr->Stop (stop);

			//---- check for stop in the subarea ----

			if (subarea_flag) {
				offset_ptr = stop_offset.Get (stop_id);
				if (offset_ptr == NULL) continue;

				if (!In_Polygon (offset_ptr->X (), offset_ptr->Y (), &select_subarea.points)) continue;
			}

			//---- find the stop link ----

			stop_ptr = stop_data.Get (stop_id);

			if (stop_ptr == NULL) {
				Warning ("Route %d Stop %d was Not Found", route, line_ptr->Stop (stop));
				continue;
			}

			link_ptr = link_data.Get (stop_ptr->Link ());

			if (link_ptr == NULL) {
				Warning ("Stop Link %d was Not Found", stop_ptr->Link ());
				continue;
			}

			if (stop_ptr->Dir () == 0) {
				dir = link_ptr->AB_Dir ();
				offset = stop_ptr->Offset ();
				low = link_ptr->Aoffset ();
				high = link_ptr->Boffset ();
			} else {
				dir = link_ptr->BA_Dir ();
				offset = link_ptr->Length () - stop_ptr->Offset ();
				low = link_ptr->Boffset ();
				high = link_ptr->Aoffset ();
			}
			dir_ptr = dir_data [dir];

			if (dir_ptr == NULL) {
				Warning ("Stop Link %d Direction %d was Not Found", stop_ptr->Link (), stop_ptr->Dir ());
				continue;
			}
			link_dir = stop_ptr->Link_Dir ();
			lane = dir_ptr->Left () + dir_ptr->Thru ();
			high = link_ptr->Length () - high;

			length = stop_length;
			offset -= length;
			if (offset < low) {
				offset = low;
				if (offset + length > high) length = high - offset;
			} else if (offset + length > high) {
				offset = high - length;
				if (offset < low) {
					offset = low;
					length = high - low;
				}
			}

			//---- add a lane blockage for each run ----

			for (run=1; run < runs; run++) {

				time = Resolve (line_ptr->Schedule (run, stop));

				period = transit_periods.In_Index (time);

				if (period == 0) continue;

				start = time - Resolve (stop_times [period]);
				if (start < 0) start = 0;

				ln = lane;

				if (dir_ptr->TOD_List () > 0) {
					for (num = dir_ptr->TOD_List (); num; num = use_ptr->TOD_List ()) {
						use_ptr = link_use_data [num]; 

						if (use_ptr->Length () > 0) continue;
						if (use_ptr->Low_Lane () > lane || lane > use_ptr->High_Lane ()) continue;
						if (Use_Permission (use_ptr->Use (), BUS)) continue;
						if (use_ptr->End () < Round (start) || use_ptr->Start () > Round (time)) continue;
						ln = use_ptr->Low_Lane () - 1;
						break;
					}
				}
				if (ln <= dir_ptr->Left ()) continue;

				new_file->Link (stop_ptr->Link ());
				new_file->Dir (stop_ptr->Dir ());
				new_file->Lane (ln);
				new_file->Use (Use_Code (Use_Code ("BUS")));
				new_file->Type (Restrict_Code (ONLY));
				new_file->Start (time_step.Format_Step (start));
				new_file->End (time_step.Format_Step (time));
				new_file->Offset (UnRound (offset));
				new_file->Length (UnRound (length));

				str_fmt (buffer, sizeof (buffer), "Route %d Stop %d Run %d", route, stop_id, run); 

				new_file->Notes (buffer);

				if (!new_file->Write ()) {
					Error ("Writing %s", new_file->File_Type ());
				}
				new_use++;
			}
		}
	}
	End_Progress ();
}
コード例 #3
0
ファイル: Network_Prep.cpp プロジェクト: kravitz/transims5
void Sim_Method::Network_Prep (void)
{
	int i, dir_index, index, dir, record, next, lanes, use_code, min_lane, max_lane, num;
	int j, k, n, cells, cell_out, bnode, *list, bear1, bear2, change, capacity, first [20];
	double factor;
	bool flag;

	Link_Data *link_ptr;
	Dir_Data *dir_ptr, *app_ptr;
	Node_Itr node_itr;
	Connect_Data *connect_ptr, *cross_ptr;
	Sim_Dir_Itr sim_dir_itr;
	Sim_Lane_Ptr sim_lane_ptr;
	Sim_Cap_Ptr sim_cap_ptr;
	Sim_Connection *sim_con_ptr;
	Lane_Use_Data *use_ptr;
	Lane_Use_Period *period_ptr;
	Link_Dir_Data *use_index;
	Pocket_Data *pocket_ptr;
	Lane_Map_Array lane_map;
	Lane_Map_Itr lane_itr;
	Turn_Pen_Data *turn_ptr;

	Integers node_link;
	Integers link_list;

	//---- initialize link dir data ----

	if (method == MESOSCOPIC) {
		node_link.assign (exe->node_array.size (), -1);
		link_list.assign (exe->dir_array.size (), -1);
	}

	use_code = Use_Code ("CAR/TRUCK/BUS/RAIL");

	for (dir_index=0, sim_dir_itr = exe->sim_dir_array.begin (); sim_dir_itr != exe->sim_dir_array.end (); sim_dir_itr++, dir_index++) {
		if (sim_dir_itr->To_Part () != partition && (sim_dir_itr->From_Part () != partition || !sim_dir_itr->Transfer ())) continue;

		dir_ptr = &exe->dir_array [dir_index];

		min_lane = dir_ptr->Left ();
		max_lane = dir_ptr->Lanes () + min_lane - 1;
	
		//---- link data by subarea method ----

		sim_dir_itr->Make_Data ();

		if (sim_dir_itr->Method () == MACROSCOPIC) {
			sim_cap_ptr = sim_dir_itr->Sim_Cap ();

			//---- calculate link pce capacity ----

			lanes = sim_dir_itr->Lanes ();
			cells = sim_dir_itr->Cells ();

			capacity = lanes * cells;

			cells--;
			cell_out = cells - sim_dir_itr->Out_Cell ();

			//----- add pocket lane cells ----

			for (index = dir_ptr->First_Pocket (); index >= 0; index = pocket_ptr->Next_Index ()) {
				pocket_ptr = &exe->pocket_array [index];

				if (pocket_ptr->Type () == LEFT_TURN || pocket_ptr->Type () == RIGHT_TURN) {
					k = cells;
					j = MIN ((pocket_ptr->Offset () / param.cell_size), cell_out);
					factor = param.turn_factor;
				} else if (pocket_ptr->Type () == LEFT_MERGE || pocket_ptr->Type () == RIGHT_MERGE) {
					j = 0;
					k = MIN (((pocket_ptr->Length () + param.cell_size - 1) / param.cell_size), cells);
					factor = param.merge_factor;
				} else {
					j = pocket_ptr->Offset () / param.cell_size;
					k = MIN (((pocket_ptr->Offset () + pocket_ptr->Length () + param.cell_size - 1) / param.cell_size), cells);
					factor = param.other_factor;
				}
				if (j < 0) j = 0;

				capacity += DTOI (pocket_ptr->Lanes () * (k - j + 1) * factor);
			}
			sim_cap_ptr->Max_Capacity (capacity);

			//---- set the link use at the start of the simulation ----

			sim_dir_itr->Reset_Use (min_lane, max_lane);

			index = dir_ptr->First_Lane_Use ();

			if (index >= 0) {
				for (period_ptr = &exe->use_period_array [index]; ; period_ptr = &exe->use_period_array [++index]) {
					if (period_ptr->Start () > exe->step) {
						if (period_ptr->Start () < use_update_time) {
							use_update_time = period_ptr->Start ();
						}
						continue;
					} else if (exe->step < period_ptr->End ()) {
						if (period_ptr->End () < use_update_time) {
							use_update_time = period_ptr->End ();
						}
						break;
					}
					if (period_ptr->Periods () == 0) goto exit_use;
				}
				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 ()];

					//---- must be a full length restriction ----
	
					if (use_ptr->Offset () > 0 || use_ptr->Length () > 0 || use_ptr->Type () == APPLY) continue;

					//---- apply to all main lanes ----

					if (use_ptr->Low_Lane () <= min_lane && use_ptr->High_Lane () >= max_lane) {

						if (use_ptr->Type () == LIMIT) {
							sim_cap_ptr->High_Use (use_ptr->Use ());
						} else if (use_ptr->Type () == PROHIBIT) {
							sim_cap_ptr->High_Use (ANY_USE_CODE ^ use_ptr->Use ());
						}
						sim_cap_ptr->High_Min_Lane (min_lane);
						sim_cap_ptr->High_Max_Lane (max_lane);

					} else {

						//---- split the capacity into two restriction groups ----

						sim_cap_ptr->High_Min_Lane ((use_ptr->Low_Lane () < min_lane) ? min_lane : use_ptr->Low_Lane ());
						sim_cap_ptr->High_Max_Lane ((use_ptr->High_Lane () > max_lane) ? max_lane : use_ptr->High_Lane ());

						lanes = sim_cap_ptr->High_Max_Lane () - sim_cap_ptr->High_Min_Lane () + 1;
						capacity = lanes * sim_dir_itr->Cells ();

						sim_cap_ptr->Low_Capacity (sim_cap_ptr->Max_Capacity () - capacity);
						sim_cap_ptr->High_Capacity (capacity);

						if (use_ptr->Type () == LIMIT) {
							sim_cap_ptr->High_Use (use_ptr->Use ());
						} else if (use_ptr->Type () == PROHIBIT) {
							sim_cap_ptr->High_Use (ANY_USE_CODE ^ use_ptr->Use ());
						}
						if (sim_cap_ptr->High_Min_Lane () == min_lane) {
							sim_cap_ptr->Low_Min_Lane (sim_cap_ptr->High_Max_Lane () + 1);
							sim_cap_ptr->Low_Max_Lane (max_lane);
						} else {
							sim_cap_ptr->Low_Min_Lane (min_lane);
							sim_cap_ptr->Low_Max_Lane (sim_cap_ptr->High_Min_Lane () - 1);
						}
					}
				}
			}

		} else if (sim_dir_itr->Method () == MESOSCOPIC) {
			
			link_ptr = &exe->link_array [dir_ptr->Link ()];

			bnode = (sim_dir_itr->Dir () == 0) ? link_ptr->Anode () : link_ptr->Bnode ();

			list = &node_link [bnode];
			link_list [dir_index] = *list;
			*list = dir_index;

			//---- initialize the pocket lanes and access restrictions ----

			cells = sim_dir_itr->Cells ();
			lanes = sim_dir_itr->Lanes ();

			for (i=0; i < lanes; i++) {
				sim_lane_ptr = sim_dir_itr->Lane (i);

				if (i < min_lane || i > max_lane) {
					sim_lane_ptr->assign (cells, -2);
				} else {
					sim_lane_ptr->assign (cells, -1);
				}
				sim_lane_ptr->Type (LIMIT);
				sim_lane_ptr->Use (link_ptr->Use ());
				sim_lane_ptr->Min_Veh_Type (-1);
				sim_lane_ptr->Max_Veh_Type (0);
				sim_lane_ptr->Min_Traveler (0);
				sim_lane_ptr->Max_Traveler (0);
				sim_lane_ptr->First_Use (-1);

				sim_lane_ptr->Thru_Lane (0);
				sim_lane_ptr->Thru_Link (-1);
			}

			//----- add pocket lane cells ----

			cells--;
			cell_out = cells - sim_dir_itr->Out_Cell ();

			for (index = dir_ptr->First_Pocket (); index >= 0; index = pocket_ptr->Next_Index ()) {
				pocket_ptr = &exe->pocket_array [index];

				if (pocket_ptr->Type () == LEFT_TURN || pocket_ptr->Type () == RIGHT_TURN) {
					k = cells;
					j = MIN ((pocket_ptr->Offset () / param.cell_size), cell_out);
				} else if (pocket_ptr->Type () == LEFT_MERGE || pocket_ptr->Type () == RIGHT_MERGE) {
					j = 0;
					k = MIN (((pocket_ptr->Length () + param.cell_size - 1) / param.cell_size), cells);
				} else {
					j = pocket_ptr->Offset () / param.cell_size;
					k = MIN (((pocket_ptr->Offset () + pocket_ptr->Length () + param.cell_size - 1) / param.cell_size), cells);
				}
				if (j < 0) j = 0;

				if (pocket_ptr->Type () == LEFT_TURN || pocket_ptr->Type () == LEFT_MERGE) {
					lanes = dir_ptr->Left () - pocket_ptr->Lanes ();
				} else {
					lanes = dir_ptr->Left () + dir_ptr->Lanes ();
				}

				for (n=0; n < pocket_ptr->Lanes (); n++, lanes++) {
					sim_lane_ptr = sim_dir_itr->Lane (lanes);

					for (i=j; i <= k; i++) {
						(*sim_lane_ptr) [i] = -1;
					}
				}
			}

			//---- initialize the connection array ----

			for (index = dir_ptr->First_Connect (); index >= 0; index = connect_ptr->Next_Index ()) {
				connect_ptr = &exe->connect_array [index];
				sim_con_ptr = &exe->sim_connection [index];

				exe->Lane_Map (connect_ptr, *sim_con_ptr);
			}

			//---- set the thru link and lane for each entry lane ----

			for (index = dir_ptr->First_Connect_From (); index >= 0; index = connect_ptr->Next_From ()) {
				connect_ptr = &exe->connect_array [index];
				
				app_ptr = &exe->dir_array [connect_ptr->Dir_Index ()];
				if ((exe->link_array [app_ptr->Link ()].Use () & use_code) == 0) continue;

				exe->Lane_Map (connect_ptr, lane_map);

				for (lane_itr = lane_map.begin (); lane_itr != lane_map.end (); lane_itr++) {
					if (lane_itr->In_Thru () && lane_itr->Out_Thru ()) {
						sim_lane_ptr = sim_dir_itr->Lane (lane_itr->Out_Lane ());
						if (sim_lane_ptr->Thru_Link () < 0) {
							sim_lane_ptr->Thru_Lane (lane_itr->In_Lane ());
							sim_lane_ptr->Thru_Link (connect_ptr->Dir_Index ());
						}
					}
				}
			}

			//---- set the lane use at the start of the simulation ----

			memset (first, -1, sizeof (first));

			index = dir_ptr->First_Lane_Use ();

			if (index >= 0) {
				for (period_ptr = &exe->use_period_array [index]; ; period_ptr = &exe->use_period_array [++index]) {
					if (period_ptr->Start () > exe->step) {
						if (period_ptr->Start () < use_update_time) {
							use_update_time = period_ptr->Start ();
						}
						continue;
					} else if (exe->step < period_ptr->End ()) {
						if (period_ptr->End () < use_update_time) {
							use_update_time = period_ptr->End ();
						}
						break;
					}
					if (period_ptr->Periods () == 0) goto exit_use;
				}
				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 ()];

					if (use_ptr->Type () == REQUIRE) {
						lanes = sim_dir_itr->Lanes ();

						for (i=0; i < lanes; i++) {
							if (i < use_ptr->Low_Lane () || i > use_ptr->High_Lane ()) {
								sim_lane_ptr = sim_dir_itr->Lane (i);
								if (sim_lane_ptr->First_Use () >= 0) continue;

								if (first [i] >= 0) {
									sim_lane_ptr->First_Use (first [i]);
									sim_lane_ptr->Type (LIMIT);
									sim_lane_ptr->Use (link_ptr->Use ());
									sim_lane_ptr->Min_Veh_Type (-1);
									sim_lane_ptr->Max_Veh_Type (0);
									sim_lane_ptr->Min_Traveler (0);
									sim_lane_ptr->Max_Traveler (0);
								} else {
									first [i] = index;
									sim_lane_ptr->Use (sim_lane_ptr->Use () ^ use_ptr->Use ());
									sim_lane_ptr->Type (LIMIT);
									if (use_ptr->Min_Veh_Type () >= 0) {
										sim_lane_ptr->Min_Veh_Type (use_ptr->Min_Veh_Type ());
										sim_lane_ptr->Max_Veh_Type (use_ptr->Max_Veh_Type ());
									}
									if (use_ptr->Min_Traveler () > 0) {
										sim_lane_ptr->Min_Traveler (use_ptr->Min_Traveler ());
										sim_lane_ptr->Max_Traveler (use_ptr->Max_Traveler ());
									}
								}
							}
						}
					} else {
						for (i=use_ptr->Low_Lane (); i <= use_ptr->High_Lane (); i++) {
							sim_lane_ptr = sim_dir_itr->Lane (i);
							if (sim_lane_ptr->First_Use () >= 0) continue;

							if (first [i] >= 0) {
								sim_lane_ptr->First_Use (first [i]);
								sim_lane_ptr->Type (LIMIT);
								sim_lane_ptr->Use (link_ptr->Use ());
								sim_lane_ptr->Min_Veh_Type (-1);
								sim_lane_ptr->Max_Veh_Type (0);
								sim_lane_ptr->Min_Traveler (0);
								sim_lane_ptr->Max_Traveler (0);
							} else {
								first [i] = index;

								if (use_ptr->Type () == PROHIBIT || use_ptr->Type () == LIMIT) {
									if (use_ptr->Type () == PROHIBIT) {
										sim_lane_ptr->Use (sim_lane_ptr->Use () ^ use_ptr->Use ());
									} else {
										sim_lane_ptr->Use (use_ptr->Use ());
									}
									sim_lane_ptr->Type (use_ptr->Type ());
									if (use_ptr->Min_Veh_Type () >= 0) {
										sim_lane_ptr->Min_Veh_Type (use_ptr->Min_Veh_Type ());
										sim_lane_ptr->Max_Veh_Type (use_ptr->Max_Veh_Type ());
									}
									if (use_ptr->Min_Traveler () > 0) {
										sim_lane_ptr->Min_Traveler (use_ptr->Min_Traveler ());
										sim_lane_ptr->Max_Traveler (use_ptr->Max_Traveler ());
									}
								}
							}
						}
					}
				}
			}
		}
exit_use:
		//---- set the turn prohibition flag ----

		sim_dir_itr->Turn (false);

		for (index = dir_ptr->First_Turn (); index >= 0; index = turn_ptr->Next_Index ()) {
			turn_ptr = &exe->turn_pen_array [index];

			if (turn_ptr->Penalty () != 0) continue;

			if (turn_ptr->Start () > exe->step) {
				if (turn_ptr->Start () < turn_update_time) {
					turn_update_time = turn_ptr->Start ();
				}
			} else if (exe->step < turn_ptr->End ()) {
				if (turn_ptr->End () < turn_update_time) {
					turn_update_time = turn_ptr->End ();
				}
				sim_dir_itr->Turn (true);
				break;
			}
		}
	}

	//---- initialize the traffic controls ----

	Traffic_Controls (true);

	if (method == MACROSCOPIC) return;

	//---- identify conflict links ----

	for (bnode = 0, node_itr = exe->node_array.begin (); node_itr != exe->node_array.end (); node_itr++, bnode++) {
		if (node_itr->Control () == -1 || node_itr->Partition () != partition) continue;

		flag = (node_itr->Control () >= 0);		//---- signal flag ----

		//---- process each link entering the node ----

		list = &node_link [bnode];

		for (index = *list; index >= 0; index = link_list [index]) {
			dir_ptr = &exe->dir_array [index];

			bear1 = dir_ptr->Out_Bearing ();
			if (flag) bear1 = exe->compass.Flip (bear1);

			//---- find connections with potential conflicts ----

			for (next = dir_ptr->First_Connect (); next >= 0; next = connect_ptr->Next_Index ()) {
				connect_ptr = &exe->connect_array [next];

				if (flag) {
					if (connect_ptr->Type () != LEFT) continue;
				} else {
					if (connect_ptr->Control () != STOP_GREEN) continue;
					if (connect_ptr->Type () == RIGHT || connect_ptr->Type () == UTURN) continue;
				}
				sim_con_ptr = &exe->sim_connection [next];
				n = sim_con_ptr->Max_Conflicts ();

				//---- search for conflicting approach links ----

				for (dir = *list; dir >= 0; dir = link_list [dir]) {
					if (dir == index) continue;

					app_ptr = &exe->dir_array [dir];

					bear2 = app_ptr->Out_Bearing ();
					change = exe->compass.Change (bear1, bear2);

					//---- check the angle ----

					if (change >= -45 && change <= 45) {
						if (!flag && connect_ptr->Type () != LEFT) continue;
						i = 0;
					} else if (change > -135 && change < -45) {
						if (flag || connect_ptr->Type () == LEFT) continue;
						i = 0;
					} else if (change > 45 && change < 135) {
						if (flag) continue;
						i = 1;
					} else {
						continue;
					}
					
					//---- find the thru movement ----
					
					for (record = app_ptr->First_Connect (); record >= 0; record = cross_ptr->Next_Index ()) {
						cross_ptr = &exe->connect_array [record];

						if (cross_ptr->Type () != THRU) continue;	// r_split l_split, r_merge, l_merge??

						if (sim_con_ptr->Conflict (i) < 0) {
							sim_con_ptr->Conflict (i, record);
						} else if (!flag && 
							((change >= -100 && change <= -80) || (change >= 80 && change <= 100))) {
							sim_con_ptr->Conflict (i, record);
						}
					}
				}
			}
		}
	}
}
コード例 #4
0
ファイル: Read_Turn.cpp プロジェクト: kravitz/transims4
bool Network_Service::Turn_Processing (Db_File *fh)
{
	bool node_flag, link_flag, ab_flag;
	int lvalue, num, node_num, link;
	char *str_ptr;

	Link_Data *link_ptr = NULL;	
	Turn_Data *turn_ptr = NULL;
	Time_Step time_step;

	Turn_File *file = (Turn_File *) fh;

	node_flag = Network_Data_Flag (NODE);
	link_flag = Network_Data_Flag (LINK);
	ab_flag = file->Node_Based ();

	//---- reserve memory ----

	if (turn_data.Max_Records () == 0) {
		if (!turn_data.Max_Records (file->Num_Records ())) goto mem_error;
	}

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

	turn_ptr = turn_data.New_Record ();
	if (turn_ptr == NULL) goto mem_error;

	node_num = file->Node ();

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

	if (node_flag) {
		num = node_data.Get_Index (node_num);

		if (num == 0) {
			return (Check_Message ("Turn Prohibition Node %d was Not Found in the Node file", node_num));
		}
		if (!Renumber ()) {
			num = node_num;
		}
	} else {
		num = node_num;
	}

	if (ab_flag) {

		//---- node-based method ----

		AB_Data *ab_ptr;
		Dir_Data *dir_ptr;

		lvalue = file->In_Node ();

		ab_ptr = ab_key.Get (lvalue, node_num);

		if (ab_ptr == NULL) {
			return (Check_Message ("A Link between %d and %d was Not Found", lvalue, node_num));
		}
		dir_ptr = dir_data [ab_ptr->dir];

		turn_ptr->In_Link_Dir (dir_ptr->Link_Dir ());

		lvalue = file->Out_Node ();

		ab_ptr = ab_key.Get (node_num, lvalue);

		if (ab_ptr == NULL) {
			return (Check_Message ("A Link between %d and %d was Not Found", node_num, lvalue));
		}

		dir_ptr = dir_data [ab_ptr->dir];

		turn_ptr->Out_Link_Dir (dir_ptr->Link_Dir ());

	} else {

		//---- link-based method ----
		
		lvalue = file->In_Link ();

		if (link_flag) {
			link = link_data.Get_Index (lvalue);

			if (link == 0) {
				return (Check_Message ("Turn Prohibition In-Link %d was Not Found in the Link file", lvalue));
			}
			link_ptr = link_data [link];

			if (!Renumber ()) {
				link = lvalue;
			}
			turn_ptr->In_Link (link);
			
			if (link_ptr->Anode () == num) {
				turn_ptr->In_Dir (1);
			} else if (link_ptr->Bnode () == num) {
				turn_ptr->In_Dir (0);
			} else {
				return (Check_Message ("Turn Prohibition In-Link %d is Not Attached to Node %d", lvalue, node_num));
			}
		} else {
			turn_ptr->In_Link (lvalue);
		}

		//---- check/convert the out-link number ----
		
		lvalue = file->Out_Link ();

		if (link_flag) {
			link = link_data.Get_Index (lvalue);

			if (link == 0) {
				return (Check_Message ("Turn Prohibition Out-Link %d was Not Found in the Link file", lvalue));
			}
			link_ptr = link_data [link];

			if (!Renumber ()) {
				link = lvalue;
			}
			turn_ptr->Out_Link (link);

			if (link_ptr->Bnode () == num) {
				turn_ptr->Out_Dir (1);
			} else if (link_ptr->Anode () == num) {
				turn_ptr->Out_Dir (0);
			} else {
				return (Check_Message ("Turn Prohibition Out-Link %d is Not Attached to Node %d", lvalue, node_num));
			}
		} else {
			turn_ptr->Out_Link (lvalue);
		}
	}
	str_ptr = file->Start ();

	if (*str_ptr == '\0') {
		turn_ptr->Start (0);
	} else {
		turn_ptr->Start (Round (time_step.Step (str_ptr)));
	}
	str_ptr = file->End ();

	if (*str_ptr == '\0') {
		turn_ptr->End (Round (MIDNIGHT));
	} else {
		turn_ptr->End (Round (time_step.Step (str_ptr)));
	}
	str_ptr = file->Use ();

	if (*str_ptr == '\0') {
		str_ptr = "ANY";
	}
	turn_ptr->Use (Use_Code (str_ptr));

	turn_ptr->Penalty (file->Penalty ());

	return (true);

mem_error:
	Error ("Insufficient Memory for Turn Prohibition Records");
	return (false);
}
コード例 #5
0
ファイル: Read_Veh_Types.cpp プロジェクト: qingswu/Transim
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));
	}
}
コード例 #6
0
ファイル: Transifer_Link.cpp プロジェクト: qingswu/Transim
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);
		}
	}
}