CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Group Selecting

  1. #1
    Join Date
    Apr 2009
    Posts
    2

    Group Selecting

    I have a specific problem to which i need an algorithm:

    Supose there are n bags each one with a different volume, and m things to put inside the bags each one with a different volume.

    You only have two options for each thing in M
    -to put the entire thing inside a bag
    -to break the thing apart in an arbitrary number of pieces, the put the pieces each one in a bag.

    However, breaking apart is too costly and should be avoided.

    also, extra rules
    1)not always there is space in the bags for all the things. the latter ones should be forgotten after filling all the bags
    2)not always there is enough things to fill the entire bag
    3)you cannot break a thing and forget a piece of it. once you break it, all pieces must be fitted into bags
    4)prefer to solve the first things in the row.

    Example:
    bag 1 vol. 300
    bag 2 vol. 100
    bag 3 vol. 15

    things
    #1 vol. 5
    #2 vol. 250
    #3 vol. 10
    #4 vol. 200

    most correct way of the example
    #1 and #3 go to bag3
    then you break apart either #2 , filling the bag 2, and the rest on bag 1.
    now you stop, because if you break the #4 you will leave some of it way, and you can't by rule #3

  2. #2
    Join Date
    Mar 2009
    Posts
    19

    Re: Group Selecting

    In order to start thinking about an algorithm, we'd need some more information.

    Is the cost of splitting the same no matter what? For example...

    Cost(splitting 10 into 5,5) == Cost(splitting 1000 into 500,500) == Cost(splitting 5 into 1,1,1,1,1)?

    In reference to extra rule #4, what exactly does that mean? For example...

    bag 1 vol. 100

    things
    #1 vol. 1
    #2 vol. 100

    Is it better to have #1 in, or #2?

  3. #3
    Join Date
    Apr 2009
    Posts
    2

    Re: Group Selecting

    well, for your answer.
    the more parts you split, the higher the cost
    so
    Cost(splitting 10 into 5,5) = Cost(splitting 1000 into 500,500) < Cost(splitting 5 into 1,1,1,1,1).


    for the second part
    cost of leaving some bag half full< cost of leaving some thing behind < cost of spliting

    so you should put #2 into bag 1 and forget #1

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured