示例#1
0
        public IList<GeneScore> Run(IList<BaseChromosomeType> chromosomeTypes, OptimiserParameters parameters)
        {
            var allScores = new List<GeneScore>();

            var exiting = false;
            var iterationCount = 0;
            var totalIterations = parameters.MaximumGenerations * parameters.PopulationSize;

            var geneValidator = GetGeneValidator(chromosomeTypes, parameters.ParameterConditions);

            var evolver = new Evolver(chromosomeTypes, parameters.Seed,
                                      new CompositeGeneValidator(geneValidator, new OnceOnlyGeneValidator()));

            evolver.ReportNoProgress += ReportNoProgress;
            evolver.ReportNoProgress += delegate(object sender, CancelEventArgs args) { exiting |= args.Cancel; };

            _fitnessEvaluator.Initialise(parameters);

            IList<Gene> population = evolver.GetInitialPopulation(parameters.PopulationSize);

            for (var generation = 0; generation < parameters.MaximumGenerations; generation++)
            {
                var scoresThisGeneration = new List<GeneScore>();

                foreach (var gene in population)
                {
                    var score = _fitnessEvaluator.Evaluate(gene);
                    scoresThisGeneration.Add(score);

                    iterationCount++;

                    if (OnIterationComplete(score, iterationCount, totalIterations - iterationCount))
                    {
                        exiting = true;
                        break;
                    }
                }

                scoresThisGeneration.Sort();

                if (exiting)
                {
                    break;
                }

                population = evolver.GetNextGeneration(parameters.ReproductionRate, parameters.MutationRate,
                                                       scoresThisGeneration.ConvertAll(score => score.Gene));

                allScores.AddRange(scoresThisGeneration);

                OnGenerationComplete(generation, scoresThisGeneration);
            }

            allScores.Sort();

            OnComplete();

            return allScores;
        }
示例#2
0
        public IList <GeneScore> Run(IList <BaseChromosomeType> chromosomeTypes, OptimiserParameters parameters)
        {
            var allScores = new List <GeneScore>();

            var exiting         = false;
            var iterationCount  = 0;
            var totalIterations = parameters.MaximumGenerations * parameters.PopulationSize;

            var geneValidator = GetGeneValidator(chromosomeTypes, parameters.ParameterConditions);

            var evolver = new Evolver(chromosomeTypes, parameters.Seed,
                                      new CompositeGeneValidator(geneValidator, new OnceOnlyGeneValidator()));

            evolver.ReportNoProgress += ReportNoProgress;
            evolver.ReportNoProgress += delegate(object sender, CancelEventArgs args) { exiting |= args.Cancel; };

            _fitnessEvaluator.Initialise(parameters);

            IList <Gene> population = evolver.GetInitialPopulation(parameters.PopulationSize);

            for (var generation = 0; generation < parameters.MaximumGenerations; generation++)
            {
                var scoresThisGeneration = new List <GeneScore>();

                foreach (var gene in population)
                {
                    var score = _fitnessEvaluator.Evaluate(gene);
                    scoresThisGeneration.Add(score);

                    iterationCount++;

                    if (OnIterationComplete(score, iterationCount, totalIterations - iterationCount))
                    {
                        exiting = true;
                        break;
                    }
                }

                scoresThisGeneration.Sort();

                if (exiting)
                {
                    break;
                }

                population = evolver.GetNextGeneration(parameters.ReproductionRate, parameters.MutationRate,
                                                       scoresThisGeneration.ConvertAll(score => score.Gene));

                allScores.AddRange(scoresThisGeneration);

                OnGenerationComplete(generation, scoresThisGeneration);
            }

            allScores.Sort();

            OnComplete();

            return(allScores);
        }
示例#3
0
        public static void Initialise(OptimiserParameters optimiserParameters, StrategyBase strategy)
        {
            _minimumTrades = optimiserParameters.MinimumTrades;
            _maximumTrades = optimiserParameters.MaximumTrades;

            _optimisationType =
                (OptimizationType) Activator.CreateInstance(Type.GetType(optimiserParameters.FitnessFunctionType));
            _optimisationType.Strategy = strategy;
        }
