Пример #1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.sun.electric.tool.routing.astar.t3.machine.AStarMachine#findPath(int,
   * int, int, int, int, int)
   */
  public List<AStarRegionNode> findPath(
      int startX, int startY, int startZ, int goalX, int goalY, int goalZ) {
    if (map == null)
      throw new IllegalStateException(
          "The searched map must be specified before path search can be done.");
    if (this.goal == null)
      throw new IllegalStateException(
          "The goal object must be specified before path search can be done.");

    AStarRegionNode startRegion = map.nodeAt(startX, startY, startZ);
    AStarRegionNode goalRegion = map.nodeAt(goalX, goalY, goalZ);

    assert (startRegion != null);
    assert (goalRegion != null);

    this.goal.setGoalNode(goalRegion);
    int goalDistance = this.goal.distanceToGoal(startX, startY, startZ);
    goalRegion.initialize(null, goalDistance, 0, goalDistance, goalX, goalY, goalZ);

    startRegion.initialize(null, 0, goalDistance, goalDistance, startX, startY, startZ);
    // openList.clearOpenList();
    // closedList.clearClosedList();
    openList.addNodeToOpenList(startRegion);
    return AStar.findPath(openList, closedList, map, this.goal, nodePool, this);
  }
Пример #2
0
 /*
  * (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);
 }
Пример #3
0
  /*
   * (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);
    }
  }