我正在尝试使用Matlab GA(在全局优化工具箱中)解决广义分配问题(将m个代理分配给n个任务)。为了减少计算时间,我创建了一个满足行和列约束的初始总体矩阵(MM),并将GA选项“ InitialPopulationMatrix”设置为MM。
opts = optimoptions(@ga,'InitialPopulationMatrix',MM);
但是,GA解决方案比我的最初人群差很多。首先,GA解的适合度值为7625,而在初始总体中,该值仅为496。其次,GA解决方案无法满足大多数约束条件。另外,当增加最大发电量时,GA解决方案不会变得更好,就像被卡在本地一样。
要获得良好的GA解决方案,如何通过设置一些GA选项来改善编码?
我的问题是大规模的,即m = 60,n = 145,二进制变量的数量是8700(60 * 145),赋值成本是二进制变量的函数(导致二次方)目标函数)。
下面是主要脚本:
%Parameter Setting
tic
nvars=8700;
b=[-dli;dui;-sj;sj];
lb=zeros(1,nvars);
ub=ones(1,nvars);
IntCon=[1:nvars];
%build constraint matrix
%ga evaluates the matrix product A*x as if x is transposed (A*x').
Ar=kron(eye(nShift),ones(1,nCombo));%Summation along rows of Xij can be expressed as a matrix-vector multiplication A1*XijT(:)
Ac=kron(ones(1,nShift),eye(nCombo));% Summation along columns can be expressed the same way with
%Note: for integer programming, Aeq and beq must be empty ([]), so
%equality contraints are rewritten to si<=Ac<=sj
A=[-Ar;Ar;-Ac;Ac];
nonlcon = [];
MM=IM(dli,dui,sj);
%PopulationSize: Positive integer | {50} whennumberOfVariables <= 5, {200} otherwise |{min(max(10*nvars,40),100)} for mixed-integer problems
opts = optimoptions(@ga, ...
'PopulationSize', 20, ...
'MaxGenerations', 10000, ...
'InitialPopulationRange',[0;1],...
'CrossoverFraction',0.9,...
'EliteCount',10,...
'InitialPopulationMatrix',MM,...
'PlotFcn', {@gaplotbestf,@gaplotstopping});
[x,faval,exitflag]=ga(@Obj_f,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,opts)
toc
Time=toc;
这是我用于健身功能的Obj_f.m
function [TotalV] = Obj_f(x)
%Time halo violation cost of using matrix Xij
nShift=60;
nCombo=145;
t=3;
%Convert the variable vector x to matrices with nCombo columns.
Xij=vec2mat(x,nCombo);
%Compute cij for the initial xij_Feasible matrix
Cij=[Xij;Xij(1:t-1,:)];%add the remaining t-1 element's cost into matrix Xij
[m,n]=size(Xij);
cij=zeros(m,n);
for j=1:nCombo
for i=1:nShift
cij(i,j)=sum(Cij((i:i+t-1),j));
end
end
Violation=cij.*Xij;
TotalV=sum(Violation(:));
end