Error parsing function variables
Mostrar comentarios más antiguos
Hello, please I need your help in debugging my code. I have added a snippet of the code because is too cumbersome to include here, but I believe that with this snippet, you may be able to advise me accordingly. Given the error, where could my problem arise from?
PS: water_pipe_length, sewer_pipe_length are arrays of over 10000 elements
The error displayed is:
Not enough input arguments.
Error in Optimization>@(r,p)[AG_LCC_MUT(r,p),AG_S(r,p)] (line 272)
MultiObj.fun = @(r,p) [AG_LCC_MUT(r,p), AG_S(r,p)];
Error in NSGAII (line 57)
Pfit = fun(P);
Error in Optimization (line 283)
NSGAII(params,MultiObj);
N = 50; %Planning period (years)
r = linspace(0.3,0.6,4); %discount rate
p = [5,6]; %frequency of maintenance
no_of_comp = [1,2,3];
OMC = @(r,p)compound_t(p,r,C4,Cr,C3,water_pipe_length(n),sewer_pipe_length(n),N);
MC = @(r,p)compound_Syn(p,r,C4,Cr,C3,assets_category(n),water_pipe_length(n),sewer_pipe_length(n),pavement_area(n),N); %Maintenance cost
AG_LCC_MUT = @(r,p) ICC + MUT_Req + C_rep + C_ist + OMC;
AG_S = @(r,p) MC/(1+r).^-N;
MultiObj.fun = @(r,p) [AG_LCC_MUT(r,p), AG_S(r,p)];
MultiObj.nVar = 2;
MultiObj.var_min = -pi.*ones(1,MultiObj.nVar);
MultiObj.var_max = pi.*ones(1,MultiObj.nVar);
params.Np = 200; % Population size
params.pc = 0.9; % Probability of crossover
params.pm = 0.5; % Probability of mutation
params.maxgen = 100; % Maximum number of generations
params.ms = 0.05; % Mutation strength
% NSGA-II algorithm
NSGAII(params,MultiObj);
%% Functions
% Function to calculate (1+r)^50 for any utility
function [U] = compound_t(p,r,C4,Cr,C3,water_pipe_length,sewer_pipe_length,N)
%AA/p +
d5 = 0; %damage state after 5 years
detr = 0; %deterioration rate
U = 0;
for ii = 1:N
d = unifrnd(0:1/p,1);%select damage state per year
dr = unifrnd(0:1/N,1);%select deterioration rate per year
detr = detr + dr; %update deterioration rate
d5 = detr*(d5+d); %add the damage per year for p years
U = U+((C4*water_pipe_length)./p + d5*Cr*water_pipe_length+(C3*sewer_pipe_length)./p + d5*Cr*sewer_pipe_length)./((1+r).^ii);
end
end
function [U] = compound_Syn(p,r,C4,Cr,C3,assets_category,water_pipe_length,sewer_pipe_length,pavement_area,N)
%AA/p +
d5 = 0; %damage state after 5 years
detr = 0; %deterioration rate
U = 0;
if strcmp(assets_category,'E')%assets_category == 'E'
pave_cons_cost = 125; %Pavement construction cost
pave_off_facil_cost = 210; %Pavement off facility cost
else
pave_cons_cost = 150;
pave_off_facil_cost = 245;
end
for ii = 1:N
d = unifrnd(0:1/p,1);%select damage state per year
dr = unifrnd(0:1/N,1);%select deterioration rate per year
detr = detr + dr; %update deterioration rate
d5 = detr*(d5+d); %add the damage per year for p years
U = U+((C4*water_pipe_length)./p + d5*Cr*water_pipe_length+(C3*sewer_pipe_length)./p + d5*Cr*sewer_pipe_length+...
(pavement_area*pave_cons_cost)+(pavement_area*pave_off_facil_cost))./((1+r).^ii);
end
end
2 comentarios
KSSV
el 16 de Ag. de 2022
You need to attach the function: NSGAII. When we run the code the error we get is:
Unrecognized function or variable 'NSGAII'.
Error in Junk (line 21)
NSGAII(params,MultiObj);
Walter Roberson
el 16 de Ag. de 2022
Editada: Walter Roberson
el 16 de Ag. de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!