Class: StableMarriage

Inherits:
Object
  • Object
show all
Defined in:
lib/stable_marriage.rb,
lib/stable_marriage/version.rb,
lib/stable_marriage/match_set.rb,
lib/stable_marriage/preference.rb,
lib/stable_marriage/match_maker.rb,
lib/stable_marriage/descending_insertion_sort_array.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Constructor Details

#initializeStableMarriage

Returns a new instance of StableMarriage.



5
6
7
# File 'lib/stable_marriage.rb', line 5

def initialize
  @match_set = MatchSet.new
end

Instance Method Details

#add_match(suitor, suitee, score) ⇒ Object

The the matching between the suitor and suitee with the match score.

Parameters:

  • suitor (Object)

    the proposal maker in the Gale-Shapely algorithm. This party tends to fare better than the suitee in the algorithm.

  • suitee (Object)

    the proposal acceptor/rejector in the Gale-Shapely algorithm.

  • score (Numeric)

    a numeric representation of the strength of the match. A higher score means a better match.



17
18
19
# File 'lib/stable_marriage.rb', line 17

def add_match(suitor, suitee, score)
  match_set.add(suitor, suitee, score)
end

#proposalsHash<Object, Object>

A map with suitors as keys and suitees as objects

Returns:

  • (Hash<Object, Object>)

    the final matching between suitors and suitees.



25
26
27
# File 'lib/stable_marriage.rb', line 25

def proposals
  MatchMaker.new(match_set).proposals
end