Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext  = this;
            SelectedType = SelectionMethods.First();
            QueueTask    = () =>
            {
                while (Queue.Count != complited)
                {
                    Fitness    fitnessFunc = new Fitness(map.Count, false);
                    Population population  = new Population(Queue[complited].PopulationCount,
                                                            new Chromosome(Cities, r, (ushort)r.Next(CitiesCount), true, (ushort)ConnectionsCount, Queue[complited].CrossoverMix, Queue[complited].KillBothParents),
                                                            fitnessFunc,
                                                            Queue[complited].SelectionMethod)
                    {
                        CrossoverRate          = Queue[complited].CrossOver,
                        MutationRate           = Queue[complited].Mutation,
                        RandomSelectionPortion = Queue[complited].RandomSelectionPortion,
                        AutoShuffling          = Queue[complited].AutoShufling
                    };

                    int  i          = 0;
                    bool needToStop = false;
                    while (!needToStop)
                    {
                        population.RunEpoch();
                        Queue[complited].Results.Add(new Result(i,
                                                                (population.BestChromosome as Chromosome).Path,
                                                                population.BestChromosome.Fitness,
                                                                population.FitnessAvg,
                                                                fitnessFunc.GetLength(population.BestChromosome),
                                                                (population.BestChromosome as Chromosome).Path.Count()
                                                                ));
                        System.Diagnostics.Debug.WriteLine("Best path: " + String.Join(",", (population.BestChromosome as Chromosome).Path) + $"\nBest fit: {population.BestChromosome.Fitness}");
                        System.Diagnostics.Debug.WriteLine("Avarge fit: " + population.FitnessAvg);
                        System.Diagnostics.Debug.WriteLine("Best length: " + fitnessFunc.GetLength(population.BestChromosome));
                        System.Diagnostics.Debug.WriteLine("Edges visited: " + (population.BestChromosome as Chromosome).Path.Count() + $"\nGeneartion: {i}");

                        if (i > Queue[complited].GenerationCount)
                        {
                            break;
                        }
                        i++;
                    }
                    Queue[complited].Name += ": " + (int)fitnessFunc.GetLength(population.BestChromosome);
                    complited++;
                }
            };
        }
Ejemplo n.º 2
0
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            lastmethod = Aggregator.SelectionMethod;
            if (lastmethod == SelectionMethods.Single)
            {
                lastmethod = SelectionMethods.Inverse;
            }

            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Single).Subscribe(t => service.IsSingleMode              = t);
            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m != SelectionMethods.Single).Subscribe(t => service.IsGroupMode               = t);
            Aggregator.WhenAnyValue(v => v.SelectorType).Select(m => m == SelectorTypes.stPoint).Subscribe(t => service.IsPointSelector                = t);
            Aggregator.WhenAnyValue(v => v.SelectorType).Select(m => m == SelectorTypes.stRectangle).Subscribe(t => service.IsRectSelector             = t);
            Aggregator.WhenAnyValue(v => v.SelectorType).Select(m => m == SelectorTypes.stCircle).Subscribe(t => service.IsCircleSelector              = t);
            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Inverse).Subscribe(t => service.SelectionMethodInverse   = t);
            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Select).Subscribe(t => service.SelectionMethodSelect     = t);
            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Unselect).Subscribe(t => service.SelectionMethodUnselect = t);

            service.OnStateChanged += (sender, args) => InvokeAsync(() => StateHasChanged());

            switch (ViewModel)
            {
            case PostProcessorComponent pst:
                pst.Problem.CurrentCatalog?.Catalog.MatCat.Enumerate().Select(c => c.Key).AsObservableChangeSet().Bind(out MaterialNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                pst.Problem.CurrentCatalog?.Catalog.BoundCat.Enumerate().Select(c => c.Key).AsObservableChangeSet().Bind(out BoundaryNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                break;

            case ProcessorManagerComponent pmc:
                pmc.WhenAnyValue(c => c.ScreenProblem.CurrentCatalog !.Catalog)
                .Subscribe(c =>
                {
                    c.MatCat.Enumerate().Select(cc => cc.Key).AsObservableChangeSet().Bind(out MaterialNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                    c.BoundCat.Enumerate().Select(cc => cc.Key).AsObservableChangeSet().Bind(out BoundaryNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                });
                break;

#if !LABVERSION
            case TelPrep3DComponent tp3d:
                tp3d.Catalog.MaterialsConnect().Transform(t => t.DisplayName).Bind(out MaterialNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                tp3d.Catalog.BoundariesConnect().Transform(t => t.DisplayName).Bind(out BoundaryNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                break;
#endif
            case TelbaseComponent tp2d:
                tp2d.Catalog.MaterialsConnect().Transform(t => t.DisplayName).Bind(out MaterialNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                tp2d.Catalog.BoundariesConnect().Transform(t => t.DisplayName).Bind(out BoundaryNames).Subscribe(_ => InvokeAsync(() => StateHasChanged()));
                break;
            }
        }
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            lastmethod = Aggregator.SelectionMethod;
            if (lastmethod == SelectionMethods.Single)
            {
                lastmethod = SelectionMethods.Inverse;
            }

            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Single).Subscribe(t => service.IsSingleMode = t);
            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m != SelectionMethods.Single).Subscribe(t => service.IsGroupMode  = t);

            service.OnStateChanged += (sender, args) => InvokeAsync(() => StateHasChanged());
        }
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            lastmethod = Aggregator.SelectionMethod;
            if (lastmethod == SelectionMethods.Single)
            {
                lastmethod = SelectionMethods.Inverse;
            }

            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Inverse).Subscribe(t => service.SelectionMethodInverse   = t);
            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Select).Subscribe(t => service.SelectionMethodSelect     = t);
            Aggregator.WhenAnyValue(v => v.SelectionMethod).Select(m => m == SelectionMethods.Unselect).Subscribe(t => service.SelectionMethodUnselect = t);

            service.OnStateChanged += (sender, args) => StateHasChanged();
        }
