Exemple #1
0
        public override object Clone()
        {
            var ret = new BooleanChromosome(StrategyType, Parameter, Index);

            ret.InitializeFrom(this);
            return(ret);
        }
Exemple #2
0
        public Chromosomes(StrategyBase strategy, bool flagInitValues)
        {
            parameters = new ParameterCollection();
            if (strategy.OptimizeDataSeries)
            {
                parameters.Add((Parameter)strategy.BarsPeriodParameter.Clone());
            }
            foreach (Parameter tmp in strategy.Parameters)
            {
                parameters.Add((Parameter)tmp.Clone());
            }

            strategyType = strategy.GetType();
            for (int idx = 0; idx < parameters.Count; idx++)
            {
                Parameter parameter     = parameters[idx];
                Type      parameterType = parameter.ParameterType;
                if (parameterType.IsEnum)
                {
                    var enumChromosome = new EnumChromosome(strategyType, parameter, idx);
                    hasBoolOrEnum = true;
                    chromosomes.Add(enumChromosome);
                    if (flagInitValues)
                    {
                        object value = enumChromosome.Get(strategy);
                        if (value != null)
                        {
                            enumChromosome.Add(value);
                        }
                    }
                }
                else
                if (parameterType == typeof(bool))
                {
                    var booleanChromosome = new BooleanChromosome(strategyType, parameter, idx);
                    hasBoolOrEnum = true;
                    chromosomes.Add(booleanChromosome);
                    if (flagInitValues)
                    {
                        booleanChromosome.Add(booleanChromosome.Get(strategy));
                    }
                }
                else
                if (parameterType.IsPrimitive)
                {
                    chromosomes.Add(new PrimitiveChromosome(parameters, idx));
                }
            }
        }