agents.jl 2.71 KB
Newer Older
1
#agent type definitions
2
3
4
5
6
7
@enum AgentDemographic begin
    Young = 1
    Adult
    Elderly
end
@enum AgentStatus begin
Peter Jentsch's avatar
Peter Jentsch committed
8
    Susceptible = 1
9
10
    Infected
    Recovered
Peter Jentsch's avatar
Peter Jentsch committed
11
    Immunized
12
13
end

Peter Jentsch's avatar
Peter Jentsch committed
14
struct AgentModel{GraphType,L1,L2}
Peter Jentsch's avatar
Peter Jentsch committed
15
16
    demographics::Vector{AgentDemographic}
    demographic_index_vectors::Vector{Vector{Int}}
17
18
    app_user::Vector{Bool}
    app_user_index::Vector{Int}
Peter Jentsch's avatar
Peter Jentsch committed
19
    base_network::GraphType
Peter Jentsch's avatar
Peter Jentsch committed
20
21
    ws_matrix_list::L1
    rest_matrix_list::L2
22
23
    function AgentModel(num_households)
        pop_list,base_network,index_vectors = generate_population(num_households)
24
        pop_sizes = length.(index_vectors)
Peter Jentsch's avatar
Peter Jentsch committed
25
        map_symmetrize(m_tuple) = map(md -> symmetrize_means(pop_sizes,md), m_tuple)
26

Peter Jentsch's avatar
Peter Jentsch committed
27
28
        workschool_contacts_mean_adjusted = map_symmetrize(workschool_mixing)
        rest_contacts_mean_adjusted = map_symmetrize(rest_mixing)
29

30
31
32
        app_user = rand(RNG,length(pop_list)) .< 0.1 #replace with parameter
        app_user_index = findall(==(true),app_user)

33
34
        return new{
            typeof(base_network),
Peter Jentsch's avatar
Peter Jentsch committed
35
36
            typeof(workschool_contacts_mean_adjusted),
            typeof(rest_contacts_mean_adjusted)
37
38
39
        }(
            pop_list,
            index_vectors,
40
41
            app_user,
            app_user_index,
42
            base_network,
Peter Jentsch's avatar
Peter Jentsch committed
43
44
45
            workschool_contacts_mean_adjusted,
            rest_contacts_mean_adjusted
        )
Peter Jentsch's avatar
Peter Jentsch committed
46
    end
47
48
end

Peter Jentsch's avatar
Peter Jentsch committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#generate population with households distributed according to household_size_distribution
function generate_population(num_households)
    households_composition = sample_household_data(num_households)
    households = map( l -> [fill(AgentDemographic(i),n) for (i,n) in enumerate(l)],households_composition) |>
                    l -> reduce(vcat,l) |>
                    l -> reduce(vcat,l)

    total_household_pop = sum(sum.(households_composition))
    household_networks = map(LightGraphs.complete_graph, sum.(households_composition))

    population_list = reduce(vcat,households)
    network = reduce(blockdiag,household_networks; init = SimpleGraph())
    index_vectors = [findall(x -> x == AgentDemographic(i), population_list) for i in 1:(AgentDemographic.size-1)]
    return (;
        population_list,
        network,
        index_vectors
    )
end



Peter Jentsch's avatar
Peter Jentsch committed
71
# func(a) = println("agent")
72
73
74
75
76
77
78
function Base.show(io::IO, status::AgentStatus) 
    if status == Susceptible
        print(io, "S")
    elseif status == Infected
        print(io, "I")
    elseif status == Recovered
        print(io, "R")
79
80
    elseif status == Immunized
        print(io, "Vac")
81
82
83
84
85
    end
end

function Base.show(io::IO, status::AgentDemographic) 
    if status == Young
86
        print(io, "<25")
87
    elseif status == Adult
88
        print(io, "20-65")
89
    elseif status == Elderly
90
        print(io, ">65")
91
92
    end
end