add java examples

This commit is contained in:
hpid91 2020-06-25 16:00:13 +02:00 committed by nojhan
commit d345f67212
19 changed files with 1208 additions and 0 deletions

View file

@ -0,0 +1,32 @@
package patterns.strategy;
import java.util.List;
import java.util.Map;
import patterns.Point;
/**
* Find the transit of minimal cost among the given edges.
Edges are given as the considered point and the sequence of neighbors points.
* @author pouyllau
*/
public class TransitOnEdge extends Transit {
public double transit(Point p, List<Point> neighbors, Map<Point, Double> costs) {
double mincost = Double.POSITIVE_INFINITY;
for (Point n : neighbors) {
if (hasCost(n, costs)) {
double c = costs.get(n) + Point.distance(p, n);
if (c < mincost) {
mincost = c;
}
}
}
assert (mincost != Double.POSITIVE_INFINITY);
return mincost;
}
}