'Not enough input arguments' when I am defining a function
Show older comments
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.
Answers (2)
Walter Roberson
on 7 Jan 2016
0 votes
However it is that your routine SimOpt is getting invoked, it is not being passed any inputs. How is your routine getting invoked?
1 Comment
Zahra Moussavi
on 7 Jan 2016
Alan Weiss
on 7 Jan 2016
Edited: Alan Weiss
on 7 Jan 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
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!