コード例 #1
0
        public void SaveAndLoadPopulationToZipArchive()
        {
            // Create a test population.
            NeatPopulation <double> pop = NestGenomeTestUtils.CreateNeatPopulation();

            // Build path to test population folder.
            string parentPath = Path.Combine(Directory.GetCurrentDirectory(), "test-pops");

            // Delete folder if it already exists.
            if (Directory.Exists(parentPath))
            {
                Directory.Delete(parentPath, true);
            }

            // Create an empty parent folder to save populations into.
            Directory.CreateDirectory(parentPath);

            // Save the population to the unit test output folder.
            NeatPopulationSaver <double> .SaveToZipArchive(pop.GenomeList, parentPath, "pop2", System.IO.Compression.CompressionLevel.Optimal);

            // Load the population.
            NeatPopulationLoader <double> loader         = NeatPopulationLoaderFactory.CreateLoaderDouble(pop.MetaNeatGenome);
            string populationZipPath                     = Path.Combine(parentPath, "pop2.zip");
            List <NeatGenome <double> > genomeListLoaded = loader.LoadFromZipArchive(populationZipPath);

            // Compare the loaded genomes with the original genome list.
            IOTestUtils.CompareGenomeLists(pop.GenomeList, genomeListLoaded);
        }
コード例 #2
0
        public void SaveAndLoadGenome()
        {
            var metaNeatGenome = new MetaNeatGenome <double>(3, 2, true, new ReLU());
            var genomeBuilder  = NeatGenomeBuilderFactory <double> .Create(metaNeatGenome);

            // Simple acyclic graph.
            var connGenes = new ConnectionGenes <double>(6);

            connGenes[0] = (0, 3, 0.123);
            connGenes[1] = (1, 3, 1.234);
            connGenes[2] = (2, 3, -0.5835);
            connGenes[3] = (2, 4, 5.123456789);
            connGenes[4] = (2, 5, 2.5);
            connGenes[5] = (5, 4, 5.4);

            // Wrap in a genome.
            NeatGenome <double> genome = genomeBuilder.Create(0, 0, connGenes);

            // Create a memory stream to save the genome into.
            using (MemoryStream ms = new MemoryStream(1024))
            {
                // Save the genome.
                NeatGenomeSaver <double> .Save(genome, ms);

                // Load the genome.
                ms.Position = 0;
                NeatGenomeLoader <double> loader       = NeatGenomeLoaderFactory.CreateLoaderDouble(metaNeatGenome);
                NeatGenome <double>       genomeLoaded = loader.Load(ms);

                // Compare the original genome with the loaded genome.
                IOTestUtils.CompareGenomes(genome, genomeLoaded);
            }
        }
コード例 #3
0
        public void LoadGenome()
        {
            var metaNeatGenome = new MetaNeatGenome <double>(3, 2, true, new ReLU());

            // Load test genome.
            NeatGenomeLoaderDouble loader       = new NeatGenomeLoaderDouble(metaNeatGenome);
            NeatGenome <double>    genomeLoaded = loader.Load("TestData/example1.genome");

            // Manually build an equivalent genome.
            NeatGenome <double> genomeBuilt = CreateGenome1(metaNeatGenome);

            // Compare the two genomes.
            IOTestUtils.CompareGenomes(genomeLoaded, genomeBuilt);
        }
コード例 #4
0
        public void SaveAndLoadPopulationToZipArchive()
        {
            // Create a test population.
            NeatPopulation <double> pop = NestGenomeTestUtils.CreateNeatPopulation();

            // Create a parent folder to save populations into.
            string parentPath = Path.Combine(TestContext.TestRunDirectory, "test-pops");

            Directory.CreateDirectory(parentPath);

            // Save the population to the unit test output folder.
            NeatPopulationSaver <double> .SaveToZipArchive(pop.GenomeList, parentPath, "pop2", System.IO.Compression.CompressionLevel.Optimal);

            // Load the population.
            NeatPopulationLoader <double> loader         = NeatPopulationLoaderFactory.CreateLoaderDouble(pop.MetaNeatGenome);
            string populationZipPath                     = Path.Combine(parentPath, "pop2.zip");
            List <NeatGenome <double> > genomeListLoaded = loader.LoadFromZipArchive(populationZipPath);

            // Compare the loaded genomes with the original genome list.
            IOTestUtils.CompareGenomeLists(pop.GenomeList, genomeListLoaded);
        }