public static Tour GetFourOptSwap(Tour tourToChange, int a, int b, int c, int d) { Tour returnTour = new Tour(); List <int> LIST_A = new List <int>(); List <int> LIST_B = new List <int>(); List <int> LIST_C = new List <int>(); List <int> LIST_D = new List <int>(); //ADDING TO LIST for (int i = 0; i <= a; i++) { LIST_A.Add(tourToChange.Cities[i]); } for (int i = a + 1; i <= b; i++) { LIST_B.Add(tourToChange.Cities[i]); } for (int i = b + 1; i <= c; i++) { LIST_C.Add(tourToChange.Cities[i]); } for (int i = c + 1; i <= tourToChange.Size - 2; i++) { LIST_D.Add(tourToChange.Cities[i]); } //ADDING TO TOUR IN FORMAT ADCB foreach (int city in LIST_A) { returnTour.AddNewCity(city); } foreach (int city in LIST_D) { returnTour.AddNewCity(city); } foreach (int city in LIST_C) { returnTour.AddNewCity(city); } foreach (int city in LIST_B) { returnTour.AddNewCity(city); } returnTour.AddNewCity(returnTour.Cities[0]); //Console.WriteLine("TC: " + tourToChange.ToString()); //Console.WriteLine("AB: " + a + "::" + b); //Console.WriteLine("RT: " + returnTour.ToString() + "\n"); return(returnTour); }
public static Tour GetTwoOptSwap(Tour tourToChange, int a, int b) { //Console.WriteLine("2C: " + tourToChange.ToString()); Tour returnTour = new Tour(); List <int> tempList = new List <int>(); for (int i = 0; i <= a - 1; i++) { returnTour.AddNewCity(tourToChange.Cities[i]); } for (int i = a; i <= b; i++) { tempList.Add(tourToChange.Cities[i]); } tempList.Reverse(); foreach (int city in tempList) { returnTour.AddNewCity(city); } for (int i = b + 1; i < tourToChange.Size - 1; i++) { returnTour.AddNewCity(tourToChange.Cities[i]); } returnTour.AddNewCity(returnTour.Cities[0]); if (returnTour.Size > tourToChange.Size || !returnTour.CheckStartEnd()) { Console.WriteLine(tourToChange.ToString() + " NOPE " + returnTour.ToString() + "AB:" + a + ":" + b + "\n"); } //Console.WriteLine(tourToChange.ToString()); //Console.WriteLine("AB: " + a + "::" + b); //Console.WriteLine(returnTour.ToString()); //totalSwapedTours.Add(returnTour); return(returnTour); }