Package ch.idsia.scenarios.test

Source Code of ch.idsia.scenarios.test.PaperEvolve

package ch.idsia.scenarios.test;

import wox.serial.Easy;
import ch.idsia.ai.Evolvable;
import ch.idsia.ai.agents.Agent;
import ch.idsia.ai.agents.RegisterableAgent;
import ch.idsia.ai.agents.ai.LargeSRNAgent;
import ch.idsia.ai.ea.ES;
import ch.idsia.ai.tasks.ProgressTask;
import ch.idsia.scenarios.Stats;
import ch.idsia.tools.CmdLineOptions;
import ch.idsia.tools.EvaluationOptions;

/**
* Created by IntelliJ IDEA.
* User: julian
* Date: Jun 13, 2009
* Time: 2:16:18 PM
*/
public class PaperEvolve {

    final static int generations = 100;
    final static int populationSize = 100;


    public static void main(String[] args) {
        EvaluationOptions options = new CmdLineOptions(new String[0]);
        options.setMaxAttempts(1);
        Evolvable initial = new LargeSRNAgent();
        if (args.length > 0) {
            initial = (Evolvable) RegisterableAgent.load (args[0]);
        }
        RegisterableAgent.registerAgent ((Agent) initial);
        options.setMaxFPS(true);
        options.setPauseWorld(false);
        options.setVisualization(false);
        ProgressTask task = new ProgressTask(options);
        int seed = (int) (Math.random () * Integer.MAX_VALUE);
        ES es = new ES (task, initial, populationSize);
        System.out.println("Evolving " + initial + " with task " + task);
        int difficulty = 0;
        final String fileName = "evolved" + (int) (Math.random () * Integer.MAX_VALUE) + ".xml";
        options.setLevelRandSeed(seed);
        for (int gen = 0; gen < generations; gen++) {
            es.nextGeneration();
            double bestResult = es.getBestFitnesses()[0];
            System.out.println("Generation " + gen + " diff " + difficulty + "  best " + bestResult);
            Easy.save (es.getBests()[0], fileName);
            if (bestResult > 4000) {
                difficulty++;
                options.setLevelDifficulty(difficulty);
                options.setLevelRandSeed(seed);
            }
        }
        Stats.main(new String[]{fileName, "0"});
        System.out.println("\n\n\n\n\n\n\n\n\n");
    }
}
TOP

Related Classes of ch.idsia.scenarios.test.PaperEvolve

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.