use of org.gephi.graph.api.NodeIterable in project gephi by gephi.
the class WeightedDegree method calculateAverageWeightedDegree.
public double calculateAverageWeightedDegree(Graph graph, boolean isDirected, boolean updateAttributes) {
double averageWeightedDegree = 0;
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = (DirectedGraph) graph;
}
Progress.start(progress, graph.getNodeCount());
NodeIterable nodesIterable = graph.getNodes();
for (Node n : nodesIterable) {
double totalWeight = 0;
if (isDirected) {
double totalInWeight = 0;
double totalOutWeight = 0;
for (Edge e : directedGraph.getEdges(n)) {
if (e.getSource().equals(n)) {
totalOutWeight += e.getWeight();
}
if (e.getTarget().equals(n)) {
totalInWeight += e.getWeight();
}
}
totalWeight = totalInWeight + totalOutWeight;
n.setAttribute(WINDEGREE, totalInWeight);
n.setAttribute(WOUTDEGREE, totalOutWeight);
n.setAttribute(WDEGREE, totalWeight);
updateDegreeDists(totalInWeight, totalOutWeight, totalWeight);
} else {
for (Edge e : graph.getEdges(n)) {
totalWeight += (e.isSelfLoop() ? 2 : 1) * e.getWeight();
}
n.setAttribute(WDEGREE, totalWeight);
updateDegreeDists(totalWeight);
}
averageWeightedDegree += totalWeight;
if (isCanceled) {
nodesIterable.doBreak();
break;
}
Progress.progress(progress);
}
averageWeightedDegree /= (isDirected ? 2.0 : 1.0) * graph.getNodeCount();
return averageWeightedDegree;
}
use of org.gephi.graph.api.NodeIterable in project gephi by gephi.
the class ExporterGML method exportData.
private void exportData(Graph graph) throws IOException {
printOpen("graph");
printTag("Creator \"Gephi\"");
if (graph.isDirected() || graph.isMixed()) {
printTag("directed 1");
} else if (graph.isUndirected()) {
printTag("directed 0");
}
NodeIterable nodeIterable = graph.getNodes();
for (Node node : nodeIterable) {
if (cancel) {
nodeIterable.doBreak();
return;
}
printNode(node, graph);
}
EdgeIterable edgeIterable = graph.getEdges();
for (Edge edge : edgeIterable) {
if (cancel) {
edgeIterable.doBreak();
return;
}
printEdge(edge, graph);
}
printClose();
}
use of org.gephi.graph.api.NodeIterable in project gephi by gephi.
the class ExporterGraphML method createNodes.
private void createNodes(Document document, Element parentE, Graph graph) throws Exception {
NodeIterable nodeIterable = graph.getNodes();
for (Node n : nodeIterable) {
if (cancel) {
nodeIterable.doBreak();
break;
}
Element nodeE = createNode(document, graph, n);
parentE.appendChild(nodeE);
}
}
use of org.gephi.graph.api.NodeIterable in project gephi by gephi.
the class AbstractLayout method ensureSafeLayoutNodePositions.
/**
* See https://github.com/gephi/gephi/issues/603 Nodes position to NaN on applied layout
*
* @param graphModel
*/
public static void ensureSafeLayoutNodePositions(GraphModel graphModel) {
Graph graph = graphModel.getGraph();
NodeIterable nodesIterable = graph.getNodes();
for (Node node : nodesIterable) {
if (node.x() != 0 || node.y() != 0) {
nodesIterable.doBreak();
return;
}
}
// All at 0.0, init some random positions
nodesIterable = graph.getNodes();
for (Node node : nodesIterable) {
node.setX((float) ((0.01 + Math.random()) * 1000) - 500);
node.setY((float) ((0.01 + Math.random()) * 1000) - 500);
}
}
use of org.gephi.graph.api.NodeIterable in project gephi by gephi.
the class ClusteringCoefficient method computeTriangles.
private HashMap<String, Double> computeTriangles(Graph graph, ArrayWrapper[] currentNetwork, int[] currentTriangles, double[] nodeClustering, boolean directed) {
HashMap<String, Double> resultValues = new HashMap<>();
int ProgressCount = 0;
Progress.start(progress, 7 * graph.getNodeCount());
graph.readLock();
try {
int n = graph.getNodeCount();
/**
* Create network for processing
*/
/**
*/
HashMap<Node, Integer> indicies = new HashMap<>();
ProgressCount = createIndiciesMapAndInitNetwork(graph, indicies, currentNetwork, ProgressCount);
int index = 0;
NodeIterable nodesIterable = graph.getNodes();
for (Node node : nodesIterable) {
HashMap<Node, EdgeWrapper> neighborTable = createNeighbourTable(graph, node, indicies, currentNetwork, directed);
EdgeWrapper[] edges = getEdges(neighborTable);
currentNetwork[index].node = node;
currentNetwork[index].setArray(edges);
index++;
Progress.progress(progress, ++ProgressCount);
if (isCanceled) {
nodesIterable.doBreak();
return resultValues;
}
}
ProgressCount = processNetwork(currentNetwork, ProgressCount);
int k = (int) Math.sqrt(n);
for (int v = 0; v < k && v < n; v++) {
newVertex(currentNetwork, currentTriangles, v, n);
Progress.progress(progress, ++ProgressCount);
}
/* remaining links */
ProgressCount = computeRemainingTrianles(graph, currentNetwork, currentTriangles, ProgressCount);
resultValues = computeResultValues(graph, currentNetwork, currentTriangles, nodeClustering, directed, ProgressCount);
} finally {
graph.readUnlock();
}
return resultValues;
}
Aggregations