Class: SportsManager::TournamentGenerator
- Extended by:
- Forwardable
- Defined in:
- lib/sports_manager/tournament_generator.rb
Overview
Public:Tournament Solver
_TEAM A______
MATCH 1 \_TEAM B______
_TEAM B______/ \
MATCH 5 \_TEAM B___
_TEAM C______ / \
MATCH 2 \_TEAM C______/ \
_TEAM D______/ \
MATCH 7 \__TEAM E__
_TEAM E______ /
MATCH 3 \_TEAM E______ /
_TEAM F______/ \ /
MATCH 6 \_TEAM E___/
_TEAM G______ /
MATCH 4 \_TEAM G______/
_TEAM H______/
Instance Attribute Summary collapse
-
#courts ⇒ Object
Returns the value of attribute courts.
-
#csp ⇒ Object
readonly
Returns the value of attribute csp.
-
#days ⇒ Object
Returns the value of attribute days.
-
#domains ⇒ Object
readonly
Returns the value of attribute domains.
-
#filtering ⇒ Object
readonly
Returns the value of attribute filtering.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#game_length ⇒ Object
Returns the value of attribute game_length.
-
#lookahead ⇒ Object
readonly
Returns the value of attribute lookahead.
-
#matches ⇒ Object
Returns the value of attribute matches.
-
#ordering ⇒ Object
readonly
Returns the value of attribute ordering.
-
#rest_break ⇒ Object
Returns the value of attribute rest_break.
-
#single_day_matches ⇒ Object
Returns the value of attribute single_day_matches.
-
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#tournament ⇒ Object
readonly
Returns the value of attribute tournament.
-
#tournament_type ⇒ Object
Returns the value of attribute tournament_type.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Class Method Summary collapse
Instance Method Summary collapse
- #add_courts(number_of_courts) ⇒ Object
- #add_day(day, start, finish) ⇒ Object
- #add_days(days) ⇒ Object
- #add_game_length(game_length) ⇒ Object
- #add_match(category, match) ⇒ Object
- #add_matches(matches) ⇒ Object
- #add_matches_per_category(category, matches) ⇒ Object
- #add_rest_break(rest_break) ⇒ Object
- #add_subscription(category, subscription) ⇒ Object
- #add_subscriptions(subscriptions) ⇒ Object
- #add_subscriptions_per_category(category, subscriptions) ⇒ Object
- #call ⇒ Object
- #enable_single_day_matches(single_day_matches) ⇒ Object
-
#initialize(format: :cli, timeout: nil) ⇒ TournamentGenerator
constructor
A new instance of TournamentGenerator.
- #single_elimination_algorithm ⇒ Object
Constructor Details
#initialize(format: :cli, timeout: nil) ⇒ TournamentGenerator
Returns a new instance of TournamentGenerator.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sports_manager/tournament_generator.rb', line 48 def initialize(format: :cli, timeout: nil) @format = format @timeout = timeout @days = {} @subscriptions = {} @matches = {} @ordering = Algorithms::Ordering::MultipleMatchesParticipant @filtering = Algorithms::Filtering::NoOverlap @lookahead = CSP::Algorithms::Lookahead::Ac3 end |
Instance Attribute Details
#courts ⇒ Object
Returns the value of attribute courts.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def courts @courts end |
#csp ⇒ Object (readonly)
Returns the value of attribute csp.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def csp @csp end |
#days ⇒ Object
Returns the value of attribute days.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def days @days end |
#domains ⇒ Object (readonly)
Returns the value of attribute domains.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def domains @domains end |
#filtering ⇒ Object (readonly)
Returns the value of attribute filtering.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def filtering @filtering end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def format @format end |
#game_length ⇒ Object
Returns the value of attribute game_length.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def game_length @game_length end |
#lookahead ⇒ Object (readonly)
Returns the value of attribute lookahead.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def lookahead @lookahead end |
#matches ⇒ Object
Returns the value of attribute matches.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def matches @matches end |
#ordering ⇒ Object (readonly)
Returns the value of attribute ordering.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def ordering @ordering end |
#rest_break ⇒ Object
Returns the value of attribute rest_break.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def rest_break @rest_break end |
#single_day_matches ⇒ Object
Returns the value of attribute single_day_matches.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def single_day_matches @single_day_matches end |
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def subscriptions @subscriptions end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def timeout @timeout end |
#tournament ⇒ Object (readonly)
Returns the value of attribute tournament.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def tournament @tournament end |
#tournament_type ⇒ Object
Returns the value of attribute tournament_type.
29 30 31 |
# File 'lib/sports_manager/tournament_generator.rb', line 29 def tournament_type @tournament_type end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
26 27 28 |
# File 'lib/sports_manager/tournament_generator.rb', line 26 def variables @variables end |
Class Method Details
.example(type = :simple, format: :cli) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sports_manager/tournament_generator.rb', line 34 def self.example(type = :simple, format: :cli) params = Helper.public_send(type) new(format: format) .add_days(params[:when]) .add_subscriptions(params[:subscriptions]) .add_matches(params[:matches]) .add_courts(params[:courts]) .add_game_length(params[:game_length]) .add_rest_break(params[:rest_break]) .enable_single_day_matches(params[:single_day_matches]) .call end |
Instance Method Details
#add_courts(number_of_courts) ⇒ Object
107 108 109 110 |
# File 'lib/sports_manager/tournament_generator.rb', line 107 def add_courts(number_of_courts) @courts = number_of_courts self end |
#add_day(day, start, finish) ⇒ Object
59 60 61 62 |
# File 'lib/sports_manager/tournament_generator.rb', line 59 def add_day(day, start, finish) days[day.to_sym] = { start: start, end: finish } self end |
#add_days(days) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/sports_manager/tournament_generator.rb', line 64 def add_days(days) days.each do |day, time_hash| add_day(day, time_hash[:start], time_hash[:end]) end self end |
#add_game_length(game_length) ⇒ Object
112 113 114 115 |
# File 'lib/sports_manager/tournament_generator.rb', line 112 def add_game_length(game_length) @game_length = game_length self end |
#add_match(category, match) ⇒ Object
89 90 91 92 93 |
# File 'lib/sports_manager/tournament_generator.rb', line 89 def add_match(category, match) matches[category] ||= [] matches[category] << match self end |
#add_matches(matches) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/sports_manager/tournament_generator.rb', line 100 def add_matches(matches) matches.each do |category, matches_per_category| add_matches_per_category(category, matches_per_category) end self end |
#add_matches_per_category(category, matches) ⇒ Object
95 96 97 98 |
# File 'lib/sports_manager/tournament_generator.rb', line 95 def add_matches_per_category(category, matches) matches.each { |match| add_match(category, match) } self end |
#add_rest_break(rest_break) ⇒ Object
117 118 119 120 |
# File 'lib/sports_manager/tournament_generator.rb', line 117 def add_rest_break(rest_break) @rest_break = rest_break self end |
#add_subscription(category, subscription) ⇒ Object
71 72 73 74 75 |
# File 'lib/sports_manager/tournament_generator.rb', line 71 def add_subscription(category, subscription) subscriptions[category] ||= [] subscriptions[category] << subscription self end |
#add_subscriptions(subscriptions) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/sports_manager/tournament_generator.rb', line 82 def add_subscriptions(subscriptions) subscriptions.each do |category, subscriptions_per_category| add_subscriptions_per_category(category, subscriptions_per_category) end self end |
#add_subscriptions_per_category(category, subscriptions) ⇒ Object
77 78 79 80 |
# File 'lib/sports_manager/tournament_generator.rb', line 77 def add_subscriptions_per_category(category, subscriptions) subscriptions.each { |subscription| add_subscription(category, subscription) } self end |
#call ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/sports_manager/tournament_generator.rb', line 132 def call setup solutions = Timeout.timeout(timeout) { csp.solve } TournamentSolution .new(tournament: tournament, solutions: solutions) .tap(&method(:print_solution)) end |
#enable_single_day_matches(single_day_matches) ⇒ Object
122 123 124 125 |
# File 'lib/sports_manager/tournament_generator.rb', line 122 def enable_single_day_matches(single_day_matches) @single_day_matches = single_day_matches self end |
#single_elimination_algorithm ⇒ Object
127 128 129 130 |
# File 'lib/sports_manager/tournament_generator.rb', line 127 def single_elimination_algorithm @tournament_type = Matches::Algorithms::SingleEliminationAlgorithm self end |