Exemple #1
0
        public TopologicalSort(AdjacencyList <T, TNode> list)
        {
            _list        = list;
            _results     = new List <TNode>();
            _sourceNodes = _list.SourceNodes;

            Sort();
        }
Exemple #2
0
        public TopologicalSort(AdjacencyList <T, TNode> list, T source)
        {
            _list    = list;
            _results = new List <TNode>();

            TNode sourceNode = list.GetNode(source);

            _sourceNodes = Enumerable.Repeat(sourceNode, 1);

            Sort();
        }
        public AdjacencyList <T, TNode> Reverse()
        {
            var result = new AdjacencyList <T, TNode>(_nodeFactory);

            foreach (var adjacency in _adjacencies.Values)
            {
                foreach (var edge in adjacency)
                {
                    result.AddEdge(edge.Target.Value, edge.Source.Value, edge.Weight);
                }
            }

            return(result);
        }
        public AdjacencyList <T, TResultNode> Transform <TResultNode>(Func <int, T, TResultNode> nodeFactory)
            where TResultNode : Node <T>
        {
            var result = new AdjacencyList <T, TResultNode>(nodeFactory);

            foreach (var adjacency in _adjacencies.Values)
            {
                foreach (var edge in adjacency)
                {
                    result.AddEdge(edge.Source.Value, edge.Target.Value, edge.Weight);
                }
            }

            return(result);
        }
Exemple #5
0
        public Tarjan(AdjacencyList <T, TNode> list)
        {
            _list   = list;
            _index  = 0;
            _result = new List <IList <TNode> >();
            _stack  = new Stack <TNode>();

            foreach (TNode node in _list.SourceNodes)
            {
                if (node.Index != -1)
                {
                    continue;
                }

                Compute(node);
            }
        }