Esempio n. 1
0
  private boolean executeInParallel(PsolBGame game, SolverThread[] threads)
      throws InterruptedException {
    // System.out.println("executing a batch");

    for (SolverThread t : threads) {
      if (t != null) t.start();
    }
    for (SolverThread t : threads) {
      if (t != null) t.join();
    }

    Set<Node> predecessors = new HashSet<Node>();
    boolean attractorFound = false;
    for (SolverThread t : threads) {
      if (t != null && t.attractorFound) {
        game.incrementFatalAttractorCount();
        attractorFound = true;
        int player = t.color % 2;
        for (Node n : t.attractor) {
          for (Node p : n.getPredecessors()) {
            if (!t.attractor.contains(p)) {
              predecessors.add(p);
            }
          }
          game.deleteNode(n);
          game.addToWinningRegion(player, n);
        }
      }
    }

    ParalellUtils.handleSuccessorLessNodes(game, predecessors);
    return attractorFound;
  }
Esempio n. 2
0
  public static LinkedList<Plan> getPlans() {
    LinkedList<Plan> returnedPlans = new LinkedList<Plan>();
    TermConstant.initialize(5);

    Domain d = new foralltest();

    d.setProblemConstants(defineConstants());

    State s = new State(3, d.getAxioms());

    JSHOP2.initialize(d, s);

    TaskList tl;
    SolverThread thread;

    createState0(s);

    tl = new TaskList(1, true);
    tl.subtasks[0] = new TaskList(new TaskAtom(new Predicate(0, 0, TermList.NIL), false, false));

    thread = new SolverThread(tl, 1);
    thread.start();

    try {
      while (thread.isAlive()) Thread.sleep(500);
    } catch (InterruptedException e) {
    }

    returnedPlans.addAll(thread.getPlans());

    return returnedPlans;
  }