Search in sources :

Example 16 with EvoAlg

use of evodef.EvoAlg in project SimpleAsteroids by ljialin.

the class EvoSGATest method main.

public static void main(String[] args) {
    EvoAlg evoAlg = new CompactSlidingGA();
    evoAlg = new NTupleBanditEA();
    // evoAlg = new SlidingMeanEDA();
    evoAlg = new GridSearch();
    StatSummary ss = new StatSummary("Overall results: " + evoAlg.getClass().getSimpleName());
    int nTrials = 1;
    for (int i = 0; i < nTrials; i++) {
        ss.add(runTrial(evoAlg));
    }
    System.out.println(ss);
}
Also used : StatSummary(utilities.StatSummary) CompactSlidingGA(ntuple.CompactSlidingGA) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg)

Example 17 with EvoAlg

use of evodef.EvoAlg in project SimpleAsteroids by ljialin.

the class GeneralGameRunnerTest method main.

public static void main(String[] args) {
    PlanetWarsLinkState linkState = new PlanetWarsLinkState();
    GeneralGameRunner runner = new GeneralGameRunner().setGame(linkState).setLength(200);
    AbstractMultiPlayer player1, player2;
    GameActionSpaceAdapterMulti.visual = false;
    GameState.includeBuffersInScore = false;
    int idPlayer1 = 0;
    int idPlayer2 = 1;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    player1 = new controllers.multiPlayer.discountOLMCTS.Agent(linkState.copy(), timer, idPlayer1);
    // try the evolutionary players
    // GameActionSpaceAdapterMulti.visual = true;
    int nResamples = 1;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 200;
    EvoAlg evoAlg2 = new SlidingMeanEDA().setHistoryLength(20);
    Agent evoAgent1 = new controllers.multiPlayer.ea.Agent(linkState.copy(), timer, evoAlg, idPlayer1, nEvals);
    evoAgent1.sequenceLength = 10;
    // player1 = evoAgent1;
    Agent evoAgent2 = new controllers.multiPlayer.ea.Agent(linkState.copy(), timer, evoAlg, idPlayer2, nEvals);
    evoAgent2.sequenceLength = 10;
    // evoAgent2.setUseShiftBuffer(false);
    player2 = evoAgent2;
    // player2 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg2, idPlayer2, nEvals);
    // player2 = new controllers.multiPlayer.ea.Agent(linkState, timer, new SimpleRMHC(nResamples), idPlayer2, nEvals);
    // player1 = new controllers.multiPlayer.smlrand.Agent();
    // player1 = new controllers.multiPlayer.smlrand.Agent();
    // player2 = new controllers.multiPlayer.doNothing.Agent(linkState.copy(), timer, 1);
    runner.setPlayers(player1, player2);
    int nGames = 100;
    runner.playGames(nGames);
    System.out.println(runner.scores);
}
Also used : Agent(controllers.multiPlayer.ea.Agent) AbstractMultiPlayer(core.player.AbstractMultiPlayer) SlidingMeanEDA(ntuple.SlidingMeanEDA) EvoAlg(evodef.EvoAlg) SimpleRMHC(ga.SimpleRMHC) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 18 with EvoAlg

use of evodef.EvoAlg in project SimpleAsteroids by ljialin.

the class EvoSequenceTest method main.

