use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class PageRankNGTest method testPathDirectedGraphPageRank.
@Test
public void testPathDirectedGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
DirectedGraph graph = graphModel.getDirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(graph);
pageRank = pr.calculatePagerank(graph, indicies, true, false, 0.001, 0.85);
Node n1 = graph.getNode("0");
Node n2 = graph.getNode("1");
Node n3 = graph.getNode("2");
Node n4 = graph.getNode("3");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
int index3 = indicies.get(n3);
int index4 = indicies.get(n4);
double pr1 = pageRank[index1];
double pr2 = pageRank[index2];
double pr3 = pageRank[index3];
double pr4 = pageRank[index4];
double res = 1.;
double diff = 0.01;
double sum = pr1 + pr2 + pr3 + pr4;
assertTrue(pr1 < pr2);
assertTrue(pr2 < pr4);
assertTrue(Math.abs(sum - res) < diff);
}
use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class PageRankNGTest method testDirectedStarOutGraphPageRank.
@Test
public void testDirectedStarOutGraphPageRank() {
pc.newProject();
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
for (int i = 1; i <= 5; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode);
directedGraph.addEdge(currentEdge);
}
DirectedGraph graph = graphModel.getDirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(graph);
pageRank = pr.calculatePagerank(graph, indicies, true, false, 0.001, 0.85);
Node n1 = graph.getNode("0");
Node n2 = graph.getNode("1");
Node n3 = graph.getNode("2");
Node n5 = graph.getNode("4");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
int index3 = indicies.get(n3);
int index5 = indicies.get(n5);
double pr1 = pageRank[index1];
double pr2 = pageRank[index2];
double pr3 = pageRank[index3];
double pr5 = pageRank[index5];
double res = 0.146;
double diff = 0.01;
assertTrue(pr1 < pr3);
assertEquals(pr2, pr5);
assertTrue(Math.abs(pr1 - res) < diff);
}
use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class PageRankNGTest method testTwoConnectedNodesPageRank.
@Test
public void testTwoConnectedNodesPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generatePathUndirectedGraph(2);
UndirectedGraph graph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(graph);
pageRank = pr.calculatePagerank(graph, indicies, false, false, 0.001, 0.85);
Node n2 = graph.getNode("1");
int index = indicies.get(n2);
double pr2 = pageRank[index];
assertEquals(pr2, 0.5);
}
use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class GraphGenerator method generateCyclicUndirectedGraph.
public static GraphModel generateCyclicUndirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
if (n <= 0) {
return graphModel;
}
Node firstNode = graphModel.factory().newNode("0");
undirectedGraph.addNode(firstNode);
Node prevNode = firstNode;
for (int i = 1; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
undirectedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode, false);
undirectedGraph.addEdge(currentEdge);
prevNode = currentNode;
}
Edge currentEdge = graphModel.factory().newEdge(prevNode, firstNode, false);
undirectedGraph.addEdge(currentEdge);
return graphModel;
}
use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class GraphGenerator method generateCyclicDirectedGraph.
public static GraphModel generateCyclicDirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
if (n <= 0) {
return graphModel;
}
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
Node prevNode = firstNode;
for (int i = 1; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode);
directedGraph.addEdge(currentEdge);
prevNode = currentNode;
}
Edge currentEdge = graphModel.factory().newEdge(prevNode, firstNode);
directedGraph.addEdge(currentEdge);
return graphModel;
}
Aggregations