示例#1
0
        /// <summary>
        /// Computes the PageRank over the <see cref="VisitedGraph"/>.
        /// </summary>
        public void Compute()
        {
            VertexDoubleDictionary tempRanks = new VertexDoubleDictionary();
            // create filtered graph
            FilteredBidirectionalGraph fg = new FilteredBidirectionalGraph(
                this.VisitedGraph,
                Preds.KeepAllEdges(),
                new InDictionaryVertexPredicate(this.ranks)
                );

            int    iter  = 0;
            double error = 0;

            do
            {
                // compute page ranks
                error = 0;
                foreach (DictionaryEntry de in this.Ranks)
                {
                    IVertex v    = (IVertex)de.Key;
                    double  rank = (double)de.Value;
                    // compute ARi
                    double r = 0;
                    foreach (IEdge e in fg.InEdges(v))
                    {
                        r += this.ranks[e.Source] / fg.OutDegree(e.Source);
                    }

                    // add sourceRank and store
                    double newRank = (1 - this.damping) + this.damping * r;
                    tempRanks[v] = newRank;
                    // compute deviation
                    error += Math.Abs(rank - newRank);
                }

                // swap ranks
                VertexDoubleDictionary temp = ranks;
                ranks     = tempRanks;
                tempRanks = temp;

                iter++;
            }while(error > this.tolerance && iter < this.maxIterations);
            Console.WriteLine("{0}, {1}", iter, error);
        }
示例#2
0
        private void BasicFiltering()
        {
            BidirectionalGraph graph = GraphProvider.FileDependency();

            DrawGraph(graph, "filedependency");

            Console.WriteLine("Source vertices:");
            foreach (NamedVertex v in graph.SelectVertices(Preds.SourceVertex(graph)))
            {
                Console.WriteLine("\t{0}", v.Name);
            }
            Console.WriteLine("Sink vertices:");
            FilteredVertexEnumerable filteredVertices =
                new FilteredVertexEnumerable(
                    graph.Vertices,
                    Preds.SinkVertex(graph)
                    );

            foreach (NamedVertex v in filteredVertices)
            {
                Console.WriteLine("\t{0}", v.Name);
            }
        }
示例#3
0
        private void FilterFsm()
        {
            AdjacencyGraph graph = GraphProvider.Fsm();

            // drawing the fsm
            DrawGraph(graph, "fsm");

            // filtering
            // putting all black besides S4
            // therefore all the edges touching s4 will be filtered out.
            VertexColorDictionary vertexColors = new VertexColorDictionary();
            IVertexPredicate      pred         = new NameEqualPredicate("S4");

            foreach (IVertex v in graph.Vertices)
            {
                if (pred.Test(v))
                {
                    vertexColors[v] = GraphColor.Black;
                }
                else
                {
                    vertexColors[v] = GraphColor.White;
                }
            }

            IVertexPredicate vp = new NoBlackVertexPredicate(vertexColors);
            IEdgePredicate   ep = new EdgePredicate(
                Preds.KeepAllEdges(),
                vp
                );
            IVertexAndEdgeListGraph filteredGraph = new FilteredVertexAndEdgeListGraph(graph,
                                                                                       ep,
                                                                                       vp
                                                                                       );

            DrawGraph(filteredGraph, "fsmfiltered");
        }