private static void RecordBest(IRegularGrid2D targetGrid, Population population, int generation, RectangularDomain domain) { List <Individual> best = population.Best; for (int j = 0; j < best.Count; ++j) { Console.Write("best[{0}] = [", j); foreach (double f in best[j].Fitness) { Console.Write(f); Console.Write(" "); } Console.WriteLine("] with {0} genes", best[j].Genome.Count); // Express the genome to create a grid Individual bestIndividual = (Individual)best[j].Clone(); Grid2DPhenotype bestPhenotype = (Grid2DPhenotype)bestIndividual.Phenome; bestPhenotype.Grid.MaskFrom(targetGrid); StringBuilder gridFileName = new StringBuilder(); gridFileName.AppendFormat("evolved_{0}_{1}.grd", generation + 1, j); bestPhenotype.Grid.WriteSurfer6BinaryFile(gridFileName.ToString()); ReportLogger.Instance.Writer.WriteStartElement("Grid"); ReportLogger.Instance.Writer.WriteStartAttribute("file"); ReportLogger.Instance.Writer.WriteValue(gridFileName.ToString()); ReportLogger.Instance.Writer.WriteEndAttribute(); ReportLogger.Instance.Writer.WriteEndElement(); // Express the genome to create a fault polygon map OutlineMapDomain mapDomain = new OutlineMapDomain(domain); OutlineMapPhenotype mapPhenotype = (OutlineMapPhenotype)bestIndividual.Genome.Express(mapDomain); StringBuilder polygonFileName = new StringBuilder(); polygonFileName.AppendFormat("evolved_{0}_{1}.poly", generation + 1, j); using (StreamWriter writer = File.CreateText(polygonFileName.ToString())) { writer.Write(mapPhenotype.ToString()); } ReportLogger.Instance.Writer.WriteStartElement("Polygons"); ReportLogger.Instance.Writer.WriteStartAttribute("file"); ReportLogger.Instance.Writer.WriteValue(polygonFileName.ToString()); ReportLogger.Instance.Writer.WriteEndAttribute(); ReportLogger.Instance.Writer.WriteEndElement(); } }
public OutlineMapPhenotype(OutlineMapDomain domain) : base(domain) { this.map = new OutlineMap(domain.Min, domain.Max); }