示例#4
0
        public void Initialise(OptimiserParameters parameters, IList<BaseChromosomeType> chromosomeTypes)
        {
            _validatorFactory = new GeneValidatorFactory(chromosomeTypes);

            generationsSpin.Value = parameters.MaximumGenerations;
            populationSizeSpin.Value = parameters.PopulationSize;
            reproductionPercentSpin.Value = (decimal) (parameters.ReproductionRate * 100);
            mutationRateSpin.Value = (decimal) (parameters.MutationRate * 100);

            screenThresholdSpin.Value = (decimal) parameters.ScreeningThreshold;
            saveLogCheckbox.Checked = parameters.ExportGenes;

            var wrappers = GetOptimisationTypeWrappers();

            fitnessFunctionComboBox.DisplayMember = "Name";
            fitnessFunctionComboBox.ValueMember = "Type";
            fitnessFunctionComboBox.DataSource = wrappers;

            try
            {
                foreach (var wrapper in wrappers)
                {
                    if (wrapper.Type.AssemblyQualifiedName == parameters.FitnessFunctionType)
                    {
                        fitnessFunctionComboBox.SelectedItem = wrapper;
                        break;
                    }
                }
            }
            catch
            {
            }

            minimumTradesSpin.Value = parameters.MinimumTrades;

            strategyParameterConditionsGrid.Rows.Clear();

            foreach (var condition in parameters.ParameterConditions)
            {
                if (IsConditionValid(condition))
                {
                    var row = strategyParameterConditionsGrid.Rows[strategyParameterConditionsGrid.Rows.Add()];
                    row.SetValues(condition);
                }
            }
        }
示例#5
0
 public void Initialise(OptimiserParameters parameters)
 {
     FitnessFunctionWrapper.Initialise(parameters, _strategy);
 }
示例#6
0
文件: MoGoNT.cs 项目: redrhino/MoGo
 static MoGoNT()
 {
     __lastParameters = GetStartingParameters();
 }
示例#7
0
文件: MoGoNT.cs 项目: redrhino/MoGo
        private void SaveParameters(OptimiserParameters parameters)
        {
            try
            {
                var parametersSerialiser = new XmlSerializer(typeof (OptimiserParameters));

                using (var xmlTextWriter = new XmlTextWriter(ParametersFilename, Encoding.ASCII))
                {
                    xmlTextWriter.Formatting = Formatting.Indented;
                    parametersSerialiser.Serialize(xmlTextWriter, parameters);
                }
            }
            catch
            {
            }
        }
示例#8
0
文件: MoGoNT.cs 项目: redrhino/MoGo
        private OptimiserParameters GetParameters(IList<BaseChromosomeType> chromosomeTypes)
        {
            _parametersForm = new ParametersForm();
            _parametersForm.Initialise(__lastParameters, chromosomeTypes);

            OptimiserParameters parameters = null;

            _parametersForm.ParametersSet +=
                delegate(object sender, ParameterEventArgs args) { parameters = args.Parameters; };

            _parametersForm.ShowDialog();

            //while (parameters == null)
            //{
            //    Application.DoEvents();
            //}

            __lastParameters = parameters;

            SaveParameters(parameters);

            return parameters;
        }
示例#9
0
文件: MoGoNT.cs 项目: redrhino/MoGo
        private static OptimiserParameters GetStartingParameters()
        {
            OptimiserParameters parameters = null;

            try
            {
                if (File.Exists(ParametersFilename))
                {
                    var parametersSerialiser = new XmlSerializer(typeof (OptimiserParameters));

                    using (var stream = File.OpenRead(ParametersFilename))
                    {
                        parameters = (OptimiserParameters) parametersSerialiser.Deserialize(stream);
                    }
                }
            }
            catch
            {
            }

            if (parameters == null)
            {
                parameters = new OptimiserParameters(5, 256, 0.1, 0.05, 0, false, null, string.Empty, 50, 1000,
                                                     new List<string>());
            }

            return parameters;
        }
示例#10
0
 public ParameterEventArgs(OptimiserParameters parameters)
 {
     _parameters = parameters;
 }