Unless your problems have extra constraints, then refusing to swap more than one at a time will allow you to get stuck in a local minima, and never find the true solution.

For example, if you have a capacity/goal of 10, and your current solution is [6], with leftovers of [1,2,3,4] No single swap will improve your score, but trading your single value for all the leftovers would get you a perfect score.

In a similar way, [5,2] with [4,4] left over, and a max and goal of 8. Swapping the 5 for a 4 makes it worse. Swapping the 2 for a 4 puts you over the max. N-to-1 swaps and 1-to-N swaps also fail. The only way to get the optimal solution without making the intermediate solution worse is a 2-for-2 swap.


In reply to Re: Exchange Heuristic and Swapping Code by SuicideJunkie
in thread Exchange Heuristic and Swapping Code by nat47

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.