Beispiel #1
0
        //用于变异、微调
        public bool getUsablePCI_new(int sid, List<int> candidate, Individual indivi, out List<pciSelection> usable)
        {
            bool result = true;

            usable = new List<pciSelection>();//存储可用PCI
            List<int> FlagList = new List<int>();//每个可选PCI的标记位

            int i, j;
            int flag, curSID, curPCI;
            pciSelection curUse; //= new pciSelection();

            #region ;遍历candidate列表,选出符合10个硬约束的PCI
            for (i = 0; i < candidate.Count; i++)
            {
                curPCI = candidate[i];
                flag = 1023;

                #region ;判断同站同PCI
                for (j = 0; j < sList.sectorList[sid].coStationList.Count; j++)
                {
                    curSID = sList.sectorList[sid].coStationList[j];//同站小区在SectorList中的索引
                    if (curPCI == indivi.gene[curSID])
                    {
                        //标志位首位置零
                        flag -= 512;
                        break;
                    }
                }
                #endregion

                #region ;判断同站同PSS
                if (sList.sectorList[sid].coStationList.Count <= 2)
                {
                    for (j = 0; j < sList.sectorList[sid].coStationList.Count; j++)
                    {
                        curSID = sList.sectorList[sid].coStationList[j];//同站小区在SectorList中的索引
                        if (indivi.gene[curSID] != -1 && curPCI % 3 == indivi.gene[curSID] % 3)
                        {
                            flag -= 256;
                            break;
                        }
                    }
                }
                else
                {
                    int count = 0;
                    for (j = 0; j < sList.sectorList[sid].coStationList.Count; j++)
                    {
                        curSID = sList.sectorList[sid].coStationList[j];//同站小区在SectorList中的索引
                        if (indivi.gene[curSID] != -1 && curPCI % 3 == indivi.gene[curSID] % 3)
                            count++;
                        if (count > 2)
                        {
                            flag -= 256;
                            break;
                        }
                    }
                }
                #endregion

                #region ;判断一阶邻区同PCI
                bool fadjNotSame = true;
                for (j = 0; j < sList.sectorList[sid].faList.Count; j++)
                {
                    curSID = sList.sectorList[sid].faList[j].FirAdjIndex;//一阶邻区在SectorList中的索引
                    if (!sList.sectorList[sid].fnNotfaIndexList.Contains(curSID))
                    {//保证是原始的一阶邻区
                        if (curPCI == indivi.gene[curSID])
                        {
                            flag -= 128;
                            fadjNotSame = false;
                            break;
                        }
                    }
                }
                if (fadjNotSame)
                {
                    for (j = 0; j < sList.sectorList[sid].saList.Count; j++)
                    {
                        curSID = sList.sectorList[sid].saList[j].SecAdjIndex;
                        if (curPCI == indivi.gene[curSID])
                        {
                            flag -= 128;
                            break;
                        }
                    }
                }
                #endregion

                #region ;判断二阶邻区同PCI
                //for (j = 0; j < sList.sectorList[sid].saList.Count; j++)
                //{
                //    curSID = sList.sectorList[sid].saList[j].SecAdjIndex;
                //    if (curPCI == indivi.gene[curSID])
                //    {
                //        flag-=64;
                //        break;
                //    }
                //}
                #endregion

                #region ;判断3000m内同PCI
                for (j = 0; j < sList.sectorList[sid].InThreeKM.Count; j++)
                {
                    curSID = sList.sectorList[sid].InThreeKM[j];//一阶邻区在SectorList中的索引
                    if (indivi.gene[curSID] != -1 && curPCI == indivi.gene[curSID])
                    {
                        flag -= 64;
                        break;
                    }
                }
                #endregion

                #region ;判断一阶邻区SSS相关系数
                for (j = 0; j < sList.sectorList[sid].faList.Count; j++)
                {
                    curSID = sList.sectorList[sid].faList[j].FirAdjIndex;

                    if (pciInfo.sssCorr[curPCI / 3, indivi.gene[curSID] / 3] >= pciInfo.sssThr)
                    {
                        flag -= 4;
                        break;
                    }
                }
                #endregion

                #region ;判断一阶邻区PCI mod 6相同
                int k6 = 0;
                for (j = 0; k6 < 6 && j < sList.sectorList[sid].faList.Count; j++)
                {
                    curSID = sList.sectorList[sid].faList[j].FirAdjIndex;
                    //if (!sList.sectorList[sid].fnNotfaIndexList.Contains(curSID))
                    {//保证是原始的一阶邻区
                        k6++;
                        if (indivi.gene[curSID] != -1 && curPCI % 6 == indivi.gene[curSID] % 6)
                        {
                            flag -= 32;
                            break;
                        }
                    }
                }
                #endregion

                #region ;判断干扰最强的一阶邻区PCImod3相同
                double maxInter = 0;//最强干扰值
                int maxCid = -1;//最强干扰一阶邻区在SectorList中的索引
                for (j = 0; j < sList.sectorList[sid].faList.Count; j++)
                {//找出干扰最强的一阶邻区
                    curSID = sList.sectorList[sid].faList[j].FirAdjIndex;//一阶邻区在SectorList中的索引
                    if (sList.InterfMatrix[sid, curSID] > maxInter)
                    {
                        maxInter = sList.InterfMatrix[sid, curSID];
                        maxCid = curSID;
                    }
                }
                if (maxCid != -1 && curPCI % 3 == indivi.gene[maxCid] % 3)
                    flag -= 2;
                #endregion

                #region ;判断3层之内的对打小区同PCI
                //for (j = 0; j < sList.sectorList[sid].ly_over_List.Count; j++)
                //{
                //    curSID = sList.sectorList[sid].ly_over_List[j].LayerIndex;

                //    if (curPCI == indivi.gene[curSID])
                //    {
                //        flag -= 1;
                //        break;
                //    }
                //}
                #endregion

                #region ;判断一阶邻区PCI mod 30相同
                int k30 = 0;
                for (j = 0; k30 < 30 && j < sList.sectorList[sid].faList.Count; j++)
                {
                    curSID = sList.sectorList[sid].faList[j].FirAdjIndex;
                    if (!sList.sectorList[sid].fnNotfaIndexList.Contains(curSID))
                    {
                        k30++;
                        if (indivi.gene[curSID] != -1 && curPCI % 30 == indivi.gene[curSID] % 30)
                        {
                            flag -= 8;
                            break;
                        }
                    }
                }
                #endregion

                #region ;判断一阶邻区PCI mod 50相同
                int k50 = 0;
                for (j = 0; k50 < 50 && j < sList.sectorList[sid].faList.Count; j++)
                {
                    curSID = sList.sectorList[sid].faList[j].FirAdjIndex;
                    if (!sList.sectorList[sid].fnNotfaIndexList.Contains(curSID))
                    {
                        k50++;
                        if (indivi.gene[curSID] != -1 && curPCI % 50 == indivi.gene[curSID] % 50)
                        {
                            flag -= 16;
                            break;
                        }
                    }
                }
                #endregion

                FlagList.Add(flag);

                if (flag == 1023)
                {
                    curUse = new pciSelection(curPCI, flag);
                    usable.Add(curUse);
                }
            }
            #endregion

            #region 如果没有符合所有硬约束的PCI,则返回可用度高于一定值的PCI
            if (usable.Count == 0)
            {
                //如果没有符合条件的可用PCI
                for (i = 0; i < FlagList.Count; i++)
                {
                    //if (FlagList[i] >= 960)
                    //if (FlagList[i] >= 992)
                    if (FlagList[i] >= 1008)
                    //if (FlagList[i] >= 1016)
                    {
                        curUse = new pciSelection(candidate[i], FlagList[i]);
                        usable.Add(curUse);
                    }
                }
            }
            #endregion

            #region 如果所有PCI的可用度都不满足设定门限,返回空PCI列表
            if (usable.Count == 0)
                result = false;
            #endregion

            return result;
        }
