Finding all possible combinations of objects
이전 댓글 표시
I have 4 different obejcts with different weights each. I know the individual weights of the objects, the empty weight of the box and the total weight. Yet I do not know the number of objects. How can I find all the possible combinations of objects inside?
For example
Object1: 3 grams, Object2: 5 grams, Object3: 2 grams, Object4: 7 grams,
Empty weight of the box: 600 grams
What function may I use to find all the possible combination of objects within the box given the total weight is 850 grams?
답변 (3개)
Steven Lord
2022년 2월 27일
0 개 추천
댓글 수: 1
Torsten
2022년 2월 27일
Usually, this gives one solution, not all.
Torsten
2022년 2월 27일
Brute force:
n1 = 83;
n2 = 50;
n3 = 125;
n4 = 35;
nsol = 0;
for i = 0:n1
for j = 0:n2
for k = 0:n3
for l = 0:n4
if 3*i + 5*j + 2*k + 7*l == 250
nsol = nsol+1;
sol(nsol,1) = i;
sol(nsol,2) = j;
sol(nsol,3) = k;
sol(nsol,4) = l;
end
end
end
end
end
카테고리
도움말 센터 및 File Exchange에서 Nearest Neighbors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!