コード例 #1
0
        /**
         * Place the cities in random locations.
         */
        private void initCities()
        {
            cities = new City[CITIES];
            for (int i = 0; i < cities.Length; i++)
            {
                int xPos = (int)(ThreadSafeRandom.NextDouble() * MAP_SIZE);
                int yPos = (int)(ThreadSafeRandom.NextDouble() * MAP_SIZE);

                cities[i] = new City(xPos, yPos);
            }
        }
コード例 #2
0
ファイル: SolveTSP.cs プロジェクト: OperatorOverload/encog-cs
        /// <summary>
        /// Place the cities in random locations.
        /// </summary>
        private void InitCities()
        {
            Random rand = new Random();

            cities = new City[CITIES];
            for (int i = 0; i < cities.Length; i++)
            {
                int xPos = (int)(rand.NextDouble() * MAP_SIZE);
                int yPos = (int)(rand.NextDouble() * MAP_SIZE);

                cities[i] = new City(xPos, yPos);
            }
        }
コード例 #3
0
        public TSPGenome(GeneticAlgorithm owner, City[] cities)
        {

            int[] organism = new int[cities.Length];
            bool[] taken = new bool[cities.Length];

            for (int i = 0; i < organism.Length; i++)
            {
                taken[i] = false;
            }
            for (int i = 0; i < organism.Length - 1; i++)
            {
                int icandidate;
                do
                {
                    icandidate = (int)(ThreadSafeRandom.NextDouble() * organism.Length);
                } while (taken[icandidate]);
                organism[i] = icandidate;
                taken[icandidate] = true;
                if (i == organism.Length - 2)
                {
                    icandidate = 0;
                    while (taken[icandidate])
                    {
                        icandidate++;
                    }
                    organism[i + 1] = icandidate;
                }
            }

            this.pathChromosome = new Chromosome();
            this.Chromosomes.Add(this.pathChromosome);

            for (int i = 0; i < organism.Length; i++)
            {
                IntegerGene gene = new IntegerGene();
                gene.Value = organism[i];
                this.pathChromosome.Genes.Add(gene);
            }
            Organism = organism;

            Encode();

        }
コード例 #4
0
ファイル: City.cs プロジェクト: OperatorOverload/encog-cs
 /// <summary>
 /// Returns how close the city is to another city.
 /// </summary>
 /// <param name="cother">The other city.</param>
 /// <returns>A distance.</returns>
 public int Proximity(City cother)
 {
     return Proximity(cother.X, cother.Y);
 }
コード例 #5
0
ファイル: TSPScore.cs プロジェクト: OperatorOverload/encog-cs
 public TSPScore(City[] cities)
 {
     this.cities = cities;
 }