Class: SportsManager::TournamentProblemBuilder
- Defined in:
- lib/sports_manager/tournament_problem_builder.rb
Overview
TODO: better name this Public: Builds a CSP for Tournament Scheduling.
Usage example: builder = ProblemBuilder.new(tournament)
builder
.add_variables(variables)
.add_domains(domains)
.add_ordering(NoOrder)
.add_filtering(NoFilter)
builder
.add_constraint(AllDifferentConstraint)
.add_constraint(NoOverlapping)
csp = builder.build
Constant Summary collapse
- MINIMUM_SOLUTIONS =
1
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#domains ⇒ Object
readonly
Returns the value of attribute domains.
-
#filtering_algorithm ⇒ Object
readonly
Returns the value of attribute filtering_algorithm.
-
#lookahead_algorithm ⇒ Object
readonly
Returns the value of attribute lookahead_algorithm.
-
#max_solutions ⇒ Object
readonly
Returns the value of attribute max_solutions.
-
#ordering_algorithm ⇒ Object
readonly
Returns the value of attribute ordering_algorithm.
-
#tournament ⇒ Object
readonly
Returns the value of attribute tournament.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#add_constraint(constraint_class) ⇒ Object
TODO: change to pass symbol instead of class?.
- #add_domains(domains) ⇒ Object
- #add_filtering(filtering_algorithm_class) ⇒ Object
- #add_lookahead(lookahead_algorithm_class) ⇒ Object
- #add_max_solutions(max_solutions) ⇒ Object
- #add_ordering(ordering_algorithm_class) ⇒ Object
- #add_variables(variables) ⇒ Object
- #build ⇒ Object
-
#initialize(tournament) ⇒ TournamentProblemBuilder
constructor
A new instance of TournamentProblemBuilder.
Constructor Details
#initialize(tournament) ⇒ TournamentProblemBuilder
Returns a new instance of TournamentProblemBuilder.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 28 def initialize(tournament) @variables = [] @domains = {} @constraints = [] @filtering_algorithm = nil @ordering_algorithm = nil @lookahead_algorithm = nil @max_solutions = MINIMUM_SOLUTIONS @tournament = tournament end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def constraints @constraints end |
#domains ⇒ Object (readonly)
Returns the value of attribute domains.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def domains @domains end |
#filtering_algorithm ⇒ Object (readonly)
Returns the value of attribute filtering_algorithm.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def filtering_algorithm @filtering_algorithm end |
#lookahead_algorithm ⇒ Object (readonly)
Returns the value of attribute lookahead_algorithm.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def lookahead_algorithm @lookahead_algorithm end |
#max_solutions ⇒ Object (readonly)
Returns the value of attribute max_solutions.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def max_solutions @max_solutions end |
#ordering_algorithm ⇒ Object (readonly)
Returns the value of attribute ordering_algorithm.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def ordering_algorithm @ordering_algorithm end |
#tournament ⇒ Object (readonly)
Returns the value of attribute tournament.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def tournament @tournament end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
22 23 24 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 22 def variables @variables end |
Instance Method Details
#add_constraint(constraint_class) ⇒ Object
TODO: change to pass symbol instead of class?
73 74 75 76 77 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 73 def add_constraint(constraint_class) @constraints |= Utils::Array.wrap(constraint_class) self end |
#add_domains(domains) ⇒ Object
48 49 50 51 52 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 48 def add_domains(domains) @domains = domains self end |
#add_filtering(filtering_algorithm_class) ⇒ Object
60 61 62 63 64 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 60 def add_filtering(filtering_algorithm_class) @filtering_algorithm = filtering_algorithm_class self end |
#add_lookahead(lookahead_algorithm_class) ⇒ Object
66 67 68 69 70 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 66 def add_lookahead(lookahead_algorithm_class) @lookahead_algorithm = lookahead_algorithm_class self end |
#add_max_solutions(max_solutions) ⇒ Object
79 80 81 82 83 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 79 def add_max_solutions(max_solutions) @max_solutions = [max_solutions, MINIMUM_SOLUTIONS].find(&:positive?) self end |
#add_ordering(ordering_algorithm_class) ⇒ Object
54 55 56 57 58 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 54 def add_ordering(ordering_algorithm_class) @ordering_algorithm = ordering_algorithm_class self end |
#add_variables(variables) ⇒ Object
42 43 44 45 46 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 42 def add_variables(variables) @variables = variables self end |
#build ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/sports_manager/tournament_problem_builder.rb', line 85 def build csp.tap do |problem| variables.each do |variable| problem.add_variable(variable, domains: domains[variable]) end problem.add_ordering(ordering(problem)) problem.add_filtering(filtering(problem)) problem.add_lookahead(lookahead(problem)) build_constraint(problem) end end |