In [27]:
Pkg.checkout("MyMatchingA")


INFO: Checking out MyMatchingA master...
INFO: Pulling MyMatchingA latest master...
INFO: No packages to install, update or remove

In [28]:
Pkg.test("MyMatchingA")


INFO: Testing MyMatchingA
Test Summary:               | Pass  Total
  Testing deferred acceptance |   18     18
INFO: MyMatchingA tests passed

In [29]:
using MyMatchingA

In [30]:
include("matching_tools.jl")


WARNING: Method definition random_prefs(Base.Random.AbstractRNG, Integer, Integer) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:108 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:108.
WARNING: Method definition #random_prefs(Array{Any, 1}, Main.#random_prefs, Base.Random.AbstractRNG, Integer, Integer) in module Main overwritten.
WARNING: replacing docs for 'random_prefs :: Tuple{AbstractRNG,Integer,Integer}' in module 'Main'.
WARNING: Method definition random_prefs(Integer, Integer) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:113 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:113.
WARNING: Method definition #random_prefs(Array{Any, 1}, Main.#random_prefs, Integer, Integer) in module Main overwritten.
WARNING: Method definition (::Type{Main.ReturnCaps})() in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:116 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:116.
WARNING: Method definition random_prefs(Base.Random.AbstractRNG, Integer, Integer, Type{Main.ReturnCaps}) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:121 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:121.
WARNING: Method definition #random_prefs(Array{Any, 1}, Main.#random_prefs, Base.Random.AbstractRNG, Integer, Integer, Type{Main.ReturnCaps}) in module Main overwritten.
WARNING: Method definition random_prefs(Integer, Integer, Type{Main.ReturnCaps}) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:134 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:134.
WARNING: Method definition #random_prefs(Array{Any, 1}, Main.#random_prefs, Integer, Integer, Type{Main.ReturnCaps}) in module Main overwritten.
WARNING: Method definition _random_prefs(Base.Random.AbstractRNG, Integer, Integer) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:140 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:140.
WARNING: Method definition _random_unmatched!(Base.Random.AbstractRNG, Array{Int64, 2}, Array{Int64, 1}) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:152 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:152.
WARNING: Method definition _random_prefs(Base.Random.AbstractRNG, Integer, Integer, Bool) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:163 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:163.
WARNING: Method definition _random_caps(Base.Random.AbstractRNG, Array{Int64, 1}) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:175 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:175.
WARNING: Method definition _random_caps(Base.Random.AbstractRNG, Int64, Int64) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:185 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:185.
WARNING: Method definition rand_lt(Base.Random.AbstractRNG, Int64) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:199 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:199.
WARNING: Method definition rand_lt(Base.Random.AbstractRNG, Int64, Int64) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:199 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:199.
WARNING: replacing docs for 'rand_lt :: Union{Tuple{AbstractRNG,Int64,Int64},Tuple{AbstractRNG,Int64}}' in module 'Main'.
WARNING: Method definition _randperm!(Base.Random.AbstractRNG, AbstractArray{#T<:Integer, 1}) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:212 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:212.
WARNING: Method definition _randperm2d!(Base.Random.AbstractRNG, AbstractArray{#T<:Integer, 2}) in module Main at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:236 overwritten at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:236.
Out[30]:
_randperm2d!

In [31]:
prop_prefs, resp_prefs, caps = random_prefs(4, 3, ReturnCaps, allow_unmatched=false);


WARNING: sub is deprecated, use view instead.
 in depwarn(::String, ::Symbol) at ./deprecated.jl:64
 in sub(::Array{Int64,2}, ::Vararg{Any,N}) at ./deprecated.jl:30
 in _random_prefs(::MersenneTwister, ::Int64, ::Int64) at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:145
 in _random_prefs(::MersenneTwister, ::Int64, ::Int64, ::Bool) at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:163
 in #random_prefs#9(::Bool, ::Function, ::MersenneTwister, ::Int64, ::Int64, ::Type{ReturnCaps}) at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:121
 in (::#kw##random_prefs)(::Array{Any,1}, ::#random_prefs, ::MersenneTwister, ::Int64, ::Int64, ::Type{ReturnCaps}) at ./<missing>:0 (repeats 2 times)
 in include_string(::String, ::String) at ./loading.jl:441
 in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/sasakiakihiro/.julia/v0.5/IJulia/src/execute_request.jl:156
 in eventloop(::ZMQ.Socket) at /Users/sasakiakihiro/.julia/v0.5/IJulia/src/eventloop.jl:8
 in (::IJulia.##13#19)() at ./task.jl:360
while loading In[31], in expression starting on line 1
WARNING: sub is deprecated, use view instead.
 in depwarn(::String, ::Symbol) at ./deprecated.jl:64
 in sub(::SubArray{Int64,2,Array{Int64,2},Tuple{UnitRange{Int64},Colon},false}, ::Vararg{Any,N}) at ./deprecated.jl:30
 in _randperm2d!(::MersenneTwister, ::SubArray{Int64,2,Array{Int64,2},Tuple{UnitRange{Int64},Colon},false}) at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:238
 in _random_prefs(::MersenneTwister, ::Int64, ::Int64) at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:145
 in _random_prefs(::MersenneTwister, ::Int64, ::Int64, ::Bool) at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:163
 in #random_prefs#9(::Bool, ::Function, ::MersenneTwister, ::Int64, ::Int64, ::Type{ReturnCaps}) at /Users/sasakiakihiro/MyMatchingA.jl/src/matching_tools.jl:121
 in (::#kw##random_prefs)(::Array{Any,1}, ::#random_prefs, ::MersenneTwister, ::Int64, ::Int64, ::Type{ReturnCaps}) at ./<missing>:0 (repeats 2 times)
 in include_string(::String, ::String) at ./loading.jl:441
 in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/sasakiakihiro/.julia/v0.5/IJulia/src/execute_request.jl:156
 in eventloop(::ZMQ.Socket) at /Users/sasakiakihiro/.julia/v0.5/IJulia/src/eventloop.jl:8
 in (::IJulia.##13#19)() at ./task.jl:360
while loading In[31], in expression starting on line 1

In [32]:
function mat2vecs{T<:Integer}(prefs::Matrix{T})
    return [prefs[1:findfirst(prefs[:, j], 0)-1, j] for j in 1:size(prefs, 2)]
end


WARNING: Method definition mat2vecs(Array{#T<:Integer, 2}) in module Main at In[22]:2 overwritten at In[32]:2.
Out[32]:
mat2vecs (generic function with 1 method)

In [33]:
prop_prefs


Out[33]:
4×4 Array{Int64,2}:
 1  3  2  1
 3  2  3  3
 2  1  1  2
 0  0  0  0

In [34]:
prop_prefs = mat2vecs(prop_prefs)


Out[34]:
4-element Array{Array{Int64,1},1}:
 [1,3,2]
 [3,2,1]
 [2,3,1]
 [1,3,2]

In [35]:
resp_prefs


Out[35]:
5×3 Array{Int64,2}:
 1  2  2
 2  3  1
 3  1  4
 4  4  3
 0  0  0

In [36]:
resp_prefs = mat2vecs(resp_prefs)


Out[36]:
3-element Array{Array{Int64,1},1}:
 [1,2,3,4]
 [2,3,1,4]
 [2,1,4,3]

In [37]:
caps


Out[37]:
3-element Array{Int64,1}:
 4
 3
 3

In [38]:
deferred_acceptance(prop_prefs,resp_prefs,caps)


Out[38]:
([1,3,2,1],[1,4,0,0,3,0,0,2,0,0],[1,5,8,11])