diff --git a/core/src/main/java/ru/trader/analysis/RouteSearcher.java b/core/src/main/java/ru/trader/analysis/RouteSearcher.java index 85443be..37ce9a5 100644 --- a/core/src/main/java/ru/trader/analysis/RouteSearcher.java +++ b/core/src/main/java/ru/trader/analysis/RouteSearcher.java @@ -29,7 +29,19 @@ public class RouteSearcher { return scorer; } + private > Edge createEdge(T source, T target){ + ConnectibleEdge edge = new ConnectibleEdge<>(new Vertex<>(source, 0), new Vertex<>(target, 0)); + Profile profile = getScorer().getProfile(); + Ship ship = profile.getShip(); + double fuelCost = profile.withRefill() ? ship.getFuelCost(ship.getTank(), source.getDistance(target)) : 0; + edge.setFuelCost(fuelCost); + return edge; + } + public List> getPath(Place from, Place to, Collection places){ + if (from.equals(to)){ + return Collections.singletonList(createEdge(from, to)); + } List>> res = search(from, to, places, 1, null); return res.isEmpty() ? Collections.emptyList() : res.get(0); } @@ -44,7 +56,6 @@ public class RouteSearcher { private List>> search(Place source, Place target, Collection places, int count, RouteSpecification specification){ Profile profile = scorer.getProfile(); - //TODO: fast search if source equals target LOG.trace("Start search path from {} to {} ", source, target); ConnectibleGraph graph = new ConnectibleGraph<>(profile, callback); LOG.trace("Build connectible graph");