Exemplo n.º 1
0
  private boolean subtaskPlanning(Problem problem, EvaluationAlgorithm algorithm) {

    if (isSubtaskLoggingOn())
      logger.debug("!!!--------- Starting Planning With Subtasks ---------!!!");

    final int maxDepthBackup = maxDepth;
    if (isSubtaskLoggingOn())
      logger.debug(
          "maxDepthBackup:" + maxDepthBackup + " sbt: " + problem.getRelsWithSubtasks().size());
    PlanningContext context = problem.getCurrentContext();

    try {

      Set<Rel> relsWithSubtasks = new LinkedHashSet<Rel>(problem.getRelsWithSubtasks());

      if (isIncremental) {
        int incrementalDepth = 0;

        while (incrementalDepth
            <= (isSubtaskRepetitionAllowed
                ? maxDepthBackup
                : problem.getRelsWithSubtasks().size() - 1)) {
          if (isSubtaskLoggingOn())
            logger.debug(
                "Incremental dfs, with max depth "
                    + (incrementalDepth + 1)
                    + " and "
                    + problem.getRelsWithSubtasks().size()
                    + " subtasks to solve");

          maxDepth = incrementalDepth++;

          // if we need to compute some specific goals, after reaching a certain depth, but not the
          // maximal depth,
          // the problem may be solved and there is no need to go any deeper.
          if (subtaskPlanningImpl(context, relsWithSubtasks, algorithm, new LinkedList<Rel>(), 0)) {
            if (isSubtaskLoggingOn())
              logger.debug("The problem was solved during idfs after some intermediate MLB");
            return true;
          }

          if (isSubtaskLoggingOn())
            logger.debug("Unsolved subtask left: " + problem.getRelsWithSubtasks().size());
        }

        if (isSubtaskLoggingOn()) logger.debug("Fininshed incremental dfs");

      } else {
        if (!isSubtaskRepetitionAllowed) {
          maxDepth = problem.getRelsWithSubtasks().size() - 1;
        }

        if (isSubtaskLoggingOn())
          logger.debug("Starting subtask dfs with maxDepth: " + (maxDepth + 1));

        if (subtaskPlanningImpl(context, relsWithSubtasks, algorithm, new LinkedList<Rel>(), 0)) {
          if (isSubtaskLoggingOn())
            logger.debug("The problem was solved during dfs after some intermediate MLB");
          return true;
        }
      }

    } finally {
      if (isSubtaskLoggingOn()) logger.debug("Fininshed dfs");

      maxDepth = maxDepthBackup;
      indSubtasks.clear();
    }

    if (isSubtaskLoggingOn()) logger.debug("Invoking final linear planning");

    return linearForwardSearch(context, algorithm, computeAll);
  }