public GAStrategy(FMap fMap, string id, GAOpts opt) : base(fMap, id) { rng = new Random(Guid.NewGuid().GetHashCode()); popSize = opt.popSize; // population size mutRate = opt.mutRate; // mutation rate fitnessMulti = opt.fitMulti; //fitness multiplier ValueDiversity = opt.diversity; //whether we value candidate diversity or not Elite = opt.elite; //Mix in the genes of the best path found when creating next generations deepCount = 1; deepeningInc = opt.deepeningInc; parents = new Individual[Math.Max((int)(popSize * 0.1), 2)]; //parents as a fifth of the population dnaPool = new List <MasterGene>(); //action counter for crossovers BestDNA = new List <MoveDir>(); //initialise generation generation = new Individual[popSize]; for (int i = 0; i < popSize; i++) { generation[i] = new Individual(fMap.Start); } started = false; }
public static SearchStrategy Create(string filename, string method, string popSize, string mutRate, string fitMulti, string diversity, string elite, string deepeningInc) { method = method.ToUpper(); GAOpts opts = new GAOpts(popSize, mutRate, fitMulti, diversity, elite, deepeningInc); switch (method) { case "DFS": return(new DFSStrategy(MapFactory.CreateFMap(filename), "DFS")); case "GBFS": return(new GBFSStrategy(MapFactory.CreateFMap(filename), "GBFS")); case "AS": return(new ASStrategy(MapFactory.CreateFMap(filename), MapFactory.CreateFMap(filename), "A*")); case "ASFS": return(new ASFSStrategy(MapFactory.CreateFMap(filename), MapFactory.CreateFMap(filename), "A* Fast Stack")); case "CUS1": case "GA": return(new GAStrategy(MapFactory.CreateFMap(filename), "Genetic Algorithm", opts)); case "CUS2": case "JPS": return(new JPSStrategy(MapFactory.CreateFMap(filename), MapFactory.CreateFMap(filename), "JPS")); case "BFS": default: return(new BFSStrategy(MapFactory.CreateFMap(filename), "BFS")); } }