private void Mute(List <Conspecifics> conspecificsList) { List <int> chosen = new List <int>(); for (int i = 0; i < (_populationSize * 0.01); i++) { chosen.Add(_random.Next(conspecificsList.Count - 1)); } foreach (var n in chosen) { List <Place> places = new List <Place>(); places.AddRange(conspecificsList[n].Population); int i = _random.Next(1, places.Count - 2); int j = _random.Next(1, places.Count - 2); var tmp = places[i]; places[i] = places[j]; places[j] = tmp; var path = CreatePath(places); if (!path.Count.Equals(0)) { Conspecifics conspecifics = new Conspecifics(places, path.TotalLength, path.Cost); conspecificsList.Add(conspecifics); } } }
private void Cross(List <Conspecifics> conspecificsList) { Place startPlace = conspecificsList[0].Population[0]; List <int> choosen = new List <int>(); for (int i = 0; i < (conspecificsList.Count * 0.8); i++) { choosen.Add(_random.Next(conspecificsList.Count - 1)); } for (int i = 0; i < choosen.Count - 1; i += 2) { List <Place> places1 = new List <Place>(); places1.AddRange(conspecificsList[choosen[i]].Population); places1.RemoveAt(0); places1.RemoveAt(places1.Count - 1); List <Place> places2 = new List <Place>(); places2.AddRange(conspecificsList[choosen[i + 1]].Population); places2.RemoveAt(0); places2.RemoveAt(places2.Count - 1); List <Place> places = new List <Place>(); for (int j = 0; j < (places1.Count / 2); j++) { places.Add(places1[j]); places2.Remove(places1[j]); } places.AddRange(places2); places.Insert(0, startPlace); places.Add(startPlace); var path = CreatePath(places); if (!path.Count.Equals(0)) { Conspecifics conspecifics = new Conspecifics(places, path.TotalLength, path.Cost); conspecificsList.Add(conspecifics); } } }