Class: StableMatching::Roommate::PhaseIIRunner

Inherits:
PhaseRunner
  • Object
show all
Defined in:
lib/stable-matching/roommate/phase_ii_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(preference_table, opts = {}) ⇒ PhaseIIRunner

Returns a new instance of PhaseIIRunner.



73
74
75
76
# File 'lib/stable-matching/roommate/phase_ii_runner.rb', line 73

def initialize(preference_table, opts = {})
  @preference_table = preference_table
  @logger = opts.fetch(:logger)
end

Instance Method Details

#runObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/stable-matching/roommate/phase_ii_runner.rb', line 78

def run
  @preference_table.members.each do |proposer|
    acceptor, rejections =
      determine_acceptor_and_their_rejections(proposer)

    @logger.debug(
      "#{proposer.name} accepted by #{acceptor.name}. "\
      "#{acceptor.name} rejecting members less preferred than "\
      "#{proposer.name}: #{rejections.map(&:name)}"
    )

    rejections.each { |rejected| acceptor.reject!(rejected) }
  end
end