Beispiel #1
0
  public static FreeLeaf getFreeRandomLink(
      ATNodeCollection nodeCollection, List<ATNode> nodeGeneList) {
    List<FreeLeaf> freeLeaves = new ArrayList<FreeLeaf>();
    // for each function node
    for (ATNode node : nodeGeneList) {
      // count how many times it is connected from each kind of a terminal
      int[] terminalCounters = new int[nodeCollection.terminals.length];
      for (ATNode child : node.children) {
        if (child.isTerminal()) {
          terminalCounters[child.getId()]++;
        }
      }

      for (int i = 0, childrenSize = node.children.size(); i < childrenSize; i++) {
        ATNode child =
            node.children.get(i); // We try all possibilities of changing "child" at index "i"
        if (!child.isTerminal()) {
          continue;
        }
        for (int j = 0; j < terminalCounters.length; j++) { // to terminal at index "j".
          if (child.getId() != j) { // Skip if no change would happen.
            if (nodeCollection.isInputById(j)) { // inputs, ...
              if (terminalCounters[j] < node.repeatInput()) {
                freeLeaves.add(new FreeLeaf(i, j, node));
              }
            } else { // constants
              if (terminalCounters[j] < node.repeatConstant()) {
                freeLeaves.add(new FreeLeaf(i, j, node));
              }
            }
          }
        }
      }
    }

    if (freeLeaves.size() == 0) {
      return null;
    }

    return RND.randomChoice(freeLeaves);
  }
Beispiel #2
0
  public static void main(String[] args) {
    long seed = RND.initializeTime();
    //        long seed = 12341957678627684L;
    System.out.println("INITIALIZED SEED: " + seed);
    RND.initialize(seed);

    if (args.length == 0) {
      throw new IllegalArgumentException("Missing parameters!");
    }

    ParameterMatrixManager manager = ParameterMatrixStorage.load(new File(args[0]));

    ReportStorage reportStorage;

    if (args.length > 1) {
      reportStorage = new ReportStorage(args[1]);

    } else {
      reportStorage = new ReportStorage();
    }

    reportStorage.startAll(seed, manager);
    reportStorage.openExperimentsOverallResults();
    for (ParameterCombination combination : manager) {
      int experiments = combination.getInteger("EXPERIMENTS");

      Stats stats = prepareStats();

      reportStorage.storeParameters(combination.toStringAllSeparatedNewLines());

      for (int i = 1; i <= experiments; i++) {
        reportStorage.startSingleRun();

        System.out.println("PARAMETER SETTING: " + combination);

        EvolutionaryAlgorithmRunner runnerEA;

        String solver = combination.getString("SOLVER");
        if (solver.equals("GP")) {
          initializeGP(combination);
          runnerEA = new GPRunner(combination);
        } else if (solver.equals("MOGP")) {
          initializeMOGP(combination);
          runnerEA = new MOGPRunner(combination);
        } else if (solver.equals("GPAT")) {
          initializeGP(combination);
          runnerEA = new GPATRunner(combination);
        } else if (solver.equals("NEAT")) {
          initializeNEAT(combination);
          runnerEA = new NEATRunner(combination);
        } else {
          throw new IllegalStateException("Unknown SOLVER: " + solver + ".");
        }

        Utils.setStaticParameters(combination, GP.class, "GP");
        Utils.setStaticParameters(combination, GEP.class, "GEP");
        Utils.setStaticParameters(combination, GPAAC.class, "GPAAC");
        Utils.setStaticParameters(combination, GPEFS.class, "GPEFS");
        Utils.setStaticParameters(combination, GPAT.class, "GPAT");
        Utils.setStaticParameters(combination, GPATSimple.class, "GPATS");

        runnerEA.run(stats, reportStorage);

        reportStorage.storeSingleRunResults();
        reportStorage.incrementExperimentId();
      }
      reportStorage.storeExperimentResults(stats);
      reportStorage.appendExperimentsOverallResults(combination.toStringOnlyChannging(), stats);
      System.out.println(stats.scopeToString("EXPERIMENT"));
      reportStorage.prepareNewParameterCombination();
    }
    reportStorage.closeExperimentsOverallResults();
    SoundHelper.playSoundFile("/System/Library/Sounds/Glass.aiff");
    String experimentDirectory = args.length > 1 ? "(" + args[1] + ")" : "";
    XMPPHelper.sendViaXMPP("NE run (Runner) finished " + experimentDirectory + ".");
  }