TDCoreDijkstra.java

  1. /*  This file is part of Openrouteservice.
  2.  *
  3.  *  Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
  4.  *  GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
  5.  *  of the License, or (at your option) any later version.

  6.  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  7.  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8.  *  See the GNU Lesser General Public License for more details.

  9.  *  You should have received a copy of the GNU Lesser General Public License along with this library;
  10.  *  if not, see <https://www.gnu.org/licenses/>.
  11.  */
  12. package org.heigit.ors.routing.graphhopper.extensions.core;

  13. import com.graphhopper.routing.Path;
  14. import com.graphhopper.routing.SPTEntry;
  15. import com.graphhopper.routing.weighting.Weighting;
  16. import com.graphhopper.storage.RoutingCHEdgeIteratorState;
  17. import com.graphhopper.storage.RoutingCHGraph;
  18. import com.graphhopper.util.Parameters;

  19. public class TDCoreDijkstra extends CoreDijkstra {
  20.     private final boolean reverse;

  21.     public TDCoreDijkstra(RoutingCHGraph graph, Weighting weighting, boolean reverse) {
  22.         super(graph, weighting);
  23.         this.reverse = reverse;
  24.     }

  25.     @Override
  26.     protected Path extractPath() {
  27.         if (finished())
  28.             return TDCorePathExtractor.extractPath(chGraph, weighting, bestFwdEntry, bestBwdEntry, bestWeight);

  29.         return createEmptyPath();
  30.     }

  31.     @Override
  32.     public boolean fillEdgesFromCore() {
  33.         if (reverse)
  34.             return true;

  35.         return super.fillEdgesFromCore();
  36.     }

  37.     @Override
  38.     public boolean fillEdgesToCore() {
  39.         if (!reverse)
  40.             return true;

  41.         return super.fillEdgesToCore();
  42.     }

  43.     @Override
  44.     long calcEdgeTime(RoutingCHEdgeIteratorState iter, SPTEntry currEdge, boolean reverse) {
  45.         return currEdge.time + (reverse ? -1 : 1) * calcTime(iter, reverse, currEdge.time);
  46.     }

  47.     @Override
  48.     public String getName() {
  49.         return Parameters.Algorithms.TD_DIJKSTRA;
  50.     }
  51. }