Click to See Complete Forum and Search --> : Help on Algoritm


ahvaldes
September 13th, 2003, 06:00 PM
Hi all
I am in the middle of a project and I need to develop and algoritm that allows to find the best combination of pieces of diferent sizes to fit some lenght.
Lets say that I have 4 pieces
#1 L1=250mm
#2 L2=300mm
#3 L3=410mm
#4 L4=103mm
and then I wan to know the best combination of pieces in order to achieve Lp=2400mm
Would any of you, please , can give any hint, idea,or tell me where to find information, anything that help me to solve this problem?
Thanks a lot
Ariel

CBasicNet
September 14th, 2003, 02:09 AM
Hope it may helps

Combinations in C++ (http://www.codeguru.com/algorithms/combination.html)

ahvaldes
September 16th, 2003, 07:21 PM
Thanks, I've found your article very interesting but looks like i didn't explain myself very well.
here is my problem through one example:
I have my piece
l1=250
l2=333
l3=100
l4=175
And i want to know which is the best combination of pieces to make one lenght, let's say 2700:

10*l1 + 2*l3 = 2700 >>>>>>>>error=0
27*l3 = 2700 >>>>>>>>error=0
10*l1 + l4 = 2675 >>>>>>>>error=-25

and so on
I want to have, if is possible and algoritm to get all the posible combinations whithin a range of error.
Thanks In advanced
Ariel

yiannakop
September 19th, 2003, 11:13 AM
I've written a small C program that finds all the combinations of 4 numbers whose sum is ALMOST equal to a known number L. It is rather slow (4 loops!) but I hope it works for u. U can change the constand MAX_ERROR and apply the tollerance according to your will.

I hope I understood what you wanted.

Ask me if any problems occure.

Theodore, Greece.