bool Data_Service::Get_Connect_Data (Connect_File &file, Connect_Data &connect_rec) { int link, dir, node, dir_index, to_index, lanes, low, high; Link_Data *link_ptr; Int_Map_Itr map_itr; //---- check/convert the link number and direction ---- link = file.Link (); dir = file.Dir (); link_ptr = Set_Link_Direction (file, link, dir); if (link_ptr == 0) return (false); if (dir) { dir_index = link_ptr->BA_Dir (); node = link_ptr->Anode (); } else { dir_index = link_ptr->AB_Dir (); node = link_ptr->Bnode (); } if (dir_index < 0) { Warning (String ("Connection %d Link %d Direction %s was Not Found") % Progress_Count () % link_ptr->Link () % ((dir) ? "BA" : "AB")); return (false); } connect_rec.Dir_Index (dir_index); //---- convert the to-link number ---- link = file.To_Link (); map_itr = link_map.find (link); if (map_itr == link_map.end ()) { Warning (String ("Connection %d Link %d was Not Found") % Progress_Count () % link); return (false); } link = map_itr->second; link_ptr = &link_array [link]; if (link_ptr->Anode () == node) { to_index = link_ptr->AB_Dir (); } else if (link_ptr->Bnode () == node) { to_index = link_ptr->BA_Dir (); } else { Node_Data *ptr = &node_array [node]; Warning (String ("Connection %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ()); return (false); } connect_rec.To_Index (to_index); //---- lane numbers ---- lanes = file.Lanes (); if (file.Version () <= 40 && lanes > 0) { low = lanes - 1; high = file.In_High () - 1; if (high < low) high = low; } else { Convert_Lane_Range (dir_index, lanes, low, high); } connect_rec.Low_Lane (low); connect_rec.High_Lane (high); lanes = file.To_Lanes (); if (file.Version () <= 40 && lanes > 0) { low = lanes - 1; high = file.Out_High () - 1; if (high < low) high = low; } else { Convert_Lane_Range (to_index, lanes, low, high); } connect_rec.To_Low_Lane (low); connect_rec.To_High_Lane (high); //---- optional fields ---- connect_rec.Type (file.Type ()); connect_rec.Penalty (file.Penalty ()); connect_rec.Speed (file.Speed ()); connect_rec.Capacity (file.Capacity ()); connect_rec.Notes (file.Notes ()); //---- check for duplicate records ---- if (file.Version () <= 40) { Int2_Map_Itr map2_itr; //max_in = dir_ptr->Thru () + dir_ptr->Left () + dir_ptr->Right (); //in_bear = dir_ptr->Out_Bearing (); //max_out = dir_ptr->Thru () + dir_ptr->Left () + dir_ptr->Right (); //out_bear = dir_ptr->In_Bearing (); //---- read and save the data ---- //int num, node_num, link, dir, in_link, out_link, max_in, max_out, in_bear, out_bear; //int in_low, in_high, out_low, out_high, type, penalty, speed, capacity, change; //if (type == 0 && compass.Num_Points () > 0) { // change = compass.Change (in_bear, out_bear) * 360 / compass.Num_Points (); // if (change >= -45 && change <= 45) { // type = THRU; // } else if (change < -165 || change > 165) { // type = UTURN; // } else if (change < 0) { // type = LEFT; // } else { // type = RIGHT; // } //} map2_itr = connect_map.find (Int2_Key (connect_rec.Dir_Index (), connect_rec.To_Index ())); if (map2_itr != connect_map.end ()) { Connect_Data *connect_ptr; //---- update optional fields ---- connect_ptr = &connect_array [map2_itr->second]; //---- merge the entry lane codes ---- if (connect_rec.Low_Lane () < connect_ptr->Low_Lane ()) { connect_ptr->Low_Lane (connect_rec.Low_Lane ()); } if (connect_rec.High_Lane () > connect_ptr->High_Lane ()) { connect_ptr->High_Lane (connect_rec.High_Lane ()); } //---- merge the exit lane codes ---- if (connect_rec.To_Low_Lane () < connect_ptr->To_Low_Lane ()) { connect_ptr->To_Low_Lane (connect_rec.To_Low_Lane ()); } if (connect_rec.To_High_Lane () > connect_ptr->To_High_Lane ()) { connect_ptr->To_High_Lane (connect_rec.To_High_Lane ()); } //---- merge the optional data ---- if (connect_rec.Type () > connect_ptr->Type ()) { connect_ptr->Type (connect_rec.Type ()); } if (connect_rec.Penalty () > connect_ptr->Penalty ()) { connect_ptr->Penalty (connect_rec.Penalty ()); } if (connect_rec.Speed () > connect_ptr->Speed ()) { connect_ptr->Speed (connect_rec.Speed ()); } connect_ptr->Capacity (connect_ptr->Capacity () + connect_rec.Capacity ()); return (false); } } return (true); }
bool Data_Service::Get_Lane_Use_Data (Lane_Use_File &file, Lane_Use_Data &lane_use_rec) { int link, dir, lanes, offset, dir_index, low, high; double rate; Link_Data *link_ptr; Int_Map_Itr map_itr; //---- check/convert the link number and direction ---- link = file.Link (); if (link <= 0) return (false); dir = file.Dir (); offset = Round (file.Offset ()); link_ptr = Set_Link_Direction (file, link, dir, offset); if (link_ptr == 0) return (false); if (dir) { dir_index = link_ptr->BA_Dir (); } else { dir_index = link_ptr->AB_Dir (); } if (dir_index < 0) { Warning (String ("Lane Use %d Link %d Direction %s was Not Found") % Progress_Count () % link_ptr->Link () % ((dir) ? "BA" : "AB")); return (false); } lane_use_rec.Dir_Index (dir_index); //---- set the restriction type ---- lane_use_rec.Type (file.Type ()); lane_use_rec.Use (file.Use ()); //---- convert the vehicle type range ---- low = file.Min_Veh_Type (); high = file.Max_Veh_Type (); if (low > 0) { map_itr = veh_type_map.find (low); if (map_itr == veh_type_map.end ()) { map_itr = veh_type_map.lower_bound (low); if (map_itr == veh_type_map.end ()) { Warning (String ("Lane Use %d Vehicle Type %d was Not Found") % Progress_Count () % low); low = -1; } else { low = map_itr->second; } } else { low = map_itr->second; } } else { low = -1; } if (high > 0) { map_itr = veh_type_map.find (high); if (map_itr == veh_type_map.end ()) { int h = high; while (h > 0) { map_itr = veh_type_map.find (--h); if (map_itr != veh_type_map.end ()) break; } if (h >= 0) { high = map_itr->second; } else { Warning (String ("Lane Use %d Vehicle Type %d was Not Found") % Progress_Count () % high); high = -1; } } else { high = map_itr->second; } if (high >= 0 && low < 0) low = 0; } else { high = -1; } if (low > high) { if (high == -1) { high = low; } else { Warning (String ("Lane Use %d Vehicle Type Range %d-%d is Illegal") % Progress_Count () % file.Min_Veh_Type () % file.Max_Veh_Type ()); high = low; } } lane_use_rec.Min_Veh_Type (low); lane_use_rec.Max_Veh_Type (high); //---- convert the traveler type range ---- low = file.Min_Traveler (); high = file.Max_Traveler (); if (low <= 0) low = -1; if (high > 0) { if (low < 0) low = 0; } else { high = -1; } if (low > high) { if (high == -1) { high = low; } else { Warning (String ("Lane Use %d Traveler Type Range %d-%d is Illegal") % Progress_Count () % file.Min_Traveler () % file.Max_Traveler ()); high = low; } } lane_use_rec.Min_Traveler (low); lane_use_rec.Max_Traveler (high); //----- length and offset ---- lane_use_rec.Length (file.Length ()); if (lane_use_rec.Length () > 0) { if (offset > 0 || lane_use_rec.Length () < link_ptr->Length ()) { lane_use_rec.Offset (offset); } else { lane_use_rec.Offset (0); lane_use_rec.Length (0); } } else { lane_use_rec.Offset (0); } //---- lane number ---- lanes = file.Lanes (); if (file.Version () <= 40 && lanes > 0) { low = high = lanes - 1; } else { Convert_Lane_Range (dir_index, lanes, low, high); } lane_use_rec.Low_Lane (low); lane_use_rec.High_Lane (high); //----- optional fields ---- lane_use_rec.Start (file.Start ()); lane_use_rec.End (file.End ()); if (lane_use_rec.End () == 0) lane_use_rec.End (Model_End_Time ()); lane_use_rec.Toll (Round (file.Toll ())); lane_use_rec.Toll_Rate (file.Toll_Rate ()); if (lane_use_rec.Toll_Rate () > 0) { rate = UnRound (lane_use_rec.Toll_Rate ()); if (Metric_Flag ()) { rate /= 1000.0; } else { rate /= MILETOFEET; } lane_use_rec.Toll (lane_use_rec.Toll () + DTOI (rate * link_ptr->Length ())); } lane_use_rec.Min_Delay (file.Min_Delay ()); lane_use_rec.Max_Delay (file.Max_Delay ()); lane_use_rec.Speed (file.Speed ()); lane_use_rec.Spd_Fac (file.Speed_Factor ()); lane_use_rec.Capacity (file.Capacity ()); lane_use_rec.Cap_Fac (file.Cap_Factor ()); lane_use_rec.Notes (file.Notes ()); return (true); }
bool Relocate::Get_Connect_Data (Connect_File &file, Connect_Data &connect_rec) { if (!target_flag) { if (!Data_Service::Get_Connect_Data (file, connect_rec)) return (false); return (true); } int link, dir, node, dir_index, to_index, lanes, low, high; bool new_flag; Link_Data *link_ptr; Int_Map_Itr map_itr; //---- check/convert the link number and direction ---- link = file.Link (); dir = file.Dir (); new_flag = false; map_itr = link_map.find (link); if (map_itr == link_map.end ()) { Warning (String ("Connection %d Link %d was Not Found") % Progress_Count () % link); return (false); } link_ptr = &link_array [map_itr->second]; if (link_ptr->Divided () == 3) { map_itr = target_link_map.find (link); if (map_itr != target_link_map.end ()) { link_ptr = &link_array [map_itr->second]; new_flag = true; } } else if (link_ptr->Divided () == 2) { new_flag = true; } if (dir) { dir_index = link_ptr->BA_Dir (); node = link_ptr->Anode (); } else { dir_index = link_ptr->AB_Dir (); node = link_ptr->Bnode (); } if (dir_index < 0) { Warning (String ("Connection %d Link %d Direction %s was Not Found") % Progress_Count () % link_ptr->Link () % ((dir) ? "BA" : "AB")); return (false); } connect_rec.Dir_Index (dir_index); connect_rec.Type (file.Type ()); //---- convert the to-link number ---- link = file.To_Link (); map_itr = link_map.find (link); if (map_itr == link_map.end ()) { Warning (String ("Connection %d Link %d was Not Found") % Progress_Count () % link); return (false); } link = map_itr->second; link_ptr = &link_array [link]; if (link_ptr->Divided () == 3) { map_itr = target_link_map.find (link); if (map_itr != target_link_map.end ()) { link_ptr = &link_array [map_itr->second]; new_flag = true; } } else if (link_ptr->Divided () == 2) { new_flag = true; } if (!new_flag) return (false); if (link_ptr->Anode () == node) { to_index = link_ptr->AB_Dir (); } else if (link_ptr->Bnode () == node) { to_index = link_ptr->BA_Dir (); } else { Node_Data *ptr = &node_array [node]; Warning (String ("Connection %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ()); return (false); } if (to_index < 0) { Node_Data *ptr = &node_array [node]; Warning (String ("Connection %d Link %d Node %d was Not Found") % Progress_Count () % link_ptr->Link () % ptr->Node ()); return (false); } connect_rec.To_Index (to_index); connect_rec.Node (node); //---- lane numbers ---- lanes = file.Lanes (); Convert_Lane_Range (dir_index, lanes, low, high); connect_rec.Low_Lane (low); connect_rec.High_Lane (high); lanes = file.To_Lanes (); Convert_Lane_Range (to_index, lanes, low, high); connect_rec.To_Low_Lane (low); connect_rec.To_High_Lane (high); //---- optional fields ---- connect_rec.Penalty (file.Penalty ()); connect_rec.Speed (file.Speed ()); connect_rec.Capacity (file.Capacity ()); return (true); }