Can intlinprog optimize a custom function?

2 views (last 30 days)
Good Morning.
I'm trying to optimize a function that has one return value and 25 parameters (which must be integers and positives).
Inside this function there is a call to a Simulink simulation.
I tried to do the optimization using genetic algorithm (code below), but this one did not converge, it was "stuck" to only one result.
% Defining non-negativity constraints
A = eye(25)*-1;
b = zeros(25,1);
% Calling G.A. with non-negativity constraints and defining that all 25 variables must be integers
x = ga(@OtimizaKanban,25,A,b,[],[],[],[],[],[1:25])
The function to be optimized is as follows:
function [Faval] = OtimizaKanban(X)
time = 365.0;
% Matéria-Prima
qtdMateriaPrima = [X(1,1), X(1,2), X(1,3), X(1,4)];
tempoProdMateriaPrima = [0.1, 0.08, 0.1, 0.08];
tempoEntMateriaPrima = [1, 0.5, 1, 0.5];
% Kanbans
nroKabansRetPeca = [X(1,5), X(1,6), X(1,7), X(1,8), X(1,9), X(1,10), X(1,11), X(1,12), X(1,13), X(1,14)];
nroKabansProcPeca = [X(1,15), X(1,16), X(1,17), X(1,18), X(1,19), X(1,20), X(1,21), X(1,22), X(1,23), X(1,24)];
nroKabansProcMontagem = X(1,25);
% Capacidade de Produção
tempoProdPeca = [2, 1.5, 2, 1.5, 1.5, 2, 1.5, 2, 1.5, 1.5];
tempoTransPeca = [1, 0.5, 1, 0.5, 0.5, 1, 0.5, 1, 0.5, 0.5];
tempoMontagemProd = 0.6;
demandaDiariaMesAno = [1, 2, 5, 10, 10, 5, 3, 2, 2, 2, 1, 1];
options = simset('SrcWorkspace','current');
sim('Kanban_Complex',[],options);
Faval = n_sol_descartadas(end)
Would there be some way to do this using intlinprog??

Accepted Answer

Alan Weiss
Alan Weiss on 18 Jul 2017
Don't give bounds by linear inequalities. Use the lb (and ub) arguments instead:
lb = zeros(25,1);
x = ga(@OtimizaKanban,25,[],[],[],[],lb,[],[],[1:25])
And the answer to your question: no, intlinprog optimizes only linear objective functions. Sorry.
Depending on your simulation, I would imagine that ga would take a very long time to iterate. I suggest that you set a plot function to monitor the iterations, such as @gaplotbestf:
options = optimoptions('ga','PlotFcn',@gaplotbestf);
x = ga(@OtimizaKanban,25,[],[],[],[],lb,[],[],[1:25],options)
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (1)

João Ricardo  Braga de Paiva
Thanks for the reply Alan Weiss. Since intlinprog can not do what I'm needing, which optimizer would you recommend?
  1 Comment
Alan Weiss
Alan Weiss on 18 Jul 2017
We don't have any good MINLP solvers for problems of that size. It is hard to find a good algorithm to optimize a simulation with 25 integer parameters.
You can try patternsearch, but I don't know that it will do well. Start it at a positive integer point, set the ScaleMesh option to false, the InitialMeshSize option to a power of 2 such as 2 or 4 or so (depends on what you think will be a reasonable value), and MeshTolerance to be something just under 1, such as 0.75. Use the default PollMethod. In this way, patternsearch will search just positive integer points. However, it is not guaranteed to reach a global minimum, so you might have to restart it from a different positive integer point. And you might want to set the (justly discouraged, but for this case maybe appropriate) Cache option to 'on'. And maybe set the PollOrderAlgorithm option to 'Random' or 'Success', but I don't really know. If you choose to set the UseCompletePoll option to true, then the poll order doesn't matter.
Sorry that we don't have anything better for you at the moment.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!