Example #1
0
        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)
            });
        }
Example #2
0
 public Chromosome(List <BoxModel> lookUpBoxModel, List <PalletModel> lookUpPalletModel, int size, double alpha)
 {
     this.lookUpBoxModel    = lookUpBoxModel;
     this.lookUpPalletModel = lookUpPalletModel;
     this.size  = size;
     this.alpha = alpha;
     chromosome = (ChromosomeModel)randomChromosome(size);
 }
Example #3
0
 private Chromosome(List <BoxModel> lookUpBoxModel, List <PalletModel> lookUpPalletModel, ChromosomeModel chromosome, int size, double alpha)
 {
     this.lookUpBoxModel    = lookUpBoxModel;
     this.lookUpPalletModel = lookUpPalletModel;
     this.size       = size;
     this.alpha      = alpha;
     this.chromosome = chromosome;
 }
        public ChromosomeModel Copy()
        {
            Dictionary <int, GeneModel> listGene = new Dictionary <int, GeneModel>();

            foreach (var geneDic in this.listGene)
            {
                listGene.Add(geneDic.Key, geneDic.Value.Copy());
            }
            ChromosomeModel newChromosome = new ChromosomeModel(listGene);

            return(newChromosome);
        }
Example #5
0
        public object randomChromosome(int size)
        {
            ChromosomeModel tempChromosome = new ChromosomeModel();

            lookUpBoxModelTemp = copyListBoxModel();
            tempChromosome.generateGene(INDEX_GENE1,
                                        size,
                                        randomGene1);
            tempChromosome.generateGene(INDEX_GENE2,
                                        size,
                                        randomGene2);
            tempChromosome.generateGene(INDEX_GENE3,
                                        size,
                                        randomGene3);
            lookUpBoxModelTemp = null;
            return(tempChromosome);
        }