In [47]:
module matching_simulation
immutable Matching
apply_prefs::Array
accept_prefs::Array
end
function Base.call(f::Matching, typ::ASCIIString)
apply_prefs = f.apply_prefs
accept_prefs = f.accept_prefs
if typ == "DA1"
apply_matched, accept_matched = DA1(apply_prefs, accept_prefs)
elseif typ == "DA2"
emp()
elseif typ == "DA2"
emp()
else
print("Please input 'DA1' or 'DA2' to 'typ'")
end
return apply_matched, accept_matched
end
function DA1(apply_prefs::Array, accept_prefs::Array)
da = zeros(Int64, length(accept_prefs[1,:]))
rem = [i for i in 1:length(apply_prefs[1,:])]
depth = ones(Int64, length(accept_prefs[:,1])-1)
while length(rem) != 0
apply = rem[end]
d = depth[apply]
if d == length(accept_prefs[:,1])
pop!(rem)
end
applied = apply_prefs[d, apply]
if applied == 0
pop!(rem)
else
if findfirst(accept_prefs[:,applied], apply) < findfirst(accept_prefs[:,applied], da[applied])
pop!(rem)
if da[applied] != 0
push!(rem, da[applied])
depth[da[applied]] += 1
end
da[applied] = apply
else
depth[apply] += 1
end
end
end
accept_matched = da
apply_matched = zeros(Int64, length(apply_prefs[1,:]))
for i in 1:length(accept_matched)
if accept_matched[i] != 0
apply_matched[accept_matched[i]] = i
end
end
return apply_matched, accept_matched
end
function g()
return 1
end
end
Out[47]:
・学校数:20校
・各学区内に居住する生徒数:100名
・受け入れ定員数はすべての学校で共通
・各生徒の学校に対する選好順位は以下の数式によってランダムに生成した効用の大小に基づいて決定される.
$$ u_{ij} = I_{ij}\theta + \alpha v_{j} + (1-\alpha) v_{ij} $$
In [ ]:
function utility(num_st, num_sch, I, theta, alpha, v_i, v_ij)
utility = Array(Float64, num_sch, num_st)
for st in 1:num_st
for sch in 1:num_sch
end
In [34]:
Array(Int64, 2, 10)
Out[34]:
In [48]:
m_prefs[1,:]
Out[48]:
In [49]:
f = matching_simulation.Matching(m_prefs, f_prefs)
f("DA1")
Out[49]:
In [4]:
include("matching_tools.jl")
Out[4]:
In [25]:
m_prefs, f_prefs = random_prefs(4, 4);
In [11]:
m_prefs
Out[11]:
In [26]:
@time deferred_acceptance(m_prefs, f_prefs)
Out[26]:
In [19]:
include("deferred_acceptance.jl")
Out[19]:
In [9]:
m_prefs[:,1]
Out[9]:
In [118]:
f = Matching.DA(m_prefs, f_prefs)
Out[118]:
In [119]:
f("DA1")
In [110]:
typeof('y')
Out[110]:
In [111]:
typ = 'DA1'
if typ == 'DA1'
g()
end
In [49]:
hoge = "hige"
if hoge[1] == "h" && hoge[2:4] == "oge"
println("hoge is hoge")
elseif hoge == "huge" || hoge == "hige"
println("hoge is huge or hige")
else
println("hoge is ", hoge)
end
In [76]:
rem = [i for i in 1:3]
Out[76]:
In [62]:
typeof(typ)
Out[62]:
In [ ]:
In [ ]:
In [61]:
typ = "DA1"
Out[61]:
In [58]:
if typ == 'DA1'
return 1
end
In [53]:
if hoge[1] == "h"
print(1)
end
In [74]:
da = Array(Float64, 10)
Out[74]:
In [75]:
da
Out[75]:
In [89]:
pop!(da)
Out[89]:
In [90]:
da
Out[90]:
In [92]:
da[end]
Out[92]:
In [104]:
da[4] = 10
Out[104]:
In [118]:
findfirst(da, 10)
Out[118]:
In [116]:
da
Out[116]:
In [90]:
typeof(2)
Out[90]:
In [92]:
"foo"*"goo"
Out[92]:
In [2]:
parent(Vector)
In [ ]:
@co