Esempio n. 1
0
        public override IChromosome CreateNew()
        {
            MemberShortArrayChromosome res = new MemberShortArrayChromosome(this);

            res.Generate();
            return(res);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="shortsCount"></param>
        /// <param name="MaxShortVals"></param>
        /// <param name="doublesCount"></param>
        /// <param name="MaxDoubleVals"></param>
        /// <param name="doublesValueCount">
        /// tells how many different double values may be generated (e.g. 2 means only 0 and max value are possible)
        /// </param>
        /// <param name="misc"></param>
        public ACompositeChromosome(int shortsCount, ushort[] MaxShortVals,
                                    int doublesCount, double[] MaxDoubleVals, int doublesValueCount,
                                    double ValueMutationProb,
                                    List <IChromosome> misc = null)
        {
            this.ShortsCount       = shortsCount;
            this.DoublesCount      = doublesCount;
            this.valueMutationProb = ValueMutationProb;

            if (shortsCount > 0)
            {
                shorts = new MemberShortArrayChromosome(shortsCount, ushort.MaxValue, valueMutationProb);
            }
            else
            {
                shorts = null;
            }

            this.maxShortVals = MaxShortVals;//new ushort[shortsCount];
            //MaxShortVals.CopyTo(this.maxShortVals,0);

            if (doublesCount > 0)
            {
                doubles = new MemberFractionArrayChsromosome(doublesCount, doublesValueCount, valueMutationProb);
            }
            else
            {
                doubles = null;
            }
            this.maxDoubleVals = MaxDoubleVals;//new double[doublesCount];
            //MaxDoubleVals.CopyTo(this.maxDoubleVals,0);

            ensureLegalVals();

            if (InitialValuesMeanFactor != -1)
            {
                double factor = 2 * InitialValuesMeanFactor; // after normal value generation, the mean is already 0.5
                if (shorts != null)
                {
                    for (int i = 0; i < shorts.count(); ++i)
                    {
                        shorts[i] = (ushort)(shorts[i] * factor);
                    }
                }
                if (doubles != null)
                {
                    for (int i = 0; i < doubles.count(); ++i)
                    {
                        doubles[i] = doubles[i] * factor;
                    }
                }
            }

            miscChromosomes = misc;

            NormalDistShortsMutation  = true;
            NormalDistDoublesMutation = true;
        }
Esempio n. 3
0
        /// <summary>
        /// clones src chromosome (and clone()s inner misc chromosomes)
        /// </summary>
        /// <param name="src"></param>
        public ACompositeChromosome(ACompositeChromosome src)
        {
            if (src.shorts != null)
            {
                shorts = new MemberShortArrayChromosome(src.shorts);
            }
            else
            {
                shorts = null;
            }

            if (src.doubles != null)
            {
                doubles = new MemberFractionArrayChsromosome(src.doubles);
            }
            else
            {
                doubles = null;
            }

            maxDoubleVals = src.maxDoubleVals;
            maxShortVals  = src.maxShortVals;
            ShortsCount   = src.ShortsCount;
            DoublesCount  = src.DoublesCount;
            Fitness       = src.Fitness;

            if (src.miscChromosomes != null)
            {
                miscChromosomes = new List <IChromosome>(src.miscChromosomes.Count);
                foreach (IChromosome c in src.miscChromosomes)
                {
                    miscChromosomes.Add(c.Clone());
                }
            }
            else
            {
                miscChromosomes = null;
            }
        }
Esempio n. 4
0
 public MemberShortArrayChromosome(MemberShortArrayChromosome src)
     : base(src)
 {
 }