Advertisement
Mhazard

JGraphT Simple Directed Graph

Feb 9th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package test;
  2.  
  3. import org.jgrapht.*;
  4. import org.jgrapht.alg.NeighborIndex;
  5. import org.jgrapht.alg.scoring.PageRank;
  6. import org.jgrapht.graph.*;
  7.  
  8. public class DirectedGraphTest {
  9.  
  10.     public static void main(String[] args) {
  11.         // TODO Auto-generated method stub
  12.  
  13.         DirectedGraph<String, DefaultEdge> g = new SimpleDirectedGraph<>(DefaultEdge.class);       
  14.        
  15.         // create vertices
  16.         String A = "A";
  17.         String B = "B";
  18.         String C = "C";
  19.         String D = "D";
  20.         String E = "E";    
  21.  
  22.  
  23.         // add the vertices to g
  24.         g.addVertex(A);
  25.         g.addVertex(B);
  26.         g.addVertex(C);
  27.         g.addVertex(D);
  28.         g.addVertex(E);    
  29.  
  30.         // add edges to g
  31.         g.addEdge(A, B);
  32.         g.addEdge(A, C);
  33.         g.addEdge(B, C);
  34.         g.addEdge(B, D);
  35.         g.addEdge(C, D);
  36.         g.addEdge(C, E);
  37.         g.addEdge(D, E);
  38.         g.addEdge(E, D);
  39.         g.addEdge(E, A);
  40.        
  41.         PageRank pg = new PageRank(g, 0.9, 50, 0.01);
  42.        
  43.         System.out.println("PageRank Score of vertex A: " + pg.getVertexScore(A));
  44.         System.out.println("PageRank Score of vertex B: " + pg.getVertexScore(B));
  45.         System.out.println("PageRank Score of vertex C: " + pg.getVertexScore(C));
  46.         System.out.println("PageRank Score of vertex D: " + pg.getVertexScore(D));
  47.         System.out.println("PageRank Score of vertex E: " + pg.getVertexScore(E));
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement