当前位置: 首页>>代码示例>>C#>>正文


C# Individual.clone方法代码示例

本文整理汇总了C#中Individual.clone方法的典型用法代码示例。如果您正苦于以下问题:C# Individual.clone方法的具体用法?C# Individual.clone怎么用?C# Individual.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Individual的用法示例。


在下文中一共展示了Individual.clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitializeAncestors

        ///初始化 个体、种群 数据结构
        private bool InitializeAncestors()
        {
            bool ret = true;
            produceWeightMatrix(ref weightMatrix);
            produceNeighbors(ref neighborsTable);//这两步初始化权重矩阵以及子种群数目

            populationSize = subPopSize * subPopNum;
            gSectorNum = endSecIndex - begSecIndex + 1;

            ancestor = new Individual(sList.sectorList.Count, objectNum);
            elder = new Individual(sList.sectorList.Count, objectNum);

            population = new Individual[populationSize];
            newPopulation = new Individual[populationSize];
            Ancestors = new Individual[subPopNum];
            elders = new Individual[subPopNum];
            alphas = new double[subPopNum];
            for (int i = 0; i < subPopNum; i++) alphas[i] = Alpha;

            //初始化种群
            for (int i = 0; i < populationSize; i++)
            {
                if (i < subPopNum)
                {
                    Ancestors[i] = new Individual(sList.sectorList.Count, objectNum);
                    elders[i] = new Individual(sList.sectorList.Count, objectNum);
                }
                population[i] = new Individual(sList.sectorList.Count, objectNum);
                newPopulation[i] = new Individual(sList.sectorList.Count, objectNum);
            }

            for (int i = 0; i < sList.sectorList.Count; i++)
                ancestor.gene[i] = sList.sectorList[i].PCI;
            calculateOriginalFitness(ref ancestor);
            Console.WriteLine("初始干扰值为:" + ancestor.interf_ori);
            Console.WriteLine("一层邻区mod3:" + ancestor.fnmod_ori);
            Console.WriteLine("一阶邻区mod3:" + ancestor.famod3_ori);

            #region ;用SectorList数据初始化ancestor个体基因、复用度数组
            ////簇信息
            //List<List<int>> clus = new List<List<int>>();
            //for (int i = 0; i < ancestor.gene.Length; i++)
            //{
            //    int cid = sList.sectorList[i].clusterID;
            //    bool isInsert = false;
            //    for (int j = 0; j < clus.Count; j++)
            //        if (cid == sList.sectorList[clus[j][0]].clusterID)
            //        {
            //            clus[j].Add(i);
            //            isInsert = true;
            //            break;
            //        }
            //    if (!isInsert)
            //    {
            //        clus.Add(new List<int>());
            //        clus[clus.Count - 1].Add(i);
            //    }
            //}
            //for (int i = 0; i < clus.Count; i++)
            //    ancestor.clusters.Add(new Cluster(clus[i]));

            //InterfEvaluation_Clusters(ref ancestor);
            //Console.WriteLine("初始干扰值为:" + ancestor.fitness_interf);
            //基因
            for (int i = 0; i < begSecIndex; i++)
                ancestor.gene[i] = sList.sectorList[i].PCI;
            for (int i = begSecIndex; i <= endSecIndex; i++)
                ancestor.gene[i] = -1;
            for (int i = endSecIndex + 1; i < sList.sectorList.Count; i++)
                ancestor.gene[i] = sList.sectorList[i].PCI;
            //复用度数组
            for (int i = 0; i < ancestor.gene.Length; i++)
                if (ancestor.gene[i] != -1)
                    ancestor.degrees[ancestor.gene[i]]++;
            #endregion

            for (int i = 0; i < Ancestors.Length; i++)
                ancestor.clone(ref Ancestors[i]);
            return ret;
        }
开发者ID:LeungGeorge,项目名称:FreqOptGA,代码行数:81,代码来源:EA.cs

示例2: getPareto

        /*检测每一个个体,迭代更新获取Pareto前端*/
        public void getPareto(ref Individual individual)
        {
            int maxCuboIndex = 0;//密度最大的超网格下标
            int loc = 0;//当前个体individual所在的超网格下标

            #region 当前pareto集为空
            if (paretoSize == 0)
            {
                individual.clone(ref pareto[paretoSize]);
                //nonemptyHipercubos = 0;////??
                paretoSize++;
                return;
            }
            #endregion

            #region 当前pareto集不为空,且当前个体不被pareto集中任何个体支配
            if (individual.rank == 0 && domainAPareto(ref individual) == 0)
            {
                if (paretoSize + 1 < maxParetoSize)
                {
                    individual.clone(ref pareto[paretoSize]);
                    paretoSize++;
                    //nonemptyHipercubos = 0;
                }
                else if (paretoSize + 1 == maxParetoSize)
                {//Pareto集未满
                    individual.clone(ref pareto[paretoSize]);
                    paretoSize++;
                    initLocation();
                    //nonemptyHipercubos = countHipercubo();
                }
                else
                {//Pareto集已满
                    maxCuboIndex = getMaxCuboIndex();//获取个体数最大的网格下标
                    loc = getCurLocation(ref individual);//获取当前个体的超网位置
                    int i = getFirstIndivInCubo(maxCuboIndex);
                    if (i == -1)
                    {
                        Console.WriteLine("err:position getPareto()");
                        return;
                    }
                    if (loc == -1)
                    {
                        individual.clone(ref pareto[i]);
                        initLocation();
                        //nonemptyHipercubos = countHipercubo();
                    }
                    else if (maxLocRelation(maxCuboIndex, loc))
                    {
                        ////////////////////////////////////////////////////////////
                        individual.location = loc;
                        individual.clone(ref pareto[i]);
                        //if (hipercubo[maxCuboIndex] <= 1 && hipercubo[loc] >= 1)
                            //nonemptyHipercubos--;
                        hipercubo[maxCuboIndex]--;
                        hipercubo[loc]++;
                    }
                }
            }
            #endregion
        }
开发者ID:LeungGeorge,项目名称:FreqOptGA,代码行数:62,代码来源:Pareto.cs


注:本文中的Individual.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。