Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is <a href="http://en.wikipedia.org/wiki/NP-hard" rel="nofollow">NP-Hard</a>, thus the <a href="http://en.wikipedia.org/wiki/Backtracking" rel="nofollow">backtracking</a> solution [or other exponential solution as suggested by @vhallac] will be your best shot, since there is not known [and if P!=NP, there is no existing] polynomial solution for this kind of problem.</p> <p><strong>NP-Hardness proof:</strong> <br>First, we know that a rectangle consists of 4 edges, that are equal in pairs [e1=e2,e3=e4]. <br>We will show that if there is a polynomial algorithm <code>A</code> to this problem, we can also solve the <a href="http://en.wikipedia.org/wiki/Partition_problem" rel="nofollow">Partition Problem</a>, by the following algorithm:</p> <pre><code>input: a group of numbers S=a1,a2,...,an output: true if and only if the numbers can be partitioned algorithm: sum &lt;- a1 + a2 + .. + an lengths &lt;- a1, a2 , ... , an , (sum*5), (sum*5) activate A with lengths. if A answered there is any rectangle [solution is not 0], answer True else answer False </code></pre> <p><strong>Correctness:</strong> <br>(1) if there is a partition to S, let it be S1,S2, there is also a rectangle with edges: <code>(sum*5),(sum*5),S1,S2</code>, and the algorithm will yield True.</p> <p>(2) if the algorithm yields True, there is a rectangle available in lengths, since a1 + a2 + ... + an &lt; sum*5, there are 2 edges with length sum*5, since the 2 other edges must be made using all remaining lengths [as the question specified], each other edge is actually of length <code>(a1 + a2 + ... + an)/2</code>, and thus there is a legal partition to the problem.</p> <p><strong>Conclusion:</strong> There is a reduction <code>PARTITION&lt;=(p) this problem</code>, and thus, this problem is NP-Hard</p> <p><strong>EDIT:</strong> <br>the <strong>backtracking solution</strong> is pretty simple, get all possible rectangles, and check each of them to see which is the best. <br>backtracking solution: pseudo-code:</p> <pre><code>getAllRectangles(S,e1,e2,e3,e4,sol): if S == {}: if legalRectangle(e1,e2,e3,e4): sol.add((e1,e2,e3,e4)) else: //S is not empty elem &lt;- S[0] getAllRectangles(S-elem,e1+elem,e2,e3,e4,sol) getAllRectangles(S-elem,e1,e2+elem,e3,e4,sol) getAllRectangles(S-elem,e1,e2,e3+elem,e4,sol) getAllRectangles(S-elem,e1,e2,e3,e4+elem,sol) getRectangle(S): RECS &lt;- new Set getAllRectangles(S,{},{},{},{},RECS) getBest(RECS) </code></pre> <p><strong>EDIT2:</strong> <br>As discussed in the comments, this answer shows not only this is hard to find the <em>BEST</em> rectangle, it is also hard to find <em>ANY</em> rectangle, making this problem hard for <a href="http://en.wikipedia.org/wiki/Heuristic" rel="nofollow">heuristic</a> solutions as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload