Example #1
0
 public SimpleNNMaker(AITrainableGame game)
 {
     bitsPerWeight    = game.BitsPerWeight();
     inputs           = game.NumInputs();
     hidden           = game.NumHidden();
     outputs          = game.NumOutputs();
     bitsPerBias      = game.BitsPerBias();
     chromosomeLength = (inputs * hidden + hidden * outputs) * bitsPerWeight + (hidden + outputs) * bitsPerBias;
 }
Example #2
0
        public Simulation(AITrainableGame game, int populationSize = 100, double crossOverBredAmount = 0.5, double mutateAfterCrossoverAmount = 0.1,
                          double mutationRate          = 0.05, int allowSinglePointCrossover = 1, int allowTwoPointCrossover = 1, int allowUniformCrossover  = 1,
                          int offspringSelectionPolicy = 0, double initialMutation           = 0.0, double initialSimilarity = 0.0, int mainDiversityMeasure = 0)
        {
            PopulationSize             = populationSize;
            CrossoverBredAmount        = crossOverBredAmount;
            MutateAfterCrossoverAmount = mutateAfterCrossoverAmount;
            MutationRate = mutationRate;
            AllowSinglePointCrossover = allowSinglePointCrossover == 1 ? true : false;
            AllowTwoPointCrossover    = allowTwoPointCrossover == 1 ? true : false;
            AllowUniformCrossover     = allowUniformCrossover == 1 ? true : false;
            ReplacementRule           = offspringSelectionPolicy;
            InitialMutation           = initialMutation;
            InitialSimilarity         = initialSimilarity;
            DiversityMeasure          = mainDiversityMeasure;


            allowedCrossoverMethods = new List <CrossoverMethod>();
            if (AllowSinglePointCrossover)
            {
                allowedCrossoverMethods.Add(new SinglePointCrossover());
            }
            if (AllowTwoPointCrossover)
            {
                allowedCrossoverMethods.Add(new TwoPointCrossover());
            }
            if (AllowUniformCrossover)
            {
                allowedCrossoverMethods.Add(new UniformCrossover());
            }

            switch (ReplacementRule)
            {
            case 0: offspringMerger = new NaiveReplacementRule(); break;

            case 1: offspringMerger = new AncestorElitismNoExtinctionReplacementRule(); break;

            case 2: offspringMerger = new AncestorElitismReplacementRule(); break;

            case 3: offspringMerger = new SingleParentElitismReplacementRule(); break;

            case 4: offspringMerger = new ExploreExploitT30ReplacementRule(); break;

            case 5: offspringMerger = new ExploreExploitT20ReplacementRule(); break;

            case 6: offspringMerger = new ExploreExploitT40ReplacementRule(); break;

            case 7: offspringMerger = new ExploreExploitB30ReplacementRule(); break;

            default: throw new Exception("Wrong offspring merge type: " + ReplacementRule);
            }

            diversityMeasure = diversityMeasures[0];

            Game = game;
            NeuralNetworkMaker = new SimpleNNMaker(game);
        }
Example #3
0
 /// <summary>
 /// Calculates the fitness value of each individual threaded
 /// </summary>
 /// <param name="offspring"></param>
 private void CalcFitnessValuesThreaded(List <AIPlayer> list)
 {
     Task[] tasks = new Task[list.Count];
     for (int i = 0; i < list.Count; i++)
     {
         int             index = i;
         AITrainableGame game  = Simulation.Game;
         tasks[index] = Task.Factory.StartNew(() => { list[index].CalcFitness(game); });
     }
     Task.WaitAll(tasks);
 }
Example #4
0
 /// <summary>
 /// Calculates the fitness of the AIPlayer based on the given game.
 /// Call GetFitness() retrieve the fitness value afterwards.
 /// </summary>
 /// <param name="game"></param>
 public void CalcFitness(AITrainableGame game)
 {
     fitness = game.CalcFitness(this);
 }
Example #5
0
 private void purchaseRadioButton_CheckedChanged(object sender, EventArgs e)
 {
     game = new Purchase();
     GameChanged();
 }
Example #6
0
 private void XORRadioButton_CheckedChanged(object sender, EventArgs e)
 {
     game = new XOR();
     GameChanged();
 }
Example #7
0
 private void rosenbrockRadioButton_CheckedChanged(object sender, EventArgs e)
 {
     game = new Rosenbrock();
     GameChanged();
 }
Example #8
0
 public Form1()
 {
     InitializeComponent();
     game = new SnakeGame();
 }
Example #9
0
 private void bankruptcyRadioButton_CheckedChanged(object sender, EventArgs e)
 {
     game = new Bankruptcy();
     GameChanged();
 }
Example #10
0
 private void leafRadioButton_CheckedChanged(object sender, EventArgs e)
 {
     game = new Leaf();
     GameChanged();
 }
Example #11
0
 private void IrisRadioButton_Click(object sender, EventArgs e)
 {
     game = new Iris();
     GameChanged();
 }
Example #12
0
 private void SnakeRadioButton_CheckedChanged(object sender, EventArgs e)
 {
     game = new SnakeGame();
     GameChanged();
 }
Example #13
0
 private void FallingStarsRadioButton_CheckedChanged(object sender, EventArgs e)
 {
     game = new FallingStarsGame();
     GameChanged();
 }