AbstractMatrixAlgorithm.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.matrix.algorithms;

  13. import com.graphhopper.GraphHopper;
  14. import com.graphhopper.routing.util.FlagEncoder;
  15. import com.graphhopper.routing.weighting.Weighting;
  16. import com.graphhopper.storage.Graph;
  17. import org.heigit.ors.exceptions.MaxVisitedNodesExceededException;
  18. import org.heigit.ors.matrix.MatrixRequest;

  19. public abstract class AbstractMatrixAlgorithm implements MatrixAlgorithm {
  20.     protected GraphHopper graphHopper;
  21.     protected Graph graph;
  22.     protected FlagEncoder encoder;
  23.     protected Weighting weighting;
  24.     protected int visitedNodes = 0;
  25.     protected int maxVisitedNodes = Integer.MAX_VALUE;

  26.     public void init(MatrixRequest req, GraphHopper gh, Graph graph, FlagEncoder encoder, Weighting weighting) {
  27.         graphHopper = gh;
  28.         this.graph = graph;
  29.         this.encoder = encoder;
  30.         this.weighting = weighting;
  31.         this.maxVisitedNodes = req.getMaximumVisitedNodes();
  32.     }

  33.     protected boolean isMaxVisitedNodesExceeded() {
  34.         if (visitedNodes > maxVisitedNodes)
  35.             throw new MaxVisitedNodesExceededException();
  36.         return false;
  37.     }
  38. }