public IEvolvable Crossover(IEvolvable other) { StencilSpeciesArr mate = (StencilSpeciesArr)other; if (this.Equals(mate)) { var result = this.Clone(); result.Mutate(); return(result); } else { int[] cPerProcessor = (int[])cellsPerProcessor.Clone(); int freeCells = this.Field.Length; // initialize field with -1 or cells that are equal in both mates Arr <int> field = new Arr <int>(this.Field.SizeX, this.Field.SizeY); freeCells -= fillWithEqualGenesOrMinusOne(field, this.Field, mate.Field, cPerProcessor); while (freeCells > 0) { int position = field.FreePosition(random.Next(0, freeCells), -1); int processor = suitableValue(random, freeCells, this.Field, mate.Field, position, cPerProcessor); field[position] = processor; cPerProcessor[processor]--; freeCells--; } StencilSpeciesArr result = new StencilSpeciesArr(this, field); result.Optimize(3); return(result); } }
public StencilSpeciesArr(StencilSpeciesArr other, Arr <int> field) : this(other.random, field, other.cellsPerProcessor, other.Mutators) { }
public StencilSpeciesArr(StencilSpeciesArr other) : this(other.random, other.Field, other.cellsPerProcessor, other.Mutators) { }