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

조회 수: 1 (최근 30일)
Zahra Moussavi
Zahra Moussavi 2016년 1월 7일
댓글: Zahra Moussavi 2016년 1월 8일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2016년 1월 7일
However it is that your routine SimOpt is getting invoked, it is not being passed any inputs. How is your routine getting invoked?
  댓글 수: 1
Zahra Moussavi
Zahra Moussavi 2016년 1월 7일
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);

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


Alan Weiss
Alan Weiss 2016년 1월 7일
편집: Alan Weiss 2016년 1월 7일
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
Zahra Moussavi
Zahra Moussavi 2016년 1월 7일
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 2016년 1월 8일
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

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

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by