use of org.gephi.graph.api.EdgeIterable in project gephi by gephi.
the class PageRank method setInitialValues.
private void setInitialValues(Graph graph, double[] pagerankValues, double[] weights, boolean directed, boolean useWeights) {
int N = graph.getNodeCount();
int index = 0;
for (Node s : graph.getNodes()) {
pagerankValues[index] = 1.0f / N;
if (useWeights) {
double sum = 0;
EdgeIterable eIter;
if (directed) {
eIter = ((DirectedGraph) graph).getOutEdges(s);
} else {
eIter = ((UndirectedGraph) graph).getEdges(s);
}
for (Edge edge : eIter) {
sum += edge.getWeight();
}
weights[index] = sum;
}
index++;
}
}
use of org.gephi.graph.api.EdgeIterable in project gephi by gephi.
the class ConnectedComponents method computeWeeklyConnectedComponents.
public LinkedList<LinkedList<Node>> computeWeeklyConnectedComponents(Graph graph, HashMap<Node, Integer> indicies) {
int N = graph.getNodeCount();
//Keep track of which nodes have been seen
int[] color = new int[N];
Progress.start(progress, N);
int seenCount = 0;
LinkedList<LinkedList<Node>> components = new LinkedList<>();
while (seenCount < N) {
//The search Q
LinkedList<Node> Q = new LinkedList<>();
//The component-list
LinkedList<Node> component = new LinkedList<>();
//Seed the seach Q
NodeIterable iter = graph.getNodes();
for (Node first : iter) {
if (color[indicies.get(first)] == 0) {
Q.add(first);
iter.doBreak();
break;
}
}
//While there are more nodes to search
while (!Q.isEmpty()) {
if (isCanceled) {
return new LinkedList<>();
}
//Get the next Node and add it to the component list
Node u = Q.removeFirst();
component.add(u);
//Iterate over all of u's neighbors
EdgeIterable edgeIter = graph.getEdges(u);
//For each neighbor
for (Edge edge : edgeIter) {
Node reachable = graph.getOpposite(u, edge);
int id = indicies.get(reachable);
//If this neighbor is unvisited
if (color[id] == 0) {
color[id] = 1;
//Add it to the search Q
Q.addLast(reachable);
//Mark it as used
Progress.progress(progress, seenCount);
}
}
color[indicies.get(u)] = 2;
seenCount++;
}
components.add(component);
}
return components;
}
use of org.gephi.graph.api.EdgeIterable in project gephi by gephi.
the class EigenvectorCentrality method computeMaxValueAndTempValues.
private double computeMaxValueAndTempValues(Graph graph, HashMap<Integer, Node> indicies, HashMap<Node, Integer> invIndicies, double[] tempValues, double[] centralityValues, boolean directed) {
double max = 0.;
int N = graph.getNodeCount();
for (int i = 0; i < N; i++) {
Node u = indicies.get(i);
EdgeIterable iter;
if (directed) {
iter = ((DirectedGraph) graph).getInEdges(u);
} else {
iter = graph.getEdges(u);
}
for (Edge e : iter) {
Node v = graph.getOpposite(u, e);
Integer id = invIndicies.get(v);
tempValues[i] += centralityValues[id];
}
max = Math.max(max, tempValues[i]);
if (isCanceled) {
return max;
}
}
return max;
}
use of org.gephi.graph.api.EdgeIterable 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;
}
}
}
use of org.gephi.graph.api.EdgeIterable in project gephi by gephi.
the class ExporterPajek method exportData.
private void exportData(Graph graph) throws Exception {
int max = graph.getNodeCount(), i = 1;
HashMap<String, Integer> idx = new HashMap<>(3 * max / 2 + 1);
Progress.start(progressTicket, max);
writer.append("*Vertices " + max + "\n");
NodeIterable nodeIterable = graph.getNodes();
for (Node node : nodeIterable) {
writer.append(Integer.toString(i));
writer.append(" \"" + node.getLabel() + "\"");
if (exportPosition) {
writer.append(" " + node.x() + " " + node.y() + " " + node.z());
}
writer.append("\n");
// assigns Ids from the interval [1..max]
idx.put(node.getId().toString(), i++);
if (cancel) {
nodeIterable.doBreak();
return;
}
}
if (graph.isUndirected()) {
writer.append("*Edges\n");
} else {
writer.append("*Arcs\n");
}
EdgeIterable edgeIterable = graph.getEdges();
for (Edge edge : edgeIterable) {
if (cancel) {
edgeIterable.doBreak();
return;
}
writer.append(Integer.toString(idx.get(edge.getSource().getId().toString())) + " ");
writer.append(Integer.toString(idx.get(edge.getTarget().getId().toString())));
if (exportEdgeWeight) {
writer.append(" " + edge.getWeight());
}
writer.append("\n");
Progress.progress(progressTicket);
}
Progress.finish(progressTicket);
}
Aggregations