private void ConnectNodesWithRoadNetwork(Carpooler Pooler, List <RNode> Nodes) { Nodes = Nodes.Where(x => x != null).ToList(); CNode src = null, dst = null; for (int i = 0; i < Nodes.Count - 1; ++i) { src = RoadNetwork.GetNode(Nodes[i].Point); dst = RoadNetwork.GetNode(Nodes[i + 1].Point); if (i == 0) { Pooler.SetSource(src); } Dictionary <string, string> tags = this.RoadNetwork.GetConnectionTags(src, dst); int srcArrivalTime = Pooler.GetLastArrivalTime(); int travelTime = (int)RoadNetwork.AreConnected(Nodes[i], Nodes[i + 1]).GetTravelTime(string.Empty, Pooler.GetLastArrivalTime(), TravelMode.Car); int dstArrivalTime = srcArrivalTime + travelTime; CConnection C = RoadNetwork.AddConnection(src, dst, srcArrivalTime, dstArrivalTime, ref Pooler, tags); Pooler.AddConnection(ref C); Pooler.AddNextArrivalTime(dstArrivalTime); } }
/*TEST********************************************************************************************************************************/ /* * */ private void ConnectNodesWithRoadNetworkTNode(Carpooler Pooler, List <TNodeCarpooling> Nodes) { Nodes = Nodes.Where(x => x != null).ToList(); CNode src = null, dst = null; int totDuration = 0; //long elapsed_time_GetNode = 0; //long elapsed_time_Other = 0; //long elapsed_time_AddConnection = 0; //long elapsed_time_AddConnection2 = 0; for (int i = 0; i < Nodes.Count - 1; ++i) { //var stopwatch_GetNode = new Stopwatch(); //stopwatch_GetNode.Start(); src = RoadNetwork.GetNode(Nodes[i].Point, Nodes[i].StopName); dst = RoadNetwork.GetNode(Nodes[i + 1].Point, Nodes[i + 1].StopName); //stopwatch_GetNode.Stop(); //elapsed_time_GetNode += stopwatch_GetNode.ElapsedMilliseconds; if (i == 0) { Pooler.SetSource(src); } Dictionary <string, string> tags = new Dictionary <string, string>(); // this.RoadNetwork.GetConnectionTags(src, dst); /* BAD: the conversion is already done in HTTPRequest.cs getCarpoolingDataFromBackend*/ /* Convert time from seconds to HH:MM:SS */ //TimeSpan time = TimeSpan.FromSeconds(Pooler.TripStartTime); //DateTime dateTime = DateTime.Today.Add(time); //string str = dateTime.ToString("hh:mm:ss"); //DateTime srcArrivalDateTime = Globals.ConvertDateAndTimeToLocalSiteDateTime(Pooler.TripDate, str); //Seconds since midnight of the http request //int srcArrivalTime = (srcArrivalDateTime.Hour * 3600) + (srcArrivalDateTime.Minute * 60) + srcArrivalDateTime.Second; int srcArrivalTime = Pooler.GetLastArrivalTime(); //var stopwatch_Other = new Stopwatch(); //stopwatch_Other.Start(); //double travelTime = RoadNetwork.AreConnected(Nodes[i], Nodes[i + 1]).GetTravelTime(string.Empty, Pooler.GetLastArrivalTime(), TravelMode.Car); int travelTime = (int)RoadNetwork.AreConnected(Nodes[i], Nodes[i + 1], "carpoolingride").GetTravelTime(string.Empty, Pooler.GetLastArrivalTime(), TravelMode.Carpool); //stopwatch_Other.Stop(); //elapsed_time_Other += stopwatch_Other.ElapsedMilliseconds; int dstArrivalTime = srcArrivalTime + travelTime; //var stopwatch_AddConnection = new Stopwatch(); //stopwatch_AddConnection.Start(); CConnection C = RoadNetwork.AddConnection(src, dst, srcArrivalTime, dstArrivalTime, ref Pooler, tags); int duration = C.DstArrivalTime - C.DepartureTime; log.Info("Connection " + (i + 1) + "/" + Nodes.Count + " - Src:\"" + C.Source.StopName + "\" - Dst:\"" + C.Destination.StopName + "\" - Duration:" + duration); //stopwatch_AddConnection.Stop(); //elapsed_time_AddConnection += stopwatch_AddConnection.ElapsedMilliseconds; //var stopwatch_AddConnection2 = new Stopwatch(); //stopwatch_AddConnection2.Start(); Pooler.AddConnection(ref C); Pooler.AddNextArrivalTime(dstArrivalTime); //stopwatch_AddConnection2.Stop(); //elapsed_time_AddConnection2 += stopwatch_AddConnection2.ElapsedMilliseconds; totDuration += duration; } log.Info("Total carpooling trip duration: " + totDuration); //log.Info("elapsed_time_GetNode:" + elapsed_time_GetNode); //log.Info("elapsed_time_Other:" + elapsed_time_Other); //log.Info("elapsed_time_AddConnection:" + elapsed_time_AddConnection); //log.Info("elapsed_time_AddConnection2:" + elapsed_time_AddConnection2); }