Skip to content

SLSP:: CircleMethod provides methods using the circle method for Sports League Scheduling Problems.

License

Notifications You must be signed in to change notification settings

wakairo/slsp-circlemethod

Repository files navigation

SLSP::CircleMethod

Ruby

SLSP:: CircleMethod provides methods using the circle method for Sports League Scheduling Problems.

Installation

Add this line to your application's Gemfile:

gem 'slsp-circlemethod'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install slsp-circlemethod

Usage

Only simple usage is shown here. For more details, please see the code documentation in slsp-circlemethod/lib/slsp/circlemethod.rb .

each()

By using the circle method, SLSP::CircleMethod.each() computes schedules of matches of n teams considering rounds.

Example:

require "slsp/circlemethod"

teams = %w(A B C D  E F G H)
enum = SLSP::CircleMethod.each(teams.size)
enum.each_slice(teams.size/2).each_with_index do |x, i|
    puts "Round #{i}: " + x.map{|p,q| "#{teams[p]} vs #{teams[q]}"}.join(", ")
end

Output:

Round 0: A vs H, B vs G, C vs F, D vs E
Round 1: B vs H, C vs A, D vs G, E vs F
Round 2: C vs H, D vs B, E vs A, F vs G
Round 3: D vs H, E vs C, F vs B, G vs A
Round 4: E vs H, F vs D, G vs C, A vs B
Round 5: F vs H, G vs E, A vs D, B vs C
Round 6: G vs H, A vs F, B vs E, C vs D

each_with_fair_break()

SLSP::CircleMethod.each_with_fair_break() computes the schedules also considering breaks. In Sports League Scheduling Problems, the break means "two consecutive home matches or two consecutive away matches". In the following example, team A, B, D, and F have "hh" (consecutive two home matches), and team C, E, G, and H have "aa" (consecutive two away matches). So, each team has one break fairly.

Example:

require "slsp/circlemethod"

teams = %w(A B C D  E F G H)
array = SLSP::CircleMethod.each_with_fair_break(teams.size).to_a
array.each_slice(teams.size/2).each_with_index do |x, i|
    puts "Round #{i}: " + x.map{|p,q| "#{teams[p]} vs #{teams[q]}"}.join(", ")
end
puts
puts "Team   : " + teams.join(" ")
array.each_slice(teams.size/2).each_with_index do |round, i|
    a = []
    round.each do |home, away|
        a[home] = "h"
        a[away] = "a"
    end
    puts "Round #{i}: " + a.join(" ")
end

Output:

Round 0: A vs H, G vs B, C vs F, E vs D
Round 1: B vs H, A vs C, D vs G, F vs E
Round 2: H vs C, B vs D, E vs A, G vs F
Round 3: D vs H, C vs E, F vs B, A vs G
Round 4: H vs E, D vs F, G vs C, B vs A
Round 5: F vs H, E vs G, A vs D, C vs B
Round 6: H vs G, F vs A, B vs E, D vs C

Team   : A B C D E F G H
Round 0: h a h a h a h a
Round 1: h h a h a h a a
Round 2: a h a a h a h h
Round 3: h a h h a h a a
Round 4: a h a h a a h h
Round 5: h a h a h h a a
Round 6: a h a h a h a h

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wakairo/slsp-circlemethod.

License

The gem is available as open source under the terms of the MIT License.

About

SLSP:: CircleMethod provides methods using the circle method for Sports League Scheduling Problems.

Resources

License

Stars

Watchers

Forks

Packages

No packages published