Пример #1
0
        /// <summary>
        /// Creates a copy of this trade system.
        /// </summary>
        /// <returns>A copy of this trade system.</returns>
        public TradeSystem Clone()
        {
            TradeSystem clone = new TradeSystem();

            clone.BuyCondition = DeepCopy.getDeepCopy(this.BuyCondition);
            return(clone);
        }
Пример #2
0
        /// <summary>
        /// Run the genetic algorithm.
        /// </summary>
        /// <param name="worker">The background worker object.</param>
        /// <param name="e">Do work event args.</param>
        public void Run(BackgroundWorker worker, DoWorkEventArgs e)
        {
            fitnessAlgorithm.SetFitness(chromosomes);
            Dictionary <string, double> fitnessResult         = fitnessAlgorithm.getFitness();
            IEnumerable <KeyValuePair <string, double> > temp = fitnessResult.OrderByDescending(d => d.Value);

            chromosomes    = chromosomes.OrderByDescending(d => d.Capital).ToArray();
            bestChromosome = DeepCopy.getDeepCopy(chromosomes[0]);
            chromosomes    = breedingAlgorithm.Breed(chromosomes);
            mutatingAlgorithm.Mutate(ref chromosomes);
            for (int j = 0; j < chromosomes.Count(); j++)
            {
                chromosomes[j].newID();
            }
        }
Пример #3
0
        /// <summary>
        /// Deep clone the object by creating new objects all the way down.
        /// </summary>
        /// <returns>A new object with a different reference and same data.</returns>
        internal TradeCondition Clone()
        {
            TradeCondition tc = new TradeCondition();

            for (int i = 0; i < this.TradeRules.Count; i++)
            {
                TradeCondition temp = new TradeCondition();
                temp.TradeRules.Add(this.TradeRules[0]);
                temp.TradeRules.ElementAt(0).IndicatorName1 = this.TradeRules.ElementAt(i).IndicatorName1;
                temp.TradeRules.ElementAt(0).IndicatorName2 = this.TradeRules.ElementAt(i).IndicatorName2;
                temp.TradeRules.ElementAt(0).CompareType    = this.TradeRules.ElementAt(i).CompareType;

                tc.TradeRules.Add(temp.TradeRules[0]);
            }
            for (int i = 0; i < this.RuleJoinTypes.Count; i++)
            {
                tc.RuleJoinTypes.Add(DeepCopy.getDeepCopy(this.RuleJoinTypes.ElementAt(i)));
            }
            //tc.RuleJoinTypes = this.RuleJoinTypes;
            //tc.TradeRules = this.TradeRules;
            return(tc);
        }