Class: SportsManager::Constraints::AllDifferentConstraint

Inherits:
CSP::Constraint
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#matchesObject (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

Returns:

  • (Boolean)


21
22
23
# File 'lib/sports_manager/constraints/all_different_constraint.rb', line 21

def satisfies?(assignment)
  assignment.values == assignment.values.uniq
end