use of org.gephi.graph.api.Node in project gephi by gephi.
the class GraphDistanceNGTest method testDirectedStarOutGraphCloseness.
@Test
public void testDirectedStarOutGraphCloseness() {
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);
}
GraphDistance d = new GraphDistance();
d.initializeStartValues();
HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());
HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
double[] closeness = metricsMap.get(GraphDistance.CLOSENESS);
Node n1 = directedGraph.getNode("0");
Node n6 = directedGraph.getNode("5");
int index1 = indicies.get(n1);
int index6 = indicies.get(n6);
assertEquals(closeness[index1], 1.0, TOLERANCE);
assertEquals(closeness[index6], 0.0, TOLERANCE);
}
use of org.gephi.graph.api.Node in project gephi by gephi.
the class GraphDistanceNGTest method testNullGraphRadius.
@Test
public void testNullGraphRadius() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
GraphDistance d = new GraphDistance();
d.initializeStartValues();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
double radius = d.getRadius();
assertEquals(radius, 0.0, TOLERANCE);
}
use of org.gephi.graph.api.Node in project gephi by gephi.
the class EigenvectorCentrality method saveCalculatedValues.
private void saveCalculatedValues(Graph graph, Column attributeColumn, HashMap<Integer, Node> indicies, double[] eigCenrtalities) {
int N = graph.getNodeCount();
for (int i = 0; i < N; i++) {
Node s = indicies.get(i);
s.setAttribute(attributeColumn, eigCenrtalities[i]);
}
}
use of org.gephi.graph.api.Node in project gephi by gephi.
the class EigenvectorCentrality method fillIndiciesMaps.
public void fillIndiciesMaps(Graph graph, double[] eigCentralities, HashMap<Integer, Node> indicies, HashMap<Node, Integer> invIndicies) {
if (indicies == null || invIndicies == null) {
return;
}
int count = 0;
for (Node u : graph.getNodes()) {
indicies.put(count, u);
invIndicies.put(u, count);
eigCentralities[count] = 1;
count++;
}
}
use of org.gephi.graph.api.Node in project gephi by gephi.
the class Hits method updateAutorithy.
void updateAutorithy(Graph graph, double[] newValues, double[] hubValues, boolean isDirected, Map<Node, Integer> indices) {
double norm = 0;
for (Node q : indices.keySet()) {
double auth = 0;
EdgeIterable edge_iter;
if (isDirected) {
edge_iter = ((DirectedGraph) graph).getInEdges(q);
} else {
edge_iter = graph.getEdges(q);
}
for (Edge edge : edge_iter) {
if (!edge.isSelfLoop()) {
Node p = graph.getOpposite(q, edge);
auth += hubValues[indices.get(p)];
}
}
newValues[indices.get(q)] = auth;
norm += auth * auth;
if (isCanceled) {
return;
}
}
norm = Math.sqrt(norm);
if (norm > 0) {
for (int i = 0; i < newValues.length; i++) {
newValues[i] = newValues[i] / norm;
}
}
}
Aggregations