Ejemplo n.º 5
0
            public Population(int size, Chromosomes.IChromosomeFactory chromosomeFactory, FitnessFunctions.IFitnessFunction fitnessFunction, SelectionMethods.ISelectionMethod selectionMethod)
            {
                this.SetCrossoverProbabilityToDefault();
                this.SetMutationProbabilityToDefault();
                this.SetSelectionRateToDefault();

                this.size = size;
                this.individuals = new Chromosomes.IChromosome[size];
                for (int i = 0; i < size; ++i)
                    this.individuals[i] = chromosomeFactory.GetNewChromosome();
                this.fitnessCalculator = fitnessFunction;
                this.selector = selectionMethod;
                this.fitnesses = new double[this.size];
                for (int i = 0; i < this.size; ++i)
                    this.fitnesses[i] = this.fitnessCalculator.GetFitness(this.individuals[i]);
            }
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            lastmethod = Aggregator.SelectionMethod;
            if (lastmethod == SelectionMethods.Single)
            {
                lastmethod = SelectionMethods.Inverse;
            }

            Aggregator.WhenAnyValue(v => v.SelectorType).Select(m => m == SelectorTypes.stPoint).Subscribe(t => service.IsPointSelector    = t);
            Aggregator.WhenAnyValue(v => v.SelectorType).Select(m => m == SelectorTypes.stRectangle).Subscribe(t => service.IsRectSelector = t);
            Aggregator.WhenAnyValue(v => v.SelectorType).Select(m => m == SelectorTypes.stCircle).Subscribe(t => service.IsCircleSelector  = t);

            service.OnStateChanged += (sender, args) => StateHasChanged();
        }
 public SelectionMethodSection()
 {
     OnSetSelMethod   = TelmaCommandAssistant.Create("OnSetSelMethod", () => { lastmethod = Aggregator.SelectionMethod = SelectionMethods.Select; });
     OnSetUnselMethod = TelmaCommandAssistant.Create("OnSetUnselMethod", () => { lastmethod = Aggregator.SelectionMethod = SelectionMethods.Unselect; });
     OnSetInvMethod   = TelmaCommandAssistant.Create("OnSetInvMethod", () => { lastmethod = Aggregator.SelectionMethod = SelectionMethods.Inverse; });
 }
        public void CreateItems()
        {
            populationSizeControl         = new NumericUpDown();
            populationSizeControl.Maximum = int.MaxValue;
            SettingItemGUI populationSize = new SettingItemGUI("Population size",
                                                               geneticSettings.PopulationSize.ToString(),
                                                               populationSizeControl
                                                               );

            selectionSizeControl         = new NumericUpDown();
            selectionSizeControl.Maximum = populationSizeControl.Value - 1;
            SettingItemGUI selectionSize = new SettingItemGUI("Selection size",
                                                              geneticSettings.SelectionSize.ToString(),
                                                              selectionSizeControl);

            populationSizeControl.ValueChanged += OnPopulationSizeChanged;

            mutationGeneControl               = new NumericUpDown();
            mutationGeneControl.Maximum       = 100;
            mutationGeneControl.DecimalPlaces = 1;
            mutationGeneControl.Increment     = 0.1M;
            SettingItemGUI geneMutation = new SettingItemGUI("Gene mutation chance",
                                                             (geneticSettings.MutationProbabilityGenes * 100).ToString(),
                                                             mutationGeneControl);

            mutationAgentControl               = new NumericUpDown();
            mutationAgentControl.Maximum       = 100;
            mutationAgentControl.DecimalPlaces = 1;
            mutationAgentControl.Increment     = 0.1M;
            SettingItemGUI agentMutation = new SettingItemGUI("Agent mutation chance",
                                                              (geneticSettings.MutationProbabiltyAgents * 100).ToString(),
                                                              mutationAgentControl);

            chromosomeSize = new SettingItemGUI("Chromesome size",
                                                geneticSettings.GeneCount.ToString(),
                                                new TextBox());
            chromosomeSize.EditControl.Enabled = false;

            selectionMethods       = new SelectionMethods();
            selectionMethodControl = new ComboBox();
            selectionMethodControl.DropDownStyle = ComboBoxStyle.DropDownList;
            selectionMethodControl.Items.Add(selectionMethods.TopPerformersSelector);
            selectionMethodControl.Items.Add(selectionMethods.RouletteWheelSelector);
            selectionMethodControl.SelectedItem = selectionMethodControl.Items[0];
            SettingItemGUI selectionMethod = new SettingItemGUI("Selection method",
                                                                geneticSettings.Selector.ToString(),
                                                                selectionMethodControl);

            crossoverMethods       = new CrossoverMethods();
            crossOverMethodControl = new ComboBox();
            crossOverMethodControl.DropDownStyle = ComboBoxStyle.DropDownList;
            crossOverMethodControl.Items.Add(crossoverMethods.OnePointCombineCrossoverRegular);
            crossOverMethodControl.Items.Add(crossoverMethods.OnePointCombinePlusElitismCrossover);
            crossOverMethodControl.SelectedItem = crossOverMethodControl.Items[0];

            SettingItemGUI crossOverMethod = new SettingItemGUI("Crossover method",
                                                                geneticSettings.Crossover.ToString(),
                                                                crossOverMethodControl);

            settingItems.Add(populationSize);
            settingItems.Add(selectionSize);
            settingItems.Add(geneMutation);
            settingItems.Add(agentMutation);
            settingItems.Add(chromosomeSize);
            settingItems.Add(selectionMethod);
            settingItems.Add(crossOverMethod);
        }
