Skip to content

Commit

Permalink
For #3260 and #3265. Gathers and reorders all statistical operators.
Browse files Browse the repository at this point in the history
Some issues remain:
- Duplicate kurtosis function to remove
- 'skew' and 'skewness' seem to be duplicates too
  • Loading branch information
AlexisDrogoul committed Dec 18, 2021
1 parent cffbdaf commit b70a748
Show file tree
Hide file tree
Showing 7 changed files with 6,149 additions and 2,642 deletions.
@@ -1,3 +1,13 @@
/*******************************************************************************************************
*
* LayoutForceDirected.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package msi.gama.util.graph.layout;

import java.util.IdentityHashMap;
Expand All @@ -14,24 +24,51 @@
import msi.gaml.operators.Spatial.Punctal;
import msi.gaml.types.Types;

/**
* The Class LayoutForceDirected.
*/
public class LayoutForceDirected {

/** The graph. */
private final Graph<IShape, IShape> graph;

/** The equi. */
private final boolean equi;

/** The criterion. */
private final double criterion;

/** The cooling rate. */
private final double coolingRate;

/** The maxit. */
private final int maxit;

/** The coeff force. */
private final double coeffForce;

/** The bounds. */
IShape bounds;

/** The iteration. */
private int iteration = 0;

/** The area. */
private double area;

/** The k. */
private double k;

/** The t. */
private double t;

/** The equilibrium reached. */
private boolean equilibriumReached = false;

/** The disp. */
private final Map<IShape, GamaPoint> disp;

/** The loc. */
private final Map<IShape, GamaPoint> loc;

/**
Expand Down Expand Up @@ -76,18 +113,12 @@ public int startSimulation(final IScope scope) {

if (equi) {
// simulate until mechanical equilibrium
while (!equilibriumReached && iteration < maxit) {
simulateStep(scope);
}
while (!equilibriumReached && iteration < maxit) { simulateStep(scope); }
} else {
// simulate maxit-steps
for (int i = 0; i < maxit; i++) {
simulateStep(scope);
}
}
for (final IShape v : graph.vertexSet()) {
v.setLocation(loc.get(v));
for (int i = 0; i < maxit; i++) { simulateStep(scope); }
}
for (final IShape v : graph.vertexSet()) { v.setLocation(loc.get(v)); }
return iteration;
}

Expand All @@ -108,9 +139,7 @@ private void simulateStep(final IScope scope) {
GamaPoint deltaPos = Points.subtract(loc.get(v), loc.get(u));
final double length = Points.norm(scope, deltaPos);

if (length != 0) {
deltaPos = Points.multiply(deltaPos, forceRepulsive(length, k) / length);
}
if (length != 0) { deltaPos = Points.multiply(deltaPos, forceRepulsive(length, k) / length); }

vDisp.add(deltaPos);

Expand All @@ -126,9 +155,7 @@ private void simulateStep(final IScope scope) {
GamaPoint deltaPos = Points.subtract(loc.get(v), loc.get(u));
final double length = Points.norm(scope, deltaPos);

if (length != 0) {
deltaPos = Points.multiply(deltaPos, forceAttractive(length, k) / length);
}
if (length != 0) { deltaPos = Points.multiply(deltaPos, forceAttractive(length, k) / length); }

disp.get(v).minus(deltaPos);
disp.get(u).add(deltaPos);
Expand All @@ -144,30 +171,22 @@ private void simulateStep(final IScope scope) {
final double length = Points.norm(scope, d);

// no equilibrium if one vertex has too high net force
if (length > criterion) {
equilibriumReached = false;
}
if (length > criterion) { equilibriumReached = false; }
// limit maximum displacement by temperature t
if (length != 0) {
d = Points.multiply(d, Math.min(length, t) / length);
}
if (length != 0) { d = Points.multiply(d, Math.min(length, t) / length); }
final GamaPoint l = loc.get(v);
l.add(d);
if (!bounds.intersects(l)) {
loc.put(v, Punctal._closest_point_to(l, bounds));
}
if (!bounds.intersects(l)) { loc.put(v, Punctal._closest_point_to(l, bounds)); }

}
final GamaPoint center = (GamaPoint) Containers.mean(scope, GamaListFactory.wrap(Types.POINT, loc.values()));
final GamaPoint center = (GamaPoint) Containers.opMean(scope, GamaListFactory.wrap(Types.POINT, loc.values()));
if (center.distance3D(bounds.getCentroid()) > toleranceCenter) {
final GamaPoint d = Points.subtract(bounds.getCentroid(), center);
d.multiplyBy(0.5);
for (final IShape v : graph.vertexSet()) {
final GamaPoint l = loc.get(v);
l.add(d);
if (!bounds.intersects(l)) {
loc.put(v, Punctal._closest_point_to(l, bounds));
}
if (!bounds.intersects(l)) { loc.put(v, Punctal._closest_point_to(l, bounds)); }
}
}
double maxDist = graph.vertexSet().stream().mapToDouble(v -> v.euclidianDistanceTo(center)).max().getAsDouble();
Expand All @@ -177,13 +196,9 @@ private void simulateStep(final IScope scope) {
final GamaPoint l = loc.get(v);
final GamaPoint d = Points.subtract(l, center);
final double len = d.norm();
if (len > 0) {
d.multiplyBy(maxDist / d.norm());
}
if (len > 0) { d.multiplyBy(maxDist / d.norm()); }
l.add(d);
if (!bounds.intersects(l)) {
loc.put(v, Punctal._closest_point_to(l, bounds));
}
if (!bounds.intersects(l)) { loc.put(v, Punctal._closest_point_to(l, bounds)); }
}
}

Expand Down
46 changes: 37 additions & 9 deletions msi.gama.core/src/msi/gama/util/graph/layout/LayoutGrid.java
@@ -1,3 +1,12 @@
/*******************************************************************************************************
*
* LayoutGrid.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package msi.gama.util.graph.layout;

import java.util.ArrayList;
Expand All @@ -15,28 +24,51 @@
import msi.gama.util.IList;
import msi.gama.util.IMap;
import msi.gama.util.graph.IGraph;
import msi.gaml.operators.Containers;
import msi.gaml.operators.Graphs;
import msi.gaml.operators.Maths;
import msi.gaml.operators.Random;
import msi.gaml.operators.Spatial;
import msi.gaml.operators.Spatial.Queries;
import msi.gaml.types.Types;
import msi.gaml.types.Types;

/**
* The Class LayoutGrid.
*/
public class LayoutGrid {

/** The graph. */
private final IGraph<IShape, IShape> graph;

/** The coeff sq. */
private final double coeffSq;

/** The envelope geometry. */
private final IShape envelopeGeometry;

/**
* Instantiates a new layout grid.
*
* @param graph
* the graph
* @param envelopeGeometry
* the envelope geometry
* @param coeffSq
* the coeff sq
*/
public LayoutGrid(final IGraph<IShape, IShape> graph, final IShape envelopeGeometry, final double coeffSq) {
this.graph = graph;
this.envelopeGeometry = envelopeGeometry;
this.coeffSq = coeffSq;
}

@SuppressWarnings("null")
/**
* Apply layout.
*
* @param scope
* the scope
*/
@SuppressWarnings ("null")
public void applyLayout(final IScope scope) {

IList<IShape> places = null;
Expand Down Expand Up @@ -84,9 +116,7 @@ public void applyLayout(final IScope scope) {
remaining.remove(n);
}
}
if (remaining.isEmpty()) {
break;
}
if (remaining.isEmpty()) { break; }
dmax = -1;
java.util.Collections.shuffle(open, scope.getRandom().getGenerator());
for (final IShape v : open) {
Expand Down Expand Up @@ -119,10 +149,8 @@ public void applyLayout(final IScope scope) {
neigh2.removeAll(open);
if (!neigh2.isEmpty()) {
final IList<GamaPoint> pts = GamaListFactory.create(Types.POINT);
for (final IShape n : neigh2) {
pts.add(locs.get(n));
}
final GamaPoint targetLoc = (GamaPoint) msi.gaml.operators.Containers.mean(scope, pts);
for (final IShape n : neigh2) { pts.add(locs.get(n)); }
final GamaPoint targetLoc = (GamaPoint) Containers.opMean(scope, pts);
center = places.size() > 0 ? Queries.closest_to(scope, places, targetLoc.getLocation())
: locs.get(nV);
} else {
Expand Down

0 comments on commit b70a748

Please sign in to comment.