Skip to content

Commit

Permalink
fixes #3273
Browse files Browse the repository at this point in the history
Now takes into account the weight for the distance computation in a graph.
  • Loading branch information
ptaillandier committed Jan 4, 2022
1 parent 22dbbd4 commit 15839b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -27,7 +27,6 @@
import msi.gama.metamodel.shape.IShape;
import msi.gama.metamodel.topology.AbstractTopology;
import msi.gama.metamodel.topology.ITopology;
import msi.gama.metamodel.topology.ITopology.SpatialRelation;
import msi.gama.metamodel.topology.filter.IAgentFilter;
import msi.gama.metamodel.topology.filter.In;
import msi.gama.runtime.IScope;
Expand Down
12 changes: 9 additions & 3 deletions msi.gama.core/src/msi/gama/util/path/GamaSpatialPath.java
Expand Up @@ -372,7 +372,9 @@ public double getDistance(final IScope scope) {
if (keepSource && keepTarget) {
double d = 0d;
for (final IShape g : segments) {
d += g.getInnerGeometry().getLength();
IShape edge = this.getRealObject(g);
double w = this.getGraph().getEdgeWeight(edge);
d += edge.getPerimeter() == 0 ? 0.0 : (g.getInnerGeometry().getLength() * w / edge.getPerimeter());
}
return d;
}
Expand Down Expand Up @@ -443,15 +445,19 @@ private double getDistanceComplex(final IScope scope, final boolean keepSource,
for (int i = index; i < nb; i++) {
final IShape line = segments.get(i);
final Coordinate coords[] = line.getInnerGeometry().getCoordinates();

IShape edge = this.getRealObject(line);
double w = this.getGraph().getEdgeWeight(edge);

double coeff = (line.getPerimeter() * w / edge.getPerimeter());

for (int j = indexSegment; j < coords.length; j++) {
GamaPoint pt = null;
if (i == nb - 1 && j == endIndexSegment) {
pt = falseTarget;
} else {
pt = new GamaPoint(coords[j]);
}
final double dist = currentLocation.euclidianDistanceTo(pt);
final double dist = currentLocation.euclidianDistanceTo(pt) * coeff;
currentLocation = pt;
distance = distance + dist;
if (i == nb - 1 && j == endIndexSegment) { break; }
Expand Down

0 comments on commit 15839b2

Please sign in to comment.