'Not enough input arguments' when I am defining a function

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (2)

Walter Roberson
Walter Roberson il 7 Gen 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 Commento
Zahra Moussavi
Zahra Moussavi il 7 Gen 2016
Thanks Walter for your answer.
As I said this function is part of another one. Let me put all the code;
unction finalresults = SimOpt ()
intcon = [1];
A=[];
b=[];
Aeq=[];
beq = [];
lb = [1];
ub= [10];
inalresults= intlinprog(@f,intcon,A,b,Aeq,beq,lb,ub);
function obj = f(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
end
------------------------------------------------------
When I run the whole code I get this warning:
Error using intlinprog (line 122) INTLINPROG requires the following inputs to be of data type double: 'f'.
Error in SimOpt (line 26) finalresults= intlinprog(@f,intcon,A,b,Aeq,beq,lb,ub);

Accedi per commentare.


Alan Weiss
Alan Weiss il 7 Gen 2016
Modificato: Alan Weiss il 7 Gen 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 Commenti
Zahra Moussavi
Zahra Moussavi il 7 Gen 2016
Thanks Alan for your answer.
Well I got the idea of the simulation/optimization code from the link below:
I tried to go through all the code I see in this video but, when I am applying it, it is not working.
Zahra Moussavi
Zahra Moussavi il 8 Gen 2016
Now that I am looking at it again, I see that in the video Genetic Algorithm was used as the optimization toolbox. Will try to use that. Hopefully I can make it work.
Thanks again

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by