/** * Adds a new node to the graph. * Internally it creates the nodeData and populates the heuristic map concerning input node into node data. * * @param nodeId the node to be added * @param isTargetNode flag indicatin the the node is a target node. Only target nodes are contained in the heuristic. */ public void addNode(T nodeId, boolean isTargetNode) { Preconditions.checkNotNull(nodeId, "The node id cannot be null"); if (!isTargetNode) { if (!heuristicMap.containsKey(nodeId)) throw new NoSuchElementException("This node (" + nodeId + ") is not a part of hueristic map"); } addNodeInternal(nodeId); // graph.put(nodeId, new HashMap<>()); // nodeIdNodeData.put(nodeId, new NodeData<>(nodeId, heuristicMap.get(nodeId))); } /**
if (isOnSea(p)) { if (!graph.containsNode(p)) { graph.addNodeInternal(p);
private void addEdges(Point2D from, Point2D to, boolean isCity, boolean initial) { if (isCity || isOnSea(to)) { if (!graph.containsNode(to)) { if (initial) { graph.addNodeInternal(to); } else { graph.addNode(to, true); } } heuristicProvider.getHeuristic(); double weight = calculateWeight(from, to); if (initial) { graph.addEdgeInternal(from, to, weight); } else { graph.addEdge(from, to, weight); } weight = calculateWeight(to, from); if (initial) { graph.addEdgeInternal(to, from, weight); } else { graph.addEdge(to, from, weight); } } }