📄 ga_alloc2.m
字号:
% GA_alloc2.m file
% Find max profits of an allocation process in which we will
% find the best allocation of commodities with 5 different
% items.
% See HOMEWORK no3 for GA.doc WORD file.
% PenChen Chou, 4-17-2002
% Revised, 7-02-2002
clear all
ans=1; who
fprintf('>>>Start this program [GA_alloc2.m] now. Please wait!\n');
pause(1)
global MUL_factor MIN_offset MTX MAX MAXV OFFSET
MUL_factor=1; MIN_offset=0;
%**********************************************************/
% User can modify the following in blocks
%**********************************************************/
MAX=-400; % For saving data if condition is met in
% falloc2.m file.
OFFSET=450; % For this problem, max is over 450. We will
% increase the sensitivity of fitness function
% value by substracting the temporal max from
% 450.
% Define MTX for 5 items for purchase.
% weight vol cost profit
MTX=[300 960 5 0.8
150 450 2.5 0.35
100 250 2.0 0.25
80 200 8.5 1.3
50 150 3.0 0.35];
% MAX weight volume cost as constraints. Violating constraints
% is not allowed.
MAXV=[70000 200000 3000];
obj_fcn = 'falloc2'; % Objective function
%range = [0 0 0 0 0
% 208 444 300 300 300]; % Range of the input variables
% Convert the range into log10 scales.
range=[-1 -1 -1 -1 -1 % 10^(-1) =0.1
2.8 2.8 2.8 2.8 2.8]; % 10^(2.8)=630.95
IC=[]; elite=1;
gen_no=600;popuSize=80;
bit_n=100; % <== Large
xover_rate=0.7;
mutate_rate=0.13; % <== 0.05 to 0.2 is OK
%************************************************************
% calling GA
tic
%[popu, popu_real, fcn_value, upper, average,...
% lower, BEST_popu, popuSize, gen_no, para, best_pi]=...
% GA_genetic(obj_fcn, range, IC, elite, gen_no, popuSize,...
% bit_n, xover_rate, mutate_rate);
[popu, popu_real, fcn_value, upper, average,...
lower, BEST_popu, popuSize, gen_no, para, best_pi]=...
GA_genetic(obj_fcn, range, IC, elite, gen_no, popuSize,...
bit_n, xover_rate, mutate_rate);
t=toc/60;
fprintf('==> Computation time is (%.2f) minutes.\n\n',t);
% Calculate the last result with best x in tempx.mat file.
load tempx
temp=x*MTX;
% Print out the final result.
fprintf('The max profit=%10.2f\n',temp(4));
fprintf('The max weight=%10.2f(<=%6d)\n',temp(1),MAXV(1));
fprintf('The max volume=%10.2f(<=%6d)\n',temp(2),MAXV(2));
fprintf('The max cost =%10.2f(<=%6d)\n',temp(3),MAXV(3));
fprintf('Items=[%3i %3i %3i %3i %3i]\n',x(1),x(2),x(3),x(4),x(5));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -