public void Save() { //SAVE string path = Mod_File.FileSaveDialog("learning_pool " + NetMain.Cam.Width + "x" + NetMain.Cam.Height + " (" + Pool.generation + ", " + Pool.species.Count + " of " + Population + ", " + Pool.measured + "%)", FILTER.TXT); //ABBRUCH if (path == null) { return; } //START LOADING UniLoad.loadingStart(); List <object> file = new List <object>(); file.Add(Duration.TotalMilliseconds); file.Add(string.Join(" ", OutputKeys)); file.Add(Pool.generation); file.Add(Pool.maxFitness); file.Add(Pool.species.Count); foreach (newSpecies species in Pool.species) //SPECIES { file.Add(species.topFitness); file.Add(species.staleness); file.Add(species.genomes.Count); foreach (newGenome genome in species.genomes) //GENOME { file.Add(genome.fitness); file.Add(genome.maxneuron); foreach (KeyValuePair <string, double> mutation in genome.mutationRates) //MUTATION { file.Add(mutation.Key); file.Add(mutation.Value); } //DONE file.Add("done"); file.Add(genome.genes.Count); foreach (newGene gene in genome.genes) //GENE { file.Add(gene.into + " " + gene.output + " " + gene.weight + " " + gene.innovation + " " + gene.enabled); } } } //END LOADING UniLoad.loadingEnd(); //CREATE FILE Mod_File.CreateFile(file.ToArray(), path); }
public void Load() { //LOAD string[] path = Mod_File.FileOpenDialog(false, FILTER.TXT); //ABBRUCH if (path == null) { return; } //START LOADING UniLoad.loadingStart(); //READ TXT FILE string[] file = Mod_TXT.readTXT(path[0]); int x = 0; //GET DURATION Duration = TimeSpan.FromMilliseconds(Mod_Convert.StringToDouble(file[x++])); //GET OUTPUT KEYS OutputKeys = file[x++].Split(' '); //INITIALIZE POOL Initialize(OutputKeys, true); Pool.generation = Mod_Convert.StringToInteger(file[x++]); Pool.maxFitness = Mod_Convert.StringToDouble(file[x++]); int numSpecies = Mod_Convert.StringToInteger(file[x++]); for (int j = 0; j < numSpecies; j++) //SPECIES { newSpecies species = new newSpecies(); Pool.species.Add(species); species.topFitness = Mod_Convert.StringToDouble(file[x++]); species.staleness = Mod_Convert.StringToInteger(file[x++]); int numGenomes = Mod_Convert.StringToInteger(file[x++]); for (int i = 0; i < numGenomes; i++) //GENOME { newGenome genome = new newGenome(); species.genomes.Add(genome); genome.fitness = Mod_Convert.StringToDouble(file[x++]); genome.maxneuron = Mod_Convert.StringToInteger(file[x++]); string line = file[x++]; while (line != "done") { genome.mutationRates[line] = Mod_Convert.StringToDouble(file[x++]); line = file[x++]; } int numGenes = Mod_Convert.StringToInteger(file[x++]); for (int k = 0; k < numGenes; k++) //GENE { newGene gene = new newGene(); genome.genes.Add(gene); string[] split = file[x++].Split(' '); gene.into = Mod_Convert.StringToInteger(split[0]); gene.output = Mod_Convert.StringToInteger(split[1]); gene.weight = Mod_Convert.StringToDouble(split[2]); gene.innovation = Mod_Convert.StringToInteger(split[3]); gene.enabled = Mod_Convert.ObjectToBool(split[4]); } } } //FITNESS ALREADY MEASURED while (fitnessAlreadyMeasured()) { nextGenome(); } initializeRun(); //UPDATE LEARN PANEL NetMain.RoundFinished(0); //END LOADING UniLoad.loadingEnd(); }