public ZeldaIndividual(ZeldaGenome genome, Crawler crawler, int numSteps, int numDeadEnds, int shortestPathLength, double revisitFactor, double branchFactor) { Debug.Assert(genome != null); this.genome = genome; this.crawler = crawler; this.numSteps = numSteps; this.numDeadEnds = numDeadEnds; this.shortestPathLength = shortestPathLength; this.revisitFactor = revisitFactor; this.branchFactor = branchFactor; }
public Pair <Genome> Crossover(Genome o, RandomNumberGenerator random) { ZeldaGenome other = (ZeldaGenome)o; // randomly distribute genes var newGenesA = new List <ZeldaGene>(genes); var newGenesB = new List <ZeldaGene>(other.genes); GeneUtils.Crossover(genes, other.genes, random); // assemble offsprings var a = new ZeldaGenome(configuration, newGenesA); var b = new ZeldaGenome(configuration, newGenesB); return(new Pair <Genome>(a, b)); }
public Individual Evaluate(Genome g) { ZeldaGenome genome = (ZeldaGenome)g; // build puzzle var builder = new ZeldaDungeonBuilder(); Profiler.BeginSample("Express"); genome.Express(builder); Profiler.EndSample(); var crawler = builder.Build(); // build initial states var initialStates = new List <State>(); foreach (var variableAssignment in initialVariables) { var state = variableAssignment.ToState(builder.Lookup); initialStates.Add(state); } // crawl puzzle Profiler.BeginSample("Crawl"); var terminalSteps = crawler.Crawl(initialStates, maxSteps); Profiler.EndSample(); // evaluate puzzle Profiler.BeginSample("Assess"); int numSteps = crawler.DebugGetSteps().Count(); int numDeadEnds = ErrorCounter.CountDeadEnds(crawler); int shortestPathLength = PathFinder.CalcShortestPathLength(terminalSteps); double revisitFactor = PathFinder.CalcRevisitFactor(crawler); double branchFactor = PathFinder.CalcBranchFactor(crawler); Profiler.EndSample(); // create individual return(new ZeldaIndividual(genome, crawler, numSteps, numDeadEnds, shortestPathLength, revisitFactor, branchFactor)); }