18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

War Story: Psychic Modeling<br />

have purchased at least one ticket that contains it.<br />

● For each new ticket we decided to buy, we would need to keep track of which prize combinations we have thus far<br />

covered. Presumably, we would want to buy tickets to cover as many thus-far-uncovered prize combinations as<br />

possible. <strong>The</strong> currently covered combinations are a subset of all possible combinations, so we would need a data<br />

structure to represent the subset. Such data structures are discussed in Section . <strong>The</strong> best candidate seemed to be a<br />

bit vector, which would permit a constant time query of ``is this combination already covered?'' in concert with a<br />

way to rank the subset, i.e. hash it to a unique integer.<br />

● We would need a search mechanism to decide which ticket to buy next. For small enough set sizes, we could do an<br />

exhaustive search over all possible subsets of tickets and pick the smallest one. For larger sizes, a randomized search<br />

process like simulated annealing (see Section ) would select tickets-to-buy to cover as many uncovered<br />

combinations as possible. By repeating this randomized procedure several times and picking the best solution, we<br />

would be likely to come up with a very good set of tickets.<br />

Excluding the search mechanism, the pseudocode for the bookkeeping looked something like this:<br />

LottoTicketSet(n,k,l)<br />

ticket to buy<br />

Initialize the -element bit-vector V to all false<br />

While there exists a false entry of V<br />

Report the set of tickets bought<br />

Select a k-subset T of as the next<br />

For each of the l-subsets of T,<br />

<strong>The</strong> bright undergraduate, Fayyaz Younas, rose to the challenge. Based on this framework, he implemented a brute-force<br />

search algorithm and found optimal solutions for problems with in a reasonable time. To solve larger problems, he<br />

implemented a random search procedure, tweaking it for a while before settling on the best variant. Finally, the day arrived<br />

when we could call Lotto Systems Group and announce that we had solved the problem.<br />

``See, our program found that optimal solution for n=15, k=6, j=6, l=3 meant buying 28 tickets.''<br />

``Twenty-eight tickets!'' complained the president. ``You must have a bug. Look, these five tickets will suffice to cover<br />

everything twice over: , , , , .''<br />

file:///E|/BOOK/BOOK/NODE19.HTM (3 of 5) [19/1/2003 1:28:18]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!