public void duplicateNetwork(ref RoutingNetwork rn2)
        {
            rn2 = new RoutingNetwork {
            };

            rn2.GNodes = new Dictionary <long, Node>();
            foreach (KeyValuePair <long, Node> GN in GNodes)
            {
                rn2.GNodes.Add(GN.Key, GN.Value);
            }

            rn2.Connections = new Dictionary <long, Connection>();
            foreach (KeyValuePair <long, Connection> C in Connections)
            {
                rn2.Connections.Add(C.Key, C.Value);
            }

            rn2.RNodes = new Dictionary <long, RNode>();
            foreach (KeyValuePair <long, RNode> RN in RNodes)
            {
                rn2.RNodes.Add(RN.Key, RN.Value);
            }

            rn2.RConnections = new Dictionary <long, RConnection>();
            foreach (KeyValuePair <long, RConnection> RC in RConnections)
            {
                rn2.RConnections.Add(RC.Key, RC.Value);
            }

            rn2.TNodes = new Dictionary <long, TNode>();
            foreach (KeyValuePair <long, TNode> TN in TNodes)
            {
                rn2.TNodes.Add(TN.Key, TN.Value);
            }

            rn2.TConnections = new Dictionary <long, TConnection>();
            foreach (KeyValuePair <long, TConnection> TC in TConnections)
            {
                rn2.TConnections.Add(TC.Key, TC.Value);
            }

            rn2.CNodes = new Dictionary <long, CNode>();
            foreach (KeyValuePair <long, CNode> CN in CNodes)
            {
                rn2.CNodes.Add(CN.Key, CN.Value);
            }

            rn2.CConnections = new Dictionary <long, CConnection>();
            foreach (KeyValuePair <long, CConnection> CC in CConnections)
            {
                rn2.CConnections.Add(CC.Key, CC.Value);
            }

            rn2.Carpoolers = new List <Carpools.Carpooler>();
            foreach (Carpools.Carpooler CP in Carpoolers)
            {
                rn2.Carpoolers.Add(CP);
            }

            rn2.SpatialQuadTree = new Containers.RTree.RTree <RNode>();
            rn2.SpatialQuadTree = SpatialQuadTree;


            rn2.MinPoint = new Point(MinPoint.Latitude, MinPoint.Longitude);
            rn2.MaxPoint = new Point(MaxPoint.Latitude, MaxPoint.Longitude);

            rn2.__MaxArcID     = __MaxArcID;
            rn2.__NumCCDeleted = __NumCCDeleted;
        }
Exemple #2
0
        public static Routing.RoutingNetwork BuildNetwork(ref Carpools.CarpoolParser CParser, ref Traffic.TrafficParser TParser, List <Carpooler> CarPoolers, List <TrafficReport> TrafficReport, double TrafficPropagationMaxDistance, int CarpoolingMaxConnectionsPerTNode)
        {
            Routing.RoutingNetwork routingNetwork = null;

            string Path = System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["dataPath"] + "\\" + ConfigurationManager.AppSettings["NetworkFileName"]);

            if (!File.Exists(Path))
            {
                log.Info("Routing network bin file not exist: " + Path + " The road network will be generated from the osm map");

                // Construct the road network.
                string OSMXMLMapFilePath = System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["dataPath"] + ConfigurationManager.AppSettings["OSMXMLMapFile"]);
                log.Info("Parsing " + OSMXMLMapFilePath + " OSM.");

                routingNetwork = new Routing.RoutingNetwork();
                OSM.XMLParser Parser = new OSM.XMLParser();
                Parser.LoadOSMMap(OSMXMLMapFilePath, ref routingNetwork);

                // Construct the transportation network.
                log.Info("Parsing GTFS.");

                GTFS.DBParser GTFSParser = new GTFS.DBParser();

                if (CarPoolers != null)
                {
                    routingNetwork.CarpoolingMaxConnectionsPerTNode = CarpoolingMaxConnectionsPerTNode;
                }

                GTFSParser.LoadTransportationNetwork(ref routingNetwork);
                log.Info("Attaching GTFS.");

                routingNetwork.ConnectTransportation();

                /* Add data to the Stops Carpooling connections */
                routingNetwork.CreateNetworkForCarpoolingRides();

                //routingNetwork.Serialize();
            }
            else
            {
                log.Info("Routing network: " + Path);
                log.Info("DeSrializing Netwrok.");
                routingNetwork = Routing.RoutingNetwork.DeSerialize();
            }

            /* Construct Carpooling network */
            if (CarPoolers != null)
            {
                log.Info("Constructing Carpooling network (" + CarPoolers.Count + " rides)");
                CParser = new CarpoolParser(routingNetwork, CarPoolers);
                //CParser.BuildCarpoolRoutesFromXML();
                //CParser.BuildCarpoolRoutesFromJson();
                CParser.ConnectWithRoadNetwork();
            }

            /* Update the network considering the traffic reports */
            if (TrafficReport != null)
            {
                routingNetwork.TrafficPropagationMaxDistance = TrafficPropagationMaxDistance;
                log.Info("Updating the network considering the traffic reports (" + TrafficReport.Count + " reports)");
                TParser = new TrafficParser(routingNetwork, TrafficReport);
                TParser.UpdateNetworkWithTrafficReport();
            }

            return(routingNetwork);
        }