/// <summary> /// I hard-code both Produce(...) methods for efficiency's sake. /// </summary> public int Produce( int min, int max, int start, int subpop, IList <Individual> inds, IEvolutionState state, int thread, IDictionary <string, object> misc) { int n = 1; if (n > max) { n = max; } if (n < min) { n = min; } for (int q = 0; q < n; q++) { IList <Individual> oldinds = state.Population.Subpops[subpop].Individuals; int index = state.Random[thread].NextInt(state.Population.Subpops[subpop].Individuals.Count); inds[start + q] = oldinds[index]; if (misc != null && misc.ContainsKey(KEY_PARENTS)) { IntBag parent = new IntBag(1); parent.Add(index); ((IntBag[])misc[KEY_PARENTS])[start + q] = parent; } } return(n); }
/// <summary> /// I hard-code both Produce(...) methods for efficiency's sake. /// </summary> public int Produce( int min, int max, int start, int subpop, IList <Individual> inds, IEvolutionState state, int thread, IDictionary <string, object> misc) { var n = 1; if (n > max) { n = max; } if (n < min) { n = min; } for (var q = 0; q < n; q++) { // pick size random individuals, then pick the best. var oldinds = state.Population.Subpops[subpop].Individuals; inds[start + q] = oldinds[0]; // note it's a pointer transfer, not a copy! if (misc != null && misc.ContainsKey(KEY_PARENTS)) { IntBag parent = new IntBag(1); parent.Add(0); ((IntBag[])misc[KEY_PARENTS])[start + q] = parent; } } return(n); }
public virtual int ProduceWithoutCloning( int min, int max, int subpop, IList <Individual> inds, IEvolutionState state, int thread, IDictionary <String, Object> misc) { int start = inds.Count; int n = INDS_PRODUCED; if (n < min) { n = min; } if (n > max) { n = max; } for (int q = 0; q < n; q++) { int index = Produce(subpop, state, thread); inds.Add(state.Population.Subpops[subpop].Individuals[index]); // by Ermo. seems the misc forget to check if misc is null if (misc != null && misc.ContainsKey(KEY_PARENTS)) { IntBag bag = new IntBag(1); bag.Add(index); ((IntBag[])misc[KEY_PARENTS])[start + q] = bag; } } return(n); }