Exemplo n.º 1
0
        /*
         * Add the traffic report into the RoutingNetwork and for each Connection type (CC, RC, TC). This is obtained by adding them to the Connection
         * Just 1 traffic report per connection is handled; if there are more, the worst case is considered.
         */
        public void AddTrafficReport(Traffic.TrafficReport TrafficReport)
        {
            this.TrafficReport.Add(TrafficReport);
            long numConnectionUpdated  = 0;
            long numCConnectionUpdated = 0;
            long numRConnectionUpdated = 0;
            long numTConnectionUpdated = 0;

            /* Add TrafficReport to the Connections */
            foreach (KeyValuePair <long, Connection> C in Connections)
            {
                /* Check if the "as the crow flies" distance between the traffic report and the connection source or destination is < deltaTrafficZone */
                Node Source      = C.Value.GetSource();
                Node Destination = C.Value.GetDestination();

                double distanceFromSource      = Source.Point.DistanceFrom(TrafficReport.Coordinates);
                double distanceFromDestination = Destination.Point.DistanceFrom(TrafficReport.Coordinates);

                if (!(C.Value is LConnection) && ((distanceFromSource < TrafficReport.TrafficPropagationMaxDistance) || (distanceFromDestination < TrafficReport.TrafficPropagationMaxDistance)))
                {
                    if ((C.Value.getTrafficReport() == null) || ((C.Value.getTrafficReport() != null) && (TrafficReport.Severity > C.Value.getTrafficReport().Severity)))
                    {
                        C.Value.setTrafficReport(TrafficReport);
                        C.Value.setTrafficDistanceFromSource(distanceFromSource);
                        C.Value.setTrafficDistanceFromDestination(distanceFromDestination);

                        numConnectionUpdated++;

                        if (C.Value is CConnection)
                        {
                            numCConnectionUpdated++;
                            //log.Info("CONNECTION: added Traffic report to the carpooling connection between " + ((CNode)C.Value.GetSource()).Id + " and " + ((CNode)C.Value.GetDestination()).Id);
                        }
                        else if (C.Value is TConnection)
                        {
                            numTConnectionUpdated++;
                            //log.Info("CONNECTION: Added Traffic report to the PT connection between " + ((TNode)C.Value.GetSource()).StopName + " and " + ((TNode)C.Value.GetDestination()).StopName);
                        }
                        else if (C.Value is RConnection)
                        {
                            numRConnectionUpdated++;
                            //log.Info("CONNECTION: Added Traffic report to the Rconnection between " + ((RNode)C.Value.GetSource()).Id + " and " + ((RNode)C.Value.GetDestination()).Id);
                        }
                        else
                        {
                            //log.Warn("CONNECTION: Added Traffic report to the connection");
                        }
                    }
                }
            }

            log.Info("TrafficReport Id:" + TrafficReport.Id +
                     " category:" + TrafficReport.Category +
                     " severity:" + TrafficReport.Severity +
                     " address:" + TrafficReport.Address +
                     " coordinates:" + TrafficReport.Coordinates.Latitude + "," + TrafficReport.Coordinates.Longitude +
                     " - " + " ConnectionUpdated:" + numConnectionUpdated + " (CConnection:" + numCConnectionUpdated +
                     " RConnection:" + numRConnectionUpdated + " TConnection:" + numTConnectionUpdated + ")");
        }
Exemplo n.º 2
0
        /*
         * Remove the traffic report from the RoutingNetwork and from each Connection type (CC, RC, TC, LC)
         */
        public void RemoveTrafficReport(Traffic.TrafficReport TrafficReport)
        {
            this.TrafficReport.Remove(TrafficReport);
            long numConnectionRemoved  = 0;
            long numCConnectionRemoved = 0;
            long numRConnectionRemoved = 0;
            long numTConnectionRemoved = 0;

            Traffic.TrafficReport TrafficReportNull = null;

            /* Remove TrafficReport from the Connections */
            foreach (KeyValuePair <long, Connection> C in Connections)
            {
                if (!(C.Value is LConnection) && (C.Value.getTrafficReport() != null) && (C.Value.getTrafficReport().Id == TrafficReport.Id))
                {
                    C.Value.setTrafficDistanceFromDestination(0);
                    C.Value.setTrafficDistanceFromSource(0);
                    C.Value.setTrafficReport(TrafficReportNull);

                    numConnectionRemoved++;

                    if (C.Value is CConnection)
                    {
                        numCConnectionRemoved++;
                    }
                    else if (C.Value is TConnection)
                    {
                        numTConnectionRemoved++;
                    }
                    else if (C.Value is RConnection)
                    {
                        numRConnectionRemoved++;
                    }
                }
            }

            log.Info("TrafficReport Id:" + TrafficReport.Id + " category:" + TrafficReport.Category + " severity:" + TrafficReport.Severity + " - " + numConnectionRemoved +
                     " Connection updated (" + numCConnectionRemoved + " CConnection, " + numRConnectionRemoved + " RConnection, " + numTConnectionRemoved + " TConnection)");
        }