Optimization problem with array input
Show older comments
Guys i need to figure out the algorithm to model a question. Question is here: I have to pickup 30 balls that are in 10 different colors. Number of the balls are in the first column of the input matrice. Only requirement here is i have to pick at least one for each color.Every balls have different numbers of holes and spike on them. These are column 2 and 3 input. The sum of the holes must be 100. I want to solve for min and max spike conditions. What is the algorithm here? I tried to assign coefficients but that doesn't seem like it works. I could solve with 10 for loops but the sizes of arrays differ from 5 to 150. It takes about 3 days to execute. I kinda search for fmincon for discrete array inputs. Thanks!
6 Comments
MEHMET SAHIN
on 25 Dec 2023
I have 10 separate matrices in .xlsx format for each color.Like c1(5,3) & c2(150,3) & c3(58,3) etc.
John D'Errico
on 25 Dec 2023
Edited: John D'Errico
on 25 Dec 2023
You CANNOT use fmincon. fmincon does not apply to discrete problems, Period. You might decide to try GA, but your question is still to vague to understand it. No matter what, this problem is never going to be solvable using brute force loops.
An example matrix with your data in it might help. For example, do all red balls have the same number of holes and spikes?
MEHMET SAHIN
on 25 Dec 2023
Edited: MEHMET SAHIN
on 25 Dec 2023
% for yellow balls
% Number of balls as package, number of holes on each,number of spikes on
% each
a = [3 5 36;1 5 25;2 8 2;4 7 23;8 22 8;8 2 7;5 12 98;6 15 5];
% for black balls
% Number of balls as package, number of holes on each,number of spikes on
% each
b = [3 3 3;1 6 6;2 8 2;3 5 2;3 11 5;8 5 31;7 6 7;9 3 8;8 4 9;2 20 3;3 4 51];...
%constraints
for aa=1:height(a)
for bb=1:height(b)...
tot_num_balls=a(aa,1)+b(bb+1);... % must be equal to 30
tot_holes=a(aa,1).*a(aa,2)+b(bb,1).*b(bb,2);... % must be equal to 100
tot_spikes=a(aa,1).*a(aa,3)+b(bb,1).*b(bb,3);... % search for min and max values
end
end
MEHMET SAHIN
on 25 Dec 2023
Edited: MEHMET SAHIN
on 25 Dec 2023
i pick balls as packages like trio,duo, single etc. For example, as indicated in the first row of a, I have 3 balls that have 5 holes and 36 spikes on each and i cannot divide them. So i have 2 choices here:
(0) Do not pick -- 0 balls 0 hole 0 spike
(1) Pick -- 3 balls 15 holes 108 spikes
Accepted Answer
More Answers (0)
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!