// simple example of NOT doing rolling horizon, but instead
// of evolving a complete sequence
public static void main(String[] args) throws Exception {
    GameState game = new GameState().defaultState();
    int nResamples = 1;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 2000;
    int seqLength = 30;
    // evoAlg = new SlidingMeanEDA().setHistoryLength(20);
    System.out.println("Initial score: " + game.getScore());
    EvoAgent evoAgent = new EvoAgent().setEvoAlg(evoAlg, nEvals).setSequenceLength(seqLength);
    int[] seq = evoAgent.getActions(game.copy(), 0);
    // System.out.println(evoAgent.simpleGameAdapter.logger().fa);
    // new JEasyFrame( LineChart.easyPlot(evoAgent.simpleGameAdapter.logger().fa), "Evo Plot");
    // visiPlay(game, seq);
    // check the sequence fitness
    System.out.println(evoAgent.simpleGameAdapter.logger().ss);
    System.out.println("Returned sequence: " + Arrays.toString(seq));
    for (int i = 0; i < 5; i++) {
        System.out.println(evoAgent.simpleGameAdapter.evaluate(seq));
    }
    System.out.println();
    System.out.println("Now using the other one");
    for (int i = 0; i < 5; i++) {
        PlanetWarsLinkState linkState = new PlanetWarsLinkState(game.copy());
        GameActionSpaceAdapterMulti adapter = new GameActionSpaceAdapterMulti(linkState, seqLength, 0, 1);
        System.out.println(adapter.evaluate(seq));
    }
    System.out.println();
    for (int i = 0; i < 5; i++) {
        System.out.println(evoAgent.simpleGameAdapter.evaluate(seq));
    }
    System.out.println();
}
Also used : SimpleRMHC(ga.SimpleRMHC) GameActionSpaceAdapterMulti(evodef.GameActionSpaceAdapterMulti) PlanetWarsLinkState(gvglink.PlanetWarsLinkState) EvoAlg(evodef.EvoAlg)

Example 19 with EvoAlg

use of evodef.EvoAlg in project SimpleAsteroids by ljialin.

the class GameLoggerTest method main.

public static void main(String[] args) {
    System.out.println("n Actions: " + GameState.nActions);
    GameState.includeBuffersInScore = false;
    GameRunner gameRunner = new GameRunner().setLength(50);
    SimplePlayerInterface p1, p2;
    p1 = new RandomAgent();
    p2 = new DoNothingAgent();
    EvoAlg evoAlg1 = new SimpleRMHC();
    int nEvals1 = 500;
    int seqLength1 = 15;
    EvoAgent evoAgent1 = new EvoAgent().setEvoAlg(evoAlg1, nEvals1).setSequenceLength(seqLength1);
    evoAgent1.setUseShiftBuffer(false);
    EvoAgent evoAgentShadow1 = new EvoAgent().setEvoAlg(new SimpleRMHC(), nEvals1).setSequenceLength(seqLength1);
    evoAgentShadow1.setUseShiftBuffer(false);
    EvoAgent evoAgentShadow2 = new EvoAgent().setEvoAlg(new SimpleRMHC(), nEvals1).setSequenceLength(3);
    evoAgentShadow2.setUseShiftBuffer(false);
    AbstractGameLogger abstractGameLogger = new AbstractGameLogger().setAgent(evoAgent1);
    abstractGameLogger.addShadow(evoAgentShadow1);
    abstractGameLogger.addShadow(evoAgentShadow2);
    abstractGameLogger.addShadow(new RandomAgent());
    abstractGameLogger.addShadow(new RandomAgent());
    abstractGameLogger.addShadow(new DoNothingAgent());
    abstractGameLogger.addShadow(new DoNothingAgent());
    // p1 = new AbstractGameLogger().setAgent(new DoNothingAgent());
    // p1 = new AbstractGameLogger().setAgent(evoAgent1);
    p1 = abstractGameLogger;
    p2 = new AbstractGameLogger().setAgent(new RandomAgent());
    SimplePlayerInterface opponentModel;
    opponentModel = new RandomAgent();
    // p2 = getMCTSAgent(new GameState().defaultState(), 1);
    p2 = evoAgent1;
    gameRunner.setPlayers(p1, p2);
    int nGames = 20;
    gameRunner.playGames(nGames);
    gameRunner.plotGameScores();
// System.out.println(p1);
// System.out.println(p2);
}
Also used : SimpleRMHC(ga.SimpleRMHC) EvoAlg(evodef.EvoAlg)

