Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Kind, Gentle Folk,

I have a need to sort a bunch of geometric boxes in two ways, and I'm not sure how to do it in perl efficiently. Here are the starting conditions of this problem:-

1. I have a text string (the name of a box)

2. I have the lower left coordinates of a box

3. I have the upper right coordinates of a box

4. I have the area of a box

I have several million overlapping boxes within the area of one large, master box. Here is what I need to do:-

1. Sort all of the areas, from largest to smallest

2. Once the sort completes, I need the N largest boxes that do not overlap at all.

I am not looking for a detailed solution, just a rough idea on the best approach. Can someone help fill in these blanks?

%NetAreaHash = (); $LL = join (" ",$MinX,$MinY); #$MinX and $MinY are decimals $UR = join (" ",$MaxX,$MaxY); #$MaxX and $MaxY are decimals $Area = abs($MaxX - $MinX) * abs($MaxY - $MinY); $NetAreaHash{$Area} = join (" ",$NetName,$LL,$UR,$Area); #$NetName is +a string #how do I numerically sort $NetAreaHash by $Area? #how do I take the sorted $NetAreaHash and identify the N largest area +s that do not overlap? N will usually be 2, 4 or 8.

Again, I'm just looking for some guidance here. The numerical sort of the hash probably won't be that tough, but identifying the N largest, non-overlapping boxes has me stumped at the moment!

Thanks,

Fiddler42


In reply to Sorting hashes... by fiddler42

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-04-19 00:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found