private Pathfinding.Network CreateNetwork(RouteMap map, Modality modality) { var nodes = map .Vertices .ToDictionary(v => v.Id, v => new Node() { Id = v.Id, Location = v.Location }); var result = new Pathfinding.Network() { Nodes = nodes.Values.ToList() }; foreach (var edge in map.Edges) { if (modality.IsAccessible(edge)) { result.Edges.Add(new Pathfinding.Edge(nodes[edge.FromId], nodes[edge.ToId]) { Id = result.Edges.Count + 1, Distance = (float)edge.Distance, }); result.Edges.Add(new Pathfinding.Edge(nodes[edge.ToId], nodes[edge.FromId]) { Id = result.Edges.Count + 1, Distance = (float)edge.Distance, }); } } result.Nodes.RemoveAll(n => n.Edges.Count == 0); return(result); }
private Pathfinder <Node, Edge> .NetworkAdapter CreateAdapter(Pathfinding.Network network) { return(new Pathfinder <Node, Edge> .NetworkAdapter() { MaxId = () => network.Nodes.Max(n => n.Id) + 1, GetEdges = node => node.Edges, GetCost = edge => edge.Distance, GetNodeId = node => node.Id, EstimateMinimumCost = (n1, n2) => Vector2.Distance(n1.Location, n2.Location), GetOtherNode = (edge, node) => edge.To }); }