Advertisement
Guest User

Untitled

a guest
May 24th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. public void RandomRoute(int initpopulation)
  2.         {
  3.             population = new int[initpopulation, 7];
  4.             for (int i = 0; i < initpopulation; i++)
  5.             {
  6.                 route = 11111;
  7.                 citycount = 0;
  8.                 Random rand = new Random();
  9.                 while (route != 0) // all 5 cities
  10.                 {
  11.                     temp = rand.Next(1, 6);
  12.                     if (route % Convert.ToInt32(Math.Pow(10, temp)) > route % Convert.ToInt32(Math.Pow(10, temp - 1)))
  13.                     {
  14.                         route = route - Convert.ToInt32(Math.Pow(10, (temp - 1)));
  15.                         population[i, citycount] = Convert.ToInt32(Math.Pow(10, (temp - 1)));
  16.                         citycount++;
  17.                     }
  18.                 }
  19.                 population[i, citycount] = population[i, 0];
  20.                 population[i, citycount + 1] = CalculateCost(i);
  21.             }
  22.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement