bool ArcDelay::Performance_Processing (Db_File *fh) { //---- check the subarea polygon ---- if (subarea_flag) { Delay_File *file = (Delay_File *) fh; if (!file->Nest ()) { int link; Node_Data *node_ptr; Link_Data *link_ptr; link = file->Link (); if (link < 0) link = -link; link_ptr = link_data.Get (link); if (link_ptr == NULL) return (false); node_ptr = node_data.Get (link_ptr->Anode ()); if (!In_Polygon (UnRound (node_ptr->X ()), UnRound (node_ptr->Y ()), &select_subarea.points)) { node_ptr = node_data.Get (link_ptr->Bnode ()); if (!In_Polygon (UnRound (node_ptr->X ()), UnRound (node_ptr->Y ()), &select_subarea.points)) { return (false); } } } } return (Demand_Service::Performance_Processing (fh)); }
void ArcSnapshot::Set_Subarea (void) { Link_Itr link_itr; Node_Data *node_ptr; for (link_itr = link_array.begin (); link_itr != link_array.end (); link_itr++) { node_ptr = &node_array [link_itr->Anode ()]; if (!In_Polygon (subarea_file, UnRound (node_ptr->X ()), UnRound (node_ptr->Y ()))) { node_ptr = &node_array [link_itr->Bnode ()]; if (!In_Polygon (subarea_file, UnRound (node_ptr->X ()), UnRound (node_ptr->Y ()))) { link_itr->Use (0); } } } }
bool SubareaNet::Node_Processing (Db_File *fh) { Node_File *file = (Node_File *) fh; //---- reserve memory ---- if (First_Record ()) { if (!node_db.Max_Records (file->Num_Records ())) { Error ("Insufficient Memory for Node Database"); } } //---- do standard processing ---- if (Network_Service::Node_Processing (fh)) { //---- copy the record to the node database ---- node_db.Copy_Fields (file); if (!node_db.Add_Record ()) { Error ("Writing Node Database"); } //---- check the subarea boundary ---- Node_Data *node_ptr = node_data.New_Record (); if (In_Polygon (UnRound (node_ptr->X ()), UnRound (node_ptr->Y ()), &subarea_boundary.points)) { node_ptr->Type (1); } else { node_ptr->Type (0); } return (true); } return (false); }
bool SubareaNet::Zone_Processing (Db_File *fh) { static Zone_File *new_file; double x, y; Zone_File *file = (Zone_File *) fh; if (First_Record ()) { new_file = (Zone_File *) Network_Db_Base (NEW_ZONE); } //---- check the ID and output file ---- if (file->Zone () == 0 || new_file == NULL) return (false); //---- check the coordinates ---- x = file->X (); y = file->Y (); if (In_Polygon (x, y, &subarea_boundary.points)) { //---- copy the fields to the subarea file ---- new_file->Copy_Fields (file); if (!new_file->Write ()) { Error ("Writing %s", new_file->File_Type ()); } nzone++; } //---- don't save the record ---- return (false); }
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; }
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 (); }
void ExportPlans::Select_Links (void) { int new_loc, count; Int_Map_Itr map_itr; Link_Data *link_ptr; Link_Itr link_itr; Node_Itr node_itr; Node_Data *anode_ptr, *bnode_ptr, *node_ptr; Data_Range_Itr range_itr; Location_Data *loc_ptr; //---- set node selection flag ---- for (node_itr = node_array.begin (); node_itr != node_array.end (); node_itr++) { node_itr->Subarea (0); if (select_subarea) { if (In_Polygon (subarea_file, UnRound (node_itr->X ()), UnRound (node_itr->Y ()))) node_itr->Subarea (1); } if (node_itr->Subarea () == 0 && select_nodes) { for (range_itr = node_ranges.begin (); range_itr != node_ranges.end (); range_itr++) { if (range_itr->In_Range (node_itr->Node ())) { node_itr->Subarea (1); break; } } } } //---- set link selection flag ---- for (link_itr = link_array.begin (); link_itr != link_array.end (); link_itr++) { link_itr->Divided (0); anode_ptr = &node_array [link_itr->Anode ()]; bnode_ptr = &node_array [link_itr->Bnode ()]; if (anode_ptr->Subarea () == 1 || bnode_ptr->Subarea () == 1) { if (anode_ptr->Subarea () == 1) link_itr->Divided (1); if (bnode_ptr->Subarea () == 1) link_itr->Divided (link_itr->Divided () + 2); if (anode_ptr->Subarea () == 0) anode_ptr->Subarea (2); if (bnode_ptr->Subarea () == 0) bnode_ptr->Subarea (2); } } //---- flag activity locations within the subarea ---- for (map_itr = location_map.begin (); map_itr != location_map.end (); map_itr++) { loc_ptr = &location_array [map_itr->second]; link_ptr = &link_array [loc_ptr->Link ()]; if (link_ptr->Divided () != 0) { loc_ptr->Zone (1); if (zone_loc_flag) { zone_loc_file.File () << (String ("%d\t%.2lf\t%.2lf") % loc_ptr->Location () % UnRound (loc_ptr->X ()) % UnRound (loc_ptr->Y ())) << endl; } } else { loc_ptr->Zone (0); } } //---- set the external stations location number ---- map_itr = --location_map.end (); new_loc = map_itr->first; new_loc = ((new_loc + 1) / 100 + 1) * 100; count = 0; for (map_itr = link_map.begin (); map_itr != link_map.end (); map_itr++) { link_ptr = &link_array [map_itr->second]; if (link_ptr->Divided () != 1 && link_ptr->Divided () != 2) continue; if (link_ptr->Divided () == 1) { node_ptr = &node_array [link_ptr->Bnode ()]; } else { node_ptr = &node_array [link_ptr->Anode ()]; } if (zone_loc_flag) { zone_loc_file.File () << (String ("%d\t%.2lf\t%.2lf") % new_loc % UnRound (node_ptr->X ()) % UnRound (node_ptr->Y ())) << endl; } node_ptr->Control (new_loc++); count++; } Print (2, "Number of New External Locations = ") << count; }
void ZoneData::Read_Zone (void) { int i, field, id, count, num_in, num_out; double dx, dy; Db_Index_Array *data; Index_Array *polygon; Boundary *ptr; num_in = num_out = 0; //---- read the zone file to count records ---- Show_Message ("Reading %s -- Record", input_file->File_Type ()); Set_Progress (1000); while (input_file->Read ()) { Show_Progress (); id = input_file->Zone (); if (id == 0) continue; //---- count the records for the data file ----- for (i=0; i < num_data_files; i++) { data = data_db [i]; if (data == NULL) continue; field = zone_field [i]; input_file->Get_Field (field, &id); if (id <= 0) continue; if (data->Get_Record (&id)) { data->Get_Field (2, &count); data->Put_Field (2, ++count); data->Write_Record (); } } } input_file->Rewind (); //---- copy the zones to the output file ---- Set_Progress (1000); while (input_file->Read ()) { Show_Progress (); id = input_file->Zone (); if (id == 0) continue; num_in++; output_file->Copy_Fields (input_file); //---- copy standard field types ----- output_file->Zone (id); output_file->X (input_file->X ()); output_file->Y (input_file->Y ()); output_file->Area_Type (input_file->Area_Type ()); //---- set the data field id ---- if (script_flag) { for (i=0; i < num_data_files; i++) { data = data_db [i]; if (data == NULL) continue; field = zone_field [i]; input_file->Get_Field (field, &id); if (!data->Get_Record (&id)) { data->Reset_Record (); } } //---- set the polygon record index ---- if (polygon_flag) { dx = input_file->X (); dy = input_file->Y (); } for (i=0; i < num_polygons; i++) { data = polygon_db [i]; if (data == NULL) continue; polygon = polygons [i]; //---- find the polygon index ---- id = 0; for (ptr = (Boundary *) polygon->First (); ptr; ptr = (Boundary *) polygon->Next ()) { if (In_Polygon (dx, dy, ptr->points)) { id = ptr->zone; break; } } if (!id || !data->Get_Record (&id)) { data->Reset_Record (); } } //---- execute the conversion script ---- if (program.Execute (num_in) == 0) continue; } //---- save the output fields ---- if (!output_file->Write ()) { Error ("Writing %s Record %d", output_file->File_Type (), id); } num_out++; } End_Progress (); input_file->Close (); output_file->Close (); Write (2, "Number of Zone Records Read = %d", num_in); Write (1, "Number of Zone Records Written = %d", num_out); }
void ArcDelay::Read_Link_Data (void) { int i, center, link, lane, num_lanes, num_rec; double length, side, start, width; bool offset_flag; XYZ_Point point, *ptr; Link_Data *link_ptr; Node_Data *node_ptr; Dir_Data *dir_ptr; offset_flag = (link_offset != 0.0); Show_Message ("Reading %s -- Record", arcview_link_data.File_Type ()); Set_Progress (1000); num_rec = 0; //---- process each link ---- while (link_data_file.Read ()) { Show_Progress (); //---- get the link ---- link = link_data_file.Link (); link_ptr = link_data.Get (link); if (link_ptr == NULL) continue; //---- check the subarea polygon ---- if (subarea_flag) { node_ptr = node_data.Get (link_ptr->Anode ()); if (!In_Polygon (UnRound (node_ptr->X ()), UnRound (node_ptr->Y ()), &select_subarea.points)) { node_ptr = node_data.Get (link_ptr->Bnode ()); if (!In_Polygon (UnRound (node_ptr->X ()), UnRound (node_ptr->Y ()), &select_subarea.points)) { continue; } } } //---- copy the data fields ---- arcview_link_data.Copy_Fields (&link_data_file); arcview_link_data.parts.Reset (); arcview_link_data.points.Reset (); //---- bandwidth processing ---- if (width_flag) { arcview_link_data.Get_Field (width_field, &width); if (width == 0.0) continue; if (width > 0) { width = width / width_factor; } else { width = -width / width_factor; } if (width < min_width) { width = min_width; } else if (width > max_width) { width = max_width; } width = -width; length = UnRound (link_ptr->Length ()); //---- get the centerline points ---- Link_Shape (link_ptr, 0, &points, 0.0, length, 0.0); ptr = points.First (); point = *ptr; if (!arcview_link_data.parts.Add (0)) goto mem_error; for (; ptr; ptr = points.Next ()) { if (!arcview_link_data.points.Add (ptr)) goto point_error; } //---- get the outside points of the band ---- Link_Shape (link_ptr, 1, &points, length, length, width); if (max_angle > 0 && min_length > 0) { Smooth_Shape (&points, max_angle, min_length); } for (ptr = points.First (); ptr; ptr = points.Next ()) { if (!arcview_link_data.points.Add (ptr)) goto point_error; } //---- close the polygon ---- if (!arcview_link_data.points.Add (&point)) goto point_error; } else { //---- draw lanes ---- if (lanes_flag) { if (link_ptr->AB_Dir () > 0) { dir_ptr = dir_data [link_ptr->AB_Dir ()]; if (dir_ptr == NULL) continue; length = UnRound (link_ptr->Length ()); start = UnRound (link_ptr->Aoffset ()); length -= start + UnRound (link_ptr->Boffset ()); lane = dir_ptr->Left (); num_lanes = dir_ptr->Thru () + lane; //---- find the center point ---- if (center_flag && link_ptr->BA_Dir () == 0) { center = num_lanes + dir_ptr->Right () + 1; } else { center = 1; } for (++lane; lane <= num_lanes; lane++) { side = (2 * lane - center) * lane_width / 2.0; Link_Shape (link_ptr, 0, &points, start, length, side); if (!arcview_link_data.parts.Add (arcview_link_data.points.Num_Points ())) goto mem_error; for (i=1; i <= points.Num_Points (); i++) { if (!arcview_link_data.points.Add (points [i])) goto mem_error; } } } if (link_ptr->BA_Dir () > 0) { dir_ptr = dir_data [link_ptr->BA_Dir ()]; if (dir_ptr == NULL) continue; length = UnRound (link_ptr->Length ()); start = length - UnRound (link_ptr->Boffset ()); length = start - UnRound (link_ptr->Aoffset ()); lane = dir_ptr->Left (); num_lanes = dir_ptr->Thru () + lane; //---- find the center point ---- if (center_flag && link_ptr->AB_Dir () == 0) { center = num_lanes + dir_ptr->Right () + 1; } else { center = 1; } for (++lane; lane <= num_lanes; lane++) { side = (2 * lane - center) * lane_width / 2.0; Link_Shape (link_ptr, 1, &points, start, length, side); if (!arcview_link_data.parts.Add (arcview_link_data.points.Num_Points ())) goto mem_error; for (i=1; i <= points.Num_Points (); i++) { if (!arcview_link_data.points.Add (points [i])) goto mem_error; } } } } else { if (offset_flag) { //---- draw link in AB direction ---- if (link_ptr->AB_Dir () > 0) { if (center_flag && link_ptr->BA_Dir () == 0) { side = 0.0; } else { side = link_offset; } Link_Shape (link_ptr, 0, &points, 0.0, -1.0, side); if (!arcview_link_data.parts.Add (0)) goto mem_error; for (i=1; i <= points.Num_Points (); i++) { if (!arcview_link_data.points.Add (points [i])) goto mem_error; } } //---- draw link in BA direciton ---- if (link_ptr->BA_Dir () > 0) { if (center_flag && link_ptr->AB_Dir () == 0) { side = 0.0; } else { side = link_offset; } Link_Shape (link_ptr, 1, &points, -1.0, -1.0, side); if (!arcview_link_data.parts.Add (arcview_link_data.points.Num_Points ())) goto mem_error; for (i=1; i <= points.Num_Points (); i++) { if (!arcview_link_data.points.Add (points [i])) goto mem_error; } } } else { //---- draw centerline ----- if (!arcview_link_data.parts.Add (0)) goto mem_error; Link_Shape (link_ptr, 0, &arcview_link_data.points); } } } //---- save the link record ---- if (!arcview_link_data.Write_Record ()) { Error ("Writing %s", arcview_link_data.File_Type ()); } num_rec++; } End_Progress (); arcview_link_data.Close (); Print (2, "Number of Arcview Link Data Records = %d", num_rec); return; point_error: Error ("Insufficient Memory for %d Points", arcview_link_data.points.Num_Points ()); mem_error: Error ("Insufficient Memory for Link Shape Points"); }
bool TripPrep::Trip_Check (int hhold, int origin, int destination, int start, int end, int mode, int purpose, int vehicle) { int org, des, period, start_period, end_period; Location_Data *loc_ptr; Factor_Data *factor_ptr; Vehicle_Data *veh_ptr; //---- household selection ---- if (traveler_flag) { if (!traveler_range.In_Range (hhold)) return (false); } //---- mode selection ----- if (mode < 0 || mode >= MAX_MODE) { Warning ("Mode %d is Out of Range (0..%d)", mode, MAX_MODE-1); return (false); } if (!trip_mode [mode]) return (false); //---- purpose selection ---- if (purpose_flag) { if (!purpose_range.In_Range (purpose)) return (false); } //---- get the mid trip time ---- start_period = time_periods.In_Index (start); end_period = time_periods.In_Index (end); period = time_periods.In_Index ((start + end + 1) / 2); if (period == 0) { period = start_period; if (period == 0) { period = end_period; } } if (period == 0) return (false); //---- set the origin ---- if (location_flag && origin >= 0 && destination >= 0) { loc_ptr = location_data.Get (origin); if (loc_ptr == NULL) { if (origin != 0) { Warning ("Location %d was Not Found in the Location File", origin); } return (false); } if (select_org_flag) { if (!In_Polygon (UnRound (loc_ptr->X ()), UnRound (loc_ptr->Y ()), &select_origin.points)) return (false); } org = loc_ptr->Zone (); if (org_zone_flag) { if (!org_zone_range.In_Range (org)) return (false); } //---- set the destination ---- loc_ptr = location_data.Get (destination); if (loc_ptr == NULL) { if (destination != 0) { Warning ("Location %d was Not Found in the Location File", destination); } return (false); } if (select_des_flag) { if (!In_Polygon (UnRound (loc_ptr->X ()), UnRound (loc_ptr->Y ()), &select_destination.points)) return (false); } des = loc_ptr->Zone (); if (des_zone_flag) { if (!des_zone_range.In_Range (des)) return (false); } //---- apply the probability factor ---- if (factor_flag) { if (zone_equiv_flag) { origin = zone_equiv.Zone_Group (org); destination = zone_equiv.Zone_Group (des); } else { origin = org; destination = des; } factor_ptr = factor_data.Get (origin, destination, time_equiv.Period ((start + end + 1) / 2)); if (factor_ptr != NULL) { if (!factor_ptr->Bucket_Factor (1.0)) return (false); } } } //---- apply selection percentage ---- if (prob_flag) { if (random2.Probability () > probability) return (false); } //---- add vehicle to the list ---- if (vehicle > 0) { //---- synthetic OD data ---- if (synod_flag) { veh_ptr = vehicle_data.Get (vehicle); //---- process trucks ---- if (veh_ptr->Type () == 2) { org_target [org] -= 1; des_target [des] -= 1; if (org_target [org] < 0) org_target [org] = 0.0; if (des_target [des] < 0) des_target [des] = 0.0; } else { if (hhold_range.In_Range (veh_ptr->Household ())) { veh_count [org] [des] += 1; next_veh [vehicle_data.Record_Index ()] = first_veh [org] [des]; first_veh [org] [des] = vehicle_data.Record_Index (); } } } if (vehicle_list.Get_Index (vehicle) == 0) { if (!vehicle_list.Add (vehicle)) { Error ("Adding Vehicle %d to the List", vehicle); } } } return (true); }
void LocationData::Write_Location (void) { int index, field, loc, num_in, num_out; int x, y, zone, zone_field, join; double dx, dy, weight, weight1, weight2, distance; Dtime time; Db_Sort_Array *data; Location_Data *location_ptr; Link_Data *link_ptr; Loc_Walk_Data *loc_walk_ptr; Subzone_Data *subzone_ptr; Sub_Group_Itr sub_itr; Data_Itr data_itr; Points_Map_Itr boundary_itr; Points_Map *polygon; Polygon_Itr poly_itr; Int2_Key key, key2; Int2_Map_Itr int2_itr; Int_Map_Itr int_itr; I2_Dbl_Map_Itr wt_itr; Int_Dbl_Map_Itr loc_itr; Int_Itr fld_itr, code_itr; num_in = num_out = 0; //---- reopen the activity location file ---- input_file->Open (0); zone_field = input_file->Zone_Field (); Show_Message (String ("Writing %s -- Record") % output_file->File_Type ()); Set_Progress (); while (input_file->Read ()) { Show_Progress (); loc = input_file->Location (); if (loc == 0) continue; int_itr = location_map.find (loc); index = int_itr->second; location_ptr = &location_array [index]; num_in++; output_file->Copy_Fields (*input_file); //---- copy standard field types ----- output_file->Location (loc); output_file->Link (input_file->Link ()); output_file->Dir (input_file->Dir ()); output_file->Offset (input_file->Offset ()); output_file->Setback (input_file->Setback ()); //---- get the zone number ---- zone = location_ptr->Zone (); if (zone_file_flag && zone >= 0) { zone = zone_array [zone].Zone (); } output_file->Zone (zone); //---- set the link use flag field ---- if (use_flag) { int_itr = link_map.find (output_file->Link ()); if (int_itr != link_map.end ()) { link_ptr = &link_array [int_itr->second]; code_itr = use_code.begin (); for (fld_itr = use_field.begin (); fld_itr != use_field.end (); fld_itr++, code_itr++) { if ((link_ptr->Use () & (*code_itr)) > 0) { output_file->Put_Field (*fld_itr, 1); } else { output_file->Put_Field (*fld_itr, 0); } } } } //---- calculate the walk access field ---- if (walk_access_flag) { loc_walk_ptr = &loc_walk_array [index]; output_file->Put_Field (walk_access_field, loc_walk_ptr->weight); } //---- calculate the subzone fields ---- for (sub_itr = sub_group.begin (); sub_itr != sub_group.end (); sub_itr++) { if (sub_itr->loc_field < 0) continue; output_file->Put_Field (sub_itr->loc_field, 0); //---- allocate subzone data ---- if (subzone_map_flag) { loc_itr = sub_itr->loc_weight.find (loc); if (loc_itr != sub_itr->loc_weight.end ()) { weight = loc_itr->second; } else { weight = 0; } } else if (sub_itr->max_distance == 0) { weight = 0; key.first = zone; key.second = 0; for (int2_itr = sub_itr->data_map.lower_bound (key); int2_itr != sub_itr->data_map.end (); int2_itr++) { if (int2_itr->first.first != zone) break; subzone_ptr = &sub_itr->data [int2_itr->second]; if (subzone_ptr->Data () == 0) continue; key2.first = int2_itr->first.second; key2.second = loc; wt_itr = subzone_weight.find (key2); if (wt_itr != subzone_weight.end () && subzone_ptr->Data () > 0) { weight += subzone_ptr->Data () * wt_itr->second; } } if (weight < 0) weight = 0; } else { //---- distance weighted attribute ---- x = location_ptr->X (); y = location_ptr->Y (); weight1 = weight2 = 0; key.first = zone; key.second = 0; for (int2_itr = sub_itr->data_map.lower_bound (key); int2_itr != sub_itr->data_map.end (); int2_itr++) { if (int2_itr->first.first != zone) break; subzone_ptr = &sub_itr->data [int2_itr->second]; dx = UnRound (subzone_ptr->X () - x); dy = UnRound (subzone_ptr->Y () - y); distance = sqrt (dx * dx + dy * dy); if (distance < sub_itr->max_distance) { weight = subzone_ptr->Data () * (sub_itr->max_distance - distance); if (weight > weight1) { weight2 = weight1; weight1 = weight; } else if (weight > weight2) { weight2 = weight; } } } weight = (weight1 + weight2) / 2.0; } output_file->Put_Field (sub_itr->loc_field, weight); } //---- set the data field id ---- if (script_flag) { for (data_itr = data_group.begin (); data_itr != data_group.end (); data_itr++) { data = data_itr->data_db; field = data_itr->loc_field; if (field == zone_field) { join = zone; } else { join = input_file->Get_Integer (field); } if (!data->Read_Record (join)) { data->Reset_Record (); } } //---- set the polygon record index ---- if (polygon_flag) { dx = UnRound (location_ptr->X ()); dy = UnRound (location_ptr->Y ()); for (poly_itr = polygons.begin (); poly_itr != polygons.end (); poly_itr++) { data = poly_itr->data_db; polygon = &poly_itr->polygon; join = 0; for (boundary_itr = polygon->begin (); boundary_itr != polygon->end (); boundary_itr++) { if (In_Polygon (boundary_itr->second, dx, dy)) { join = boundary_itr->first; break; } } if (join == 0 || !data->Read_Record (join)) { data->Reset_Record (); } } } //---- execute the conversion script ---- if (program.Execute (num_in) == 0) continue; } //---- save the output fields ---- if (!output_file->Write ()) { Error (String ("Writing %s Record %d") % output_file->File_Type () % loc); } num_out++; } End_Progress (); input_file->Close (); output_file->Close (); }