コード例 #1
0
ファイル: Read_Line.cpp プロジェクト: kravitz/transims4
void Network_Service::Read_Line (void)
{
	Line_File *file = (Line_File *) Network_Db_File (TRANSIT_ROUTE);

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

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

	if (Check_Data () || Renumber ()) {
		if (!Network_Data_Flag (TRANSIT_STOP) && 
			(Network_File_Flag (TRANSIT_STOP) || Network_Option_Flag (TRANSIT_STOP))) {
			Error (file_error, "Transit Stop", file->File_ID ());
		}
	}
	First_Record (true);
	int i, num;

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

		if (Line_Processing (file)) {
			if (!line_data.Add ()) goto add_error;

		}
		First_Record (false);

		num = file->Stops ();

		for (i=1; i <= num; i++) {
			if (!file->Read (true)) {
				Error ("Number of Nested Records for Route %d", file->Route ());
			}
			Show_Progress ();

			if (Line_Processing (file)) {
				if (!line_data.Add ()) goto add_error;
			}			
		}	
	}
	End_Progress ();
	file->Close ();

	line_data.Route_Records (Progress_Count ());

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

	num = line_data.Num_Records ();

	if (num && num != Progress_Count ()) {
		Print (1, "Number of Transit Route Data Records = %d", num);
	}
	line_data.Optimize ();

	if (num > 0) Network_Data_True (TRANSIT_ROUTE);
	return;

