Example #1
0
        public IEnumerable <PlaceDto> GetBestRoute(string originName, string destinationName, string criteria)
        {
            if (string.IsNullOrEmpty(originName) && string.IsNullOrEmpty(destinationName))
            {
                throw new ArgumentException("The Origin and Destination are required fields.");
            }

            var origin      = _readUnit.ReadRepository <Place>().Get(x => x.Description.Equals(originName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            var destination = _readUnit.ReadRepository <Place>().Get(x => x.Description.Equals(destinationName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (origin == null)
            {
                throw new InvalidOperationException("The Origin provided does not exist.");
            }

            if (destination == null)
            {
                throw new InvalidOperationException("The Destination provided does not exist.");
            }

            //Retrieve filter criteria
            //if the passed criteria is null, the default value is Cost
            //if find a match will return a RouteCriteria type
            //if the passed value doesn't exist, will throw an exception
            RouteCriteria criteriaRoute = string.IsNullOrEmpty(criteria) ? RouteCriteria.Cost :
                                          RouteCriteria.FromDisplayName <RouteCriteria>(criteria);

            //retrieve routes and places from DB
            var routes = _readRepository.GetAllIncluding(x => x.Origin, x => x.Destination).ToList();
            var places = _readUnit.ReadRepository <Place>().GetAll().ToList();

            //create the graph network
            RoutingGraph <Place> graph = new RoutingGraph <Place>();

            places.ForEach(x => graph.AddNode(x));
            routes.ForEach(r => {
                int cost = RouteCriteria.Equals(criteriaRoute, RouteCriteria.Time) ? r.Time : r.Cost;
                graph.Connect(r.Origin, r.Destination, cost);
            });

            //processa o resultado
            var         processor = new RouteProcessor <Place>(graph);
            IPathResult result    = processor.Process(origin, destination);

            //build the result
            List <Place> resultados = new List <Place>();

            result.GetPath().ToList().ForEach(x => resultados.Add(graph[x].Item));
            return(resultados.EnumerableTo <PlaceDto>());
        }
Example #2
0
        public static Graph.RoutingGraph ReadOsmData(string path, string testPointsPath, string name)
        {
            RoutingGraph graph = new RoutingGraph(name, testPointsPath);

            {
                using (var fileStreamSource = File.OpenRead(path))
                {
                    var source       = new PBFOsmStreamSource(fileStreamSource);
                    var filtered     = name.Equals("VA")? source.FilterBox(-77.8f, 39.4f, -77f, 38.67f) : source;
                    var nodesAndWays = from osmGeo in filtered
                                       where osmGeo.Type == OsmSharp.OsmGeoType.Node || (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.ContainsKey("highway"))
                                       select osmGeo;
                    var completed = nodesAndWays.ToComplete();

                    foreach (var obj in completed)
                    {
                        if (obj.Type == OsmSharp.OsmGeoType.Way)
                        {
                            OsmSharp.Complete.CompleteWay way = (OsmSharp.Complete.CompleteWay)obj;

                            var    vList      = new List <Vertex>();
                            Vertex fromVertex = null;
                            foreach (OsmSharp.Node node in way.Nodes)
                            {
                                var location = new Coordinates(node.Latitude, node.Longitude);
                                var toVertex = graph.AddVertex(location);
                                if (fromVertex != null)
                                {
                                    var edge = new Edge(fromVertex, toVertex);
                                    graph.AddEdge(edge);
                                }
                                fromVertex = toVertex;
                            }
                        }
                    }
                }
            }
            graph.CleanGraph();
            return(graph);
        }
        private void DisplayGraph(MapView mapView, RoutingGraph graph)
        {
            var graphicsLayer = mapView.Map.Layers["GraphGraphics"] as GraphicsLayer;

            foreach (var vertex in graph.Verticies)
            {
                //update current graphic otherwise create a new one
                var routeGraphic = new Graphic()
                {
                    Symbol = new SimpleMarkerSymbol()
                    {
                        Color = Colors.DarkGray,
                        Style = SimpleMarkerStyle.Circle
                    }
                };
                routeGraphic.Geometry = vertex.Coordinates.ToMapPoint();
                //add the new route graphic
                graphicsLayer.Graphics.Add(routeGraphic);

                foreach (var edge in vertex.Neighbors)
                {
                    var lineGraphic = new Graphic()
                    {
                        Symbol = new SimpleLineSymbol()
                        {
                            Color = Colors.DarkGray,
                            Style = SimpleLineStyle.Solid
                        }
                    };

                    lineGraphic.Geometry = new Polyline(new List <MapPoint>()
                    {
                        edge.Value.From.Coordinates.ToMapPoint(), edge.Value.To.Coordinates.ToMapPoint()
                    }, SpatialReferences.Wgs84);

                    graphicsLayer.Graphics.Add(lineGraphic);
                }
            }
        }
Example #4
0
 public AStarPathFinder(RoutingGraph graph) : base(graph)
 {
 }
 public DijkstraApproximateBucketPathFinder(RoutingGraph graph) : base(graph)
 {
 }
 public DijkstraPathFinder(RoutingGraph graph) : base(graph)
 {
 }
Example #7
0
File: RC.cs Project: sopel30/tsst2
 public SetupStore(int source, int target, RoutingGraph ownTopology, int connectN, int requieredCapacity)
 {
     this.source = source;
     this.target = target;
     this.ownTopology = ownTopology;
     this.connectN = connectN;
     path = new List<RoutingGraph.Link>();
     vcivpiList = new List<string>();
     this.requieredCapacity = requieredCapacity;
 }
Example #8
0
File: RC.cs Project: sopel30/tsst2
 private RoutingGraph.Node IDtoNode(int id, RoutingGraph ownTopology)
 {
     return ownTopology.Vertices.ToList().Find(delegate(RoutingGraph.Node no)
     {
         return no.Id == id;
     });
 }
Example #9
0
 public AStarApproximateBucketPathFinder(RoutingGraph graph) : base(graph)
 {
 }
Example #10
0
 public PathFinder(RoutingGraph graph)
 {
     this.graph = graph;
 }