Beispiel #2
0
        //初始化分配函数
        public bool DisSectorPCI_Mod(int sectorIndex, List<pciSelection> usable, ref Individual individual)
        {
            bool result = true;
            int threshold = 3;
            int retIndex = -1;

            #region ;更新可用PCI列表
            bool f;
            for (int i = 0; i < sList.sectorList[sectorIndex].UsablePCI.Count; i++)
            {
                f = false;
                //同站同PCI
                for (int j = 0; j < sList.sectorList[sectorIndex].coStationList.Count; j++)
                {
                    int index = sList.sectorList[sectorIndex].coStationList[j];
                    if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci == individual.gene[index])
                    {
                        f = true;
                        break;
                    }
                }
                //同站MOD3同
                if (!f && sList.sectorList[sectorIndex].coStationList.Count < 3)
                    for (int j = 0; j < sList.sectorList[sectorIndex].coStationList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].coStationList[j];
                        if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci % 3 == individual.gene[index] % 3)
                        {
                            f = true;
                            break;
                        }
                    }
                //一阶邻区同PCI
                if (!f)
                    for (int j = 0; j < sList.sectorList[sectorIndex].faList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].faList[j].FirAdjIndex;
                        if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci == individual.gene[index])
                        {
                            f = true;
                            break;
                        }
                    }

                //二阶邻区同PCI
                if (!f)
                    for (int j = 0; j < sList.sectorList[sectorIndex].saList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].saList[j].SecAdjIndex;
                        if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci == individual.gene[index])
                        {
                            f = true;
                            break;
                        }
                    }
                //3000m内小区同PCI
                if (!f)
                    for (int j = 0; j < sList.sectorList[sectorIndex].InThreeKM.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].InThreeKM[j];
                        if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci == individual.gene[index])
                        {
                            f = true;
                            break;
                        }
                    }
                //一阶邻区SSS
                if (!f)
                    for (int j = 0; j < sList.sectorList[sectorIndex].faList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].faList[j].FirAdjIndex;
                        if (individual.gene[index] != -1 && pciInfo.sssCorr[sList.sectorList[sectorIndex].UsablePCI[i].pci / 3, individual.gene[index] / 3] > pciInfo.sssThr)
                        {
                            f = true;
                            break;
                        }
                    }
                //一阶MOD6
                if (!f)
                    for (int j = 0; j < 6 && j < sList.sectorList[sectorIndex].faList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].faList[j].FirAdjIndex;
                        if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci % 6 == individual.gene[index] % 6)
                        {
                            f = true;
                            break;
                        }
                    }
                //一阶MOD50
                if (!f)
                    for (int j = 0; j < 50 && j < sList.sectorList[sectorIndex].faList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].faList[j].FirAdjIndex;
                        if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci % 50 == individual.gene[index] % 50)
                        {
                            f = true;
                            break;
                        }
                    }
                //一阶mod30
                if (!f)
                    for (int j = 0; j < 30 && j < sList.sectorList[sectorIndex].faList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].faList[j].FirAdjIndex;
                        if (individual.gene[index] != -1 && sList.sectorList[sectorIndex].UsablePCI[i].pci % 30 == individual.gene[index] % 30)
                        {
                            f = true;
                            break;
                        }
                    }

                if (f)
                    sList.sectorList[sectorIndex].UsablePCI.Remove(sList.sectorList[sectorIndex].UsablePCI[i]);
            }
            #region ;没有可用PCI时,则盗用其他段的PCI;添加一阶mod6后,无法找到合适的PCI
            if (sList.sectorList[sectorIndex].UsablePCI.Count == 0)
            {
                pciSelection t = new pciSelection();
                List<int> candidate = new List<int>();

                int isLegal;
                bool flag;

                //初始化当前小区的类型
                string celltype = sList.sectorList[sectorIndex].sectorType;
                //初始化待选PCI列表
                if (celltype == "OUTDOOR")
                    candidate = outdoor;
                if (celltype == "INDOOR")
                    candidate = indoor;
                if (celltype == "SPECIAL")
                    candidate = special;

                //获取可盗用PCI列表
                List<int> toSteal = new List<int>();
                for (int p = 0; p < 504; p++)
                    if (p < candidate[0] || p > candidate[candidate.Count - 1])
                        toSteal.Add(p);

                isLegal = 0;
                while (isLegal == 0)
                {
                    int Index = rand.Next(toSteal.Count);
                    t.pci = toSteal[Index];

                    #region ;检查是否符合硬约束
                    flag = false;
                    //同站同PCI
                    for (int j = 0; j < sList.sectorList[sectorIndex].coStationList.Count; j++)
                    {
                        int index = sList.sectorList[sectorIndex].coStationList[j];

                        if (individual.gene[index] != -1 && t.pci == individual.gene[index])
                        {
                            flag = true;
                            break;
                        }
                    }
                    //同站MOD3同
                    if (sList.sectorList[sectorIndex].coStationList.Count <= 2 && !flag)
                    {
                        for (int j = 0; j < sList.sectorList[sectorIndex].coStationList.Count; j++)
                        {
                            int index = sList.sectorList[sectorIndex].coStationList[j];
                            if (individual.gene[index] != -1 && t.pci % 3 == individual.gene[index] % 3)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    //一阶邻区同PCI
                    if (!flag)
                    {
                        for (int j = 0; j < sList.sectorList[sectorIndex].faList.Count; j++)
                        {
                            int index = sList.sectorList[sectorIndex].faList[j].FirAdjIndex;
                            if (individual.gene[index] != -1 && t.pci == individual.gene[index])
                            {
                                flag = true;
                                break;
                            }
                        }
                    }

                    //二阶邻区同PCI
                    if (!flag)
                    {
                        for (int j = 0; j < sList.sectorList[sectorIndex].saList.Count && j < 200; j++)
                        {
                            int index = sList.sectorList[sectorIndex].saList[j].SecAdjIndex;
                            if (individual.gene[index] != -1 && t.pci == individual.gene[index])
                            {
                                flag = true;
                                break;
                            }
                        }
                    }

                    //一阶邻区SSS相关系数
                    if (!flag)
                    {
                        for (int j = 0; j < sList.sectorList[sectorIndex].faList.Count; j++)
                        {
                            int index = sList.sectorList[sectorIndex].faList[j].FirAdjIndex;
                            if (individual.gene[index] != -1 && pciInfo.sssCorr[t.pci / 3, individual.gene[index] / 3] >= pciInfo.sssThr)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    #endregion

                    if (flag)
                    {
                        isLegal = 0;
                        toSteal.Remove(toSteal[Index]);
                    }
                    else
                        isLegal = 1;
                }//END of WHILE
                usable.Add(t);
                //sList.sectorList[sectorIndex].UsablePCI.Add(t);
            }//END of IF
            #endregion
            #endregion

            if (usable.Count < threshold)//随机指定
                retIndex = rand.Next(usable.Count);
            else
            {
                for (int i = 0; i < usable.Count; i++)
                    usable[i].mod = getFNmodthree(sectorIndex, usable[i].pci, individual);
                usable.Sort(SortRewrite.CompareMod);
                //寻找复用距离最远的PCI
                List<double> minDists = new List<double>();
                for (int i = 0; i < usable.Count / 2; i++)
                {//找出第i个可用PCI的最近距离
                    double minD = double.MaxValue / 10.0;
                    double sumD = 0;
                    int sameCount = 0;
                    for (int j = begSecIndex; j <= endSecIndex; j++)
                        if (usable[i].pci == individual.gene[j])
                        {
                            double d = CJWDHelper.distance(sList.sectorList[sectorIndex].Longitude, sList.sectorList[sectorIndex].Latitude, sList.sectorList[j].Longitude, sList.sectorList[j].Latitude, 0);
                            sumD += d;
                            sameCount++;
                            //if (d < minD)
                            //    minD = d;
                        }
                    if (sameCount > 0)
                        sumD /= sameCount;
                    else
                        sumD = double.MaxValue / 10.0;
                    minDists.Add(sumD);
                }
                //选定距离最远的PCI
                double maxD = 0;
                int maxInd = -1;
                for (int i = 0; i < minDists.Count; i++)
                    if (maxD < minDists[i])
                    {
                        maxD = minDists[i];
                        maxInd = i;
                    }
                retIndex = maxInd;

                if (retIndex == -1)
                    retIndex = rand.Next(usable.Count / 2);
            }
            return result;
        }