public object decodeChromosome() { DecodeModel decodeData = new DecodeModel(); List <BoxModel> listBoxModel = copyListBoxModel(); List <PalletModel> listPalletModel = copyListPalletModel(); //Gene GeneModel gene1 = this.chromosome.listGene[INDEX_GENE1]; GeneModel gene2 = this.chromosome.listGene[INDEX_GENE2]; GeneModel gene3 = this.chromosome.listGene[INDEX_GENE3]; //decode Gene1 foreach (float index in gene1.gene) { decodeData.ListBoxIndex.Add(listBoxModel[(int)index - 1].Index); listBoxModel.RemoveAt((int)index - 1); } foreach (float ratio in gene2.gene) { decodeData.ListRatio.Add(ratio); } foreach (float palletIndex in gene3.gene) { decodeData.ListPalletIndex.Add((int)palletIndex); } return(decodeData); }
public List <Object> crossover(object chromosome, int[] listIndexGene) { Object chromosomeData = ((Chromosome)chromosome).getChromosome(); ChromosomeModel offspringChromosome1 = ((ChromosomeModel)chromosomeData).Copy(); ChromosomeModel offspringChromosome2 = (this.chromosome).Copy(); for (int i = 0; i < listIndexGene.Length; i++) { Random random = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); if (listIndexGene[i] < this.chromosome.listGene.Count) { int indexGene = listIndexGene[i]; if (indexGene == INDEX_GENE1 || indexGene == INDEX_GENE2 || indexGene == INDEX_GENE3) { GeneModel parentGene1 = ((ChromosomeModel)chromosomeData).listGene[indexGene]; GeneModel parentGene2 = this.chromosome.listGene[indexGene]; GeneModel offspringGene1 = offspringChromosome1.listGene[indexGene]; GeneModel offspringGene2 = offspringChromosome2.listGene[indexGene]; int subIndexGene = random.Next(0, parentGene2.gene.Count - 1); for (int crossIndex = subIndexGene; i < parentGene2.gene.Count; i++) { offspringGene1.gene[crossIndex] = parentGene2.gene[crossIndex]; offspringGene2.gene[crossIndex] = parentGene1.gene[crossIndex]; } } } } return(new List <object> { new Chromosome(this.lookUpBoxModel, this.lookUpPalletModel, offspringChromosome1, this.size, this.alpha) , new Chromosome(this.lookUpBoxModel, this.lookUpPalletModel, offspringChromosome2, this.size, this.alpha) }); }
public void mutation(int[] listIndexGene) { for (int i = 0; i < listIndexGene.Length; i++) { Random random = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); if (listIndexGene[i] < this.chromosome.listGene.Count) { int indexGene = listIndexGene[i]; if (indexGene == INDEX_GENE2) { double randValue = randomGene2(); GeneModel gene = chromosome.listGene[indexGene]; int subIndexGene = random.Next(0, gene.gene.Count - 1); gene.gene[subIndexGene] = randValue; } else if (indexGene == INDEX_GENE3) { double randValue = randomGene3(); GeneModel gene = chromosome.listGene[indexGene]; int subIndexGene = random.Next(0, gene.gene.Count - 1); gene.gene[subIndexGene] = randValue; } } } }
public GeneModel Copy() { GeneModel newGene = new GeneModel(); List <double> newData = new List <double>(); for (int i = 0; i < gene.Count; i++) { newData.Add(gene[i]); } newGene.gene = newData; return(newGene); }
public void generateGene(int index, int numberGene, GeneModel.randomValue callback) { GeneModel gene = new GeneModel(numberGene, callback); listGene.Add(index, gene); }