/*
  * (non-Javadoc)
  *
  * @see
  * com.sun.electric.tool.routing.astar.t3.machine.AStarMachine#setUpSearchSpace
  * (com.sun.electric.tool.routing.astar.t3.algorithm.AStarMapBase,
  * com.sun.electric.tool.routing.astar.t3.algorithm.AStarGoalBase)
  */
 public void setUpSearchSpace(
     AStarMapBase<AStarRegionNode> newMap, AStarGoalBase<AStarRegionNode> newGoal) {
   if (newMap == null) throw new IllegalArgumentException("The map to search may not be null.");
   if (newGoal == null) throw new IllegalArgumentException("The goal object may not be null.");
   this.map = newMap;
   openList.setMap(map);
   closedList.setMap(map);
   this.goal = newGoal;
   this.goal.setNodeStorage(this.openList);
 }
  /*
   * (non-Javadoc)
   *
   * @seecom.sun.electric.tool.routing.astar.t3.algorithm.AStarMapVisitorBase#
   * visitNeighbour
   * (com.sun.electric.tool.routing.astar.t3.algorithm.AStarNodeBase, int, int,
   * int)
   */
  public void visitNeighbour(AStarRegionNode origin, int x, int y, int z) {
    // If there's no capacity into this direction, don't visit.
    if (origin.getX() == x)
      if ((!origin.isTerminalRegion() && origin.getVerticalCapacity() == 0)
          || (!map.nodeAt(x, y, z).isTerminalRegion()
              && map.nodeAt(x, y, z).getVerticalCapacity() == 0)) return;
    if (origin.getY() == y)
      if ((!origin.isTerminalRegion() && origin.getHorizontalCapacity() == 0)
          || (!map.nodeAt(x, y, z).isTerminalRegion()
              && map.nodeAt(x, y, z).getHorizontalCapacity() == 0)) return;

    int costFromStart = origin.getCostFromStart() + goal.getNodeCost(origin, x, y, z);
    int costToGoal = goal.distanceToGoal(x, y, z);
    int totalCost = costFromStart + costToGoal;

    // Check if on open/closed list
    // If yes, check if new path is more efficient (lower f value)
    // and update path if so.
    AStarRegionNode foundNode = openList.findOpenNode(x, y, z);
    AStarNode portal = null;
    boolean foundCheaperPath = false;
    if (foundNode != null) {
      if (totalCost < foundNode.getTotalCost()) {
        // If no portal can be found, don't visit.
        portal = this.findPortal(origin, foundNode); // TODO: Do
        // it!
        if (portal != null) {
          foundCheaperPath = true;
          openList.removeNodeFromOpenList(foundNode);
        }
      }
    } else {
      foundNode = closedList.findClosedNode(x, y, z);
      if (foundNode != null) {
        if (totalCost < foundNode.getTotalCost()) {
          // If no portal can be found, don't visit.
          portal = this.findPortal(origin, foundNode); // TODO: Do
          // it!
          if (portal != null) {
            foundCheaperPath = true;
            closedList.removeNodeFromClosedList(foundNode);
          }
        }
      } else {
        foundNode = map.nodeAt(x, y, z);
        // If no portal can be found, don't visit.
        portal = this.findPortal(origin, foundNode);
        if (portal != null) {
          // Node not found in open and closed list, thus put a
          // new one on the open list.
          foundCheaperPath = true;
        }
      }
    }

    if (foundCheaperPath) {
      foundNode.initialize(origin, costFromStart, costToGoal, totalCost, x, y, z);
      foundNode.setEntryPoint(portal);
      openList.addNodeToOpenList(foundNode);
    }
  }