gusucode.com > 遗传算法matlab源码程序 > 时间满意度遗传算法/problemgen.m
function [fixcost,demand,covermatrix,beta]=problemgen(NofD,NofF) % output parameters: fixcost,demand,covermatrix,beta % input parameters:NofD,the number of demand nodes, and NofF,the number of service nodes %===================================================================== % do some input check msg = nargchk(2,2,nargin); if ~isempty(msg) error(msg); end % any positive integer valid = isreal(NofD) && isscalar(NofD) && (NofD > 0) && (NofD == floor(NofD)); if(~valid) msg = sprintf('Number of Demand nodes must be a positive and nonnegative integer.'); error(msg); end valid = isreal(NofF) && isscalar(NofF) && (NofF >= 0) && (NofF == floor(NofF)); if(~valid) msg = sprintf('Number of Facility nodes must be a positive and nonnegative integer.'); error(msg); end %-------------------------------------------------------------------- n=NofD; m=NofF; demand=normrnd(100,50,1,n);% the amount of demand of each node demand(find(demand<0))=0;% make sure every element is nonegtive fixcost=normrnd(200,60,1,m);% the fixed cost of facility beta=unifrnd(0.5,0.9);% time satisfaction control level alfa=unifrnd(0.7,1,1,n);% time satisfaction control level ftij=zeros(n,m);%TS value generated by TS function covermatrix=ftij; tij=normrnd(130,70,n,m);% the distance matrix between demand node i and potential facility j tij(find(tij<0))=0;% make sure every element is nonegtive Li=unifrnd(20,80,1,n);% the lower bound of TS that customer at node i feel satisfied di=unifrnd(10,60,1,n); Ui=Li+di;% the upper bound of TS that customer at node i feel totally unsatisfied ki=unifrnd(0.5,1.5,1,n);% the parameter of TS function of customer i %------------------- for i=1:n for j=1:m ftij(i,j)=concavevex(tij(i,j),Li(i),Ui(i),ki(i)); if ftij(i,j)<alfa(i) covermatrix(i,j)=0; else covermatrix(i,j)=1; end end end %------------------------------------------------------------------------- % check if it is a infeasible problem covered=zeros(1,n);%covered demand points bb=sum(covermatrix,2); for i=1:n if bb(i)>=1 covered(i)=1; else covered(i)=0; end end coveD=covered*demand'; if coveD<beta*sum(demand) error('this problem does not have a feasible solution') end