Пример #1
0
        private IChromosome GenerateGAAlocChromosome()
        {
            var ch = GAVChromosome.NewChromosome();

            ch.Generate();
            return(ch);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="factory"></param>
        /// <param name="curLine"></param>
        /// <param name="typeChromosome"></param>
        /// <returns></returns>
        private int MainPopulationFromString(string[] lines, GPFactory factory, int curLine)
        {
            curLine++;
            //Line 8: populationSize; maxFitness; BestChromosome
            if (lines.Length <= curLine)
            {
                //MessageBox.Show("Fie is corrupt!");
                return(-1);
            }
            var str = lines[curLine].Split(';');


            if (lines[curLine] == "-" || lines[curLine] == "-\r")
            {
                return(curLine += 2);
            }

            if (_GPModel == GPModelType.TSP)
            {
                PrepareTSP(false);
            }
            else if (_GPModel == GPModelType.AP)
            {
                PrepareALOC(false);
            }
            else if (_GPModel == GPModelType.TP)
            {
                PrepareTrans(false);
            }
            else
            {
                PrepareGP(false);
            }


            int popSize = 0;

            if (!int.TryParse(str[0], out popSize))
            {
                popSize = 0;
            }

            List <IChromosome> chromosomes = new List <IChromosome>();

            for (int i = 0; i < popSize; i++)
            {
                IChromosome ch = null;
                if (_GPModel == GPModelType.TSP || _GPModel == GPModelType.AP)
                {
                    ch = GAVChromosome.CreateFromString(lines[i + curLine + 1]);
                }
                else if (_GPModel == GPModelType.TP)
                {
                    ch = GAMChromosome.CreateFromString(lines[i + curLine + 1]);
                }
                else
                {
                    ch = GPChromosome.CreateFromString(lines[i + curLine + 1]);
                }
                chromosomes.Add(ch);
            }

            factory.SetChromosomes(chromosomes);

            factory.CalculatePopulation();
            return(popSize + 7);
        }