示例#1
0
bool NewFormat::Get_Trip_Data (Trip_File &file, Trip_Data &trip_rec, int partition)
{
	static int part_num = -1;
	static Trip_File *out_file = 0;

	if (part_num != partition) {
		part_num = partition;

		if (new_trip_flag) {
			out_file = System_Trip_File (true);

			if (out_file != 0 && out_file->Part_Flag () && part_num > 1) {
				if (!out_file->Open (part_num)) {
					Error (String ("Opening %s") % out_file->Filename ());
				}
				if (part_num > max_trip_part) max_trip_part = part_num;
			} else {
				max_trip_part = 1;
			}
		} else {
			max_trip_part = 1;
		}
	}
	if (file.Version () < 60) {
		trip_rec.Household (file.Household ());
		if (trip_rec.Household () < 1) return (false);

		trip_rec.Person (file.Person ());
		trip_rec.Tour (file.Tour ());
		if (trip_rec.Tour () < 1) trip_rec.Tour (1);
		trip_rec.Trip (file.Trip ());

		trip_rec.Start (file.Start ());
		trip_rec.End (file.End ());
		trip_rec.Duration (file.Duration ());

		trip_rec.Origin (file.Origin ());
		trip_rec.Destination (file.Destination ());

		trip_rec.Purpose (file.Purpose ());
		trip_rec.Constraint (file.Constraint ());
		trip_rec.Priority (file.Priority ());

		int vehicle = file.Vehicle ();
		int veh_type = file.Veh_Type ();

		if (file.Version () <= 40) {
			trip_rec.Mode (Trip_Mode_Map (file.Mode ()));

			if (vehicle > 0) {
				Veh_ID_Map_Itr itr = vehicle40_map.find (vehicle);

				if (itr == vehicle40_map.end () || itr->second.Household () != trip_rec.Household ()) return (false);

				vehicle = itr->second.Vehicle ();
			}
		} else {
			trip_rec.Mode (file.Mode ());
		}
		if (vehicle > 0) {
			Vehicle_Index veh_index (trip_rec.Household (), vehicle);

			Vehicle_Map_Itr itr = vehicle_type.find (veh_index);

			if (itr != vehicle_type.end ()) {
				Veh_Type_Data *ptr = &veh_type_array [itr->second];
				veh_type = ptr->Type ();
			} else if (file.Version () < 50 || veh_type == 0) {
				return (false);
			}
		} else {
			veh_type = 0;
		}
		trip_rec.Vehicle (vehicle);
		trip_rec.Veh_Type (veh_type);
		trip_rec.Type (file.Type ());
		trip_rec.Partition (file.Partition ());
		if (trip_rec.Partition () < partition) trip_rec.Partition (partition);

	} else {

		if (!Data_Service::Get_Trip_Data (file, trip_rec, partition)) return (false);
	}
	if (select_households && !hhold_range.In_Range (trip_rec.Household ())) return (false);
	if (trip_rec.Mode () >= 0 && trip_rec.Mode () < MAX_MODE && !select_mode [trip_rec.Mode ()]) return (false);
	if (select_purposes && !purpose_range.In_Range (trip_rec.Purpose ())) return (false);
	if (select_vehicles && !vehicle_range.In_Range (trip_rec.Veh_Type ())) return (false);
	if (select_travelers && !traveler_range.In_Range (trip_rec.Type ())) return (false);
	if (select_start_times && !start_range.In_Range (trip_rec.Start ())) return (false);
	if (select_end_times && !end_range.In_Range (trip_rec.End ())) return (false);
	if (select_origins && !org_range.In_Range (trip_rec.Origin ())) return (false);
	if (select_destinations && !des_range.In_Range (trip_rec.Destination ())) return (false);

	if (new_trip_flag) {
		num_new_trip += Put_Trip_Data (*out_file, trip_rec);
	}
	if (new_plan_flag) return (true);
	return (false);
}
示例#2
0
bool Data_Service::Get_Event_Data (Event_File &file, Event_Data &event_rec)
{
	int hhold, lvalue, link, dir, offset, dir_index;

	hhold = file.Household ();
	if (hhold < 1) return (false);

	event_rec.Household (hhold);

	event_rec.Person (file.Person ());
	event_rec.Tour (MAX (file.Tour (), 1));
	event_rec.Trip (file.Trip ());
	event_rec.Event (file.Event ());

	if (file.Version () <= 40) {
		event_rec.Mode (Trip_Mode_Map (file.Mode ()));
	} else {
		event_rec.Mode (file.Mode ());
	}
	event_rec.Schedule (file.Schedule ());
	event_rec.Actual (file.Actual ());

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

	link = file.Link ();

	if (link > 0) {
		dir = file.Dir ();
		offset = Round (file.Offset ());
	
		Link_Data *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 ("Event %d Link %d Direction %s was Not Found") % Progress_Count () % 
				link_ptr->Link () % ((dir) ? "BA" : "AB"));
		}
		event_rec.Dir_Index (dir_index);
		event_rec.Offset (offset);
		event_rec.Lane (file.Lane ());
	}

	lvalue = file.Route ();

	if (lvalue > 0) {
		if (System_File_Flag (TRANSIT_ROUTE)) {
			Int_Map_Itr map_itr = line_map.find (lvalue);

			if (map_itr == line_map.end ()) {
				Warning (String ("Event %d Route %d was Not Found") % Progress_Count () % lvalue);
				return (false);
			}
			event_rec.Route (map_itr->second);
		} else {
			event_rec.Route (lvalue);
		}
	}
	return (true);
}
示例#3
0
bool Data_Service::Get_Trip_Data (Trip_File &file, Trip_Data &trip_rec, int partition)
{
	int hhold, lvalue;
	Int_Map_Itr map_itr;
	Vehicle_Index veh_index;
	Vehicle_Map_Itr veh_itr;

	//---- check the household id ----

	hhold = file.Household ();
	if (hhold < 1) return (false);

	trip_rec.Household (hhold);

	trip_rec.Person (file.Person ());
	trip_rec.Tour (MAX (file.Tour (), 1));
	trip_rec.Trip (file.Trip ());

	trip_rec.Start (file.Start ());
	trip_rec.End (file.End ());

	//---- convert the origin ----

	lvalue = file.Origin ();

	map_itr = location_map.find (lvalue);

	if (map_itr == location_map.end ()) {
		Warning (String ("Trip %d Origin %d was Not Found") % Progress_Count () % lvalue);
		return (false);
	}
	trip_rec.Origin (map_itr->second);

	//---- convert the destination ----

	lvalue = file.Destination ();

	map_itr = location_map.find (lvalue);

	if (map_itr == location_map.end ()) {
		Warning (String ("Trip %d Destination %d was Not Found") % Progress_Count () % lvalue);
		return (false);
	}
	trip_rec.Destination (map_itr->second);

	lvalue = file.Vehicle ();

	if (file.Version () <= 40) {
		lvalue = Fix_Vehicle_ID (lvalue);
	}
	if (lvalue > 0) {
		veh_index.Household (hhold);
		veh_index.Vehicle (lvalue);

		veh_itr = vehicle_map.find (veh_index);
		if (veh_itr == vehicle_map.end ()) {
			Warning (String ("Trip %d Vehicle %d was Not Found") % Progress_Count () % lvalue);
			return (false);
		}
		lvalue = veh_itr->second;
	} else {
		lvalue = -1;
	}
	trip_rec.Vehicle (lvalue);

	if (file.Version () <= 40) {
		trip_rec.Mode (Trip_Mode_Map (file.Mode ()));
	} else {
		trip_rec.Mode (file.Mode ());
	}
	trip_rec.Purpose (file.Purpose ());
	trip_rec.Constraint (file.Constraint ());
	trip_rec.Passengers (file.Passengers ());

	trip_rec.Type (file.Type ());

	if (file.Partition_Flag ()) {
		trip_rec.Partition (file.Partition ());
	} else {
		trip_rec.Partition (partition);
	}	
	//trip_rec.Notes (file.Notes ());

	return (true);
}