use of org.gephi.graph.api.Table in project gephi-plugins-bootcamp by gephi.
the class AverageEuclideanDistance method execute.
@Override
public void execute(GraphModel graphModel) {
Graph graph = graphModel.getGraphVisible();
//Look if the result column already exist and create it if needed
Table nodeTable = graphModel.getNodeTable();
Column col = nodeTable.getColumn(AVG_EUCLIDEAN_DISTANCE);
if (col == null) {
col = nodeTable.addColumn(AVG_EUCLIDEAN_DISTANCE, "Average Euclidean Distance", Double.class, Origin.DATA);
}
//Lock to graph. This is important to have consistent results if another
//process is currently modifying it.
graph.readLock();
//Iterate on all nodes
Node[] nodes = graph.getNodes().toArray();
for (Node n : nodes) {
double avg = 0;
int count = 0;
if (useOnlyConnections) {
//Calculate distance with neighbors
for (Node m : graph.getNeighbors(n)) {
double xDist = n.x() - m.x();
double yDist = n.y() - m.y();
double dist = Math.sqrt(xDist * xDist + yDist * yDist);
avg = (dist + avg) / ++count;
}
} else {
//Calculate distance with all other nodes
for (Node m : nodes) {
if (n != m) {
double xDist = n.x() - m.x();
double yDist = n.y() - m.y();
double dist = Math.sqrt(xDist * xDist + yDist * yDist);
avg = (dist + avg) / ++count;
}
}
}
//Store the average in the node attribute
n.setAttribute(col, avg);
}
graph.readUnlock();
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class ClusteringCoefficient method execute.
public void execute(Graph graph) {
isCanceled = false;
HashMap<String, Double> resultValues = new HashMap<>();
if (isDirected) {
avgClusteringCoeff = bruteForce(graph);
} else {
initStartValues(graph);
resultValues = computeTriangles(graph, network, triangles, nodeClustering, isDirected);
totalTriangles = resultValues.get("triangles").intValue();
avgClusteringCoeff = resultValues.get("clusteringCoefficient");
}
//Set results in columns
Table nodeTable = graph.getModel().getNodeTable();
Column clusteringCol = nodeTable.getColumn(CLUSTERING_COEFF);
if (clusteringCol == null) {
clusteringCol = nodeTable.addColumn(CLUSTERING_COEFF, "Clustering Coefficient", Double.class, new Double(0));
}
Column triCount = null;
if (!isDirected) {
triCount = nodeTable.getColumn("Triangles");
if (triCount == null) {
triCount = nodeTable.addColumn("Triangles", "Number of triangles", Integer.class, new Integer(0));
}
}
for (int v = 0; v < N; v++) {
if (network[v].length() > 1) {
network[v].node.setAttribute(clusteringCol, nodeClustering[v]);
if (!isDirected) {
network[v].node.setAttribute(triCount, triangles[v]);
}
}
}
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class AbstractProcessor method flushColumns.
protected void flushColumns(ContainerUnloader container) {
TimeRepresentation timeRepresentation = container.getTimeRepresentation();
Table nodeTable = graphModel.getNodeTable();
for (ColumnDraft col : container.getNodeColumns()) {
if (!nodeTable.hasColumn(col.getId())) {
Class typeClass = col.getTypeClass();
if (col.isDynamic()) {
if (timeRepresentation.equals(TimeRepresentation.TIMESTAMP)) {
typeClass = AttributeUtils.getTimestampMapType(typeClass);
} else {
typeClass = AttributeUtils.getIntervalMapType(typeClass);
}
}
nodeTable.addColumn(col.getId(), col.getTitle(), typeClass, Origin.DATA, col.getDefaultValue(), !col.isDynamic());
}
}
Table edgeTable = graphModel.getEdgeTable();
for (ColumnDraft col : container.getEdgeColumns()) {
if (!edgeTable.hasColumn(col.getId())) {
Class typeClass = col.getTypeClass();
if (col.isDynamic()) {
if (timeRepresentation.equals(TimeRepresentation.TIMESTAMP)) {
typeClass = AttributeUtils.getTimestampMapType(typeClass);
} else {
typeClass = AttributeUtils.getIntervalMapType(typeClass);
}
}
edgeTable.addColumn(col.getId(), col.getTitle(), typeClass, Origin.DATA, col.getDefaultValue(), !col.isDynamic());
}
}
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class Modularity method saveValues.
private void saveValues(int[] struct, Graph graph, CommunityStructure theStructure) {
Table nodeTable = graph.getModel().getNodeTable();
Column modCol = nodeTable.getColumn(MODULARITY_CLASS);
if (modCol == null) {
modCol = nodeTable.addColumn(MODULARITY_CLASS, "Modularity Class", Integer.class, 0);
}
for (Node n : graph.getNodes()) {
int n_index = theStructure.map.get(n);
n.setAttribute(modCol, struct[n_index]);
}
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class DynamicClusteringCoefficient method execute.
@Override
public void execute(GraphModel graphModel) {
this.graphModel = graphModel;
this.isDirected = graphModel.isDirected();
this.averages = new HashMap<>();
//Attributes cols
if (!averageOnly) {
TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
Table nodeTable = graphModel.getNodeTable();
dynamicCoefficientColumn = nodeTable.getColumn(DYNAMIC_CLUSTERING_COEFFICIENT);
if (dynamicCoefficientColumn == null) {
dynamicCoefficientColumn = nodeTable.addColumn(DYNAMIC_CLUSTERING_COEFFICIENT, NbBundle.getMessage(DynamicClusteringCoefficient.class, "DynamicClusteringCoefficient.nodecolumn.ClusteringCoefficient"), tr.equals(TimeRepresentation.INTERVAL) ? IntervalDoubleMap.class : TimestampDoubleMap.class, null);
}
}
}
Aggregations