private StackPanel InitGeneticSettings()
        {
            // Population
            var populationValidity  = StringExtensions.IsInt().And(StringExtensions.InRange(2, 10000));
            var updatePopulation    = new Action <string>(str => GeneticSettings = GeneticSettings.WithPopulation(int.Parse(str)));
            var populationContainer = HorizontalContainerStrecherd.Create()
                                      .AddLeft(TextBlockCreator.RegularTextBlock("Population").WithBullet())
                                      .AsDock(InteractiveTextBox.Create(GeneticSettings.Population.ToString(), populationValidity, updatePopulation, Dispatcher));

            // Mutation Rate
            var mutationRateValidity  = StringExtensions.IsDouble().And(StringExtensions.InRange(0, 1));
            var updateMutationRate    = new Action <string>(str => GeneticSettings = GeneticSettings.WithMutationRate(double.Parse(str)));
            var mutationRateContainer = HorizontalContainerStrecherd.Create()
                                        .AddLeft(TextBlockCreator.RegularTextBlock("Mutation Rate").WithBullet())
                                        .AsDock(InteractiveTextBox.Create(this.GeneticSettings.MutationRate.ToString(), mutationRateValidity, updateMutationRate, Dispatcher));

            // Elitism Rate
            var elitismRateValidity  = StringExtensions.IsDouble().And(StringExtensions.InRange(0, 1));
            var updateElitismRate    = new Action <string>(str => GeneticSettings = GeneticSettings.WithMutationRate(double.Parse(str)));
            var elitismRateContainer = HorizontalContainerStrecherd.Create()
                                       .AddLeft(TextBlockCreator.RegularTextBlock("Elitism Rate").WithBullet())
                                       .AsDock(InteractiveTextBox.Create(this.GeneticSettings.ElitismRate.ToString(), elitismRateValidity, updateElitismRate, Dispatcher));


            // New Genes Rate
            var newGenesRateValidity  = StringExtensions.IsDouble().And(StringExtensions.InRange(0, 1));
            var updateNewGenesRate    = new Action <string>(str => GeneticSettings = GeneticSettings.WithMutationRate(double.Parse(str)));
            var newGenesRateContainer = HorizontalContainerStrecherd.Create()
                                        .AddLeft(TextBlockCreator.RegularTextBlock("New Genes Rate").WithBullet())
                                        .AsDock(InteractiveTextBox.Create(this.GeneticSettings.NewGenesRate.ToString(), newGenesRateValidity, updateNewGenesRate, Dispatcher));

            var title = TextBlockCreator.TitleTextBlock("Genetic Settings");

            return(GuiExtensions.CreateStackPanel(title, populationContainer, mutationRateContainer, elitismRateContainer, newGenesRateContainer));
        }
    /// <summary>
    /// Gets the fitness of the individual
    /// </summary>
    public override float fitness()
    {
        float f6 = distanceMade * 15f;
        float f7 = -accumulatedDistanceFromRoutePosition / 4;

        return(GeneticSettings.normalizeFitness(f6 + f7));
    }
 public ListedGeneticSettingsGUI(SnakeAISettings snakeAISettings, bool canEdit) : base(canEdit)
 {
     this.snakeAISettings = snakeAISettings;
     geneticSettings      = snakeAISettings.GeneticSettings;
     CreateItems();
     AddSettingItems();
 }
Пример #4
0
    /// <summary>
    /// Gets the fitness of the individual
    /// </summary>
    public override float fitness()
    {
        float f1 = distanceMade * 15f;
        float f2 = -accumulatedDistanceFromRoutePosition / 5;

        return(GeneticSettings.normalizeFitness(f1 + f2));
    }
Пример #5
0
        public SettingsGUI(GeneticSettings geneticSettings, NetworkSettings networkSettings, SnakeSettings snakeSettings)
        {
            this.geneticSettings = geneticSettings;
            this.networkSettings = networkSettings;
            this.snakeSettings   = snakeSettings;

            InitializeComponent();
        }
Пример #6
0
 /// <summary>
 /// Kill the individual
 /// </summary>
 /// <param name="fullFitness">indicates if the drone died for natural death or not</param>
 public void die(bool fullFitness)
 {
     if (GeneticSettings.hasToBeSaved(id) && fullFitness)
     {
         ((GAmanager)father).addDataToDs(new float[] { getAge(), fitness() });
     }
     Destroy(spawnedWaypoint);
     Destroy(this.gameObject);
 }
Пример #7
0
        private void RefreshGenetic(string name, int index, GeneticSettings settings)
        {
            AlgorithmOptionGenetic alg = new AlgorithmOptionGenetic(name, index, ConvertToViewModelSettings(settings));

            alg.Changed += new EventHandler <AlgorithmOptionChangedEventArgs>(AlgorithmOption_Changed);
            AlgorithmOptions.Add(alg);
            AlgorithmElements.Add(alg);

            UpdateGeneticSettings(alg.Index);
        }
Пример #8
0
        public SettingsGUI(SnakeAISettings snakeAISettings)
        {
            this.snakeAISettings = snakeAISettings;

            this.geneticSettings = snakeAISettings.GeneticSettings;
            this.networkSettings = snakeAISettings.NetworkSettings;
            this.snakeSettings   = snakeAISettings.SnakeSettings;

            StartPosition = FormStartPosition.CenterScreen;

            InitializeComponent();
        }
