Ejemplo n.º 1
0
        public Vertex getOtherVertex(Vertex currentVertex)
        {
            Vertex nextVertex = null;
            if (Vertex1.Equals(currentVertex))
                nextVertex = Vertex2;
            else if (Vertex2.Equals(currentVertex))
                nextVertex = Vertex1;

            return nextVertex;
        }
Ejemplo n.º 2
0
 public Vertex AddUniqueVertex(Vertex v)
 {
     Vertex foundVertex = Vertices.Find(x => x.Location == v.Location);
     if (foundVertex == null)
     {
         Vertices.Add(v);
         return v;
     }
     else
     {
         return foundVertex;
     }
 }
Ejemplo n.º 3
0
        public void AddRoads(IEnumerable<Tuple<Vector2, Vector2>> roads)
        {
            foreach (Tuple<Vector2, Vector2> road in roads)
            {
                Vertex vertex1 = new Vertex(road.Item1, null);
                Vertex vertex2 = new Vertex(road.Item2, null);

                vertex1 = AddUniqueVertex(vertex1);
                vertex2 = AddUniqueVertex(vertex2);
                Edge edge = new Edge(vertex1, vertex2);
                Edges.Add(edge);

                vertex1.AddUniqueConnectedEdge(edge);
                vertex2.AddUniqueConnectedEdge(edge);
            }
        }
Ejemplo n.º 4
0
        private void visitNextVertex(Vertex currentVertex)
        {
            currentVertex.Visited = true;
            foreach (Edge edge in currentVertex.ConnectedEdges)
            {
                Vertex nextVertex = null;
                if (edge.Vertex1.Equals(currentVertex))
                    nextVertex = edge.Vertex2;
                else if (edge.Vertex2.Equals(currentVertex))
                    nextVertex = edge.Vertex1;

                double newDistance = currentVertex.Route.Distance + edge.weight;
                double oldDistance = nextVertex.Route.Distance;

                if (newDistance < oldDistance)
                {
                    Route newRoute = new Route(currentVertex.Route.Distance, currentVertex.Route.Edges);
                    newRoute.Edges.Add(edge);
                    newRoute.Distance = newDistance;
                    nextVertex.Route = newRoute;
                    nextVertex.Visited = false;
                }

                if (!nextVertex.Visited)
                {
                    visitNextVertex(nextVertex);
                }
            }
        }
Ejemplo n.º 5
0
 public Edge(Vertex v1, Vertex v2)
 {
     Vertex1 = v1;
     Vertex2 = v2;
     weight = Program.DistanceBetween(v1.Location, v2.Location);
 }