2

The abstraction of my problem is that in a cartesian plane there are a lot of rectangles. These rectangles have known integer sizes and must have integer coordinates their abscissas (horizontal coordinates) are known and fixed, only their ordinates (vertical coordinates) may vary.

The problem is to find those ordinates for which the smallest rectangle that contains all the given rectangles is minimum. This means that it should have minimum height, since its width is fixed because the small rectangles have fixed abscissas.

I don't know if i should use backtracking or there is a faster way, i can imagine that at 50 rectangles it would take some measurable time to compute the correct solution and a greedy algorithm doesn't sit well with me.

Edit: I'm sorry, I now realize I wasn't clear enough. When I first asked this question I was building a calendar application. A manager would fill in events for his team:

  • event A starts from 2p.m. and ends at 4p.m.
  • event B starts from 5p.m. and ends at 6p.m.
  • event C starts from 4p.m. and ends at 6p.m.
  • event D starts from 2p.m. and ends at 3p.m.
  • event E starts from 3p.m. and ends at 5p.m.

I want to display these events on a timeline and I want them to take as little screen estate as possible, without overlapping(because the manager wants to see each event in its rectangle, and to see a description in that rectangle).

The best arrangement for the example above would be the following:

+-----+-----+
|  A  |  C  |
+---+-+-+---+
| D | E | B |
+---+---+---+

A and C are on a line, D, E, B are on another. A greedy approach would have put A and B on the same line, C and D on another line, and E on a third line.

Valentin Brasso
  • 1,388
  • 7
  • 21
  • 41
  • 1
    It is unclear just what information you have, what information you have to generate, and what constraints are on them. For instance, does abscissas mean both X (Hz) values or just the width? And you know a rectangles "size", but not its Y (Vt) values, does that mean you know its area and must infer height, or you know height but must infer the exact Y values? And are rectangles allowed to overlap? Could you please give a small example say 4-6 rectangles) that demonstrates the problem type and its solution? Thanks. – RBarryYoung Mar 09 '14 at 16:12

2 Answers2

1

If I correctly read your question, you need to find a minimum rectangle, which covers a given set of rectangles – is that right?

And since its abscissa range is fixed by the input conditions, you only need to find the ordinate range?

If so, just scan the given set of rectangles for their 'minimum bottom' and for the 'maximum top', and those will define the rectangle sought.

CiaPan
  • 9,381
  • 2
  • 21
  • 35
1

I would maintain the chronological order of events. You are building a calendar, so chronological order makes perfect sense. First show the event that starts first.

I would solve screen estate problem differently, not by repacking the elements. For instance reduce the elements size, but show a tool tip with more info when user hovers a mouse over the element. When user selects an element (with mouse click) then show complete information.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • sorry, but I can't change that requirement. The manager benefits from the arrangement that I posted: he can see how many times he has to split his team(or how little people he has to send) to attend all events. – Valentin Brasso Mar 10 '14 at 14:57