use of org.gephi.graph.api.GraphModel 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.GraphModel in project gephi by gephi.
the class ClusteringCoefficientNGTest method testSpecial2DirectedGraphClusteringCoefficient.
@Test
public void testSpecial2DirectedGraphClusteringCoefficient() {
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 edge21 = graphModel.factory().newEdge(node2, node1);
Edge edge24 = graphModel.factory().newEdge(node2, node4);
Edge edge31 = graphModel.factory().newEdge(node3, node1);
Edge edge32 = graphModel.factory().newEdge(node3, node2);
Edge edge43 = graphModel.factory().newEdge(node4, node3);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge24);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge32);
directedGraph.addEdge(edge43);
DirectedGraph graph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[4];
int[] triangles = new int[4];
double[] nodeClustering = new double[4];
HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
double res = 0.4167;
double diff = 0.01;
assertTrue(Math.abs(avClusteringCoefficient - res) < diff);
}
use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class ClusteringCoefficientNGTest method testStarGraphClusteringCoefficient.
@Test
public void testStarGraphClusteringCoefficient() {
GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
Graph graph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
cc.setDirected(false);
ArrayWrapper[] network = new ArrayWrapper[6];
int[] triangles = new int[6];
double[] nodeClustering = new double[6];
HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, 0.0);
}
use of org.gephi.graph.api.GraphModel 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.GraphModel 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