Example #1
0
 public Edge GetRightEdgeBy(Edge edge)
 {
     if (edge == null)
     {
         return(Edges.First());
     }
     if (Edges.FirstOrDefault(item => item == edge) == null)
     {
         throw new System.Exception("Ребро должно принадлежать этому узлу!");
     }
     if (edge == South)
     {
         return(East ?? Edges.FirstOrDefault(item => item != edge));
     }
     if (edge == East)
     {
         return(South ?? Edges.FirstOrDefault(item => item != edge));
     }
     if (edge == Nord)
     {
         return(West ?? Edges.FirstOrDefault(item => item != edge));
     }
     if (edge == West)
     {
         return(Nord ?? Edges.FirstOrDefault(item => item != edge));
     }
     throw new System.Exception("Ну такого просто не может быть!");
 }
Example #2
0
 /// <summary>
 ///     Others the edge.
 /// </summary>
 /// <param name="thisVertex">The this vertex.</param>
 /// <param name="willAcceptNullAnswer">if set to <c>true</c> [will accept null answer].</param>
 /// <returns>Edge.</returns>
 public Edge OtherEdge(Vertex thisVertex, bool willAcceptNullAnswer = false)
 {
     if (willAcceptNullAnswer)
     {
         return(Edges.FirstOrDefault(e => e != null && e.To != thisVertex && e.From != thisVertex));
     }
     return(Edges.First(e => e != null && e.To != thisVertex && e.From != thisVertex));
 }
Example #3
0
        private void SetEdgeWeight(Edge <T> edge, double weight)
        {
            Edge <T> e = Edges.FirstOrDefault(x => x.Node1.Id == edge.Node1.Id && x.Node2.Id == edge.Node2.Id || x.Node1.Id == edge.Node2.Id && x.Node2.Id == edge.Node1.Id);

            if (e != null)
            {
                e.Weight = e.Weight + weight;
            }
        }
Example #4
0
            public void DisconnectFrom(int targetIndex)
            {
                Edge TargetEdge = Edges.FirstOrDefault(X => X.Index == targetIndex);

                if (TargetEdge == new Edge())
                {
                    return; // Default value is returned, therefore the TargetEdge does not exist.
                }
                Edges.Remove(TargetEdge);
            }
        private Vertex NextVertexByToken(Vertex source, char token)
        {
            Vertex result = null;
            var    e      = Edges.FirstOrDefault(edge => edge.Source.Compare(source) && edge.Tag.Equals(token));

            if (e != null)
            {
                result = e.Target;
            }
            return(result);
        }
Example #6
0
        public Edge GetOrCreateEdge(Node node1, Node node2)
        {
            Edge edge = Edges.FirstOrDefault(e => (e.Node1 == node1 && e.Node2 == node2) || (e.Node2 == node1 && e.Node1 == node2));

            if (edge != null)
            {
                return(edge);
            }
            edge = new Edge {
                Node1 = node1, Node2 = node2
            };
            Edges.Add(edge);
            return(edge);
        }
Example #7
0
        private void DepthFirstSearch(ISimpleGraphNode <T> node, Dictionary <ISimpleGraphNode <T>, bool> visited, Stack <ISimpleGraphNode <T> > stack)
        {
            visited[node] = true;
            foreach (var terminal in node.Outputs)
            {
                var nextNodeEdge = Edges.FirstOrDefault(e => e.From == terminal);
                if (nextNodeEdge == null)
                {
                    continue;
                }
                var nextNode = nextNodeEdge.To.ParentNode;
                if (!visited[nextNode])
                {
                    DepthFirstSearch(nextNode, visited, stack);
                }
            }

            stack.Push(node);
        }
Example #8
0
 public GraphvizEdge FindEdge(string fromName, string toName)
 {
     return(Edges.FirstOrDefault(x => x.From == fromName && x.To == toName));
 }
Example #9
0
 public Edge GetEdge(Node node1, Node node2)
 {
     return(Edges.FirstOrDefault(e => (e.Node1 == node1 && e.Node2 == node2) || (e.Node2 == node1 && e.Node1 == node2)));
 }
Example #10
0
 /// <summary>
 /// O(n) operation.
 /// </summary>
 /// <param name="targetIndex"></param>
 /// <returns></returns>
 public bool IsNeighbor(int targetIndex)
 {
     return(Edges.FirstOrDefault(X => X.Index == targetIndex) != new Edge());
 }
Example #11
0
 public Edge GetEdge(int targetIndex) => Edges.FirstOrDefault(X => X.Index == targetIndex);
Example #12
0
 public Edge GetStartingEdgeForJob(int JobId)
 {
     return(Edges.FirstOrDefault(ed => ed.JobId == JobId && ed.StartNode == StartNode));
 }
Example #13
0
 public override Task <IEdge> GetEdge(string id)
 {
     return(Task.FromResult(Edges.FirstOrDefault(x => x.Id == id)));
 }
Example #14
0
 public Edge NearestEdge()
 {
     Edges.Sort(Edge.CompareSiteDistances);
     return(Edges.FirstOrDefault());
 }