Пример #9
0
        public void CreateGenetic()
        {
            NewModel();

            GeneticSettings settings = _model.CreateGeneticAlgorithm();

            Assert.AreEqual(1, _context.Algorithms.Count());

            _visitorParam = new AlgorithmVisitorParam((x) => Assert.Fail(),
                                                      (x) => Assert.AreEqual(settings, x.Settings));
            _visitorParam.Visit(_context.Algorithms[0].Element);
            Assert.IsTrue(_context.AlgorithmsChanged);
        }
Пример #10
0
 public void TestInitialize()
 {
     _settings = new GeneticSettings
     {
         SelectionRate              = 0.1,
         AbsoluteSelection          = 0.2,
         MutationChance             = 0.3,
         StablePairWeight           = 1,
         GroupHappinessWeight       = 2,
         EgalitarianHappinessWeight = 3,
         Size        = 200,
         Generations = 200
     };
 }
Пример #11
0
        /// <summary>
        /// Show replay of the given agent.
        /// </summary>
        /// <param name="agentToShow"></param>
        /// <param name="geneticSettings"></param>
        public void ViewAgent(Agent agentToShow, GeneticSettings geneticSettings)
        {
            networkSettings = (geneticSettings.FitnessCalculator as SnakeFitnessCalculator).NetworkSettings;
            snakeSettings   = (geneticSettings.FitnessCalculator as SnakeFitnessCalculator).SnakeSettings;
            SnakeFitnessCalculator fitnessCalculator = geneticSettings.FitnessCalculator as SnakeFitnessCalculator;

            FitnessCalculatorRecording recording = fitnessCalculator.RecordCalculation(agentToShow);

            MilisecondsForm milisecondsForm = new MilisecondsForm();

            milisecondsForm.ShowDialog();
            speedMS = milisecondsForm.speedMS;

            ShowPlay(recording);
        }
Пример #12
0
        private GeneticSettings MakeGeneticSettings(NetworkSettings networkSettings, SnakeSettings snakeSettings)
        {
            GeneticSettings geneticSettings = new GeneticSettings(ProgramSettings.POPULATION_SIZE,
                                                                  networkSettings.numberOfWeights,
                                                                  ProgramSettings.SELECTION_SIZE,
                                                                  ProgramSettings.MUTATION_PROBABALITY_AGENT,
                                                                  ProgramSettings.MUTATION_PROBABILITY_GENE,
                                                                  ProgramSettings.RANDOM_GENERATOR,
                                                                  new SnakeFitnessCalculator(networkSettings, snakeSettings),
                                                                  ProgramSettings.MUTATION_METHOD,
                                                                  ProgramSettings.SELECTION_METHOD,
                                                                  ProgramSettings.CROSSOVER_METHOD,
                                                                  ProgramSettings.AGENT_VIEWER,
                                                                  ProgramSettings.TOP_K_AGENTS_COUNT);

            return(geneticSettings);
        }
Пример #13
0
        private void UpdateGeneticAlgorithm(GeneticAlgorithm algorithm, IGeneticSettings settings)
        {
            GeneticSettings newSettings = new GeneticSettings
            {
                SelectionRate              = settings.SelectionRate,
                AbsoluteSelection          = settings.AbsoluteSelection,
                MutationChance             = settings.MutationChance,
                StablePairWeight           = settings.StablePairWeight,
                GroupHappinessWeight       = settings.GroupHappinessWeight,
                EgalitarianHappinessWeight = settings.EgalitarianHappinessWeight,
                Size        = settings.Size,
                Generations = settings.Generations
            };

            algorithm.Settings = newSettings;

            settings = newSettings;
            Context.AlgorithmsChanged = true;
        }
Пример #14
0
        public GeneticSettings CreateGeneticAlgorithm()
        {
            GeneticSettings settings = new GeneticSettings
            {
                SelectionRate              = 0.2,
                AbsoluteSelection          = 0.01,
                MutationChance             = 0.05,
                StablePairWeight           = 1,
                GroupHappinessWeight       = 0,
                EgalitarianHappinessWeight = 0,
                Size        = 200,
                Generations = 200
            };
            GeneticAlgorithm algorithm = new GeneticAlgorithm(Context.StableMarriage, settings);

            Context.Algorithms.Add(new AlgorithmData
            {
                Name      = "Genetikus Algoritmus",
                Algorithm = algorithm,
                Element   = algorithm
            });
            Context.AlgorithmsChanged = true;
            return(settings);
        }
Пример #15
0
 public void UpdateGeneticSettings(GeneticSettings geneticSettings)
 {
     GeneticSettings = geneticSettings;
 }
Пример #16
0
 public SnakeAISettings(GeneticSettings geneticSettings, NetworkSettings networkSettings, SnakeSettings snakeSettings)
 {
     GeneticSettings = geneticSettings;
     NetworkSettings = networkSettings;
     SnakeSettings   = snakeSettings;
 }
Пример #17
0
 public ListedGeneticSettingsGUI(GeneticSettings geneticSettings, bool canEdit) : base(canEdit)
 {
     this.geneticSettings = geneticSettings;
     CreateItems();
     AddSettingItems();
 }
Пример #18
0
 /// <summary>
 /// Creates a new genetic algorithm to solve a stable marriage problem.
 /// </summary>
 /// <param name="stableMarriage">The stable marriage to be solved</param>
 /// <param name="settings">The settings of the genetic algorithm</param>
 public GeneticAlgorithmBase(StableMarriage stableMarriage, GeneticSettings settings) : base(stableMarriage)
 {
     Settings = settings;
     _random  = new Random();
 }
Пример #19
0
 public GeneticAlgorithm(StableMarriage stableMarriage, GeneticSettings settings) : base(stableMarriage, settings)
 {
 }