Exemplo n.º 1
0
        static void Main(string[] args)
        {
            GridGameParameters gg = GridGameParameters.GetParameters(args);
            if (gg == null)
                return;

            experiment = new GridGameExperiment(gg.ConfigPath);
            experiment.Evaluator = new CondorEvaluator(gg, CondorGroup.Grad);
            ea = experiment.CreateEvolutionAlgorithm();
            ea.UpdateScheme = new SharpNeat.Core.UpdateScheme(1);
            ea.UpdateEvent += new EventHandler(ea_UpdateEvent);

            using (TextWriter writer = new StreamWriter(gg.ResultsPath))
                writer.WriteLine("Generation,Best,Average");

            ea.StartContinue();

            while (!finished) Thread.Sleep(1000);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            GridGameParameters gg = GridGameParameters.GetParameters(args);
            if (gg == null)
                return;

            using (TextWriter writer = new StreamWriter(gg.ConfigPath))
            {
                XmlSerializer ser = new XmlSerializer(typeof(GridGameParameters));
                ser.Serialize(writer, gg);
            }

            experiment = new GridGameExperiment(gg.ConfigPath);
            ea = experiment.CreateEvolutionAlgorithm();
            ea.UpdateScheme = new SharpNeat.Core.UpdateScheme(1);
            ea.UpdateEvent += new EventHandler(ea_UpdateEvent);

            using (TextWriter writer = new StreamWriter(gg.ResultsPath))
                writer.WriteLine("Generation,Best,Average");

            ea.StartContinue();

            while (!finished) Thread.Sleep(1000);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length != 5)
            {
                Console.WriteLine("Usage: CondorEvaluator.exe <model_id> <model_file> <results_file> <finished_flag> <config_file>");
                return;
            }

            int curArg = 0;
            int modelId = int.Parse(args[++curArg]);
            string modelFile = args[++curArg];
            string resultsFile = args[++curArg];
            string finishedFlag = args[++curArg];
            string configFile = args[++curArg];

            GridGameExperiment experiment = new GridGameExperiment(configFile);

            IAgent model = experiment.CreateTargetAgent();
            IAgent benchmark = experiment.CreateEvalAgent();

            using (TextWriter tw = new StreamWriter(resultsFile))
            {
                // Evaluate
                if (model == null)
                {   // Non-viable genome.
                    tw.WriteLine("0.0 0.0");
                }
                else
                {
                    double score = Evaluate(model, benchmark, experiment.Parameters);
                    tw.WriteLine(score + " " + score);
                }
            }

            File.Create(finishedFlag);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            _params = GridGameParameters.GetParameters(args);
            if (_params == null)
                return;

            Debug.Assert(_params.AgentPath != null);
            Debug.Assert(File.Exists(_params.AgentPath));

            using (TextWriter writer = new StreamWriter(_params.ConfigPath))
            {
                XmlSerializer ser = new XmlSerializer(typeof(GridGameParameters));
                ser.Serialize(writer, _params);
            }

            _experiment = new GridGameExperiment(_params.ConfigPath);

            IAgent agent = null;
            IAgent benchmark = null;

            // Load the agent to benchmark
            var modelGenome = _experiment.LoadPopulation(XmlReader.Create(_params.AgentPath))[0];
            var brain = _experiment.CreateGenomeDecoder().Decode(modelGenome);
            if (_params.MctsNeat)
            {
                Console.WriteLine("Creating MCTS-NEAT agent");
                agent = _params.CreateMctsNeatAgent(1, brain);
            }
            else
            {
                Console.WriteLine("Creating MCTS agent");
                agent = _params.CreateMctsAgent(1, false);
            }

            // Create the benchmark MCTS agent
            if (_params.Evaluator == "mcts")
            {
                Console.WriteLine("Creating MCTS benchmark agent");
                benchmark = _params.CreateMctsAgent(-1, true);
            }
            else
            {
                Console.WriteLine("Creating Random benchmark agent");
                benchmark = new RandomAgent(-1);
            }

            Outcome[] outcomes = new Outcome[_params.MatchesPerOpponent * 2];

            Console.WriteLine("Starting games as player 1..");
            using (_moveLog = new StreamWriter(_params.BenchmarkGameLogPath))
            {
                for (int i = 0; i < _params.MatchesPerOpponent; i++)
                {
                    Console.Write(i + "...");
                    if (i > 0 && i % 10 == 0)
                        Console.WriteLine();
                    outcomes[i] = RunTrial(agent, benchmark, 1);
                }
                Console.WriteLine();

                Console.WriteLine("Starting games as player 2..");
                for (int i = 0; i < _params.MatchesPerOpponent; i++)
                {
                    Console.Write(i + "...");
                    if (i > 0 && i % 10 == 0)
                        Console.WriteLine();
                    outcomes[i + _params.MatchesPerOpponent] = RunTrial(benchmark, agent, -1);
                }
                Console.WriteLine();
                Console.WriteLine("Saving log file...");
            }

            using (TextWriter writer = new StreamWriter(_params.BenchmarkResultsPath))
            {
                // games
                // wins, ties, losses
                // win %, tie %, loss %
                // p1 wins, p1 ties, p1 losses, 
                // p1 win %, p1 tie %, p1 loss %, 
                // p2 wins, p2 ties, p2 losses, 
                // p2 win %, p2 tie %, p2 loss %,
                // time per move, turns per game
                writer.WriteLine("games,wins,win%,ties,tie%,losses,loss%,p1 wins,p1 win%,p1 ties,p1 tie%,p1 losses,p1 loss%,p2 wins,p2 win%,p2 ties,p2 tie%,p2 losses,p2 loss%,avg time per move, avg total moves per game");

                writer.WriteLine(
                    outcomes.Length + "," + // games
                    
                    outcomes.Count(o => o.Winner == o.AgentId) + "," + // wins
                    Pct(outcomes.Count(o => o.Winner == o.AgentId), outcomes.Length) + "," + // win %
                    outcomes.Count(o => o.Winner == 0) + "," + // ties
                    Pct(outcomes.Count(o => o.Winner == 0), outcomes.Length) + "," + // tie %
                    outcomes.Count(o => o.Winner == o.BenchmarkId) + "," + // losses
                    Pct(outcomes.Count(o => o.Winner == o.BenchmarkId), outcomes.Length) + "," + // loss %
                    
                    outcomes.Count(o => o.Winner == o.AgentId && o.AgentId == 1) + "," + // p1 wins
                    Pct(outcomes.Count(o => o.Winner == o.AgentId && o.AgentId == 1), outcomes.Count(o => o.AgentId == 1)) + "," + // p1 win %
                    outcomes.Count(o => o.Winner == 0 && o.AgentId == 1) + "," + // p1 ties
                    Pct(outcomes.Count(o => o.Winner == 0 && o.AgentId == 1), outcomes.Count(o => o.AgentId == 1)) + "," + // p1 tie %
                    outcomes.Count(o => o.Winner == o.BenchmarkId && o.AgentId == 1) + "," + // p1 losses
                    Pct(outcomes.Count(o => o.Winner == o.BenchmarkId && o.AgentId == 1), outcomes.Count(o => o.AgentId == 1)) + "," + // p1 loss %

                    outcomes.Count(o => o.Winner == o.AgentId && o.AgentId == -1) + "," + // p2 wins
                    Pct(outcomes.Count(o => o.Winner == o.AgentId && o.AgentId == -1), outcomes.Count(o => o.AgentId == -1)) + "," + // p2 win %
                    outcomes.Count(o => o.Winner == 0 && o.AgentId == -1) + "," + // p2 ties
                    Pct(outcomes.Count(o => o.Winner == 0 && o.AgentId == -1), outcomes.Count(o => o.AgentId == -1)) + "," + // p2 tie %
                    outcomes.Count(o => o.Winner == o.BenchmarkId && o.AgentId == -1) + "," + // p2 losses
                    Pct(outcomes.Count(o => o.Winner == o.BenchmarkId && o.AgentId == -1), outcomes.Count(o => o.AgentId == -1)) + "," + // p2 loss %

                    string.Format("{0:N2},", outcomes.Average(o => o.AverageTurnTime)) +
                    string.Format("{0:N2}", outcomes.Average(o => o.TotalMoves))
                    );
            }
            Console.WriteLine("Done!");
        }