use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class EigenvectorCentralityNGTest method testCompleteUndirectedGraphEigenvectorCentrality.
@Test
public void testCompleteUndirectedGraphEigenvectorCentrality() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
UndirectedGraph graph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
ec.setDirected(false);
double[] centralities = new double[5];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(graph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(graph, centralities, indicies, invIndicies, false, 100);
Node n1 = graph.getNode("0");
Node n3 = graph.getNode("2");
int index1 = invIndicies.get(n1);
int index3 = invIndicies.get(n3);
double ec1 = centralities[index1];
double ec3 = centralities[index3];
assertEquals(ec1, 1.0);
assertEquals(ec3, 1.0);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class EigenvectorCentralityNGTest method testSpecial1UndirectedGraphEigenvectorCentrlity.
@Test
public void testSpecial1UndirectedGraphEigenvectorCentrlity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge34 = graphModel.factory().newEdge(node3, node4, false);
Edge edge13 = graphModel.factory().newEdge(node1, node3, false);
Edge edge24 = graphModel.factory().newEdge(node2, node4, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge34);
undirectedGraph.addEdge(edge13);
undirectedGraph.addEdge(edge24);
UndirectedGraph graph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[4];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(graph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(graph, centralities, indicies, invIndicies, false, 100);
int index1 = invIndicies.get(node1);
int index2 = invIndicies.get(node2);
int index3 = invIndicies.get(node3);
double ec1 = centralities[index1];
double ec2 = centralities[index2];
double ec3 = centralities[index3];
assertEquals(ec2, ec3);
assertNotEquals(ec1, ec2);
assertEquals(ec3, 1.0);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class ConnectedComponents method execute.
@Override
public void execute(GraphModel graphModel) {
isDirected = graphModel.isDirected();
isCanceled = false;
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraphVisible();
undirectedGraph.readLock();
try {
weaklyConnected(undirectedGraph);
if (isDirected) {
DirectedGraph directedGraph = graphModel.getDirectedGraphVisible();
stronglyConnected(directedGraph, graphModel);
}
} finally {
undirectedGraph.readUnlock();
}
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class ConnectedComponentsNGTest method testSpecial1UndirectedGraphConnectedComponents.
@Test
public void testSpecial1UndirectedGraphConnectedComponents() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
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");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge14 = graphModel.factory().newEdge(node1, node4, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge25 = graphModel.factory().newEdge(node2, node5, false);
Edge edge35 = graphModel.factory().newEdge(node3, node5, false);
Edge edge43 = graphModel.factory().newEdge(node4, node3, false);
Edge edge51 = graphModel.factory().newEdge(node5, node1, false);
Edge edge54 = graphModel.factory().newEdge(node5, node4, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge14);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge25);
undirectedGraph.addEdge(edge35);
undirectedGraph.addEdge(edge43);
undirectedGraph.addEdge(edge51);
undirectedGraph.addEdge(edge54);
UndirectedGraph graph = graphModel.getUndirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
assertEquals(components.size(), 1);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class ConnectedComponentsNGTest method testNullGraphWeeklyConnectedComponents.
@Test
public void testNullGraphWeeklyConnectedComponents() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
UndirectedGraph graph = graphModel.getUndirectedGraph();
Node n0 = graph.getNode("0");
Node n1 = graph.getNode("1");
Node n2 = graph.getNode("2");
Node n3 = graph.getNode("3");
Node n4 = graph.getNode("4");
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = new HashMap<>();
indicies.put(n0, 0);
indicies.put(n1, 1);
indicies.put(n2, 2);
indicies.put(n3, 3);
indicies.put(n4, 4);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
assertEquals(components.size(), 5);
}
Aggregations