How do I make simulation/optimization work in Matlab?

266 Views Asked by At

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 an optimization function. I got the idea of the simulation/optimization code from the link below:

http://au.mathworks.com/videos/optimizing-manufacturing-production-processes-68961.html

I tried to go through all the code I see in this video but, when I am applying it, it is not working. Here is my code:


function finalresults = SimOpt ()

intcon = [1];

A=[];

b=[];

Aeq=[];

beq = [];

lb = [1];

ub= [10];

finalresults= 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);


Any help will be appreciated.

1

There are 1 best solutions below

1
On

Change the last line in the function to

obj = waiting * 1000.0 + cost

MATLAB and many other HLLs convert data type to integer if multiplied by an integer type constant value. So it is necessary to multiply the constant as double type by adding a decimal point.