/// <summary> /// Create child dna by breeding two parents from the mating pool /// </summary> /// <param name="dna1"></param> /// <param name="dna2"></param> /// <returns></returns> private IDNAI Breed() { IDNAI child = new DNAI(); IDNAI parent1 = _matingPool[UnityEngine.Random.Range(0, _matingPool.Count)]; IDNAI parent2 = _matingPool[UnityEngine.Random.Range(0, _matingPool.Count)]; child.Crossover(parent1, parent2); return(child); }
/// <summary> /// Create a new DNA from genes /// </summary> /// <param name="genes"></param> /// <returns></returns> public static IDNAI CreateFromGenes(int[] genes) { var dna = new DNAI(); for (int i = 0; i < genes.Length; i++) { dna.SetGene(i, genes[i]); } return(dna); }
public void ResetStackFromStackData() { OpenFileDialog choofdlog = new OpenFileDialog(); choofdlog.Filter = "All Files (*.*)|*.*"; choofdlog.FilterIndex = 1; choofdlog.Multiselect = true; if (choofdlog.ShowDialog() == DialogResult.OK) { string sFileName = choofdlog.FileName; string[] arrAllFiles = choofdlog.FileNames; //used when Multiselect = true CellStackData stackdata = Interop.DeserializeBinary <CellStackData>(sFileName); if (stackdata.ColumnCount != _rowCount || stackdata.RowCount != _columnCount || stackdata.LayerCount != _layerCount) { _columnCount = stackdata.ColumnCount; _rowCount = stackdata.RowCount; _layerCount = stackdata.LayerCount; InitializeCells(); } //set stack values _name = stackdata.Name; _meanStackDensity = stackdata.MeanStackDensity; _maxLayerDensity = stackdata.MaxLayerDensity; _minLayerDensity = stackdata.MinLayerDensity; _maxAge = stackdata.MaxAge; _avgAge = stackdata.AvgAge; _fitness = stackdata.Fitness; _dna = DNAI.CreateFromGenes(stackdata.DNAGENES); UpdateDataText(); for (int z = 0; z < _layerCount; z++) { CellLayer layer = _layers[z]; //set layer values layer.Density = stackdata.LayerDensities[z]; layer.AvgAge = stackdata.LayerAvgAges[z]; layer.MaxAge = stackdata.LayerMaxAges[z]; for (int x = 0; x < _rowCount; x++) { for (int y = 0; y < _columnCount; y++) { Cell cell = layer.Cells[x, y]; cell.State = 0; //set cell values cell.Age = stackdata.CellAges[x, y, z]; cell.State = stackdata.CellStates[x, y, z]; } } } } }
public FitnessDNA(CellStackData data) { fitness = data.Fitness; DNA = DNAI.CreateFromGenes(data.DNAGENES); }