用遗传算法求解信道分配问题,算法不收敛

[复制链接]
查看11 | 回复3 | 2021-1-27 06:48:00 | 显示全部楼层 |阅读模式
我做毕设,用遗传算法求解信道分配问题,但算法的结果不收敛,不知道什么原因,请教各位。
一、信道分配问题建模
1.n个小区,m个信道,M个用户,各小区所分配的信道数为Di,且Di之和等于M
2.n个小区之间存在信道干扰,用二维对称矩阵Cij表示,Cij=0表示不存在干扰。
3.n*m的信道分配矩阵F,Fij=1表示信道j分配给小区i使用,Fij=0表示信道j未分配给小区i使用
将m个信道分配给n个小区,要求满足小区之间的干扰最小。
二、遗传算法
1.对整个分配矩阵进行编码,二进制编码方式,一个解对应遗传算法中的一个个体。因为考虑到各小区的同小区干扰和信道需求,采用了一种最小间隔的编码方式,减少了解空间。
2、交叉、变异操作针对上述编码方式做了修改,以保证交叉和变异后各小区的同小区干扰和信道需求仍然满足
3、每代种群中适应度最高的个体(信道分配矩阵)作为系统的最优解
三、问题
1、算法不收敛,不论如何设置种群大小还是迭代次数,算法都未收敛
算法是用c#编写的,是在了解了遗传算法原理的基础上开发的,未参考一些遗传算法库,代码我

分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:48:00 | 显示全部楼层
代码传不上来,我就把代码贴到这儿,主要分三个类:
首先是染色体类:Individul
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Collections;
usingSystem.Text;
namespaceGA2
{
classIndividul
{
publicintcellNum;
publicintchanNum;
publicint[][]matrix;//信道分配矩阵
publicint[][]compactMatrix;//采用最小间隔编码后的信道分配压缩矩阵,方便交叉和变异操作
publicint[]demind;//信道需求向量
publicintcost;//代价函数
publicintfitness;//个体适应度
publicint[][]constrains;//指向干扰约束的矩阵
privateStackfilo;
publicstaticRandomrnd=newRandom();
publicIndividul()
{
matrix=null;
compactMatrix=null;
demind=null;
rnd=null;
cost=0;
constrains=null;
demind=null;
filo=null;
}
publicIndividul(intn,intm,int[]d,int[][]c)
{
if(d==null||c==null)
return;
cellNum=n;
chanNum=m;
demind=d;
constrains=c;
matrix=newint[n][];
compactMatrix=newint[n][];
for(inti=0;i=0;j--)
{
//Console.WriteLine(vec[j]);
intindex=0;
if(j>=1)
index=vec[j]+j*(constrains-1);
else
index=vec[j];
if(index>=chanNum)
matrix[chanNum-1]=1;
matrix[index]=1;
}
}
/*
Console.WriteLine("allocationmatrixis:");
ShowAllocMatrix();
Console.WriteLine('\n');
Console.WriteLine("compactallocationmatrixis:");
ShowCompactMatrix();
*/
}
//将用最小间隔编码后的压缩矩阵转化为信道分配矩阵
publicvoidCompactMatrix2Matrix()
{
for(inti=0;i=0;j--)
{
if(compactMatrix[j]==1)
{
intindex=0;
if(demand>=1)
index=j+(demand-1)*(constrains-1);
else
index=j;
if(index>=chanNum)
matrix[chanNum-1]=1;
else
matrix[index]=1;
demand--;
}
}
}
}

回复

使用道具 举报

千问 | 2021-1-27 06:48:00 | 显示全部楼层

//显示采用最小间隔编码后的压缩信道分配矩阵
publicvoidShowCompactMatrix()
{
for(inti=0;i0;j++)
{
for(intk=0;k0)
{
for(intl=(k-(constrains[j]-1)>0?k-(constrains[j]-1):0);
l0)
cost++;
}
}
}
}
}
fitness=cellNum*chanNum-cost;
returncost;
}
//交叉辅助函数,rno:染色体交叉操作的行号,sindex:交叉开始位置,eindex交叉结束位置
privatevoidCrossOverHelp(Individulind,intrno,intsindex,inteindex)
{
for(inti=sindex;ir2)
{
tmp=r1;
r1=r2;
r2=tmp;
}
//c1和c2为随机生成的列号
intc1=rnd.Next(compactMatrix[r1].Length);
intc2=rnd.Next(compactMatrix[r2].Length);
if(r1!=r2)
{
CrossOverHelp(ind,r1,c1,compactMatrix[r1].Length-1);
for(inti=r1+1;i=0;j--)
{
if(compactMatrix[r][j]==1)
{
intindex=0;
if(demand>=1)
index=j+(demand-1)*(constrains[r][r]-1);
else
index=j;
if(index>=chanNum)
matrix[r][chanNum-1]=1;
else
matrix[r][index]=1;
demand--;
}
}
}
}
}

回复

使用道具 举报

千问 | 2021-1-27 06:48:00 | 显示全部楼层
另外一个是种群类:Population,代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Collections;
usingSystem.Text;
namespaceGA2
{
classPopulation
{
publicintpopSize;//种群数目,须为偶数
publicdoublepcross;//交叉概率
publicdoublepmutate;//变异概率
publicinttotalFitness;//种群总适应度
publicintcellNum;
publicintchanNum;
publicintbestCost;//个体中最好的适应度
publicintbestCostInd;//具有最好适应度个体的编号
publicintmaxIteNum;//迭代次数
publicList[I]population;
publicList[I]newPopulation;
publicPopulation(intsize,doublepc,doublepm,intite)
{
popSize=size;
pcross=pc;
pmutate=pm;
maxIteNum=ite;
population=newList[I]();
newPopulation=newList[I]();
}
publicvoidInitPop(intcell,intchan,int[]dem,int[][]cons)
{
cellNum=cell;
chanNum=chan;
totalFitness=0;
bestCost=0;
bestCostInd=0;
for(inti=0;i
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行