use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class GraphGenerator method generateNullDirectedGraph.
public static GraphModel generateNullDirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
for (int i = 0; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
}
return graphModel;
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class GraphGenerator method generatePathDirectedGraph.
public static GraphModel generatePathDirectedGraph(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;
}
return graphModel;
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class HitsNGTest method testDirectedSpecial2GraphHits.
@Test
public void testDirectedSpecial2GraphHits() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
directedGraph.addNode(node6);
Edge edge21 = graphModel.factory().newEdge(node2, node1);
Edge edge31 = graphModel.factory().newEdge(node3, node1);
Edge edge41 = graphModel.factory().newEdge(node4, node1);
Edge edge51 = graphModel.factory().newEdge(node5, node1);
Edge edge36 = graphModel.factory().newEdge(node3, node6);
Edge edge46 = graphModel.factory().newEdge(node4, node6);
Edge edge56 = graphModel.factory().newEdge(node5, node6);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge41);
directedGraph.addEdge(edge51);
directedGraph.addEdge(edge36);
directedGraph.addEdge(edge46);
directedGraph.addEdge(edge56);
DirectedGraph graph = graphModel.getDirectedGraph();
Hits hit = new Hits();
double[] authority = new double[6];
double[] hubs = new double[6];
HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
hit.calculateHits(graph, hubs, authority, indices, true, EPSILON);
int index1 = indices.get(node1);
int index2 = indices.get(node2);
int index3 = indices.get(node3);
int index5 = indices.get(node5);
int index6 = indices.get(node6);
double hub2 = hubs[index2];
double hub3 = hubs[index3];
double hub5 = hubs[index5];
double hub6 = hubs[index6];
double auth1 = authority[index1];
double auth3 = authority[index3];
double auth6 = authority[index6];
assertEquals(hub3, hub5);
assertTrue(hub3 > hub2);
assertTrue(auth1 > auth6);
assertEquals(hub6, 0.0);
assertEquals(auth3, 0.0);
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class HitsNGTest method testDirectedSpecial3GraphHits.
@Test
public void testDirectedSpecial3GraphHits() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
directedGraph.addNode(node6);
Edge edge15 = graphModel.factory().newEdge(node1, node5);
Edge edge25 = graphModel.factory().newEdge(node2, node5);
Edge edge35 = graphModel.factory().newEdge(node3, node5);
Edge edge45 = graphModel.factory().newEdge(node4, node5);
Edge edge56 = graphModel.factory().newEdge(node5, node6);
directedGraph.addEdge(edge15);
directedGraph.addEdge(edge25);
directedGraph.addEdge(edge35);
directedGraph.addEdge(edge45);
directedGraph.addEdge(edge56);
DirectedGraph graph = graphModel.getDirectedGraph();
Hits hit = new Hits();
double[] authority = new double[6];
double[] hubs = new double[6];
HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
hit.calculateHits(graph, hubs, authority, indices, true, EPSILON);
int index1 = indices.get(node1);
int index3 = indices.get(node3);
int index5 = indices.get(node5);
int index6 = indices.get(node6);
double hub1 = hubs[index1];
double hub3 = hubs[index3];
double hub5 = hubs[index5];
double auth5 = authority[index5];
double auth6 = authority[index6];
assertEquals(hub1, hub3);
assertTrue(hub1 > hub5);
assertTrue(auth5 > auth6);
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class PageRankNGTest method testCyclicDirectedGraphPageRank.
@Test
public void testCyclicDirectedGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
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 n3 = graph.getNode("2");
int index3 = indicies.get(n3);
double pr3 = pageRank[index3];
double res = 0.2d;
double diff3 = Math.abs(pr3 - res);
assertTrue(diff3 < 0.01);
}
Aggregations