multiple variable optimization GA

조회 수: 3 (최근 30일)
MANANJAYA NAYAK
MANANJAYA NAYAK 2023년 2월 8일
댓글: MANANJAYA NAYAK 2023년 2월 8일
A = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37]; % Activity set
predecessor = [0 1 1 2 2 3 5 4 6 7 8 9 10 12 13 11 14 15 17 16 18 19 14 15 18 21 19 18 22 23 24 25 26 28 29 20 20 25 31 32 33 35 36]; % Predecessor relationship
t = [0 15 11 20 21 12 10 10 7 10 9 12 10 10 7 7 15 7 7 14 10 14 7 7 3 7 15 4 10 1]; % Time (day)
r = [0 2 2 4 5 2 2 4 4 5 4 4 5 5 4 4 2 4 4 4 3 4 5 3 2 4 4 1 2]; % Resource requirement (employee)
c = [0 3000 2200 8000 10500 4800 2000 3000 4000 2800 3600 6000 4000 5000 2800 2800 6000 2800 4200 4000 2800 4200 2100 2800 6000 2900 1400 900 3000 2800 1000 100]; % Direct cost
K = 30; % Available resource
T = 185; % Available time
% Define the objective function
fun = @(x) [sum(c.*x) sum(t.*x)]; % Minimize the total cost and time
% Define the constraints
Aeq = zeros(37, 37); % Initialize the equality constraint matrix
for i = 1:37
Aeq(predecessor(i)+1, i) = 1;
end
beq = ones(37, 1); % Equality constraint right-hand side
lb = zeros(37, 1); % Lower bound for binary constraint
ub = ones(37, 1); % Upper bound for binary constraint
nonlcon = @(x) deal([sum(r.*x) - K; sum(t.*x) - T], []); % Nonlinear constraint
% Call the genetic algorithm solver
options = gaoptimset('PlotFcns', {@gaplotpareto}); % Plot the Pareto front
[x, fval] = gamultiobj(fun, 37, [], [], Aeq, beq, lb, ub, nonlcon, options);
% Display the results
disp('Selected activities:');
disp(A(x == 1));
disp('Total cost:');
disp(fval[1]);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
disp('Total time:');
disp(fval(2));
%% i am geeting an error in disp(fval[1]); & disp(fval(2));

답변 (1개)

Divyank
Divyank 2023년 2월 8일
Hello @MANANJAYA NAYAK, I believe the error is caused due to incorrect use of square brackets. To access elements of a matrix, you should use parentheses instead of square brackets.
Try changing the following line of code:
disp(fval[1]);
to:
disp(fval(1));
  댓글 수: 3
Divyank
Divyank 2023년 2월 8일
It seems that the optimization problem is infeasible and the solver is not able to find a feasible solution that satisfies the constraints. The issue could be with the equality constraint matrix, Aeq, or the constraint tolerance set in the options. It's also possible that the nonlinear constraint is not well-formed. I would suggest double-checking these parts of the code to see if there are any errors or omissions.
MANANJAYA NAYAK
MANANJAYA NAYAK 2023년 2월 8일
NO IN CODING OR IN VALUE DECLATION NO ERROR IS THERE

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by