Class: SportsManager::Constraints::AllDifferentConstraint
- Inherits:
-
CSP::Constraint
- Object
- CSP::Constraint
- SportsManager::Constraints::AllDifferentConstraint
- Defined in:
- lib/sports_manager/constraints/all_different_constraint.rb
Overview
Public: Constraint to all timeslot assignments be different for each match
Instance Attribute Summary collapse
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(matches) ⇒ AllDifferentConstraint
constructor
A new instance of AllDifferentConstraint.
- #satisfies?(assignment) ⇒ Boolean
Constructor Details
#initialize(matches) ⇒ AllDifferentConstraint
Returns a new instance of AllDifferentConstraint.
16 17 18 19 |
# File 'lib/sports_manager/constraints/all_different_constraint.rb', line 16 def initialize(matches) super @matches = matches end |
Instance Attribute Details
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
8 9 10 |
# File 'lib/sports_manager/constraints/all_different_constraint.rb', line 8 def matches @matches end |
Class Method Details
.for_tournament(tournament:, csp:) ⇒ Object
10 11 12 13 14 |
# File 'lib/sports_manager/constraints/all_different_constraint.rb', line 10 def self.for_tournament(tournament:, csp:) matches = tournament.matches.values.flatten csp.add_constraint(new(matches)) end |
Instance Method Details
#satisfies?(assignment) ⇒ Boolean
21 22 23 |
# File 'lib/sports_manager/constraints/all_different_constraint.rb', line 21 def satisfies?(assignment) assignment.values == assignment.values.uniq end |