Exemplo n.º 1
0
        public void StartEvolution()
        {
            //Load and Scale Feature
            try {
                switch (featurepath)
                {
                case COMMAND_NORMAL_RANDOM_FUNCTION:
                    _model.Setting.Mean = feature_random_function_values[0];
                    _model.Setting.StandardDeviation = feature_random_function_values[1];
                    _model.CreateNormalDist(1, Distribution.DistributionType.Feature);
                    break;

                case COMMAND_UNIFORM_RANDOM_FUNCTION:
                    _model.Setting.UnifMin = feature_random_function_values[0];
                    _model.Setting.UnifMax = feature_random_function_values[1];
                    _model.CreateUnifDist(1, Distribution.DistributionType.Feature);
                    break;

                case COMMAND_EXP_RANDOM_FUNCTION:
                    _model.Setting.ExpLambda = feature_random_function_values[0];
                    _model.CreateExpDist(1, Distribution.DistributionType.Feature);
                    break;

                default:
                    try
                    {
                        _model.DStore.SelectedFeatureDistribution = CreateDistFromFile(featurepath, "feature");
                    }
                    catch (Exception e) { Console.WriteLine(e); }
                    if (_model.Setting.SelectedFeature == 0)
                    {
                        _model.CreateNormalDist(2, Distribution.DistributionType.Feature);
                    }
                    else
                    {
                        _model.CreateUnifDist(2, Distribution.DistributionType.Feature);
                    }
                    Console.WriteLine("Selected Feature");
                    _model.BestDistribution(_model.DStore.SelectedFeatureDistribution, _model.Setting.NumberOfFeatures, 100, 2);
                    break;
                }
                _model.DStore.SelectedFeatureDistribution = _model.DStore.ScaledFeatureDistributions[_model.Setting.SelectedFeature];
            }
            catch (Exception e) { Console.WriteLine("Feature Scale failed"); }

            //Load and Scale Interaction
            try
            {
                switch (interactionpath)
                {
                case COMMAND_NORMAL_RANDOM_FUNCTION:
                    _model.Setting.Mean = interaction_random_function_values[0];
                    _model.Setting.StandardDeviation = interaction_random_function_values[1];
                    _model.CreateNormalDist(1, Distribution.DistributionType.Interaction);
                    break;

                case COMMAND_UNIFORM_RANDOM_FUNCTION:
                    _model.Setting.UnifMin = interaction_random_function_values[0];
                    _model.Setting.UnifMax = interaction_random_function_values[1];
                    _model.CreateUnifDist(1, Distribution.DistributionType.Interaction);
                    break;

                case COMMAND_EXP_RANDOM_FUNCTION:
                    _model.Setting.ExpLambda = feature_random_function_values[0];
                    _model.CreateExpDist(1, Distribution.DistributionType.Interaction);
                    break;

                default:
                    _model.DStore.SelectedInteractionDistribution = CreateDistFromFile(interactionpath, "interaction");
                    if (_model.Setting.SelectedInteraction == 0)
                    {
                        _model.CreateNormalDist(2, Distribution.DistributionType.Interaction);
                    }
                    else
                    {
                        _model.CreateUnifDist(2, Distribution.DistributionType.Interaction);
                    }
                    Console.WriteLine("Selected Interaction");
                    _model.BestDistribution(_model.DStore.SelectedInteractionDistribution, _model.Setting.NumberOfInteractions, 100, 2);
                    break;
                }
                _model.DStore.SelectedInteractionDistribution = _model.DStore.ScaledInteractionDistributions[_model.Setting.SelectedInteraction];
            }
            catch (Exception e) { Console.WriteLine("Interaction Scale failed"); }
            //Load Variant
            _model.DStore.SelectedTargetDistribution = CreateDistFromFile(variantpath, "variant");
            Console.WriteLine("Selected Variant");

            //Evolution
            Console.WriteLine("Start Evolution");
            try
            {
                //System.Windows.Forms.Application.DoEvents();
                backgroundWorker1.RunWorkerAsync(_model);
            }
            catch (Exception e) { Console.WriteLine("Evolution failed"); }

            while (!write_finished)
            {
                //Wait half a second.
                System.Threading.Thread.Sleep(500);
            }
        }