use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class WeightedDegreeNGTest method testDirectedStarOutGraphDegree.
@Test
public void testDirectedStarOutGraphDegree() {
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();
Node n1 = graph.getNode("0");
Node n3 = graph.getNode("2");
WeightedDegree d = new WeightedDegree();
d.execute(graph);
double inDegree1 = (Double) n1.getAttribute(WeightedDegree.WINDEGREE);
double outDegree1 = (Double) n1.getAttribute(WeightedDegree.WOUTDEGREE);
double degree3 = (Double) n3.getAttribute(WeightedDegree.WDEGREE);
assertEquals(inDegree1, 0.0);
assertEquals(outDegree1, 5.0);
assertEquals(degree3, 1.0);
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class WeightedDegreeNGTest method testSelfLoopDirectedGraphDegree.
@Test
public void testSelfLoopDirectedGraphDegree() {
GraphModel graphModel = GraphGenerator.generateSelfLoopDirectedGraph(1);
DirectedGraph graph = graphModel.getDirectedGraph();
Node n = graph.getNode("0");
WeightedDegree d = new WeightedDegree();
d.execute(graph);
assertEquals(n.getAttribute(WeightedDegree.WDEGREE), 2.0);
assertEquals(n.getAttribute(WeightedDegree.WINDEGREE), 1.0);
assertEquals(n.getAttribute(WeightedDegree.WOUTDEGREE), 1.0);
}
use of org.gephi.graph.api.DirectedGraph 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.DirectedGraph 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.DirectedGraph 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