Exemplo n.º 1
0
        public Graph()
        {
            GraphDeep = 0;
            GraphId = Utils.IdGenerator.UniqueId;

            var source = new Vertex();
            source.GenerateVertexId();
            source.ParentGraph = this;
            source_ = source;

            var target = new Vertex();
            target.GenerateVertexId();
            target.ParentGraph = this;
            target_ = target;
        }
Exemplo n.º 2
0
        /*
        public void AddEdge(IEdge<IVertex> edge)
        {            
            var from = edge.Source;
            var to = edge.Destination;

            var deepDiff = from.ParentGraph.GraphDeep - to.ParentGraph.GraphDeep;
            var sameSurface = deepDiff == 0; // jsme na stejne rovine, rovny smer
            var fromIsUnderTo = deepDiff < 0; // vstupujem do podgrafu smereme nahoru
            var fromUpperTo = deepDiff > 0; // vyspupujeme z podgrafu smerem dolu


            var sameGraph = from.ParentGraph.GraphId == to.ParentGraph.GraphId;

            if (sameGraph)
            {
                from.AddOutEdge(to);
            }           
            else if (fromIsUnderTo)
            {
                if (to.ParentGraph is IVertex)
                {
                    from.AddOutEdge((IVertex) to.ParentGraph);
                }

                to.ParentGraph.Source.AddOutEdge(to);
            }
            else if (from.ParentGraph.GraphDeep > to.ParentGraph.GraphDeep)
            {
                if (from.ParentGraph is IVertex)
                {
                    // Povede bud do bodu
                    ((IVertex)from.ParentGraph).AddOutEdge(to);
                    // nebo na kraj bohu
                    ((IVertex)from.ParentGraph).AddOutEdge((IVertex)to.ParentGraph);
                }
                from.AddOutEdge(from.ParentGraph.Target);
            }
            else
            {
                throw new Exception("Unresolved graph relationship");
            }
            edges_.Add(edge);
        }
        */

        public void AddEdge(Edge edge)
        {
            var source = edge.Source;
            var target = edge.Destination;
            
            var previuosTarget = target;
            IParentGraph parent = previuosTarget.ParentGraph;
            // >[>[>]] jeste [[>]>]>
            while ((parent is IHasParent) && (parent.GraphId != source.ParentGraph.GraphId))
                {
                    var newIn = new Vertex();                      
                    parent.AddSourceVertex(newIn);


                    newIn.AddOutEdge(previuosTarget);
                    previuosTarget.AddInEdge(newIn);

                    previuosTarget = newIn;
                   
                    parent = (parent as IHasParent).ParentGraph;                    
                }
                
            
            if (parent is IHasParent)
            {
                // Jak poznat ze parent je samotny graf a ne podgraf?
                var newOut = new Vertex();
                parent.AddTargetVertex(newOut);
                newOut.AddOutEdge(previuosTarget);
                previuosTarget.AddInEdge(newOut);
            
                newOut.AddInEdge(source);
                source.AddOutEdge(newOut);
            }
            else 
            {
                // Pro hlavni graf
                source.AddOutEdge(previuosTarget);
                previuosTarget.AddInEdge(source);
            }
            
            edges_.Add(edge);
        }