Class: SportsManager::Constraints::MultiCategoryConstraint
- Inherits:
-
CSP::Constraint
- Object
- CSP::Constraint
- SportsManager::Constraints::MultiCategoryConstraint
- Defined in:
- lib/sports_manager/constraints/multi_category_constraint.rb
Constant Summary collapse
- MINUTE =
60- IN_PAIRS =
2
Instance Attribute Summary collapse
-
#break_time ⇒ Object
readonly
Returns the value of attribute break_time.
-
#match_time ⇒ Object
readonly
Returns the value of attribute match_time.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#minimum_match_gap ⇒ Object
readonly
Returns the value of attribute minimum_match_gap.
-
#target_participant ⇒ Object
readonly
Returns the value of attribute target_participant.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(target_participant:, matches:, match_time:, break_time:) ⇒ MultiCategoryConstraint
constructor
A new instance of MultiCategoryConstraint.
-
#satisfies?(assignment) ⇒ Boolean
TODO: See if needs review in case of solution of split timeslots under match_time.
Constructor Details
#initialize(target_participant:, matches:, match_time:, break_time:) ⇒ MultiCategoryConstraint
Returns a new instance of MultiCategoryConstraint.
29 30 31 32 33 34 35 36 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 29 def initialize(target_participant:, matches:, match_time:, break_time:) super(matches) @target_participant = target_participant @matches = matches @match_time = match_time @break_time = break_time @minimum_match_gap = match_time + break_time end |
Instance Attribute Details
#break_time ⇒ Object (readonly)
Returns the value of attribute break_time.
6 7 8 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 6 def break_time @break_time end |
#match_time ⇒ Object (readonly)
Returns the value of attribute match_time.
6 7 8 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 6 def match_time @match_time end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
6 7 8 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 6 def matches @matches end |
#minimum_match_gap ⇒ Object (readonly)
Returns the value of attribute minimum_match_gap.
6 7 8 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 6 def minimum_match_gap @minimum_match_gap end |
#target_participant ⇒ Object (readonly)
Returns the value of attribute target_participant.
6 7 8 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 6 def target_participant @target_participant end |
Class Method Details
.for_tournament(tournament:, csp:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 12 def self.for_tournament(tournament:, csp:) tournament.multi_tournament_participants.each do |participant| matches = tournament.find_participant_matches(participant) matches.combination(IN_PAIRS) do |match1, match2| constraint = new( target_participant: participant, matches: [match1, match2], match_time: tournament.match_time, break_time: tournament.break_time ) csp.add_constraint(constraint) end end end |
Instance Method Details
#satisfies?(assignment) ⇒ Boolean
TODO: See if needs review in case of solution of split timeslots under match_time
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sports_manager/constraints/multi_category_constraint.rb', line 39 def satisfies?(assignment) return true unless variables.all? { |variable| assignment.key?(variable) } timeslots = assignment.slice(*variables).values.map(&:slot) timeslots.combination(2).all? do |timeslot1, timeslot2| diff_in_minutes = (timeslot1 - timeslot2).abs / MINUTE diff_in_minutes >= minimum_match_gap end end |