Finding optimal height for objects in 2D packing

63 Views Asked by At

I have a problem that I need to find the right algorithm for and I am not sure which avenues are going to be easiest.

I have a 'row' of fixed height and we can assume infinite length.

fig.1

-------------------> X we can assume is infinite
^
| Y is fixed.
v
-------------

Then I have a series of objects that need to fill vertically the 'row' and that have a fixed horizontal position.

fig2.

---------------
 |--1--|
    |---3---|
 |----2----|
---------------

fig3.

----------------------
 |--1--|  |----3----|
    |---2---|     
----------------------

So as we see. In fig 2 the maximum allowed height for the objects in our 'row' are 1/3 as all objects overlap, the vertical order is not important. In fig 3 they are 1/2, as only 1 and 2 and 2 and 3 overlap, vertical order therefore puts 1 and 3 in the same vertical position and 2 in a vertical position of its own.

Is there one or a set of algoritms that I should be looking into to help solve this problem? The ones I have read about tend to assume fixed sizes of objects and space, and that order of the packing is not important.

This is for a calendar control built in software, so will need to accomodate best guess and some limitations that I don't mind working out. I appereciate that this is an NP problem and if a lot of overlaps occur into the 'future' there might be NO viable solution.

Any help would be very warmly recieved!