add_error:
	Error ("Adding Record to the Transit Route Data List");
}
コード例 #2
0
ファイル: Read_Lines.cpp プロジェクト: qingswu/Transim
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);
}
コード例 #3
0
ファイル: Read_Shapes.cpp プロジェクト: qingswu/Transim
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);
}
コード例 #4
0
ファイル: Read_Locations.cpp プロジェクト: kravitz/transims5
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);
}
コード例 #5
0
ファイル: Read_Events.cpp プロジェクト: kravitz/transims5
void Data_Service::Read_Events (void)
{
	Event_File *file = (Event_File *) System_File_Handle (EVENT);
	
	int num;
	Event_Data event_rec;
	Event_Index event_index;
	Event_Map_Stat map_stat;

	//---- store the event data ----

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

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

		event_rec.Clear ();

		if (Get_Event_Data (*file, event_rec)) {
			event_rec.Get_Event_Index (event_index);

			map_stat = event_map.insert (Event_Map_Data (event_index, (int) event_array.size ()));

			if (!map_stat.second) {
				Warning (String ("Duplicate Event Record = %d-%d-%d-%d-%d") % 
					event_index.Household () % event_index.Person () % event_index.Tour () % 
					event_index.Trip () % event_index.Event ());

				continue;
			} else {
				event_array.push_back (event_rec);
			}
		}
	}
	End_Progress ();
	file->Close ();
	
	Print (2, String ("Number of %s Records = %d") % file->File_Type () % Progress_Count ());

	num = (int) event_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 (EVENT);
}
コード例 #6
0
ファイル: Read_Zones.cpp プロジェクト: kravitz/transims5
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);
}
コード例 #7
0
ファイル: Write_Subzone.cpp プロジェクト: kravitz/transims4
void ArcNet::Write_Subzone (void)
{
	XYZ_Point point;

	int z_field = subzone_file.Optional_Field ("Z_COORD", "ELEVATION", "Z");

	arcview_subzone.Num_Points (1);

	Show_Message ("Reading %s -- Record", subzone_file.File_Type ());
	Set_Progress (1000);

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

		arcview_subzone.Copy_Fields (&subzone_file);

		point.x = subzone_file.X ();
		point.y = subzone_file.Y ();
		subzone_file.Get_Field (z_field, &(point.z));

		arcview_subzone.points.Set (1, &point);

		if (!arcview_subzone.Write_Record ()) {
			Error ("Writing ArcView Subzone File");
		}
	}
	End_Progress ();
	
	subzone_file.Close ();
	arcview_subzone.Close ();

	Print (2, "Number of %s Records = %d", subzone_file.File_Type (), Progress_Count ());
}
コード例 #8
0
ファイル: Read_Deletes.cpp プロジェクト: kravitz/transims4
void IntControl::Read_Deletes (void)
{
    int node;

    //---- store the delete data ----

    Show_Message ("Reading %s -- Record", delete_file.File_Type ());
    Set_Progress ();

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

        Get_Integer (delete_file.Record (), &node);
        if (node == 0) continue;

        if (!delete_node.Add (node)) {
            Error ("Adding Delete Node Record");
        }
    }
    End_Progress ();

    delete_file.Close ();

    Print (2, "Number of %s Records = %d", delete_file.File_Type (), Progress_Count ());
}
コード例 #9
0
ファイル: Read_Phasing.cpp プロジェクト: kravitz/transims4
void Network_Service::Read_Phasing (void)
{
	Db_File *file = Network_Db_File (PHASING_PLAN);

	//---- store the phasing plan data ----

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

	if (Check_Data () || Renumber ()) { 
		if (!Network_File_Flag (NODE) && Network_Option_Flag (NODE)) {
			Error (file_error, "Node", file->File_ID ());
		}
		if (!Network_File_Flag (LINK) && Network_Option_Flag (LINK)) {
			Error (file_error, "Link", file->File_ID ());
		}
		if (!Network_File_Flag (TIMING_PLAN) && Network_Option_Flag (TIMING_PLAN)) {
			Error (file_error, "Timing Plan", file->File_ID ());
		}
	}
	file->Num_Records ();
	First_Record (true);

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

		if (Phasing_Processing (file)) {
			if (!phasing_data.Add ()) {
				Error ("Adding Record to the Phasing Plan List");
			}
		}
		First_Record (false);
	}
	End_Progress ();
	file->Close ();

	phasing_data.Max_Records (phasing_data.Num_Records ());

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

	int num = phasing_data.Num_Records ();

	if (num && num != Progress_Count ()) {
		Print (1, "Number of Phasing Plan Data Records = %d", num);
	}
	if (num > 0) Network_Data_True (PHASING_PLAN);
}
コード例 #10
0
ファイル: Read_Polygons.cpp プロジェクト: kravitz/transims4
void LocationData::Read_Polygons (void)
{
	int i, index, num_pts;

	Arcview_File *poly_file;
	Boundary poly_rec;
	Index_Array *polygon;
	Db_Index_Array *data;

	//---- read the arcview boundary file ----

	for (i=0; i < num_polygons; i++) {
		poly_file = polygon_files [i];
		if (poly_file == NULL) continue;

		Show_Message ("Reading %s -- Record", poly_file->File_Type ());
		Set_Progress (1000);

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

		index = 0;
		polygon = polygons [i];
		data = polygon_db [i];

		while (poly_file->Read_Record ()) {
			Show_Progress ();

			poly_rec.zone = ++index;
			num_pts = poly_file->Num_Points ();

			poly_rec.points = new Point_Data ();

			if (poly_rec.points == NULL || !poly_rec.points->Num_Points (num_pts)) {
				Error ("Insufficient Memory for Boundary Polygons");
			}
			num_pts *= sizeof (XY_Point);

			memcpy (poly_rec.points->Get_XY_Data (1), poly_file->Get_XY_Data (1), num_pts);

			if (!polygon->Add (&poly_rec)) {
				Error ("Adding Boundary Polygon");
			}

			//----- add to the database ----

			data->Copy_Fields (poly_file);
			data->Put_Field (1, index);

			if (!data->Add_Record ()) {
				Error ("Writing Boundary Polygon Database");
			}
		}
		End_Progress ();

		Print (2, "Number of %s Records = %d", poly_file->File_Type (), Progress_Count ());
		
		poly_file->Close ();
	}
}
コード例 #11
0
ファイル: Read_Turn.cpp プロジェクト: kravitz/transims4
void Network_Service::Read_Turn (void)
{
	Turn_File *file = (Turn_File *) Network_Db_File (TURN_PROHIBITION);

	//---- store the turn prohibition data ----

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

	if (Check_Data () || Renumber ()) {
		if (!Network_File_Flag (NODE) && Network_Option_Flag (NODE) && file->Node_Based ()) {
			Error (file_error, "Node", file->File_ID ());
		}
		if (!Network_File_Flag (LINK) && Network_Option_Flag (LINK)) {
			Error (file_error, "Link", file->File_ID ());
		}
	}
	file->Num_Records ();
	First_Record (true);

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

		if (Turn_Processing (file)) {
			if (!turn_data.Add ()) {
				Error ("Adding Record to the Turn Data List");
			}
		}
		First_Record (false);
	}
	End_Progress ();
	file->Close ();

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

	int num = turn_data.Num_Records ();

	if (num && num != Progress_Count ()) {
		Print (1, "Number of Turn Prohibition Data Records = %d", num);
	}
	turn_data.Optimize ();

	if (num > 0) Network_Data_True (TURN_PROHIBITION);
}
コード例 #12
0
ファイル: Read_Node_Map.cpp プロジェクト: qingswu/Transim
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 ());
}
コード例 #13
0
ファイル: Read_Vehicle.cpp プロジェクト: kravitz/transims4
void Demand_Service::Read_Vehicle (void)
{
	vehicle_data.Sorted (!sort_flag);

	Db_File *file = Demand_Db_File (VEHICLE);

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

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

	if (Check_Data () || Renumber ()) { 
		if (!Network_File_Flag (PARKING) && Network_Option_Flag (PARKING)) {
			Error (file_error, "Parking", file->File_ID ());
		}
	}
	//file->Num_Records ();
	First_Record (true);

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

		if (Vehicle_Processing (file)) {
			if (!vehicle_data.Add ()) {
				Error ("Adding Record to the Vehicle Data Array");
			}
		}
		First_Record (false);
	}
	End_Progress ();
	file->Close ();

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

	int num = vehicle_data.Num_Records ();

	if (num && num != Progress_Count ()) {
		Print (1, "Number of Vehicle Data Records = %d", num);
	}
	vehicle_data.Optimize (compress_flag);

	if (num > 0) Demand_Data_True (VEHICLE);
}
コード例 #14
0
ファイル: Survey_Weights.cpp プロジェクト: kravitz/transims4
void CheckSurvey::Survey_Weights (void)
{
	int id, count;
	double weight;
	char *str_ptr;

	Household_Data *household_ptr;

	count = 0;

	//---- read the survey household weights ----

	Show_Message ("Reading %s -- Record", weight_file.File_Type ());
	Set_Progress (50000);
	
	while (weight_file.Read ()) {
		str_ptr = weight_file.Record ();

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

		str_ptr = Get_Integer (str_ptr, &id);
		if (id <= 0) continue;

		Show_Progress ();

		household_ptr = survey_hh_data.Get (id);
		if (household_ptr == NULL) continue;

		Get_Double (str_ptr, &weight);

		household_ptr->Location ((int) (weight + random.Probability ()));
		count++;
	}
	End_Progress ();
	weight_file.Close ();

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

	if (count != Progress_Count ()) {
		Print (1, "Number of Household Weights Kept = %d", count);
	}
}
コード例 #15
0
ファイル: Read_Link.cpp プロジェクト: kravitz/transims5
void TransitAccess::Read_Link (void)
{
	int anode, bnode, dist, zone, type;
	double len;
	String text;
	Zone_Map_Itr zone_itr;
	Node_Map_Itr node_itr;

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

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

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

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

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

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

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

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

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

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

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

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

	Print (2, "Number of Link Data Records = ") << Progress_Count ();
}
コード例 #16
0
ファイル: Read_Population.cpp プロジェクト: kravitz/transims4
void Demand_Service::Read_Population (void)
{
	Db_File *file = Demand_Db_File (POPULATION);

	//---- store the population data ----

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

	if (Check_Data () || Renumber ()) {
		if (!Demand_File_Flag (HOUSEHOLD) && Demand_Option_Flag (HOUSEHOLD)) {
			Error (file_error, "Household", file->File_ID ());
		}
	}
	//file->Num_Records ();
	First_Record (true);

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

		if (Population_Processing (file)) {
			if (!population_data.Add ()) {
				Error ("Adding Record to the Population Data Array");
			}
		}
		First_Record (false);
	}
	End_Progress ();
	file->Close ();

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

	int num = population_data.Num_Records ();

	if (num && num != Progress_Count ()) {
		Print (1, "Number of Population Data Records = %d", num);
	}
	population_data.Optimize ();

	if (num > 0) Demand_Data_True (POPULATION);
}
コード例 #17
0
void ActivityPattern::Survey_Population (void)
{
	int hhold;

	Survey_HHold *household_ptr;
	Survey_Person *population_ptr;

	if (!survey_pop_data.Max_Records (survey_pop_file.Num_Records ())) goto mem_error;

	//---- read the survey population file ----

	Show_Message ("Reading %s -- Record", survey_pop_file.File_Type ());
	Set_Progress (50000);
	
	while (survey_pop_file.Read ()) {
		Show_Progress ();

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

		hhold = survey_pop_file.Household ();
		if (hhold <= 0) continue;

		household_ptr = survey_hh_data.Get (hhold);
		if (household_ptr == NULL) {
			Error ("Survey Person Household %d was Not Found", hhold);
		}

		population_ptr = survey_pop_data.New_Record (true);
		if (population_ptr == NULL) goto mem_error;

		population_ptr->Household (hhold);
		population_ptr->Person (survey_pop_file.Person ());
		population_ptr->Age (survey_pop_file.Age ());
		population_ptr->Gender (survey_pop_file.Gender ());
		population_ptr->Work (survey_pop_file.Work ());
		population_ptr->Drive (survey_pop_file.Drive ());
		population_ptr->Count (0);

		if (!survey_pop_data.Add ()) {
			Error ("Adding Record to the Population Data Array");
		}
	}
	End_Progress ();
	survey_pop_file.Close ();

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

	survey_pop_data.Optimize ();
	return;

mem_error:
	Error ("Insufficient Memory for Survey Population Data");
}
コード例 #18
0
ファイル: Write_Turns.cpp プロジェクト: kravitz/transims4
void PlanSum::Write_Turns (void)
{
    int i;
    char *time1_ptr, *time2_ptr;

    Movement_Data *move_ptr;
    Movement_Array *array_ptr;
    Dir_Data *dir_ptr;

    Show_Message ("Writing %s -- Record", turn_file.File_Type ());
    Set_Progress (10000);

    //---- write each turn movement ----

    for (i=1; i <= num_inc; i++) {
        array_ptr = movement_data [i];

        time1_ptr = time_periods.Range_Format (i);

        time2_ptr = strstr (time1_ptr, "..");
        *time2_ptr = '\0';
        time2_ptr += 2;

        for (move_ptr = array_ptr->First_Key (); move_ptr; move_ptr = array_ptr->Next_Key ()) {
            Show_Progress ();

            turn_file.Node (move_ptr->node);

            dir_ptr = dir_data [move_ptr->in_link];
            turn_file.In_Link (dir_ptr->Link ());

            dir_ptr = dir_data [move_ptr->out_link];
            turn_file.Out_Link (dir_ptr->Link ());

            turn_file.Start (time1_ptr);
            turn_file.End (time2_ptr);
            turn_file.Volume (move_ptr->volume);

            //---- save the record ----

            if (!turn_file.Write ()) {
                Error ("Writing Turn Movement File");
            }
        }
    }
    End_Progress ();

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

    turn_file.Close ();
}
コード例 #19
0
ファイル: Read_Persons.cpp プロジェクト: kravitz/transims5
void NewFormat::Read_Persons (void)
{
	int hhold;

	Person_Data person_rec;
	Int_Map_Itr map_itr;
	Household_Data *hhold_ptr;

	//---- process the person file ----

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

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

		hhold = person_file.Household ();

		map_itr = hhold_map.find (hhold);
		if (map_itr == hhold_map.end ()) {
			Error (String ("Person %d Household %d was Not Found") % Progress_Count () % hhold);
		}
		hhold_ptr = &hhold_array [map_itr->second];

		person_rec.Person (person_file.Person ());
		person_rec.Age (person_file.Age ());
		person_rec.Relate (person_file.Relate ());
		person_rec.Gender (person_file.Gender ());
		person_rec.Work (person_file.Work ());
		person_rec.Drive (person_file.Drive ());

		hhold_ptr->push_back (person_rec);
	}
	End_Progress ();
	person_file.Close ();

	Print (2, String ("Number of %s Records = %d") % person_file.File_Type () % Progress_Count ());
}
コード例 #20
0
ファイル: Read_Node.cpp プロジェクト: kravitz/transims4
void GISNet::Read_Node (void)
{
	int node, node_field, z_field;
	XYZ_Point *pt_ptr;

	Node_Data node_rec;

	//---- initialize the node array ----

	node_field = gis_node.Required_Field ("NODE", "ID", "NODE_ID", "NODEID", "N");
	z_field = gis_node.Optional_Field ("Z_COORD", "ELEVATION", "Z");

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

	Show_Message ("Reading %s -- Record", gis_node.File_Type ());
	Set_Progress (1000);

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

		//---- read the node data ----

		gis_node.Get_Field (node_field, &node);
		if (node == 0) continue;

		if (node >= first_node) first_node = node + 1;
		
		pt_ptr = gis_node.points.First ();

		//---- save to index class -----

		node_rec.Node (node);
		node_rec.X (Round (pt_ptr->x));
		node_rec.Y (Round (pt_ptr->y));
		node_rec.Z (Round (pt_ptr->z));

		if (!node_data.Add (&node_rec)) {
			Error ("Adding Node Data Record");
		}
	}
	End_Progress ();

	gis_node.Close ();

	Print (2, "Number of %s Records = %d", gis_node.File_Type (), Progress_Count ());
}
コード例 #21
0
ファイル: Read_Boundary.cpp プロジェクト: kravitz/transims4
void LocationData::Read_Boundary (void)
{
	int zone, num_pts;

	Boundary zone_rec;

	//---- read the arcview boundary file ----

	Show_Message ("Reading %s -- Record", boundary_file.File_Type ());
	Set_Progress (1000);

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

		//---- get the zone field ----

		boundary_file.Get_Field (zone_field, &zone);
		if (zone == 0) continue;

		zone_rec.zone = zone;
		num_pts = boundary_file.Num_Points ();

		zone_rec.points = new Point_Data ();

		if (zone_rec.points == NULL || !zone_rec.points->Num_Points (num_pts)) {
			Error ("Insufficient Memory for Zone Polygons");
		}
		num_pts *= sizeof (XY_Point);

		memcpy (zone_rec.points->Get_XY_Data (1), boundary_file.Get_XY_Data (1), num_pts);

		if (!zone_boundary.Add (&zone_rec)) {
			Error ("Adding Zone Boundary");
		}
	}
	End_Progress ();

	Print (2, "Number of %s Records = %d", boundary_file.File_Type (), Progress_Count ());
	
	boundary_file.Close ();
}
コード例 #22
0
ファイル: Write_Trips.cpp プロジェクト: kravitz/transims4
void TripSum::Write_Trips (void)
{
	int org, des, period, trips, total;

	Matrix_Data *trip_ptr;

	//---- write the records ----

	Show_Message ("Writing %s -- Record", trip_file.File_Type ());
	Set_Progress (10000);

	total = 0;

	for (trip_ptr = trip_table.First_Key (); trip_ptr; trip_ptr = trip_table.Next_Key ()) {
		Show_Progress ();

		trips = trip_ptr->Data ();

		if (trips == 0) continue;

		trip_table.Key (trip_ptr->ID (), &org, &des, &period);

		trip_file.Origin (org);
		trip_file.Destination (des);
		trip_file.Period (period);
		trip_file.Data (trips);

		total += trips;

		if (!trip_file.Write ()) {
			Error ("Writing %s", trip_file.File_Type ());
		}
	}
	End_Progress ();

	trip_file.Close ();

	Print (2, "Number of %s Records = %d", trip_file.File_Type (), Progress_Count ());
	Print (1, "Number of %s Trips = %d", trip_file.File_Type (), total);
} 
コード例 #23
0
ファイル: Write_Activity.cpp プロジェクト: kravitz/transims4
void LinkSum::Write_Activity (void)
{
	Show_Message ("Writing Link Activity File -- Record");
	Set_Progress ();

	link_db.Rewind ();

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

		activity_file.Copy_Fields (&link_db);

		if (!activity_file.Write ()) {
			Error ("Writing the Link Activity File");
		}
	}
	End_Progress ();

	Print (2, "Number of Link Activity Records = %d", Progress_Count ());

	activity_file.Close ();
}
コード例 #24
0
ファイル: Read_Vehicle.cpp プロジェクト: kravitz/transims4
void TripSum::Read_Vehicle (void)
{
	int id, num_out;

	Vehicle_File *file, *new_file;
	
	file = (Vehicle_File *) Demand_Db_Base (VEHICLE);
	new_file = (Vehicle_File *) Demand_Db_Base (NEW_VEHICLE);

	//---- process each vehicle ----

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

	num_out = 0;

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

		id = file->Vehicle ();
		if (id == 0) continue;

		if (vehicle_list.Get_Index (id) == 0) continue;

		new_file->Copy_Fields (file);

		if (!new_file->Write ()) {
			Error ("Writing %s", new_file->File_Type ());
		}
		num_out++;
	}
	End_Progress ();

	Print (2, "Number of Vehicle Records Read = %d", Progress_Count ());
	Print (1, "Number of Vehicle Records Written = %d", num_out);

	file->Close ();
	new_file->Close ();
}
コード例 #25
0
ファイル: Write_Count.cpp プロジェクト: kravitz/transims4
void ActivityPattern::Write_Count (void)
{
	char buffer [STRING_BUFFER];

	Survey_Person *person_ptr;

	Show_Message ("Writing %s -- Record", count_file.File_Type ());
	Set_Progress (10000);

	for (person_ptr = survey_pop_data.First_Key (); person_ptr; person_ptr = survey_pop_data.Next_Key ()) {
		Show_Progress ();

		str_fmt (buffer, sizeof (buffer), "%d\t%d\t%d", 
			person_ptr->Household (), person_ptr->Person (), person_ptr->Count ());

		if (!count_file.Write (buffer)) {
			Error ("Writing %s", count_file.File_Type ());
		}
	}
	End_Progress ();
	count_file.Close ();

	Print (2, "Number of %s Records = %d", count_file.File_Type (), Progress_Count ());
}
コード例 #26
0
ファイル: Read_Timing_Plans.cpp プロジェクト: qingswu/Transim
void Data_Service::Read_Timing_Plans (Timing_File &file)
{
	int i, num, count;
	bool keep;

	Timing_Record timing_rec;
	Timing_Data *timing_ptr;
	Signal_Data *signal_ptr;

	//---- store the timing plan data ----

	Show_Message (String ("Reading %s -- Record") % file.File_Type ());
	Set_Progress ();
	
	Initialize_Timing_Plans (file);
	count = 0;

	timing_ptr = &(timing_rec.timing_data);

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

		timing_rec.Clear ();

		keep = Get_Timing_Data (file, timing_rec);

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

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

			Get_Timing_Data (file, timing_rec);
		}

		//---- save the results ----

		if (keep) {
			if (file.Version () <= 40) {
				bool keep;
				Timing40_Map_Itr timing40_itr;
				Timing40_Data *timing40_ptr;
				Timing_Itr timing_itr;

				timing40_itr = timing40_map.find (timing_ptr->Timing ());

				if (timing40_itr == timing40_map.end ()) {
					Warning (String ("Timing Plan %d was Not Found in the Signal file") % timing_ptr->Timing ());
					continue;
				}
				timing40_ptr = (Timing40_Data *) &(timing40_itr->second);
				timing_rec.Signal (timing40_ptr->Signal ());

				signal_ptr = &signal_array [timing_rec.Signal ()];
				keep = true;

				for (timing_itr = signal_ptr->timing_plan.begin (); timing_itr != signal_ptr->timing_plan.end (); timing_itr++) {
					if (timing_itr->Timing () == timing40_ptr->Timing ()) {
						Timing_Phase_Itr phase_itr = timing_ptr->begin ();
						timing_itr->push_back (*phase_itr);
						count++;
						keep = false;
						break;
					}
				}
				if (!keep) continue;

				timing_ptr->Timing (timing40_ptr->Timing ());
				timing_ptr->Type (timing40_ptr->Type ());
				timing_ptr->Offset (timing40_ptr->Offset ());
			} else {
				signal_ptr = &signal_array [timing_rec.Signal ()];
			}
			signal_ptr->timing_plan.push_back (*timing_ptr);

			count += (int) timing_ptr->size () + 1;
		}
	}
	End_Progress ();
	file.Close ();

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

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

	//---- repair Version 4.0 data ----

	if (file.Version () <= 40) {
		int first, prev, next, barrier, ring, position, cycle;
		bool flag;
		Signal_Itr signal_itr;
		Timing_Itr timing_itr;
		Timing_Phase_Itr phase_itr;

		for (signal_itr = signal_array.begin (); signal_itr != signal_array.end (); signal_itr++) {
			for (timing_itr = signal_itr->timing_plan.begin (); timing_itr != signal_itr->timing_plan.end (); timing_itr++) {

				//---- map the ring positions ----

				for (ring=1; ; ring++) {
					flag = false;

					for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) {
						if (phase_itr->Ring () == ring) {
							flag = true;
							break;
						}
					}
					if (!flag) break;
					first = prev = phase_itr->Phase ();
					next = phase_itr->Position ();

					barrier = phase_itr->Barrier ();
					if (barrier == 0) {
						phase_itr->Barrier ((barrier = 1));
					}
					count = (int) timing_itr->size ();
					position = 1;
					phase_itr->Position (position);

					cycle = MAX ((phase_itr->Min_Green () + phase_itr->Extension ()), phase_itr->Max_Green ()) +
							phase_itr->Yellow () + phase_itr->All_Red ();

					while (next != first && count-- > 0) {
						flag = false;

						for (phase_itr = timing_itr->begin (); phase_itr != timing_itr->end (); phase_itr++) {
							if (phase_itr->Phase () == next) {
								flag = true;
								break;
							}
						}
						if (!flag) {
							Warning (String ("Signal %d Timing %d Phase %d was Not Found") % 
								signal_itr->Signal () % timing_itr->Timing () % next);
							break;
						}
						if (phase_itr->Ring () == 0) {
							phase_itr->Ring (ring);
						} else if (phase_itr->Ring () != ring) {
							Warning (String ("Signal %d Timing %d Phase %d to %d is Not in Ring %d") %
								signal_itr->Signal () % timing_itr->Timing () % prev % next % ring);
							break;
						}
						if (phase_itr->Barrier () == 0) {
							phase_itr->Barrier (barrier);
						}
						if (phase_itr->Barrier () == barrier) {
							position++;
						} else {
							position = 1;
							barrier = phase_itr->Barrier ();
						}
						prev = next;
						next = phase_itr->Position ();
						phase_itr->Position (position);
						cycle += MAX ((phase_itr->Min_Green () + phase_itr->Extension ()), phase_itr->Max_Green ()) +
								phase_itr->Yellow () + phase_itr->All_Red ();					
					}
					if (ring == 1) {
						timing_itr->Cycle (cycle);
					}
				}
			}
		}
	}
}
コード例 #27
0
ファイル: Read_Zone.cpp プロジェクト: kravitz/transims5
void TransitAccess::Read_Zone (void)
{
	int zone, barrier, pef;
	double area;

	Int_Itr value_itr;
	Dbl_Itr factor_itr;
	Zone_Data zone_data;
	Zone_Map_Stat map_stat;
	Zone_Map_Itr zone_itr;
	Data_Range_Itr range_itr;

	bool barrier_flag = (location_map.size () > 0);

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

	nzones = 0;
	memset (&zone_data, '\0', sizeof (zone_data));

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

		zone = zone_file.Get_Integer (zone_fld);
		if (zone == 0) continue;

		zone_data.x_coord = zone_file.Get_Integer (zone_x_fld);
		zone_data.y_coord = zone_file.Get_Integer (zone_y_fld);

		if (zone_data.x_coord == 0 && zone_data.y_coord == 0) continue;

		zone_data.location = zone_file.Get_Integer (zone_loc_fld);
		zone_data.barrier = 0;

		if (barrier_flag) {
			for (barrier=1, range_itr = location_map.begin (); range_itr != location_map.end (); range_itr++, barrier++) {
				if (range_itr->In_Range (zone_data.location)) {
					zone_data.barrier = barrier;
					break;
				}
			}
			if (zone_data.barrier == 0) {
				Warning (String ("Location %d was Not Assigned to a Barrier Group") % zone_data.location);
				continue;
			}
		}
		area = zone_file.Get_Double (zone_area_fld);

		zone_data.distance = MIN (1.0, (0.75 * sqrt (area)));

		zone_data.walk = zone_file.Get_Integer (zone_long_fld);

		pef = zone_file.Get_Integer (zone_pef_fld);
		zone_data.weight = 1.0;

		for (value_itr = pef_values.begin (), factor_itr = pef_factors.begin (); value_itr != pef_values.end (); value_itr++, factor_itr++) {
			if (pef < *value_itr) {
				zone_data.weight = *factor_itr;
				break;
			}
		}
		map_stat = zone_map.insert (Zone_Map_Data (zone, zone_data));

		if (!map_stat.second) {
			Warning (String ("Duplicate Zone Number = %d") % zone);
		}
		if (zone > nzones) nzones = zone;
	}
	End_Progress ();
	zone_file.Close ();

	Print (2, "Number of Zone Records = ") << Progress_Count ();

	zone = (int) zone_map.size ();

	if (zone != Progress_Count ()) {
		Print (1, "Number of Zones Kept = ") << zone;
	}
	Print (1, "Highest Zone Number = ") << nzones;

	//---- get the CBD coordinates ----

	zone_itr = zone_map.find (cbd_zone);

	if (zone_itr == zone_map.end ()) {
		Error (String ("CBD Zone %d was Not Found") % cbd_zone);
	}
	cbd_x = zone_itr->second.x_coord;
	cbd_y = zone_itr->second.y_coord;
}
コード例 #28
0
ファイル: Read_Routes.cpp プロジェクト: qingswu/Transim
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 ());
}
コード例 #29
0
ファイル: Read_Events.cpp プロジェクト: qingswu/Transim
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);
}
コード例 #30
0
ファイル: Read_Traveler.cpp プロジェクト: kravitz/transims4
void ArcTraveler::Read_Traveler (void)
{
	int id_field, veh_field, start_field, end_field, dist_field, ttime_field, speed_field;
	int i, traveler, last_traveler, last_spd, last_time, time, nsaved, link, dir, lane, start_time;
	double distance, ttime, offset, side, speed;
	bool select_flag;

	Link_Data *link_ptr;
	Point_Data points;
	Traveler_Data *data_ptr;

	Show_Message ("Reading %s -- Record", traveler_file.File_Type ());
	Set_Progress (10000);
	
	select_flag = (travelers.Num_Ranges () > 0);

	id_field = arcview_traveler.Field_Number ("TRAVELER");
	veh_field = arcview_traveler.Field_Number ("VEHICLE");
	start_field = arcview_traveler.Field_Number ("STARTTIME");
	end_field = arcview_traveler.Field_Number ("ENDTIME");
	dist_field = arcview_traveler.Field_Number ("DISTANCE");
	ttime_field = arcview_traveler.Field_Number ("TTIME");
	speed_field = arcview_traveler.Field_Number ("SPEED");

	if (!traveler_data.Max_Records (MIN (traveler_file.Estimate_Records (), 100000))) goto mem_error;

	//---- read and sort the traveler file ----

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

		//---- check the traveler id ----

		traveler = traveler_file.Traveler ();

		if (select_flag && !travelers.In_Range (traveler)) continue;

		//---- check the time ----

		time = times.Step (traveler_file.Time ());

		if (time_flag && !times.In_Range (time)) continue;

		//---- check the location ----

		link = traveler_file.Link ();
		dir = traveler_file.Dir ();
		offset = traveler_file.Offset ();
		lane = traveler_file.Lane ();

		if (link == 0 || lane == 0) continue;

		if (subarea_flag) {
			link_ptr = link_data.Get (link);
			if (link_ptr == NULL) continue;

			if (dir == 0) {
				distance = offset;
			} else {
				distance = UnRound (link_ptr->Length ()) - offset;
			}
			Link_Shape (link_ptr, dir, &points, distance, 0.0, 0.0);

			if (!In_Polygon (points [1]->x, points [1]->y, &select_subarea.points)) continue;
		}

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

		data_ptr = traveler_data.New_Record (true);
		if (data_ptr == NULL) goto mem_error;

		data_ptr->Traveler (traveler);
		data_ptr->Time (time);
		data_ptr->Vehicle (traveler_file.Vehicle ());
		data_ptr->Link (link);
		data_ptr->Dir (dir);
		data_ptr->Offset (Round (offset));
		data_ptr->Lane (lane);
		data_ptr->Distance (Round (traveler_file.Distance ()));
		data_ptr->Speed (Round (traveler_file.Speed ()));

		if (!traveler_data.Add ()) goto mem_error;
	}
	End_Progress ();

	Print (2, "Number of Traveler Records Read = %d", Progress_Count ());

	traveler_file.Close ();

	//---- output the selected travelers ----

	Show_Message ("Writing %s -- Record", arcview_traveler.File_Type ());
	Set_Progress (10000);

	last_traveler = last_time = start_time = time = nsaved = 0;
	last_spd = 1;
	distance = ttime = 0.0;

	for (data_ptr = traveler_data.First_Key (); ; data_ptr = traveler_data.Next_Key ()) {
		Show_Progress ();

		if (data_ptr != NULL) {
			traveler = data_ptr->Traveler ();
			time = data_ptr->Time ();
		}
		if (traveler != last_traveler || (last_spd > 0 && (time - last_time) > 1) || data_ptr == NULL) {
			if (last_traveler > 0 && last_time > start_time) {
				ttime = last_time - start_time;
				speed = distance / ttime;

				if (speed > 0.01) {
					arcview_traveler.Put_Field (end_field, times.Format_Time (last_time));
					arcview_traveler.Put_Field (dist_field, distance);
					arcview_traveler.Put_Field (ttime_field, ttime);
					arcview_traveler.Put_Field (speed_field, distance / ttime);

					if (!arcview_traveler.Write_Record ()) {
						Error ("Writing ArcView Traveler File");
					}
					nsaved++;
				}
			}
			if (data_ptr == NULL) break;

			last_traveler = traveler;
			distance = 0;

			arcview_traveler.Put_Field (id_field, traveler);

			last_time = start_time = data_ptr->Time ();
			last_spd = data_ptr->Speed ();

			arcview_traveler.Put_Field (start_field, times.Format_Time (start_time));

			arcview_traveler.points.Reset ();
		}
		if (data_ptr->Vehicle () > 0) {
			arcview_traveler.Put_Field (veh_field, data_ptr->Vehicle ());
		}
		link = data_ptr->Link ();
		dir = data_ptr->Dir ();
		lane = data_ptr->Lane ();
		offset = UnRound (data_ptr->Offset ());
		distance += UnRound (data_ptr->Distance ());
		last_time = time;
		last_spd = data_ptr->Speed ();

		link_ptr = link_data.Get (link);

		side = (2 * lane - 1) * lane_width / 2.0;

		if (dir == 1) offset = UnRound (link_ptr->Length ()) - offset;

		Link_Shape (link_ptr, dir, &points, offset, 0.0, side);

		for (i=1; i <= points.Num_Points (); i++) {
			if (!arcview_traveler.points.Add (points [i])) goto mem_error;
		}
	}
	End_Progress ();

	arcview_traveler.Close ();

	Print (1, "Number of Traveler Records Saved = %d", nsaved);
	return;

mem_error:
	Error ("Insufficient Memory for Traveler Data");
	return;
}