Пример #1
0
bool Data_Service::Get_Lane_Use_Data (Lane_Use_File &file, Lane_Use_Data &lane_use_rec)
{
	int link, dir, lanes, offset, dir_index, low, high;
	double rate;

	Link_Data *link_ptr;
	Int_Map_Itr map_itr;

	//---- check/convert the link number and direction ----

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

	dir = file.Dir ();
	offset = Round (file.Offset ());

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

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

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

	//---- set the restriction type ----

	lane_use_rec.Type (file.Type ());
	lane_use_rec.Use (file.Use ());

	//---- convert the vehicle type range ----

	low = file.Min_Veh_Type ();
	high = file.Max_Veh_Type ();

	if (low > 0) {
		map_itr = veh_type_map.find (low);
		if (map_itr == veh_type_map.end ()) {
			map_itr = veh_type_map.lower_bound (low);
			if (map_itr == veh_type_map.end ()) {
				Warning (String ("Lane Use %d Vehicle Type %d was Not Found") % Progress_Count () % low);
				low = -1;
			} else {
				low = map_itr->second;
			}
		} else {
			low = map_itr->second;
		}
	} else {
		low = -1;
	}
	if (high > 0) {
		map_itr = veh_type_map.find (high);
		if (map_itr == veh_type_map.end ()) {
			int h = high;
			while (h > 0) {
				map_itr = veh_type_map.find (--h);
				if (map_itr != veh_type_map.end ()) break;
			}
			if (h >= 0) {
				high = map_itr->second;
			} else {
				Warning (String ("Lane Use %d Vehicle Type %d was Not Found") % Progress_Count () % high);
				high = -1;
			}
		} else {
			high = map_itr->second;
		}
		if (high >= 0 && low < 0) low = 0;
	} else {
		high = -1;
	}
	if (low > high) {
		if (high == -1) {
			high = low;
		} else {
			Warning (String ("Lane Use %d Vehicle Type Range %d-%d is Illegal") % Progress_Count () % file.Min_Veh_Type () % file.Max_Veh_Type ());
			high = low;
		}
	}
	lane_use_rec.Min_Veh_Type (low);
	lane_use_rec.Max_Veh_Type (high);

	//---- convert the traveler type range ----

	low = file.Min_Traveler ();
	high = file.Max_Traveler ();

	if (low <= 0) low = -1;
	if (high > 0) {
		if (low < 0) low = 0;
	} else {
		high = -1;
	}
	if (low > high) {
		if (high == -1) {
			high = low;
		} else {
			Warning (String ("Lane Use %d Traveler Type Range %d-%d is Illegal") % Progress_Count () % file.Min_Traveler () % file.Max_Traveler ());
			high = low;
		}
	}
	lane_use_rec.Min_Traveler (low);
	lane_use_rec.Max_Traveler (high);

	//----- length and offset ----

	lane_use_rec.Length (file.Length ());

	if (lane_use_rec.Length () > 0) {
		if (offset > 0 || lane_use_rec.Length () < link_ptr->Length ()) {
			lane_use_rec.Offset (offset);
		} else {
			lane_use_rec.Offset (0);
			lane_use_rec.Length (0);
		}
	} else {
		lane_use_rec.Offset (0);
	}

	//---- lane number ----

	lanes = file.Lanes ();

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

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

	lane_use_rec.Start (file.Start ());
	lane_use_rec.End (file.End ());
	if (lane_use_rec.End () == 0) lane_use_rec.End (Model_End_Time ());

	lane_use_rec.Toll (Round (file.Toll ()));
	lane_use_rec.Toll_Rate (file.Toll_Rate ());

	if (lane_use_rec.Toll_Rate () > 0) {
		rate = UnRound (lane_use_rec.Toll_Rate ());

		if (Metric_Flag ()) {
			rate /= 1000.0;
		} else {
			rate /= MILETOFEET;
		}
		lane_use_rec.Toll (lane_use_rec.Toll () + DTOI (rate * link_ptr->Length ()));
	}
	lane_use_rec.Min_Delay (file.Min_Delay ());
	lane_use_rec.Max_Delay (file.Max_Delay ());
	lane_use_rec.Speed (file.Speed ());	
	lane_use_rec.Spd_Fac (file.Speed_Factor ());
	lane_use_rec.Capacity (file.Capacity ());
	lane_use_rec.Cap_Fac (file.Cap_Factor ());
	lane_use_rec.Notes (file.Notes ());

	return (true);
}
Пример #2
0
int Data_Service::Put_Lane_Use_Data (Lane_Use_File &file, Lane_Use_Data &data)
{
	double rate, toll;

	Dir_Data *dir_ptr;
	Link_Data *link_ptr;
	Veh_Type_Data *veh_type_ptr;

	dir_ptr = &dir_array [data.Dir_Index ()];
	link_ptr = &link_array [dir_ptr->Link ()];

	file.Link (link_ptr->Link ());
	file.Dir (dir_ptr->Dir ());

	file.Lanes (Make_Lane_Range (dir_ptr, data.Low_Lane (), data.High_Lane ()));

	file.Use (data.Use ());
	file.Type (data.Type ());

	if (data.Min_Veh_Type () < 0) {
		file.Min_Veh_Type (0);
	} else if (veh_type_array.size () > 0) {
		veh_type_ptr = &veh_type_array [data.Min_Veh_Type ()];
		file.Min_Veh_Type (veh_type_ptr->Type ());
	} else {
		file.Min_Veh_Type (data.Min_Veh_Type ());
	}
	if (data.Max_Veh_Type () < 0) {
		file.Max_Veh_Type (0);
	} else if (veh_type_array.size () > 0) {
		veh_type_ptr = &veh_type_array [data.Max_Veh_Type ()];
		file.Max_Veh_Type (veh_type_ptr->Type ());
	} else {
		file.Max_Veh_Type (data.Max_Veh_Type ());
	}
	file.Min_Traveler (MAX (data.Min_Traveler (), 0)); 
	file.Max_Traveler (MAX (data.Max_Traveler (), 0));

	file.Start (data.Start ());
	file.End (data.End ());
	file.Length (UnRound (data.Length ()));
	file.Offset (UnRound (data.Offset ()));

	toll = UnRound (data.Toll ());
	rate = UnRound (data.Toll_Rate ());

	if (rate > 0) {
		if (Metric_Flag ()) {
			rate /= 1000.0;
		} else {
			rate /= MILETOFEET;
		}
		toll -= DTOI (rate * link_ptr->Length ());
	}
	file.Toll (DTOI (toll));
	file.Toll_Rate (rate);

	file.Min_Delay (UnRound (data.Min_Delay ()));
	file.Max_Delay (UnRound (data.Max_Delay ()));
	file.Speed (UnRound (data.Speed ()));
	file.Speed_Factor (UnRound (data.Spd_Fac ()) / 10.0);
	file.Capacity (data.Capacity ());
	file.Cap_Factor (UnRound (data.Cap_Fac ()) / 10.0);
	file.Notes (data.Notes ());

	if (!file.Write ()) {
		Error (String ("Writing %s") % file.File_Type ());
	}
	return (1);
}