optimization - Algorithm for optimal combinations to cut -


input: have master length of 10m , have products need cut in 3m, 4m, 5m dimensions.

i tried writing algorithm generate following table me (optimal lengths):

3m 4m 5m waste 3  0  0  1 2  1  0  0 1  0  1  2 0  1  1  1 0  2  0  2 0  0  2  0 

i understand how works don't know how turn code.

i need pseudocode or (am supposed use recursion)?

here's naive attempt. exhaustive search within known limits.

masterlength = 10  print "3m 4m 5m waste"  l3m = 0 floor(masterlenth/3) {     l4m = 0 floor(masterlength/4)     {         l5m = 0 floor(masterlength/5)         {             usedlength = l3m*3 + l4m*4 + l5m*5             waste = masterlength - usedlength             if (waste<3 , waste>=0)             {                 print l3m,l4m,l5m,waste             }         }     } } 

[edit] slight improvement, reducing search space.

print "3m 4m 5m waste"  masterlength = 10 remaining = masterlength  l3m = 0 floor(remaining/3) {     remaining = remaining-l3m*3     l4m = 0 floor(remaining/4)     {         remaining = remaining-l4m*4         l5m = 0 floor(remaining/5)         {             waste = remaining - l5m*5             if (waste<3 , waste>=0)             {                 print l3m,l4m,l5m,waste             }         }     } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -