Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import org.jgrapht.*;
- import org.jgrapht.alg.NeighborIndex;
- import org.jgrapht.alg.scoring.PageRank;
- import org.jgrapht.graph.*;
- public class DirectedGraphTest {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- DirectedGraph<String, DefaultEdge> g = new SimpleDirectedGraph<>(DefaultEdge.class);
- // create vertices
- String A = "A";
- String B = "B";
- String C = "C";
- String D = "D";
- String E = "E";
- // add the vertices to g
- g.addVertex(A);
- g.addVertex(B);
- g.addVertex(C);
- g.addVertex(D);
- g.addVertex(E);
- // add edges to g
- g.addEdge(A, B);
- g.addEdge(A, C);
- g.addEdge(B, C);
- g.addEdge(B, D);
- g.addEdge(C, D);
- g.addEdge(C, E);
- g.addEdge(D, E);
- g.addEdge(E, D);
- g.addEdge(E, A);
- PageRank pg = new PageRank(g, 0.9, 50, 0.01);
- System.out.println("PageRank Score of vertex A: " + pg.getVertexScore(A));
- System.out.println("PageRank Score of vertex B: " + pg.getVertexScore(B));
- System.out.println("PageRank Score of vertex C: " + pg.getVertexScore(C));
- System.out.println("PageRank Score of vertex D: " + pg.getVertexScore(D));
- System.out.println("PageRank Score of vertex E: " + pg.getVertexScore(E));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement