/// <summary> /// Converts this individual to a map based on the base map included in the map search options. /// </summary> /// <returns> The <see cref="MapPhenotype"/> that corresponds to this individual.</returns> public MapPhenotype ConvertToPhenotype() { var map = MapConversionHelper.ConvertToPhenotype(this.MapPoints, this.MapSearchOptions, this.Random); this.ConvertedPhenotype = map.CreateFinishedMap(Enums.Half.Top, this.MapSearchOptions.MapCompletion); this.hasBeenConverted = true; return(this.ConvertedPhenotype); }
/// <summary> /// Converts this individual onto an empty map. /// </summary> /// <param name="xSize"> The width of the map. </param> /// <param name="ySize"> The height of the map. </param> /// <returns> The <see cref="MapPhenotype"/> that corresponds to this individual.</returns> public MapPhenotype ConvertToPhenotype(int xSize, int ySize) { var map = new MapPhenotype(ySize, xSize); map = MapConversionHelper.ConvertToPhenotype(this.MapPoints, new MapSearchOptions(map, MapSearchOptions), this.Random); return(map); }
/// <summary> /// Spawns a mutation of this individual. /// </summary> /// <returns>A newly mutated individual.</returns> public override Evolvable SpawnMutation() { var newPoints = MapConversionHelper.MutateMapPoints( this.MapPoints, this.MutationChance, this.MapSearchOptions, this.Random); return(new EvolvableMap(this.MapSearchOptions, this.MutationChance, this.Random, this.MapFitnessOptions, newPoints)); }
/// <summary> /// Initializes a new instance of the <see cref="MapSearcher"/> class. /// </summary> /// <param name="r"> /// The random to use in searching. /// </param> /// <param name="mapSearchOptions"> /// The map options for this search. /// </param> /// <param name="noveltySearchOptions"> /// The novelty Search Options. /// </param> public MapSearcher(Random r, MapSearchOptions mapSearchOptions, NoveltySearchOptions noveltySearchOptions) : base(r, noveltySearchOptions) { this.MapSearchOptions = mapSearchOptions; this.FeasiblePopulation = new MapPopulation(true, noveltySearchOptions.FeasiblePopulationSize); this.InfeasiblePopulation = new MapPopulation(false, noveltySearchOptions.InfeasiblePopulationSize); this.Archive = new MapNovelArchive(); var numberOfAttempts = 0; while (this.FeasiblePopulation.CurrentGeneration.Count < noveltySearchOptions.FeasiblePopulationSize) { var list = MapConversionHelper.GenerateInitialMapPoints(mapSearchOptions, r); var ms = new MapSolution(this.MapSearchOptions, this.NoveltySearchOptions, list, r); if (ms.IsFeasible) { this.FeasiblePopulation.CurrentGeneration.Add(ms); } else if (InfeasiblePopulation.CurrentGeneration.Count < noveltySearchOptions.InfeasiblePopulationSize) { this.InfeasiblePopulation.CurrentGeneration.Add(ms); } if (numberOfAttempts > 1000) { break; } numberOfAttempts++; } while (this.InfeasiblePopulation.CurrentGeneration.Count < noveltySearchOptions.InfeasiblePopulationSize) { var list = MapConversionHelper.GenerateInitialMapPoints(mapSearchOptions, r); for (var j = 0; j < list.Count; j++) { var item = list[j]; var distance = r.Next(2) == 1 ? (r.Next(2) == 1 ? (item.Distance + 1.0) : (item.Distance - 1.0)) : item.Distance; var degree = r.Next(2) == 1 ? (r.Next(2) == 1 ? (item.Degree + 180) : (item.Degree - 180)) : item.Degree; var mp = new MapPoint(distance, degree, item.Type, Enums.WasPlaced.NotAttempted); list[j] = mp; } var ms = new MapSolution(this.MapSearchOptions, this.NoveltySearchOptions, list, r); this.InfeasiblePopulation.CurrentGeneration.Add(ms); } foreach (var ms in this.FeasiblePopulation.CurrentGeneration) { var novelty = ms.CalculateNovelty( this.FeasiblePopulation, this.Archive, noveltySearchOptions.NumberOfNeighbours); if (novelty >= noveltySearchOptions.MinimumNovelty) { this.Archive.Archive.Add(ms); } } }
/// <summary> /// Converts this individual onto a specific map. /// </summary> /// <param name="map"> The map to convert this individual onto. </param> /// <returns> The <see cref="MapPhenotype"/> that corresponds to this individual.</returns> public MapPhenotype ConvertToPhenotype(MapPhenotype map) { map = MapConversionHelper.ConvertToPhenotype(this.MapPoints, new MapSearchOptions(map, this.MapSearchOptions), this.Random); return(map); }
/// <summary> /// Initializes this individual. /// </summary> public override void InitializeObject() { this.MapPoints = MapConversionHelper.GenerateInitialMapPoints(this.MapSearchOptions, this.Random); }