Info
此问题已关闭。 请重新打开它进行编辑或回答。
Generating random number with constrainsts
1 次查看(过去 30 天)
显示 更早的评论
I am trying to generate population for an evolutionary algorithm, subject to two constraints, Σp + ϵ < 1 and Φ * μ - λ*p > 0, I have written following code to generate number which follow above constraints but behavior is not consistent with respect to ratio ( r = λ/u). Some time it works fine but if I change value of r above certain value it cannot produce feasible population. I need to run a simulation where r ranges from 0.2 to 0.9, I would highly appreciate any help in this regard.
count =1;
varSize =[100,1];
r=0.7; % other values 0.4, 0.7,0.8; r=0.6 & below produces feasible results
epsilon = 0.0000001;
for i=1:1000000
p = rand(varSize); % 0 ~ 1
phi= rand(varSize); % 0 ~ 1
a=1;b=2; u= a + (b-a) * rand(varSize); % 1 ~ 2
lamda= r*sum(u); % r = lamda/u
x1= rand(varSize); x1 =min(rand(varSize), (phi.*u/lamda)+epsilon);
p_out=x1/sum(x1);
status = chk_voilation(lamda, phi, u, p_out); % to check feasibility
if status ==1
count = count+1;
end
end
disp(count); disp(lamda)
function status = chk_voilation(lamda, phi, u, p)
c = (phi.*u -lamda* p)>0 ;
if all(c == 1)
status=1;
else
status=0;
end
end
0 个评论
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!