Search in sources :

Example 1 with ShortestPathTest

use of evomaze.ShortestPathTest in project SimpleAsteroids by ljialin.

the class BanditEA method runTrials.

public static StatSummary runTrials(int nBandits, int nTrials) throws Exception {
    StatSummary ss = new StatSummary();
    ArrayList<int[][]> examples = new ArrayList<>();
    // System.out.println(examples);
    rankCorrelation = new RankCorrelation();
    for (int i = 0; i < nTrials; i++) {
        BanditEA ea = new BanditEA(nBandits);
        ea.evaluator = new ShortestPathTest();
        ElapsedTimer t = new ElapsedTimer();
        ea.run(nEvals);
        System.out.println(t);
        if (ea.success) {
        // ss.add(ea.trialsSoFar);
        }
        ss.add(ea.evaluate(ea.genome));
        System.out.println("Checking fitness: " + ea.evaluate(ea.genome));
        examples.add(toSquareArray(ea.genome.toArray()));
        System.out.println("Rank correlation check:");
        rankCorrelation.rankCorrelation();
    }
    System.out.println("Created mazes");
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String out = gson.toJson(examples);
    System.out.println("Created JSON String");
    // System.out.println(out);
    String outputFile = "data/mazes.json";
    PrintWriter writer = new PrintWriter(outputFile);
    writer.print(out);
    writer.close();
    System.out.println("Wrote file with " + examples.size() + " examples");
    return ss;
}
Also used : StatSummary(utilities.StatSummary) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) RankCorrelation(ntuple.RankCorrelation) ShortestPathTest(evomaze.ShortestPathTest) Gson(com.google.gson.Gson) ElapsedTimer(utilities.ElapsedTimer) PrintWriter(java.io.PrintWriter)

Example 2 with ShortestPathTest

use of evomaze.ShortestPathTest in project SimpleAsteroids by ljialin.

the class ConvMazeTest method runTrials.

public StatSummary runTrials(int nDimenions, int nTrials) throws Exception {
    StatSummary ss = new StatSummary();
    ArrayList<int[][]> examples = new ArrayList<>();
    // System.out.println(examples);
    rankCorrelation = new RankCorrelation();
    ElapsedTimer timer = new ElapsedTimer();
    for (int i = 0; i < nTrials; i++) {
        evaluator = new ShortestPathTest();
        System.out.println("N DIMS = " + evaluator.searchSpace().nDims());
        ElapsedTimer t = new ElapsedTimer();
        NTupleBanditEA nTupleBanditEA = new NTupleBanditEA().setKExplore(nDimenions);
        nTupleBanditEA.setKExplore(10).setNeighbours(50);
        convNTuple.reset();
        nTupleBanditEA.setModel(convNTuple);
        // nTupleBanditEA.s
        int[] solution = nTupleBanditEA.runTrial(evaluator, nEvals);
        System.out.println("Solution array: " + Arrays.toString(solution));
        System.out.println(t);
        double fitness = evaluator.evaluate(solution);
        ss.add(fitness);
        System.out.println("Checking fitness: " + fitness);
        examples.add(toSquareArray(solution));
        System.out.println("Rank correlation check:");
        // rankCorrelation.rankCorrelation();
        convNTuple.report(evaluator);
        MazeView.showMaze(solution, "" + fitness);
        System.out.println(timer);
    }
    if (createFiles) {
        System.out.println("Created mazes");
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String out = gson.toJson(examples);
        System.out.println("Created JSON String");
        // System.out.println(out);
        String outputFile = "data/mazes.json";
        PrintWriter writer = new PrintWriter(outputFile);
        writer.print(out);
        writer.close();
        System.out.println("Wrote file with " + examples.size() + " examples");
    }
    return ss;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) StatSummary(utilities.StatSummary) ShortestPathTest(evomaze.ShortestPathTest) ElapsedTimer(utilities.ElapsedTimer) PrintWriter(java.io.PrintWriter)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ShortestPathTest (evomaze.ShortestPathTest)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 ElapsedTimer (utilities.ElapsedTimer)2 StatSummary (utilities.StatSummary)2 RankCorrelation (ntuple.RankCorrelation)1