Manual Reference Pages - ALGORITHM::PAIR::SWISS (3)
Algorithm::Pair::Swiss - Generate unique pairings for tournaments
This document describes Algorithm::Pair::Swiss version 0.14
my $pairer = Algorithm::Pair::Swiss->new;
@round_1 = $pairer->pairs;
@round_2 = $pairer->pairs;
This module was created as an alternative for Algorithm::Pair::Best, which
probably offers more control over the pairings, in particular regarding
ensuring the highest overal quality of pairings. Algorithm::Pair::Swiss is
sort of dumb in this regard, but uses a slightly more intuitive interface
and an algorithm that should perform noticably faster. The module was
primarily designed based on the Swiss rounds system used for Magic: The
After creating an Algorithm::Pair::Swiss-><B>newB> object, use the <B>partiesB>
method to supply a list of parties (players or teams) to be paired. At any
time the <B>excludeB> method can be used to indicate which pairs shouldnt be
generated (probably because theyve already been paired in an earlier round).
The list of parties is sorted and the pairer tries to find a set of pairs that
respects the exclude list, and tries to pair the parties that appear first
in the sorted list with each other most aggresively.
To influence the sort order, use objects as parties and overload either the
<B>cmpB> or <B>0+B> operators in the object class to sort as desired.
Algorithm::Pair::Swiss-><B>pairsB> explores the parties and returns the first
pairing solution which satisfies the excludes. Because it doesnt exhaustively
try all possible solutions, performance is generally pretty reasonable.
For a large number of parties, it is generally easy to find a non-excluded pair,
and for a smaller number of parties traversal of the possible pairs is done
This module uses the parties as keys in a hash, and uses the empty string ()
as a special case in this same hash. For this reason, please observe the
following restrictions regarding your party values:
All the restrictions on the stringifications are compatible with the perls
default stringification of objects, and should be safe for any stringification
which returns a unique party-identifier (for instance a primary key from a
- make sure it is defined (not undef)
- make sure it is defined when stringified
- make sure each is a non-empty string when stringified
- make sure each is unique when stringified
my $pairer = <B>Algorithm::Pair::Swiss->newB>( @parties )
A <B>newB> Algorithm::Pair::Swiss object is used to generate pairings.
Optionally @parties can be given when instantiating the object. This is
the same as using the <B>partiesB> method described below.
$pairer-><B>partiesB>( @parties )
Provides the pairer with a complete list of all individuals that can
be paired. If no parties are specified, it returns the sorted list
of all parties. This allows you to use this method to extract rankings
if you happen to have implemented a <B>cmpB> operator overload in the
class your parties belong to.
@pairs = $pairer-><B>pairsB>
Returns the best pairings found as a list of arrayrefs, each containing
one pair of parties.
$pair-><B>excludeB>( @pairs )
Excludes the given pairs from further pairing. The @pairs array
should consist of a list of references to arrays, each containing the two
parties of that pair. This means you can easily feed it the output of
a previous call to $pair-><B>pairsB>. The selection given is added
to previously excluded pairs.
If there was an odd number of parties, the lowest ranked party will be
paired with undef, unless it has already been paired with undef. In
that case, the second-lowest ranked party will get that pairing. Etcetera,
etcetera. Lowest-ranked is defined as being last in the party-list after
sorting. In MTG terms, being paired with undef would mean getting a bye
(and getting the full three points for that round as a consequence).
$pair-><B>dropB>( @parties )
Excludes the given parties from further pairing. The given parties will
be removed from the internal parties list and wont be returned by the
parties method anymore. This method is usually used when a participant
has decided to quit playing.
None by default.
BUGS AND LIMITATIONS
No bugs that I know of...
The modules performance will probably break down
if you use 1000+ parties and 100+ rounds though...
Perl 5.6.0 or later (though it will probably work ok with earlier versions)
The <B>Algorithm::Pair::BestB> module if you need more control
over your pairings.
For proper results youll want to overload the <B>cmpB> and/or <B>0+B>
operators of the objects youre using as parties. This will allow
for the correct sort order, so higher-ranked parties are matched
Reid Augustin for by <B>Algorithm::Pair::BestB>
Elizabeth Mattijsen for giving me some pointers on getting this module CPAN-ready.
Gilion Goudsmit, <email@example.com>
I can also be found on http://www.perlmonks.org as Gilimanjaro. You can direct
any questions concerning this module there as well.
COPYRIGHT AND LICENSE
Copyright (C) 2006 by Gilion Goudsmit
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.5 or,
at your option, any later version of Perl 5 you may have available.
|perl v5.20.3 ||ALGORITHM::PAIR::SWISS (3) ||2016-03-17 |
Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.