'Not enough input arguments' when I am defining a function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I am trying to link SimEvent and the optimization module of MATLAB. For that, I first need to define a function that runs the simulation then call it in the optimization function that I will define later. But I am getting the "not enough arguments" when defining the function. And I cannot fix it! here is my code and the warning:
function obj = SimOpt(vecX)
NumServers = vecX(1);
NumTruck = vecX(2);
set_param('concreting10/Positioning and Unloading','NumberOfServers',num2str(NumServers));
set_param('concreting10/Washing','NumberOfServers',num2str(NumTruck));
simOut = sim('concreting10','SaveOutput','on','OutputSaveName','WaitingTimeInQueue');
z = simOut.get('WaitingTimeInQueue');
waiting = max(z);
cost = [100 200]*vecX';
obj = waiting*1000+cost;
end
-----------------------------------------------------------
Not enough input arguments.
Error in SimOpt (line 31) NumServers = vecX(1);
-------------------------------------------------------
Would appreciate any help.
0 comentarios
Respuestas (2)
Walter Roberson
el 7 de En. de 2016
However it is that your routine SimOpt is getting invoked, it is not being passed any inputs. How is your routine getting invoked?
1 comentario
Alan Weiss
el 7 de En. de 2016
Editada: Alan Weiss
el 7 de En. de 2016
I think that you have a misunderstanding about what intlinprog does. It does NOT minimize nonlinear functions, such as a function that is the result of a simulation. It minimizes a LINEAR function of a variable x, such as
f(1)*x(1) + f(2)*x(2) + ... + f(N)*x(N)
where the f vector is a constant numeric vector. You appear to be attempting to minimize a nonlinear function by passing a function handle @f, and that is why you get an error.
It is possible that you are trying to minimize a nonlinear function while restricting x(1) to be integer-valued. If that is the case, then I recommend that you minimize using fmincon or fminunc with the value of your x(1) variable set manually to various integer values. You can easily program a search over a one-dimensional integer range, especially since it looks like you want x(1) to go from 1 to 10.
Alan Weiss
MATLAB mathematical toolbox documentation
2 comentarios
Ver también
Categorías
Más información sobre Genetic Algorithm en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!