Ejemplo n.º 9
0
 private void selectBySelectionMethod(SelectionMethods selectionMethod)
 {
     switch (selectionMethod)
     {
         case SelectionMethods.deterministically : selectDeterministically(); break;
         case SelectionMethods.flatTournament    : selectFlatTournament();    break;
         case SelectionMethods.steppedTournament : selectSteppedTournament(); break;
     }
     parents.Sort(GlobalSettings.qualityComparer);
 }
Ejemplo n.º 10
0
 public SelectionPanel()
 {
     OnSetSingleMode     = TelmaCommandAssistant.Create("OnSetSingleMode", () => { Aggregator.SelectionMethod = SelectionMethods.Single; });
     OnSetGroupMode      = TelmaCommandAssistant.Create("OnSetGroupMode", () => { Aggregator.SelectionMethod = lastmethod; });
     OnSetPointSelector  = TelmaCommandAssistant.Create("OnSetPointSelector", () => { Aggregator.SelectorType = SelectorTypes.stPoint; });
     OnSetRectSelector   = TelmaCommandAssistant.Create("OnSetRectSelector", () => { Aggregator.SelectorType = SelectorTypes.stRectangle; });
     OnSetCircleSelector = TelmaCommandAssistant.Create("OnSetCircleSelector", () => { Aggregator.SelectorType = SelectorTypes.stCircle; });
     OnSetSelMethod      = TelmaCommandAssistant.Create("OnSetSelMethod", () => { lastmethod = Aggregator.SelectionMethod = SelectionMethods.Select; });
     OnSetUnselMethod    = TelmaCommandAssistant.Create("OnSetUnselMethod", () => { lastmethod = Aggregator.SelectionMethod = SelectionMethods.Unselect; });
     OnSetInvMethod      = TelmaCommandAssistant.Create("OnSetInvMethod", () => { lastmethod = Aggregator.SelectionMethod = SelectionMethods.Inverse; });
 }