Optimising data blocks - The IKEA packaging dilemma

36 Views Asked by At

In my system (for info - written in C#) there are the following concepts:

  • Data Blocks: An array of bytes
  • Groups of Data Blocks: A list containing mutiple Data blocks

They can be many Data Blocks (1000's) of various sizes. The max size allowed applies to all Data Blocks and Groups (let's call it MaxSize).
Groups have to be created out of the available Data Blocks at a given time and their total composition must not exceed MaxSize (eg. If MaxSize = 500, A Group can contain a Data Block of size 499 and one of size 1, but it cannot contain a Data Block of size 499 and one of size 2).
The idea here is to create the minimum amount of Groups out of the available Data Blocks.

Is there a Mathematical way to solve this problem while keeping the processing relatively fast (a few ms at most). If not, is there a model that would give me a relatively optimal solution. It does not have to be perfect.

I think there is an equivalent mathematical model where you try to fill in a minimum amount of boxes (of same sizes) with a bunch of balls of different sizes.
That is also the IKEA packaging dilemma when trying to minimize the packaging.