Link_Delay_File::Link_Delay_File (Access_Type access, Format_Type format, Units_Type flow, bool turn_flag, bool flow_flag) : Db_Header (access, format) { Flow_Units (flow); Turn_Flag (turn_flag); Lane_Use_Flows (flow_flag); Setup (); }
void Data_Service::Read_Lane_Uses (Lane_Use_File &file) { int i, num, index, first_index, rec, lanes0, lanes1, lane, group, periods, size; Dir_Itr dir_itr; Link_Data *link_ptr; Lane_Use_Period period_rec; Use_Period_Array period_array; Use_Period_Itr period_itr; Int_Set time_sort; Int_Set_Itr time_itr; Link_Dir_Data index_rec, *index_ptr; Integers lane_type; Int_RItr lane_ritr; Lane_Use_Data lane_use_rec; //---- store the lane use data ---- Show_Message (String ("Reading %s -- Record") % file.File_Type ()); Set_Progress (); Initialize_Lane_Uses (file); num = 0; while (file.Read ()) { Show_Progress (); lane_use_rec.Clear (); if (Get_Lane_Use_Data (file, lane_use_rec)) { lane_use_array.push_back (lane_use_rec); } } End_Progress (); file.Close (); Print (2, String ("Number of %s Records = %d") % file.File_Type () % Progress_Count ()); num = (int) lane_use_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 (LANE_USE); Lane_Use_Data *lane_use_ptr; Dir_Data *dir_ptr; //---- create directional link list ---- while (num--) { lane_use_ptr = &lane_use_array [num]; dir_ptr = &dir_array [lane_use_ptr->Dir_Index ()]; lane_use_ptr->Next_Index (dir_ptr->First_Lane_Use ()); dir_ptr->First_Lane_Use (num); } //----- identify time period restrictions ---- size = (int) dir_array.size (); for (index=0, dir_itr = dir_array.begin (); dir_itr != dir_array.end (); dir_itr++, index++) { first_index = dir_itr->First_Lane_Use (); if (first_index < 0) continue; //---- sort lane use time points ---- link_ptr = &link_array [dir_itr->Link ()]; time_sort.clear (); for (num = first_index; num >= 0; num = lane_use_ptr->Next_Index ()) { lane_use_ptr = &lane_use_array [num]; time_sort.insert (lane_use_ptr->Start ()); time_sort.insert (lane_use_ptr->End ()); } //---- create start-end time combinations ---- period_array.clear (); period_rec.Clear (); periods = 0; for (time_itr = time_sort.begin (); time_itr != time_sort.end (); time_itr++) { period_rec.End (*time_itr); if (periods > 0) { period_array.push_back (period_rec); } period_rec.Start (*time_itr); periods++; } periods = 0; //---- identify lane use records within each time period ---- dir_itr->First_Lane_Use ((int) use_period_array.size ()); for (period_itr = period_array.begin (); period_itr != period_array.end (); period_itr++) { period_itr->Index ((int) use_period_index.size ()); for (num = first_index; num >= 0; num = lane_use_ptr->Next_Index ()) { lane_use_ptr = &lane_use_array [num]; if (period_itr->Start () >= lane_use_ptr->Start () && period_itr->End () <= lane_use_ptr->End ()) { period_itr->Add_Record (); index_rec.Link (num); index_rec.Dir (0); use_period_index.push_back (index_rec); } } if (period_itr->Records () == 0) continue; periods++; //---- check for lane groups ---- num = period_itr->Records (); lanes1 = 0; lanes0 = dir_itr->Lanes (); lane_type.assign (lanes0, 0); for (i=1, rec=period_itr->Index (); i <= num; i++, rec++) { index_ptr = &use_period_index [rec]; lane_use_ptr = &lane_use_array [index_ptr->Link ()]; //---- must be a full length restriction ---- if (lane_use_ptr->Offset () > 0 || lane_use_ptr->Length () > 0) continue; group = i; if (lane_use_ptr->Type () == APPLY) { //---- must apply to a subset of lanes ---- if (lane_use_ptr->Low_Lane () <= dir_itr->Left () && lane_use_ptr->High_Lane () >= (dir_itr->Left () + dir_itr->Lanes ())) { continue; } } else if ((lane_use_ptr->Type () == LIMIT && dat->Use_Permission (lane_use_ptr->Use (), NONE)) || (lane_use_ptr->Type () == PROHIBIT && lane_use_ptr->Use () == ANY_USE_CODE)) { group = -1; } lanes0 = lane_use_ptr->Low_Lane () - dir_itr->Left (); if (lanes0 < 0) lanes0 = 0; lanes1 = lane_use_ptr->High_Lane () - dir_itr->Left (); if (lanes1 >= dir_itr->Lanes ()) lanes1 = dir_itr->Lanes () - 1; for (lane = lanes0; lane <= lanes1; lane++) { lane_type [lane] = group; } } lanes0 = lanes1 = group = 0; for (lane_ritr = lane_type.rbegin (); lane_ritr != lane_type.rend (); lane_ritr++) { if (*lane_ritr < 0) continue; if (lanes0 == 0) { lanes0++; group = *lane_ritr; } else if (*lane_ritr == group) { lanes0++; } else { lanes1++; } } period_itr->Lanes0 (lanes0); period_itr->Lanes1 (lanes1); if (lanes0 != 0 && lanes1 != 0) { //----- set flow index for lane groups ---- if (Lane_Use_Flows () && dir_itr->Use_Index () < 0) { dir_itr->Use_Index (size + Add_Lane_Use_Flows ()); lane_use_flow_index.push_back (index); } //---- set the group flags ---- for (i=1, rec=period_itr->Index (); i <= num; i++, rec++) { index_ptr = &use_period_index [rec]; if (i > group) index_ptr->Dir (1); } } } //---- save the period records ---- for (period_itr = period_array.begin (); period_itr != period_array.end (); period_itr++) { if (period_itr->Records () > 0) { period_itr->Periods (--periods); use_period_array.push_back (*period_itr); } } } Print (1, "Number of Lane Use Flow Records = ") << Num_Lane_Use_Flows (); } }
void LinkSum::Program_Control (void) { int i, field, ngroup, num; bool binary; String key, token; Location_File *location_file; Db_Field *fld; Doubles dbl; Doubles_Itr itr; //---- set the equivalence flags ---- Zone_Equiv_Flag (Check_Control_Key (NEW_GROUP_TRAVEL_FILE)); group_select = Set_Control_Flag (SELECT_BY_LINK_GROUP); Link_Equiv_Flag (group_select || Report_Flag (LINK_GROUP) || Report_Flag (TRAVEL_TIME) || Report_Flag (GROUP_REPORT) || Report_Flag (GROUP_SUMMARY) || Check_Control_Key (NEW_GROUP_SUMMARY_FILE)); //---- open network files ---- Data_Service::Program_Control (); Read_Select_Keys (); turn_flag = System_File_Flag (TURN_DELAY); Print (2, String ("%s Control Keys:") % Program ()); //---- open the compare performance file ---- key = Get_Control_String (COMPARE_PERFORMANCE_FILE); if (!key.empty ()) { compare_file.File_Type ("Compare Performance File"); Print (1); if (Check_Control_Key (COMPARE_PERFORMANCE_FORMAT)) { compare_file.Dbase_Format (Get_Control_String (COMPARE_PERFORMANCE_FORMAT)); } compare_file.Open (Project_Filename (key)); compare_flag = true; } num_inc = sum_periods.Num_Periods (); if (num_inc < 1) num_inc = 1; cap_factor = (double) sum_periods.Range_Length () / (Dtime (1, HOURS) * num_inc); if (cap_factor <= 0.0) cap_factor = 1.0; //---- open the compare link map file ---- key = Get_Control_String (COMPARE_LINK_MAP_FILE); if (!key.empty ()) { link_map_file.File_Type ("Compare Link Map File"); Print (1); if (Check_Control_Key (COMPARE_LINK_MAP_FORMAT)) { link_map_file.Dbase_Format (Get_Control_String (COMPARE_LINK_MAP_FORMAT)); } link_map_file.Open (Project_Filename (key)); link_map_flag = true; } //---- get minimum volume ---- minimum_volume = Get_Control_Double (MINIMUM_LINK_VOLUME); //---- person-based statistics ---- person_flag = Get_Control_Flag (PERSON_BASED_STATISTICS); //---- get the select by link group flag ---- group_select = Get_Control_Flag (SELECT_BY_LINK_GROUP); if (group_select || select_subareas || select_polygon || select_facilities) select_flag = true; //---- turning movement data ---- if (turn_flag) { //---- open the compare turn delays file ---- key = Get_Control_String (COMPARE_TURN_DELAY_FILE); if (!key.empty ()) { turn_compare_file.File_Type ("Compare Turn Delay File"); Print (1); if (Check_Control_Key (COMPARE_TURN_DELAY_FORMAT)) { turn_compare_file.Dbase_Format (Get_Control_String (COMPARE_TURN_DELAY_FORMAT)); } turn_compare_file.Open (Project_Filename (key)); turn_compare_flag = true; } //---- select turn nodes---- key = exe->Get_Control_Text (TURN_NODE_RANGE); if (!key.empty () && !key.Equals ("ALL")) { if (!turn_range.Add_Ranges (key)) { exe->Error ("Adding Turn Node Ranges"); } } } //---- create link activity file ---- key = Get_Control_String (NEW_LINK_ACTIVITY_FILE); if (!key.empty ()) { if (!System_File_Flag (LOCATION)) { Error ("A Location File is needed for the Link Activity File"); } location_file = System_Location_File (); binary = (location_file->Record_Format () == BINARY); Print (1); activity_file.File_Type ("New Link Activity File"); if (Check_Control_Key (NEW_LINK_ACTIVITY_FORMAT)) { activity_file.Dbase_Format (Get_Control_String (NEW_LINK_ACTIVITY_FORMAT)); } activity_file.Create (Project_Filename (key)); //---- copy location field name ---- key = Get_Control_Text (COPY_LOCATION_FIELDS); if (key.empty ()) { Error ("Location Field Names are Required for Link Activity File"); } link_db.File_Type ("Link Location Database"); //---- set required fields ---- link_db.Add_Field ("LINK", DB_INTEGER, 10); activity_file.Add_Field ("LINK", DB_INTEGER, 10); //---- copy selected fields ---- while (!key.Split (token)) { field = location_file->Field_Number (token); if (field < 0) { Error (String ("Field %s was Not Found in the Location File") % token); } field_list.push_back (field); fld = location_file->Field (field); link_db.Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Units (), binary); activity_file.Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Units (), binary); } activity_file.Write_Header (); activity_flag = true; } //---- create zone travel file ---- key = Get_Control_String (NEW_ZONE_TRAVEL_FILE); if (!key.empty ()) { if (!System_File_Flag (LOCATION)) { Error ("A Location File is needed for the Zone Travel File"); } Print (1); zone_file.File_Type ("New Zone Travel File"); if (Check_Control_Key (NEW_ZONE_TRAVEL_FORMAT)) { zone_file.Dbase_Format (Get_Control_String (NEW_ZONE_TRAVEL_FORMAT)); } zone_file.Create (Project_Filename (key)); zone_flag = true; } //---- create zone group travel file ---- key = Get_Control_String (NEW_GROUP_TRAVEL_FILE); if (!key.empty ()) { if (!System_File_Flag (LOCATION)) { Error ("A Location File is needed for the Group Travel File"); } Print (1); group_file.File_Type ("New Group Travel File"); if (Check_Control_Key (NEW_GROUP_TRAVEL_FORMAT)) { group_file.Dbase_Format (Get_Control_String (NEW_GROUP_TRAVEL_FORMAT)); } group_file.Create (Project_Filename (key)); group_flag = true; } if (!activity_flag && !zone_flag && !group_flag) { System_File_False (LOCATION); } //---- get the number of direction groups ---- ngroup = Highest_Control_Group (NEW_LINK_DIRECTION_FILE, 0); if (ngroup > 0) { Dir_Group group, *group_ptr; //---- process each group ---- for (i=1; i <= ngroup; i++) { key = Get_Control_String (NEW_LINK_DIRECTION_FILE, i); if (key.empty ()) continue; Print (1); dir_group.push_back (group); group_ptr = &dir_group.back (); group_ptr->group = i; group_ptr->file = new Link_Direction_File (); group_ptr->file->File_Type (String ("New Link Direction File #%d") % i); if (Check_Control_Key (NEW_LINK_DIRECTION_FORMAT, i)) { group_ptr->file->Dbase_Format (Get_Control_String (NEW_LINK_DIRECTION_FORMAT, i)); } group_ptr->file->Lane_Use_Flows (Lane_Use_Flows ()); group_ptr->file->Create (Project_Filename (key)); //---- get the field name ---- key = Get_Control_Text (NEW_LINK_DIRECTION_FIELD, i); if (key.empty ()) { Error (String ("New Link Direction Field #%d is Missing") % i); } group_ptr->field = Performance_Code (key); group_ptr->index = Get_Control_Flag (NEW_LINK_DIRECTION_INDEX, i); group_ptr->flip = Get_Control_Flag (NEW_LINK_DIRECTION_FLIP, i); if (group_ptr->flip && !compare_flag) { Warning ("Link Direction Flipping requires Comparison Data"); group_ptr->flip = false; } Set_Link_Dir (group_ptr); } } //---- get the number of groups ---- ngroup = Highest_Control_Group (NEW_LINK_DATA_FILE, 0); if (ngroup > 0) { Data_Group group, *group_ptr; //---- process each group ---- for (i=1; i <= ngroup; i++) { key = Get_Control_String (NEW_LINK_DATA_FILE, i); if (key.empty ()) continue; Print (1); data_group.push_back (group); group_ptr = &data_group.back (); group_ptr->group = i; group_ptr->file = new Link_Data_File (); group_ptr->file->File_Type (String ("New Link Data File #%d") % i); if (Check_Control_Key (NEW_LINK_DATA_FORMAT, i)) { group_ptr->file->Dbase_Format (Get_Control_String (NEW_LINK_DATA_FORMAT, i)); } group_ptr->file->Lane_Use_Flows (Lane_Use_Flows ()); group_ptr->file->Create (Project_Filename (key)); //---- get the field name ---- key = Get_Control_Text (NEW_LINK_DATA_FIELD, i); if (key.empty ()) { Error (String ("New Link Data Field #%d is Missing") % i); } group_ptr->field = Performance_Code (key); Set_Link_Data (group_ptr); } } //---- data summary file ---- key = Get_Control_String (NEW_DATA_SUMMARY_FILE); if (!key.empty ()) { Print (1); summary_file.File_Type ("New Data Summary File"); if (Check_Control_Key (NEW_DATA_SUMMARY_FORMAT)) { summary_file.Dbase_Format (Get_Control_String (NEW_DATA_SUMMARY_FORMAT)); } summary_file.Add_Field ("MEASURE", DB_STRING, 40); summary_file.Add_Field ("VALUE", DB_DOUBLE, 12.2); if (compare_flag) summary_file.Add_Field ("COMPARE", DB_DOUBLE, 12.2); summary_file.Create (Project_Filename (key)); summary_flag = true; //---- data summary periods ---- if (!Control_Key_Empty (NEW_DATA_SUMMARY_PERIODS)) { periods_flag = data_periods.Add_Ranges (Get_Control_Text (NEW_DATA_SUMMARY_PERIODS)); } //---- data summary ratios ---- if (Check_Control_Key (NEW_DATA_SUMMARY_RATIOS)) { Double_List list; Dbl_Itr itr; Get_Control_List (NEW_DATA_SUMMARY_RATIOS, list); for (i=0, itr = list.begin (); itr != list.end (); itr++, i++) { if (i > 0 && *itr >= 1.0) { data_ratios.push_back (Round (*itr * 100.0)); ratios_flag = true; } } } } //---- group summary file ---- key = Get_Control_String (NEW_GROUP_SUMMARY_FILE); if (!key.empty ()) { Print (1); group_sum_file.File_Type ("New Group Summary File"); if (Check_Control_Key (NEW_GROUP_SUMMARY_FORMAT)) { group_sum_file.Dbase_Format (Get_Control_String (NEW_GROUP_SUMMARY_FORMAT)); } group_sum_file.Add_Field ("MEASURE", DB_STRING, 40); group_sum_file.Add_Field ("VALUE", DB_DOUBLE, 12.2); if (compare_flag) group_sum_file.Add_Field ("COMPARE", DB_DOUBLE, 12.2); group_sum_file.Create (Project_Filename (key)); group_sum_flag = true; } //---- read report types ---- List_Reports (); if (!compare_flag && (Report_Flag (TIME_CHANGE) || Report_Flag (VOLUME_CHANGE) || Report_Flag (TOP_TIME_CHANGE) || Report_Flag (TOP_VOL_CHANGE) || Report_Flag (RELATIVE_GAP))) { Error ("A Compare Performance File is Required for Change Reports"); } //---- process support data ---- if (Link_Equiv_Flag ()) { link_equiv.Read (Report_Flag (LINK_EQUIV)); } if (group_flag) { zone_equiv.Read (Report_Flag (ZONE_EQUIV)); } //---- allocate work space ---- if (periods_flag || ratios_flag) { num = (periods_flag) ? (int) data_periods.size () : 1; num += (ratios_flag) ? (int) data_ratios.size () : 1; if (num_inc + 1 > num) { num = num_inc + 1; } } else { num = num_inc + 1; } sum_bin.assign (num, dbl); for (itr = sum_bin.begin (); itr != sum_bin.end (); itr++) { itr->assign (NUM_SUM_BINS, 0.0); } }
bool Link_Delay_File::Set_Field_Numbers (void) { bool flag = false; //---- required fields ---- link = Required_Field ("LINK"); flow = Required_Field (FLOW_RATE_FIELD_NAMES); if (Version () <= 40) { start = Optional_Field (START_FIELD_NAMES); end = Optional_Field (END_FIELD_NAMES); if (start < 0 && end < 0) { start = end = Required_Field ("PERIOD", "TIME"); time = Required_Field ("AVG_TIME", "TTIME", "SUM"); flag = true; } else { time = Required_Field (TRAVEL_TIME_FIELD_NAMES); } } else { time = Required_Field (TRAVEL_TIME_FIELD_NAMES); start = Required_Field (START_FIELD_NAMES); end = Required_Field (END_FIELD_NAMES); } if (link < 0 || flow < 0 || time < 0 || start < 0 || end < 0) return (false); //---- other required fields ---- dir = LinkDir_Type_Field (); type = Optional_Field ("TYPE", "USE", "HOV", "GROUP"); //---- nested optional fields ---- Num_Nest_Field (Optional_Field (CONNECTION_FIELD_NAMES)); if (Num_Nest_Field () < 0) turn_flag = false; out_link = Optional_Field (OUT_LINK_FIELD_NAMES); out_flow = Optional_Field (FLOW_OUT_FIELD_NAMES); out_time = Optional_Field (TIME_OUT_FIELD_NAMES); //---- set default units ---- if (flag) { Set_Units (start, SECONDS); Set_Units (end, SECONDS); } else { Set_Units (start, DAY_TIME); Set_Units (end, DAY_TIME); } Set_Units (flow, flow_units); Set_Units (time, SECONDS); Set_Units (out_flow, flow_units); Set_Units (out_time, SECONDS); Units_Type units = Get_Units (flow); if (units != NO_UNITS) Flow_Units (units); Lane_Use_Flows ((type >= 0)); return (true); }