📄 falloc2.m
字号:
function PI=falloc2(x)
% Allocation process and fitness value evaluation
% Used with GA_alloc2.m file.
global MIN_offset MUL_factor MTX MAX MAXV OFFSET
% Get the numbers of items
x=10.^x; % Convert it back to the original form
x=fix(x); % Only integers allowed
I=find(x<10 & x>0); % Buying one item, the least quantity
if ~isempty(I) % is 10. Otherwise, set it to zero.
x(I)=10*ones(size(I));
end
% Get the constraint matrix--- temp with
% temp(1) : total weight
% temp(2) : total volume
% temp(3) : total cost
% temp(4) : total profit
temp=x*MTX;
PI=temp(4); % Violating each constraint, give each penalty
if temp(1)>MAXV(1), PI=PI-1000*(temp(1)-MAXV(1)); end;
if temp(2)>MAXV(2), PI=PI-1000*(temp(2)-MAXV(2)); end;
if temp(3)>MAXV(3), PI=PI-1000*(temp(3)-MAXV(3)); end;
% Increase SENSITIVITY of profit function
PI=PI-OFFSET;
% As usual
attached_part;
% Save data
if PI>MAX
MAX=PI; save tempx x % Save integers
fprintf('x=[%3i %3i %3i %3i %3i]\n',x(1),x(2),x(3),x(4),x(5));
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -