There's more than one way to do things PerlMonks

### Re^2: Possible pairings for first knockout round of UEFA champions league

by LanX (Chancellor)
 on Dec 22, 2012 at 15:36 UTC ( #1010024=note: print w/replies, xml ) Need Help??

It's a branch and bound-algorithm, by early cutting unnecessary branches I avoid calculating all permutations, which is (far¹) more efficient.²

And it gave me the opportunity to check some mathematical approaches (which are more challenging for me)

But you're welcome to show us your way to do it!(BTW: I saw your approach already been done in Python, if you're interested)

Cheers Rolf

¹) since 8! is only ~40000 it's not too obvious in this special case.

²) Furthermore branching allows to cache/memoize results for subtrees to go even faster.

• Comment on Re^2: Possible pairings for first knockout round of UEFA champions league

Replies are listed 'Best First'.
Re^3: Possible pairings for first knockout round of UEFA champions league
by Anonymous Monk on Dec 22, 2012 at 20:22 UTC
²) Furthermore branching allows to cache/memoize results for subtrees to go even faster.
What? How?
The algorithm constructs recursively possible combinations of runner-ups meeting an ordered set of group winners:

```Paris Schalke Malaga Dortmund Turin  Bayern   Barcelona  ManU

now if you take a look at this excerpt of the results and you will notice that the last 4 branches are repeating.

```                            |
...                         |
Arsenal Porto Donezk Mailand Madrid Celtic Galatasaray Valencia
Arsenal Porto Donezk Mailand Valencia Madrid Galatasaray Celtic
Arsenal Porto Donezk Mailand Valencia Celtic Galatasaray Madrid
Arsenal Porto Donezk Mailand Celtic Madrid Galatasaray Valencia
...                         |
Arsenal Mailand Porto Donezk Madrid Celtic Galatasaray Valencia
Arsenal Mailand Porto Donezk Valencia Madrid Galatasaray Celtic
Arsenal Mailand Porto Donezk Valencia Celtic Galatasaray Madrid
Arsenal Mailand Porto Donezk Celtic Madrid Galatasaray Valencia
...                         |
|

Which is obviously right since the first 4 are only permutations of the same set.

So the following pairings (Turin  Bayern   Barcelona  ManU) x (Madrid Celtic Galatasaray Valencia) are always the same.

Now storing the result for a normalized representation of a already calculated set,

(something like join "-",sort(@drawn) as a hash key)

helps reusing the once calculated subresult after encountering any permutation of (Arsenal Mailand Porto Donezk)

It depends on the ratio between memory and time complexity but this normally gives an enormous boost to such search algorithms.

Cheers Rolf

Create A New User
Node Status?
node history
Node Type: note [id://1010024]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-08-16 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (276 votes). Check out past polls.

Notices?