use of org.gephi.graph.api.Edge in project gephi by gephi.
the class YifanHuLayout method getAverageEdgeLength.
public float getAverageEdgeLength(Graph graph) {
float edgeLength = 0;
int count = 1;
for (Edge e : graph.getEdges()) {
edgeLength += ForceVectorUtils.distance(e.getSource(), e.getTarget());
count++;
}
return edgeLength / count;
}
use of org.gephi.graph.api.Edge in project gephi by gephi.
the class FruchtermanReingold method goAlgo.
@Override
public void goAlgo() {
this.graph = graphModel.getGraphVisible();
graph.readLock();
try {
Node[] nodes = graph.getNodes().toArray();
Edge[] edges = graph.getEdges().toArray();
for (Node n : nodes) {
if (n.getLayoutData() == null || !(n.getLayoutData() instanceof ForceVectorNodeLayoutData)) {
n.setLayoutData(new ForceVectorNodeLayoutData());
}
ForceVectorNodeLayoutData layoutData = n.getLayoutData();
layoutData.dx = 0;
layoutData.dy = 0;
}
// Déplacement limite : on peut le calibrer...
float maxDisplace = (float) (Math.sqrt(AREA_MULTIPLICATOR * area) / 10f);
// La variable k, l'idée principale du layout.
float k = (float) Math.sqrt((AREA_MULTIPLICATOR * area) / (1f + nodes.length));
for (Node N1 : nodes) {
for (Node N2 : nodes) {
// On fait toutes les paires de noeuds
if (N1 != N2) {
// distance en x entre les deux noeuds
float xDist = N1.x() - N2.x();
float yDist = N1.y() - N2.y();
// distance tout court
float dist = (float) Math.sqrt(xDist * xDist + yDist * yDist);
if (dist > 0) {
// Force de répulsion
float repulsiveF = k * k / dist;
ForceVectorNodeLayoutData layoutData = N1.getLayoutData();
// on l'applique...
layoutData.dx += xDist / dist * repulsiveF;
layoutData.dy += yDist / dist * repulsiveF;
}
}
}
}
for (Edge E : edges) {
// Idem, pour tous les noeuds on applique la force d'attraction
Node Nf = E.getSource();
Node Nt = E.getTarget();
float xDist = Nf.x() - Nt.x();
float yDist = Nf.y() - Nt.y();
float dist = (float) Math.sqrt(xDist * xDist + yDist * yDist);
float attractiveF = dist * dist / k;
if (dist > 0) {
ForceVectorNodeLayoutData sourceLayoutData = Nf.getLayoutData();
ForceVectorNodeLayoutData targetLayoutData = Nt.getLayoutData();
sourceLayoutData.dx -= xDist / dist * attractiveF;
sourceLayoutData.dy -= yDist / dist * attractiveF;
targetLayoutData.dx += xDist / dist * attractiveF;
targetLayoutData.dy += yDist / dist * attractiveF;
}
}
// gravity
for (Node n : nodes) {
ForceVectorNodeLayoutData layoutData = n.getLayoutData();
float d = (float) Math.sqrt(n.x() * n.x() + n.y() * n.y());
float gf = 0.01f * k * (float) gravity * d;
layoutData.dx -= gf * n.x() / d;
layoutData.dy -= gf * n.y() / d;
}
// speed
for (Node n : nodes) {
ForceVectorNodeLayoutData layoutData = n.getLayoutData();
layoutData.dx *= speed / SPEED_DIVISOR;
layoutData.dy *= speed / SPEED_DIVISOR;
}
for (Node n : nodes) {
// Maintenant on applique le déplacement calculé sur les noeuds.
// nb : le déplacement à chaque passe "instantanné" correspond à la force : c'est une sorte d'accélération.
ForceVectorNodeLayoutData layoutData = n.getLayoutData();
float xDist = layoutData.dx;
float yDist = layoutData.dy;
float dist = (float) Math.sqrt(layoutData.dx * layoutData.dx + layoutData.dy * layoutData.dy);
if (dist > 0 && !n.isFixed()) {
float limitedDist = Math.min(maxDisplace * ((float) speed / SPEED_DIVISOR), dist);
n.setX(n.x() + xDist / dist * limitedDist);
n.setY(n.y() + yDist / dist * limitedDist);
}
}
} finally {
graph.readUnlockAll();
}
}
use of org.gephi.graph.api.Edge in project gephi by gephi.
the class EdgeWeightRankingImpl method refresh.
@Override
protected void refresh() {
if (graph.getEdgeCount() > 0) {
double minV = Double.MAX_VALUE;
double maxV = Double.MIN_VALUE;
for (Edge e : graph.getEdges()) {
if (e.hasDynamicWeight()) {
TimeMap timeMap = (TimeMap) e.getAttribute("weight");
if (timeMap != null) {
Double numMin = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MIN);
Double numMax = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MAX);
minV = Math.min(numMin, minV);
maxV = Math.max(numMax, maxV);
}
} else {
minV = Math.min(e.getWeight(), minV);
maxV = Math.max(e.getWeight(), maxV);
}
}
min = minV;
max = maxV;
}
}
use of org.gephi.graph.api.Edge 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.Edge in project gephi by gephi.
the class ClusteringCoefficientNGTest method testTriangleNonCompleteDirectedGraphClusteringCoefficient.
@Test
public void testTriangleNonCompleteDirectedGraphClusteringCoefficient() {
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");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge21 = graphModel.factory().newEdge(node2, node1);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge32 = graphModel.factory().newEdge(node3, node2);
Edge edge13 = graphModel.factory().newEdge(node1, node3);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge32);
directedGraph.addEdge(edge13);
DirectedGraph graph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[3];
int[] triangles = new int[3];
double[] nodeClustering = new double[3];
HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
double res = 0.833;
double diff = 0.01;
assertTrue(Math.abs(avClusteringCoefficient - res) < diff);
}
Aggregations