Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.8'
#- 'nightly'
- '1'
- '1.10'
os:
- ubuntu-latest
- macOS-latest
Expand Down Expand Up @@ -71,4 +71,4 @@ jobs:
using Documenter: DocMeta, doctest
using MultilayerGraphs
DocMeta.setdocmeta!(MultilayerGraphs, :DocTestSetup, :(using MultilayerGraphs); recursive=true)
doctest(MultilayerGraphs)'
doctest(MultilayerGraphs)'
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ Distributions = "0.25"
Graphs = "1"
IterTools = "1.4"
MetaGraphs = "0.7, 0.8"
OMEinsum = "0.7, 0.8"
OMEinsum = "0.7, 0.8, 0.9"
PrettyTables = "2.2, 3"
SimpleTraits = "0.9"
SimpleValueGraphs = "0.4"
SimpleWeightedGraphs = "1.2"
Statistics = "1"
TensorOperations = "3.2, 4"
TensorOperations = "4"
WhereTraits = "1"
julia = "1.8"
8 changes: 4 additions & 4 deletions src/subgraphs/layer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ Return a random `Layer`.
"""
function Layer(
name::Symbol,
vertices::Vector{Union{V,N}},
vertices::Union{Vector{MultilayerVertex{nothing}},Vector{Node}},
ne::Int64,
null_graph::G,
weighttype::Type{U};
default_vertex_metadata::Function=mv -> NamedTuple(),
default_edge_weight::Function=(src, dst) -> nothing,
default_edge_metadata::Function=(src, dst) -> NamedTuple(),
allow_self_loops::Bool=false,
) where {T<:Integer,U<:Real,G<:AbstractGraph{T},V<:MultilayerVertex{nothing},N<:Node}
) where {T<:Integer,U<:Real,G<:AbstractGraph{T}}
_nv = length(vertices)
@assert(
length(unique(vertices)) == _nv, "The argument `vertices` must be a unique list"
Expand All @@ -211,7 +211,7 @@ function Layer(
"The number of required edges, $ne, is greater than the number of edges the provided graph supports i.e. $maxe"
)

vertex_type = @isdefined(V) ? MultilayerVertex : Node
vertex_type = eltype(vertices)

edge_list = NTuple{2,MultilayerVertex{nothing}}[] #MultilayerEdge
fadjlist = Dict{vertex_type,Vector{vertex_type}}()
Expand Down Expand Up @@ -250,7 +250,7 @@ function Layer(
end

# Add the edge to the edge list. Convert it to a MultilayerVertex if a list of Nodes was given as `vertices`
if @isdefined(V)
if vertex_type == MultilayerVertex{nothing}
push!(edge_list, (rand_vertex_1, rand_vertex_2))
else
push!(edge_list, (MV(rand_vertex_1), MV(rand_vertex_2)))
Expand Down
2 changes: 1 addition & 1 deletion src/tensorsfactorizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function to_matrix(A, a, b; return_tensor_shape=false)

# Permute the indices of A to the right order
perm = vcat(a, b)
A = tensorcopy(A, collect(1:ndims(A)), perm)
A = tensorcopy(collect(1:ndims(A)), A, perm)
# The lists shp_a and shp_b list the dimensions of the bonds in a and b
shp = size(A)
shp_a = shp[1:length(a)]
Expand Down
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ SimpleValueGraphs = "b43c691f-cac2-5415-8122-396fe16a49fc"
SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Agents = "6"
40 changes: 23 additions & 17 deletions test/agents_jl_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,17 @@ graph = MultilayerGraph(all_layers_u, all_interlayers_u)
new_value::Float64
end
# Instantiate the agent
function EigenAgent(id, pos; initial_opinion::Float64)
return EigenAgent(id, pos, initial_opinion, initial_opinion, -1.0)
end
# Define the agent-based model
EigenABM = ABM(EigenAgent, GraphSpace(graph))
# Add agents to the ABM so that agent i is located in vertex i
for (i, mv) in enumerate(mv_vertices(graph))
initial_opinion = 1.0
add_agent!(i, EigenABM; initial_opinion=initial_opinion)
end
# function EigenAgent(; id, pos, initial_opinion::Float64)
# return EigenAgent(id, pos, initial_opinion, initial_opinion, -1.0)
# end
# Define the individual-level dynamics (micro-dynamics)
function agent_step!(agent::EigenAgent, model)
agent.previous_value = agent.old_value
return agent.new_value = sum([
agent.new_value = sum([
outneighbor_agent.old_value for
outneighbor_agent in nearby_agents(agent, model; neighbor_type=:all)
])
return agent
end
# Define the system-level dynamics (macro-dynamics)
function model_step!(model)
Expand All @@ -37,6 +31,20 @@ function model_step!(model)
agent.old_value = agent.new_value
end
end
# Define the agent-based model
EigenABM = ABM(EigenAgent, GraphSpace(graph); agent_step!, model_step!)
# Add agents to the ABM so that agent i is located in vertex i
for (i, mv) in enumerate(mv_vertices(graph))
initial_opinion = 1.0
add_agent!(
i,
EigenAgent,
EigenABM;
previous_value=initial_opinion,
old_value=initial_opinion,
new_value=-1.0,
)
end
# Set the rule to stop the model simulation
function terminate(model, s)
# println(s, typeof(s))
Expand All @@ -49,14 +57,12 @@ function terminate(model, s)
end
end
# Simulate the model
agent_data, _ = run!(
EigenABM, agent_step!, model_step!, terminate; adata=[:new_value], when=terminate
)
agent_data, _ = run!(EigenABM, terminate; adata=[:new_value], when=terminate)
# Compute the eigenvector centrality of the surrounding multilayer graph
eig_centr_swm, err_swm = eigenvector_centrality(
EigenABM.space.graph; weighted=false, tol=1e-18, norm="null"
abmspace(EigenABM).graph; weighted=false, tol=1e-18, norm="null"
)

for (val_1, val_2) in zip(eig_centr_swm, agent_data.new_value)
@test val_1val_2
for a in allagents(EigenABM)
@test a.new_valueeig_centr_swm[a.id]
end
Loading