use of org.gephi.graph.api.Edge 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.Edge 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;
}
use of org.gephi.graph.api.Edge in project gephi by gephi.
the class GraphGenerator method generateSelfLoopDirectedGraph.
public static GraphModel generateSelfLoopDirectedGraph(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);
Edge currentEdge = graphModel.factory().newEdge(currentNode, currentNode);
directedGraph.addEdge(currentEdge);
}
return graphModel;
}
use of org.gephi.graph.api.Edge in project gephi by gephi.
the class GraphGenerator method generateCompleteDirectedGraph.
public static GraphModel generateCompleteDirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node[] nodes = new Node[n];
for (int i = 0; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
nodes[i] = currentNode;
directedGraph.addNode(currentNode);
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j]);
directedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(nodes[j], nodes[i]);
directedGraph.addEdge(currentEdge);
}
}
return graphModel;
}
use of org.gephi.graph.api.Edge in project gephi by gephi.
the class HitsNGTest method testExampleDirectedGraph.
@Test
public void testExampleDirectedGraph() {
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");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge13 = graphModel.factory().newEdge(node1, node3);
Edge edge14 = graphModel.factory().newEdge(node1, node4);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge24 = graphModel.factory().newEdge(node2, node4);
Edge edge32 = graphModel.factory().newEdge(node3, node2);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge13);
directedGraph.addEdge(edge14);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge24);
directedGraph.addEdge(edge32);
DirectedGraph graph = graphModel.getDirectedGraph();
Hits hit = new Hits();
double[] authority = new double[4];
double[] hubs = new double[4];
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 index4 = indices.get(node4);
assertEquals(hubs[index1], 0.7887);
assertEquals(hubs[index2], 0.5774);
assertEquals(hubs[index3], 0.2113);
assertEquals(hubs[index4], 0);
assertEquals(authority[index1], 0);
assertEquals(authority[index2], 0.4597);
assertEquals(authority[index3], 0.6280);
assertEquals(authority[index4], 0.6280);
}
Aggregations