Example 20 with EvoAlg

use of evodef.EvoAlg in project SimpleAsteroids by ljialin.

the class GameRunnerTest method main.

public static void main(String[] args) {
    GameState.includeBuffersInScore = false;
    GameRunner gameRunner = new GameRunner().setLength(200);
    SimplePlayerInterface p1, p2;
    p1 = new RandomAgent();
    // p2 = new DoNothingAgent();
    EvoAlg evoAlg1 = new SimpleRMHC();
    // evoAlg1.mu
    int nEvals1 = 200;
    int seqLength1 = 10;
    int nEvals2 = 400;
    int seqLength2 = 5;
    SlidingMeanEDA evoAlg2 = new SlidingMeanEDA().setHistoryLength(40);
    SimpleGA simpleGA = new SimpleGA().setPopulationSize(20);
    EvoAgent evoAgent1 = new EvoAgent().setEvoAlg(evoAlg1, nEvals1).setSequenceLength(seqLength1);
    evoAgent1.setUseShiftBuffer(true);
    // evoAgent1.mu
    // evoAgent1.u
    // evoAgent1.setOpponent(new RandomAgent()).setUseShiftBuffer(false);
    // evoAgent1.setOpponent(new RandomAgent());
    p1 = evoAgent1;
    SimplePlayerInterface opponentModel;
    opponentModel = new DoNothingAgent();
    opponentModel = new RandomAgent();
    // p2 = new EvoAgent().setEvoAlg(simpleGA, nEvals).setSequenceLength(seqLength).setOpponent(opponentModel);
    // p2 = new EvoAgent().setEvoAlg(evoAlg1, nEvals/2).setSequenceLength(seqLength*2).setOpponent(opponentModel);
    EvoAgent evoAgent2 = new EvoAgent().setEvoAlg(evoAlg1, nEvals2).setSequenceLength(seqLength2).setOpponent(opponentModel);
    evoAgent2.setUseShiftBuffer(true);
    p2 = evoAgent2;
    p2 = getMCTSAgent(new GameState().defaultState(), 1);
    // p2 = new RandomAgent();
    gameRunner.setPlayers(p1, p2);
    // now play a number of games and observe the outcomes
    // verbose is set to true by default so after the games have been played
    // it will report the outcomes
    int nGames = 20;
    gameRunner.playGames(nGames);
    // now access the game logs to plot the scores
    gameRunner.plotGameScores();
// System.out.println(evoAlg2.pVec);
}
Also used : SimpleGA(ga.SimpleGA) SimpleRMHC(ga.SimpleRMHC) SlidingMeanEDA(ntuple.SlidingMeanEDA) EvoAlg(evodef.EvoAlg)

Aggregations

EvoAlg (evodef.EvoAlg)23 SimpleRMHC (ga.SimpleRMHC)17 Random (java.util.Random)9 NTupleBanditEA (ntuple.NTupleBanditEA)9 ElapsedCpuTimer (tools.ElapsedCpuTimer)9 Types (ontology.Types)7 ElapsedTimer (utilities.ElapsedTimer)7 SlidingMeanEDA (ntuple.SlidingMeanEDA)6 AbstractMultiPlayer (core.player.AbstractMultiPlayer)5 JEasyFrame (utilities.JEasyFrame)5 Agent (controllers.singlePlayer.ea.Agent)4 AbstractPlayer (core.player.AbstractPlayer)4 StatSummary (utilities.StatSummary)4 StateObservation (core.game.StateObservation)3 SimpleMaxGame (altgame.SimpleMaxGame)2 BattleView (battle.BattleView)2 Agent (controllers.multiPlayer.ea.Agent)2 StateObservationMulti (core.game.StateObservationMulti)2 AnnotatedFitnessSpace (evodef.AnnotatedFitnessSpace)2 CompactSlidingGA (ntuple.CompactSlidingGA)2