@Test
  public void testSolving() {
    GridModel grid = new GridModel(4);

    GridFiller filler = new GridFiller(grid);
    filler.fillRandom(grid.getSize() * 3 / 2);
    grid.shuffle();

    ClusterManager cluster = new ClusterManager(new NullLog());
    GridModel solutionGrid = new GridModel();

    AStarSolverMkI solver = new AStarSolverMkI(grid, solutionGrid, cluster);
    solver.run();
    assertTrue(solutionGrid.isComplete());
  }
예제 #2
0
  private static void computeStats(
      List<String> solvers, List<String> paths, int samples, int sizeMin, int sizeMax)
      throws InterruptedException, ExecutionException {
    // Grid cpuGrid = GridFactory.start();

    for (int gridsize = sizeMin; gridsize <= sizeMax; gridsize++) {

      int patterns = (int) (gridsize * 1.5);
      Collector reference = null;

      for (String solverName : solvers) {

        List<String> pathsQueue = new ArrayList<String>();
        if (SolverFactory.isSolverPathSensitive(solverName)) {
          pathsQueue.addAll(paths);
        } else {
          pathsQueue.add(null);
        }

        for (String pathName : pathsQueue) {

          String collectorName = computeCollectorName(solverName, pathName, gridsize, patterns);

          Collector collector = new Collector(collectorName, reference);
          if (reference == null) {
            reference = collector;
          }

          // ExecutorService executor =
          // cpuGrid.newGridExecutorService();
          ExecutorService executor =
              Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
          Set<Future<Collector>> collectors = new LinkedHashSet<Future<Collector>>();

          for (int sample = 0; sample < samples; sample++) {
            GridModel grid = new GridModel(gridsize);
            GridFiller filler = new GridFiller(grid);
            filler.fillRandom(patterns);
            grid.shuffle();
            SolverMeter solverMeter = new SolverMeter(solverName, pathName, grid);
            collectors.add(executor.submit(solverMeter));
          }

          for (Future<Collector> futureCollector : collectors) {
            collector.recordExecutions(futureCollector.get());
          }

          executor.shutdown();
          while (!executor.isTerminated()) {
            try {
              executor.awaitTermination(10, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
              // Do nothing, keep looping
            }
          }

          collector.displayResults();
        }
      }

      System.out.println();
    }
  }