<p>For whatever it's worth, a straightforward, unoptimized Python implementation of the "complete Karmarkar Karp" (CKK) search procedure in [Korf88] -- modified only slightly to bail out of the search after a given time limit (say, 4.95 seconds) and return the best solution found so far -- is sufficient to score <strong>14.204234</strong> on the SPOJ problem, beating the score for Karmarkar-Karp. <strike>As of this writing, this is <a href="http://www.spoj.com/ranks/JOHNNY/" rel="nofollow noreferrer">#3 on the rankings</a></strike> (<strong><em>see Edit #2 below</em></strong>)</p>

<p>A slightly more readable presentation of Korf's CKK algorithm can be found in [Mert99]. </p>

<hr>

<p><strong>EDIT #2</strong> - I've implemented <a href="https://stackoverflow.com/a/32467262/594729">Evgeny Kluev's</a> hybrid heuristic of applying Karmarkar-Karp until the list of numbers is below some threshold and then switching over to the exact Horowitz-Sahni subset enumeration method [HS74] (a concise description may be found in [Korf88]). As suspected, my Python implementation required lowering the switchover threshold versus his C++ implementation. With some trial and error, I found that a threshold of 37 was the maximum that allowed my program to finish within the time limit. Yet, even at that lower threshold, I was able to achieve a score of <strong>15.265633</strong>, good enough for <a href="http://www.spoj.com/ranks/JOHNNY/" rel="nofollow noreferrer">second place</a>. </p>

<p>I further attempted to incorporate this hybrid KK/HS method into the CKK tree search, basically by using HS as a very aggressive and expensive pruning strategy. In plain CKK, I was unable to find a switchover threshold that even matched the KK/HS method. However, using the ILDS (see below) search strategy for CKK and HS (with a threshold of 25) to prune, I was able to yield a very small gain over the previous score, up to <strong>15.272802</strong>. It probably should not be surprising that CKK+ILDS would outperform plain CKK in this context since it would, by design, provide a greater diversity of inputs to the HS phase.</p>

<hr>

<p><strong>EDIT #1</strong> - 
I've tried two further refinements to the base CKK algorithm:</p>

<ol>
<li><p>"Improved Limited Discrepancy Search" (ILDS) [Korf96] This is an alternative to the natural DFS ordering of paths within the search tree. It has a tendency to explore more diverse solutions earlier on than regular Depth-First Search. </p></li>
<li><p>"Speeding up 2-Way Number Partitioning" [Cerq12] This generalizes one of the pruning criteria in CKK from nodes within 4 levels of the leaf nodes to nodes within 5, 6, and 7 levels above leaf nodes. </p></li>
</ol>

<p>In my test cases, both of these refinements generally provided noticeable benefits over the original CKK in reducing the number of nodes explored (in the case of the latter) and in arriving at better solutions sooner (in the case of the former). However, within the confines of the SPOJ problem structure, neither of these were sufficient to improve my score. </p>

<p>Given the idiosyncratic nature of this SPOJ problem (i.e.: 5-second time limit and only one specific and undisclosed problem instance), it is hard to give advice on what may actually improve the score<sup>*</sup>. For example, should we continue to pursue alternate search ordering strategies (e.g.: many of the papers by Wheeler Ruml <a href="http://www.cs.unh.edu/~ruml/papers/index.html" rel="nofollow noreferrer">listed here</a>)? Or should we try incorporating some form of local improvement heuristic to solutions found by CKK in order to help pruning? Or maybe we should abandon CKK-based approaches altogether and try for a dynamic programming approach? How about a PTAS? Without knowing more about the specific shape of the instance used in the SPOJ problem, it's very difficult to guess at what kind of approach would yield the most benefit. Each one has its strengths and weaknesses, depending on the specific properties of a given instance. </p>

<p><sup>*</sup> <em>Aside from simply running the same thing faster, say, by implementing in C++ instead of Python.</em></p>

<hr>

<h2>References</h2>

<p>[Cerq12] Cerquides, Jesús, and Pedro Meseguer. "Speeding Up 2-way Number Partitioning." ECAI. 2012, doi:<a href="http://dx.doi.org/10.3233/978-1-61499-098-7-223" rel="nofollow noreferrer">10.3233/978-1-61499-098-7-223</a></p>

<p>[HS74] Horowitz, Ellis, and Sartaj Sahni. "<a href="http://www.cise.ufl.edu/~sahni/papers/computingPartitions.pdf" rel="nofollow noreferrer">Computing partitions with applications to the knapsack problem.</a>" Journal of the ACM (JACM) 21.2 (1974): 277-292.</p>

<p>[Korf88] Korf, Richard E. (1998), "<a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.90.993" rel="nofollow noreferrer">A complete anytime algorithm for number partitioning</a>", Artificial Intelligence 106 (2): 181–203, doi:<a href="https://dx.doi.org/10.1016%2FS0004-3702%2898%2900086-1" rel="nofollow noreferrer">10.1016/S0004-3702(98)00086-1</a>,</p>

<p>[Korf96] Korf, Richard E. "<a href="http://www.aaai.org/Papers/AAAI/1996/AAAI96-043.pdf" rel="nofollow noreferrer">Improved limited discrepancy search</a>." AAAI/IAAI, Vol. 1. 1996.</p>

<p>[Mert99] Mertens, Stephan (1999), A complete anytime algorithm for balanced number partitioning, arXiv:<a href="https://arxiv.org/abs/cs/9903011" rel="nofollow noreferrer">cs/9903011</a></p>
Better results in set partition than by differencing
<p><a href="https://en.wikipedia.org/wiki/Partition_problem">Partition problem</a> is known to be NP-hard. Depending on the particular instance of the problem we can try dynamic programming or some heuristics like differencing (also known as Karmarkar-Karp algorithm).</p>

<p>The latter seems to be very useful for the instances with big numbers (what makes dynamic programming intractable), however not always perfect. What is an efficient way to find a better solution (random, tabu search, other approximations)?</p>

<p>PS: The question has some story behind it. There is a challenge <a href="http://www.spoj.com/problems/JOHNNY/">Johnny Goes Shopping</a> available at SPOJ since July 2004. Till now, the challenge has been solved by 1087 users, but only 11 of them scored better than correct Karmarkar-Karp algorithm implementation (with current scoring, Karmarkar-Karp gives 11.796614 points). How to do better? (Answers supported by accepted submission most wanted but please do not reveal your code.) </p>