public void EvolveParameters()
        {
            //var mapDescription = new MapDescription<int>()
            //    .SetupWithGraph(GraphsDatabase.GetExample3())
            //    .AddClassicRoomShapes(new IntVector2(1, 1));
            //    // .AddCorridorRoomShapes(new List<int>() { 2 }, true);

            // var input = CorridorConfigurationSpaces.GetMapDescriptionsSet(new IntVector2(1, 1), true, new List<int>() { 2, 4, 6, 8 }, false)[2];

            var settings = new JsonSerializerSettings()
            {
                PreserveReferencesHandling = PreserveReferencesHandling.All,
                TypeNameHandling           = TypeNameHandling.All,
            };

            var input = new GeneratorInput <MapDescription <int> >(
                "DeadCells",
                JsonConvert.DeserializeObject <MapDescription <int> >(File.ReadAllText("Resources/MapDescriptions/deadCells.json"), settings)
                );
            //var input = new GeneratorInput<MapDescription<int>>(
            //    "example1_corridors",
            //    JsonConvert.DeserializeObject<MapDescription<int>>(File.ReadAllText("Resources/MapDescriptions/example1_corridors.json"), settings)
            //);

            // input.MapDescription.SetDefaultTransformations(new List<Transformation>() { Transformation.Identity }); // TODO: fix later, wrong deserialization

            var analyzers = new List <IPerformanceAnalyzer <DungeonGeneratorConfiguration <int>, Individual <int> > >()
            {
                //new MaxStageTwoFailuresAnalyzer<DungeonGeneratorConfiguration, GeneratorData>(),
                //new ChainMergeAnalyzer<DungeonGeneratorConfiguration, int, GeneratorData>(),
                //new ChainOrderAnalyzer<DungeonGeneratorConfiguration, int, GeneratorData>(),
                new MaxIterationsAnalyzer <DungeonGeneratorConfiguration <int>, GeneratorData>(),
                new MaxBranchingAnalyzer <DungeonGeneratorConfiguration <int>, GeneratorData>(),
                //new ChainDecompositionAnalyzer<DungeonGeneratorConfiguration, int, GeneratorData>(input.MapDescription),
            };

            var evolution = new DungeonGeneratorEvolution <int>(input.MapDescription, analyzers, new EvolutionOptions()
            {
                MaxMutationsPerIndividual = 20,
                EvaluationIterations      = 75,
            }, Path.Combine("DungeonGeneratorEvolutions", FileNamesHelper.PrefixWithTimestamp(input.Name)));

            var initialConfiguration = new DungeonGeneratorConfiguration <int>();

            evolution.Evolve(initialConfiguration);
        }
Beispiel #2
0
        public static Result RunEvolution(Input input, Options options, List <IPerformanceAnalyzer <DungeonGeneratorConfiguration <int>, Individual <int> > > analyzers)
        {
            var evolution = new DungeonGeneratorEvolution <int>(input.MapDescription, analyzers, new EvolutionOptions()
            {
                MaxPopulationSize            = options.Eval ? 2 : 20,
                MaxMutationsPerIndividual    = 20,
                EvaluationIterations         = options.EvolutionIterations,
                WithConsoleOutput            = false,
                AllowWorseThanInitial        = !options.Eval,
                AllowRepeatingConfigurations = !options.Eval,
            }, Path.Combine(Directory, FileNamesHelper.PrefixWithTimestamp(input.Name)));

            var result = evolution.Evolve(input.Configuration);

            return(new Result()
            {
                Input = input,
                NewConfiguration = result.BestConfiguration,
                Individuals = result.AllIndividuals,
            });
        }