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; }
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); }
/// <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); }
/// <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); }
private void purchaseRadioButton_CheckedChanged(object sender, EventArgs e) { game = new Purchase(); GameChanged(); }
private void XORRadioButton_CheckedChanged(object sender, EventArgs e) { game = new XOR(); GameChanged(); }
private void rosenbrockRadioButton_CheckedChanged(object sender, EventArgs e) { game = new Rosenbrock(); GameChanged(); }
public Form1() { InitializeComponent(); game = new SnakeGame(); }
private void bankruptcyRadioButton_CheckedChanged(object sender, EventArgs e) { game = new Bankruptcy(); GameChanged(); }
private void leafRadioButton_CheckedChanged(object sender, EventArgs e) { game = new Leaf(); GameChanged(); }
private void IrisRadioButton_Click(object sender, EventArgs e) { game = new Iris(); GameChanged(); }
private void SnakeRadioButton_CheckedChanged(object sender, EventArgs e) { game = new SnakeGame(); GameChanged(); }
private void FallingStarsRadioButton_CheckedChanged(object sender, EventArgs e) { game = new FallingStarsGame(); GameChanged(); }