1
- # # Social networks with Graphs.jl
1
+ # # [ Social networks with Graphs.jl](@id social_networks)
2
2
3
3
# ```@raw html
4
4
# <video width="auto" controls autoplay loop>
5
5
# <source src="../schoolyard.mp4" type="video/mp4">
6
6
# </video>
7
7
# ```
8
8
9
- # Many ABM frameworks provide graph infrastructure for analysing network properties of agents.
10
- # Agents.jl is no different in that aspect, we have [`GraphSpace`](@ref) for when spatial structure
11
- # is not important, but connections are.
9
+ # Many ABM frameworks provide graph infrastructure for implementing network-based interactions
10
+ # properties of agents. Agents.jl does not provide any graph infrastructure for network-based
11
+ # interactions because it doesn't have to!
12
+ # Since Agents.jl is implemented in Julia, it can integrate directly
13
+ # with Julia's premier package for graphs, Graphs.jl.
12
14
13
- # What if you wish to model something a little more complex? Perhaps a school yard full of students
14
- # running around (in space), interacting via some social network. This is precisely the scenario that
15
- # the [MASON](https://cs.gmu.edu/~eclab/projects/mason/) ABM framework uses as an introductory example
16
- # in their [documentation](https://cs.gmu.edu/~eclab/projects/mason/manual.pdf).
15
+ # _Note as mentioned in the documentation of [`GraphSpace`](@ref) that network-based
16
+ # interactions should not be modeled as a space, even though other ABM frameworks
17
+ # implement it as such as an only option!_
17
18
18
- # Rather than implementing an Agents.jl⸺specific graph structure, we can interface with
19
- # [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl): a high class library for managing
20
- # and implementing graphs, which can be re-used to establish social networks within existing spaces.
19
+ # In this example we will model the situation where there is both a network structure
20
+ # in agent interactions, but also a completely independent spatial structure in the model.
21
+ # We will model a school yard full of students
22
+ # running around (in space) _and_ interacting via some social network.
21
23
22
24
# To begin, we load in some dependencies
23
25
@@ -47,21 +49,22 @@ const Student = ContinuousAgent{2,Float64}
47
49
# ## Initialising the model
48
50
49
51
function schoolyard (;
50
- numStudents = 50 ,
51
- teacher_attractor = 0.15 ,
52
- noise = 0.1 ,
53
- max_force = 1.7 ,
54
- spacing = 4.0 ,
55
- seed = 6998 ,
56
- velocity = (0 , 0 ),
57
- )
52
+ numStudents = 50 ,
53
+ teacher_attractor = 0.15 ,
54
+ noise = 0.1 ,
55
+ max_force = 1.7 ,
56
+ spacing = 4.0 ,
57
+ seed = 6998 ,
58
+ velocity = (0 , 0 ),
59
+ )
58
60
model = StandardABM (
59
61
Student,
60
62
ContinuousSpace ((100 , 100 ); spacing= spacing, periodic= false );
61
63
agent_step!,
62
64
properties = Dict (
63
65
:teacher_attractor => teacher_attractor,
64
66
:noise => noise,
67
+ # # This is the graph
65
68
:buddies => SimpleWeightedDiGraph (numStudents),
66
69
:max_force => max_force,
67
70
),
@@ -81,9 +84,10 @@ function schoolyard(;
81
84
model
82
85
end
83
86
84
- # Our model contains the `buddies` property, which is our Graphs.jl directed, weighted graph.
85
- # As we can see in the loop, we choose one `friend` and one `foe` at random for each `student` and
86
- # assign their relationship as a weighted edge on the graph.
87
+ # Our model contains the `buddies` property, which is our Graphs.jl directed and weighted graph.
88
+ # Here we chose one `friend` and one `foe` at random for each student` and assign their
89
+ # relationship as a weighted edge on the graph.
90
+ # By construction, the agent ID and graph node ID coincide.
87
91
88
92
# ## Movement dynamics
89
93
132
136
# that force should be in a positive or negative direction (*friend* or *foe*?).
133
137
134
138
# The `findnz` function is something that may require some further explanation.
135
- # Graphs uses sparse vectors internally to efficiently represent data.
139
+ # Graphs.jl uses sparse vectors internally to efficiently represent data.
136
140
# When we find the `network` of our `student`, we want to convert the result to
137
141
# a dense representation by **find**ing the **n**on-**z**ero (`findnz`) elements.
138
142
0 commit comments