bool Data_Service::Get_Location_Data (Location_File &file, Location_Data &location_rec) { int link, dir, offset; double setback; Link_Data *link_ptr; //---- read and save the data ---- location_rec.Location (file.Location ()); if (location_rec.Location () == 0) return (false); //---- check/convert the link number and direction ---- link = file.Link (); dir = file.Dir (); offset = Round (file.Offset ()); link_ptr = Set_Link_Direction (file, link, dir, offset); location_rec.Link (link); location_rec.Dir (dir); location_rec.Offset (offset); setback = file.Setback (); location_rec.Setback (setback); if (Location_XY_Flag ()) { Points points; Link_Shape (link_ptr, dir, points, UnRound (offset), 0.0, setback); if (points.size () > 0) { location_rec.X (points [0].x); location_rec.Y (points [0].y); } else { Node_Data *node_ptr = &node_array [link_ptr->Anode ()]; location_rec.X (node_ptr->X ()); location_rec.Y (node_ptr->Y ()); } } location_rec.Zone (file.Zone ()); if (location_rec.Zone () > 0 && System_Data_Flag (ZONE)) { Int_Map_Itr map_itr = zone_map.find (location_rec.Zone ()); if (map_itr == zone_map.end ()) { Warning (String ("Location %d Zone %d was Not Found") % location_rec.Location () % location_rec.Zone ()); return (false); } location_rec.Zone (map_itr->second); } else if (location_rec.Zone () == 0) { location_rec.Zone (-1); //---- delete extra activity location used for transit stops ---- if (file.Version () <= 40) return (false); } location_rec.Notes (file.Notes ()); return (true); }
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); }
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 Data_Service::Get_Driver_Data (Driver_File &file, Driver_Data &driver_rec) { int route; //---- process a header line ---- if (!file.Nested ()) { int type; Int_Map_Itr map_itr; route = file.Route (); if (route == 0) return (false); if (file.Links () < 1) return (false); map_itr = line_map.find (route); if (map_itr == line_map.end ()) { Warning (String ("Transit Route %d was Not Found") % route); return (false); } driver_rec.Route (map_itr->second); type = file.Type (); driver_rec.Type (type); if (file.SubType_Flag () && file.Version () <= 40) { driver_rec.Type (VehType40_Map (type, file.SubType ())); } if (driver_rec.Type () > 0) { map_itr = veh_type_map.find (driver_rec.Type ()); if (map_itr == veh_type_map.end ()) { Warning (String ("Driver Route %d Vehicle Type %d was Not Found") % route % driver_rec.Type ()); return (false); } driver_rec.Type (map_itr->second); } return (true); } //---- process a link record ---- int link, dir, dir_index; Link_Data *link_ptr; 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 (); } else { dir_index = link_ptr->AB_Dir (); } if (dir_index < 0) { Line_Data *line_ptr = &line_array [driver_rec.Route ()]; route = line_ptr->Route (); link = file.Link (); Warning (String ("Route %d Link %d Direction %s was Not Found") % route % link % ((dir) ? "BA" : "AB")); return (false); } driver_rec.push_back (dir_index); return (true); }
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 TransimsNet::Get_Phasing_Data (Phasing_File &file, Phasing_Record &phasing_rec) { int link, dir, node, dir_index, to_index, num, detector, signal; String svalue; Int_Map_Itr map_itr; Int2_Map_Itr map2_itr; Link_Data *link_ptr; Dir_Data *dir_ptr; Phasing_Data *phasing_ptr = &(phasing_rec.phasing_data); //---- process the header record ---- if (!file.Nested ()) { signal = file.Signal (); if (signal == 0) return (false); map_itr = signal_map.find (signal); if (map_itr == signal_map.end ()) { Warning (String ("Phasing Signal %d was Not Found") % signal); return (false); } phasing_rec.Signal (map_itr->second); phasing_ptr->Phasing (file.Phasing ()); phasing_ptr->Phase (file.Phase ()); //---- process the detectors ---- svalue = file.Detectors (); if (!svalue.empty ()) { Strings detect; Str_Itr itr; num = svalue.Parse (detect, "|+/"); for (itr = detect.begin (); itr != detect.end (); itr++) { detector = itr->Integer (); if (detector <= 0) break; map_itr = detector_map.find (detector); if (map_itr == detector_map.end ()) { Warning (String ("Signal %d Detector %d was Not Found") % file.Signal () % detector); break; } phasing_ptr->detectors.push_back (map_itr->second); } } if (file.Version () > 40) return (phasing_rec.Signal () >= 0); } Movement_Data move_rec; move_rec.Movement (file.Movement ()); //---- convert the link 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 ("Phasing Plan %d Link %d Direction %s was Not Found") % Progress_Count () % link_ptr->Link () % ((dir) ? "BA" : "AB")); return (false); } //---- convert the to-link number ---- link = file.To_Link (); map_itr = link_map.find (link); if (map_itr == link_map.end ()) { Warning (String ("Phasing Plan %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 ("Phasing Plan %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ()); return (false); } //---- check the link connection ---- map2_itr = connect_map.find (Int2_Key (dir_index, to_index)); if (map2_itr == connect_map.end ()) { to_index = link_ptr->Link (); dir_ptr = &dir_array [dir_index]; link_ptr = &link_array [dir_ptr->Link ()]; dir_index = link_ptr->Link (); if (file.Version () > 40) { Warning (String ("No Link Connection between %d and %d") % dir_index % to_index); } return (false); } //---- save the data ---- move_rec.Connection (map2_itr->second); move_rec.Protection (file.Protection ()); if (file.Version () <= 40 && move_rec.Movement () == 0) { Connect_Data *connect_ptr; const char *direction; dir_ptr = &dir_array [dir_index]; direction = compass.Point_Text (dir_ptr->In_Bearing (), 4); if (*direction == 'N') { dir = NB_TH; } else if (*direction == 'S') { dir = SB_TH; } else if (*direction == 'E') { dir = EB_TH; } else { dir = WB_TH; } connect_ptr = &connect_array [map2_itr->second]; num = connect_ptr->Type (); if (num == RIGHT || num == R_SPLIT) { dir += NB_RT - NB_TH; } else if (num == LEFT || num == L_SPLIT) { dir += NB_LT - NB_TH; } else if (num == UTURN) { dir += NB_UT - NB_TH; } move_rec.Movement (dir); } phasing_ptr->push_back (move_rec); return (phasing_rec.Signal () >= 0); }