static bool AreaCheck(CityInfo cityOne, CityInfo cityTwo, CityInfo cityThree, CityInfo cityFour) { float areaOne, areaTwo; areaOne = 0.5f * DistanceHelper.DistanceBetweenTwoPoints(cityOne, cityThree) * (DistanceHelper.DistanceFromPointToLine(cityOne, cityThree, cityTwo) + DistanceHelper.DistanceFromPointToLine(cityOne, cityThree, cityFour)); areaTwo = 0.5f * DistanceHelper.DistanceBetweenTwoPoints(cityTwo, cityFour) * (DistanceHelper.DistanceFromPointToLine(cityTwo, cityFour, cityOne) + DistanceHelper.DistanceFromPointToLine(cityTwo, cityFour, cityThree)); return(areaOne == areaTwo ? true : false); }
//the second one is order crossover operator static void CrossoverOperation2(List <CityInfo> parentOne, List <CityInfo> parentTwo, out List <CityInfo> childOne, out List <CityInfo> childTwo) { CityInfo[] tempOne = new CityInfo[parentOne.Count]; CityInfo[] tempTwo = new CityInfo[parentTwo.Count]; int cutPointOne, cutPointTwo; cutPointOne = (int)parentOne.Count / 3; cutPointTwo = (int)2 * parentOne.Count / 3; List <CityInfo> centerOne = parentOne.GetRange(cutPointOne, cutPointTwo - cutPointOne); List <CityInfo> centerTwo = parentTwo.GetRange(cutPointOne, cutPointTwo - cutPointOne); for (int i = cutPointOne; i < cutPointTwo; i++) { tempOne[i] = parentOne[i]; tempTwo[i] = parentTwo[i]; } #region Child One int counter = 0; int index = cutPointTwo; for (int i = index; counter < parentTwo.Count - (cutPointTwo - cutPointOne); i++) { if (i == parentOne.Count) { i = 0; } if (tempOne.Contains(parentTwo[i])) { continue; } else { tempOne[index] = parentTwo[i]; index++; counter++; } if (index == parentTwo.Count) { index = 0; } } #endregion #region Child Two counter = 0; index = cutPointTwo; for (int i = index; counter < parentTwo.Count - (cutPointTwo - cutPointOne); i++) { if (i == parentTwo.Count) { i = 0; } if (tempTwo.Contains(parentOne[i])) { continue; } else { tempTwo[index] = parentOne[i]; index++; counter++; } if (index == parentOne.Count) { index = 0; } } #endregion childOne = new List <CityInfo>(tempOne); childTwo = new List <CityInfo>(tempTwo); }