/** * Add a new target node to the heuristic. * @param source location to be added. */ public void addSourceNodeToHeuristic(Point2D source) { Preconditions.checkNotNull(source, "The source node may not be null"); if (!heuristicForSourceAvailable(source)) { synchronized (lock) { ObjectDoubleMap<Point2D> hueristicForTarget = calculateHeuristicForSource(source, map.getCities()); heuristicMap.put(source, hueristicForTarget); } } else { logger.debug("Heuristic for source point {} is available (point is contained as key)", source); } } /**
@VisibleForTesting void createGraph() { long timestamp = System.currentTimeMillis(); synchronized (lock) { List<ICity> cities = map.getCities(); for (ICity city : cities) { ObjectDoubleMap<Point2D> hueristicForTarget = calculateHeuristicForSource(city.getCoordinates(), cities); heuristicMap.put(city.getCoordinates(), hueristicForTarget); } for (int x = 0; x < width; x += CHECK_DISTANCE) { // TODO: andi 1/3/16 split to different threads for (int y = 0; y < height; y += CHECK_DISTANCE) { Point2D source = getPoint(x, y); ObjectDoubleMap<Point2D> hueristicForTarget = calculateHeuristicForSource(source, cities); heuristicMap.put(source, hueristicForTarget); } } } long took = System.currentTimeMillis() - timestamp; logger.debug("Created heuristic for "+heuristicMap.size()+" sources connecting to "+heuristicMap.values().iterator().next().size()+" nodes taking "+took+"ms"); clientServerEventBus.post(new HeuristicGraphInitialisationComplete()); initializing = false; }