Exemplo n.º 1
0
        public void AddEdge(INode <T> start, INode <T> end, bool directed)
        {
            int startComponent = -1;
            int endComponent   = -2;

            for (int i = 0; i < components.Count; i++)
            {
                if (components[i].Contains(start))
                {
                    startComponent = i;
                }
                if (components[i].Contains(end))
                {
                    endComponent = i;
                }
            }

            if (startComponent == endComponent)
            {
                tree = false;
            }
            else
            {
                for (int i = 0; i < components[endComponent].Count; i++)
                {
                    components[startComponent].Add(components[endComponent][i]);
                }
                components.Remove(components[endComponent]);
            }
            start.AddEdge(end);
            if (!directed)
            {
                end.AddEdge(start);
            }
        }
Exemplo n.º 2
0
 public Edge(string edgeId, INode source, INode target) : base(edgeId)
 {
     source.AddEdge(this);
     target.AddEdge(this);
     this.source = source;
     this.target = target;
 }
        public void CreateDirectedEdge(INode _StartNode, INode _EndNode, IWeight _Weight)
        {
            var hNewDirectedEdge = new DirectedEdge(_StartNode, _EndNode, _Weight);

            // Todo: Checken dass keine Duplikate entstehen?
            FEdgeIndices.Add(hNewDirectedEdge);
            _StartNode.AddEdge(hNewDirectedEdge);
        }
        public Edge CreateUndirectedEdge(INode _NodeOne, INode _NodeTwo, IWeight _Weight)
        {
            var hNewUndirectedEdge = new UndirectedEdge(_NodeOne, _NodeTwo, _Weight);

            FEdgeIndices.Add(hNewUndirectedEdge);
            _NodeOne.AddEdge(hNewUndirectedEdge);
            _NodeTwo.AddEdge(hNewUndirectedEdge);

            return(hNewUndirectedEdge);
        }
Exemplo n.º 5
0
        public IEdge ConnectTo(INode otherNode, IEdge edge)
        {
            if (edge.GetOtherNode(this) != otherNode)
            {
                logger.Error("Other node is not valid when connecting to it.");
                throw new InvalidNodeException(otherNode);
            }

            // add edge to nodes
            this.AddEdge(edge);
            otherNode.AddEdge(edge);

            return(edge);
        }
Exemplo n.º 6
0
 //加入连边 by Node
 private void AddEdge(INode curNode, INode tarNode, IEdge newEdge)
 {
     if (curNode == null || tarNode == null || newEdge == null)
     {
         return;
     }
     //连边的头指针指向起节点
     newEdge.From = curNode;
     //连边的尾指针指向目标节点
     newEdge.To = tarNode;
     //将新连边加入起始节点的outbound
     if (curNode.AddEdge(newEdge) == false)
     {
         return;
     }
     //将新连边加入目标节点的Inbound
     if (tarNode.RegisterInbound(newEdge) == false)
     {
         return;
     }
     //全部完成后将连边加入网络连边列表
     myEdgeList.Add(newEdge);
 }