how can i make globalsearch return integer results(select the whole item and not fraction of the item) ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I have an optimization problem at which I would like to find the maximum value of the objective function at given constraints. it is easy to be described as rucksack problem, which means no fraction of the item should be selected rather the whole item should be selected.
using the GA function in matlab does solve the problem for me, yet it may find a local maximum and not the global maximum. in order to avoid this problem of GA function, I have tried to use globalsearch "gs" function in matlab.
unfortunately, I was unable to force gs function to return results containing whole items. here is my code:
%Data contain information about the item to be selected (number of columns = number of items can be selected and number of rows = number of constraints)
Data= [0.3909 0.3143 0.4323 0.3573;
0.8218 0.6681 0.6925 0.7125;
0.0002 0.0003 0.0002 0.0003;
21.0000 24.5000 31.5000 38.5000;
3.0000 7.0000 13.5000 22.0000
1 1 1 1];
Temp.Input.Aly = [1 1 1 1];
Lim = [1; 1; 1; 100; 50; 1 ];
rng default % For reproducibility
gs = GlobalSearch;
MyObj = @(x)(-1*(x(1) + x(2) + x(3) + x(4) ));
c = @(x)[x(1) + x(2) + x(3) + x(4) + x(5) - Lim(1);
x(1) + x(2) + x(3) + x(4) + x(5) - Lim(2);
x(1) + x(2) + x(3) + x(4) + x(5) - Lim(3);
x(1) + x(2) + x(3) + x(4) + x(5) - Lim(4);
x(1) + x(2) + x(3) + x(4) + x(5) - Lim(5);
x(1) + x(2) + x(3) + x(4) + x(5) - Lim(6)];
nonlinfcn = @(x)deal(c(x));problem = createOptimProblem('fmincon','x0',zeros(length(Temp.Input.Aly),1),...
'objective',MyObj,'lb',zeros(length(Temp.Input.Aly),1),'ub',Temp.Input.Aly,...
'nonlcon',nonlinfcn);
problem.options.TolCon = 1.0000e-12;
x = run(gs,problem);
so I would like the optimum selected result to be the global maximum and to be the whole item and not part of each item.
best regards,
0 comentarios
Respuestas (1)
Walter Roberson
el 3 de Dic. de 2017
fmincon() cannot be used with integer constraints. For fmincon(), the objective function must be continuous and differentiable within its limits. The same is true for all four of the searches supported by createOptimProblem: fmincon, fminunc, lsqnonlin, and lsqcurvefit .
Ver también
Categorías
Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!