/// <summary> /// Inject in dependencies, in the event we want to test out different wheel spinners or payout calculators /// </summary> /// <param name="wheel">The wheel to use during the simulation. The only thing we need is to get a series of results from it</param> /// <param name="payoutCalculator">Calculate what the payout is for the roll. I assume we can only do a straight bet, for simplicity</param> public RouletteRunner( IRouletteWheel wheel, IPayoutCalculator payoutCalculator) { _wheel = wheel; _payoutCalculator = payoutCalculator; _players = new ConcurrentBag<IRoulettePlayer>(); _tableBets = new Dictionary<IRoulettePlayer, IReadOnlyCollection<IRouletteBet>>(); }
public void Generate() { IRouletteWheel rouletteWheel = breedingFactory.CreateRouletteWheel(generation); breeder.SetRouletteWheel(rouletteWheel); breeder.CalcFitness(generation); Solution[] newGeneration = new Solution[population]; for (int i = 0; i < population; i++) { newGeneration[i] = breeder.Breed(); } logger.logBestFitSolution(writer, FindBestFit()); generation = newGeneration; }
/// <summary> /// This is the roulette wheel selection algorithm function. It will return a list of matches that will be used for reproduction. /// Each chomosome will get a weigthed opportunity to be in a match based on it's fintess score. /// </summary> /// <param name="population"></param> /// <param name="selectionProbabilities"></param> /// <returns></returns> private IEnumerable <Match> CreateMatches(IPopulation population, IRouletteWheel wheel) { if (population.Count <= 1) { return new Match[] { } } ; Dictionary <Tuple <int, int>, Match> result = new Dictionary <Tuple <int, int>, Match>(); int matchesNeeded = population.Count / 2; Random randomNumber = new Random(); while (result.Count < matchesNeeded) { IChromosome patternal = population.GetMate(wheel.GetFitnessValue()); IChromosome matternal = population.GetMate(wheel.GetFitnessValue()); //This makes sure that there is no asexual matting. if (patternal.Equals(matternal)) { continue; } Tuple <int, int> key = new Tuple <int, int>(patternal.Fitness, matternal.Fitness); if (result.ContainsKey(key)) { continue; } result.Add(key, new Match(patternal, matternal)); } return(result.Values); }
public void SetRouletteWheel(IRouletteWheel rouletteWheel) { this.rouletteWheel = rouletteWheel; this.rouletteWheel.SetRand(new Random()); }
public MatchMaker(IPopulation population, IRouletteWheel wheel) { Matches = CreateMatches(population, wheel); }