@@ -11,23 +11,17 @@ graph = MultilayerGraph(all_layers_u, all_interlayers_u)
1111 new_value:: Float64
1212end
1313# Instantiate the agent
14- function EigenAgent (id, pos; initial_opinion:: Float64 )
15- return EigenAgent (id, pos, initial_opinion, initial_opinion, - 1.0 )
16- end
17- # Define the agent-based model
18- EigenABM = ABM (EigenAgent, GraphSpace (graph))
19- # Add agents to the ABM so that agent i is located in vertex i
20- for (i, mv) in enumerate (mv_vertices (graph))
21- initial_opinion = 1.0
22- add_agent! (i, EigenABM; initial_opinion= initial_opinion)
23- end
14+ # function EigenAgent(; id, pos, initial_opinion::Float64)
15+ # return EigenAgent(id, pos, initial_opinion, initial_opinion, -1.0)
16+ # end
2417# Define the individual-level dynamics (micro-dynamics)
2518function agent_step! (agent:: EigenAgent , model)
2619 agent. previous_value = agent. old_value
27- return agent. new_value = sum ([
20+ agent. new_value = sum ([
2821 outneighbor_agent. old_value for
2922 outneighbor_agent in nearby_agents (agent, model; neighbor_type= :all )
3023 ])
24+ return agent
3125end
3226# Define the system-level dynamics (macro-dynamics)
3327function model_step! (model)
@@ -37,6 +31,20 @@ function model_step!(model)
3731 agent. old_value = agent. new_value
3832 end
3933end
34+ # Define the agent-based model
35+ EigenABM = ABM (EigenAgent, GraphSpace (graph); agent_step!, model_step!)
36+ # Add agents to the ABM so that agent i is located in vertex i
37+ for (i, mv) in enumerate (mv_vertices (graph))
38+ initial_opinion = 1.0
39+ add_agent! (
40+ i,
41+ EigenAgent,
42+ EigenABM;
43+ previous_value= initial_opinion,
44+ old_value= initial_opinion,
45+ new_value= - 1.0 ,
46+ )
47+ end
4048# Set the rule to stop the model simulation
4149function terminate (model, s)
4250 # println(s, typeof(s))
@@ -49,14 +57,12 @@ function terminate(model, s)
4957 end
5058end
5159# Simulate the model
52- agent_data, _ = run! (
53- EigenABM, agent_step!, model_step!, terminate; adata= [:new_value ], when= terminate
54- )
60+ agent_data, _ = run! (EigenABM, terminate; adata= [:new_value ], when= terminate)
5561# Compute the eigenvector centrality of the surrounding multilayer graph
5662eig_centr_swm, err_swm = eigenvector_centrality (
57- EigenABM. space . graph; weighted= false , tol= 1e-18 , norm= " null"
63+ abmspace ( EigenABM) . graph; weighted= false , tol= 1e-18 , norm= " null"
5864)
5965
60- for (val_1, val_2) in zip (eig_centr_swm, agent_data . new_value )
61- @test val_1 ≈ val_2
66+ for a in allagents (EigenABM )
67+ @test a . new_value ≈ eig_centr_swm[a . id]
6268end
0 commit comments