Summary
Successfully importing and modeling temporal multilayer directed networks in NetLogo requires addressing multiplex data structure preservation, dynamic breed assignment, and attribute mapping from networkx-temporal outputs to NetLogo’s turtle-based agents.
Root Cause
The core issue stems from mismatches between:
- GraphML serialization: Multiplex layers and temporal edges are embedded as metadata, not native agent breeds.
- NetLogo syntax limitations: No built-in support for temporal/graphML edge attributes in
nw:load-graphml. - Agent breed confusion: Creating vehicle turtle breeds dynamically based on
edgeIDrequires manual attribute parsing.
Why This Happens in Real Systems
- Multiplex layers (e.g.,
veh_type): Stored as edge attributes, not native NetLogo breeds. - Temporal edges: Wrapped in
edge listrows with timestamps, requiring aggregation byedgeID. - Agent breed scoping: NetLogo lacks first-class support for heterogeneous agent breeds.
Real-World Impact
- Failed agent creation: Missing
edgeID-to-turtle mapping causes vehicles to vanish. - Stagnant edges: Nodes remain as patches, blocking pathfinding.
- Temporal drift: Time synchronization between Python
end_timeand NetLogoticksbreaks simulation fidelity.
Example or Code
globals [graph]
breed [nodes node]
breed [vehicles vehicle]
extensions [nw]
to setup
clear-all
nw:init
load-graphml "path/to/graph.xml" ; Ensure graphML includes node/edge attributes
setup-nodes
setup-vehicles
reset-ticks
end
to setup-nodes
; Convert patches to turtles for node mobility
ask patches [ create-nodes ]
ask nodes [ pen-down set-shape "circle" set-color orange ]
end
to create-nodes
let current-node one-of patches-with []
ifelse count patches with [empty?] > 0 [
ask current-node [ set pcolor white create-nodes ]
][
set pcolor black set-shaped? true
hatch-nodes 1 [
setxy current-node-xcor current-node-ycor
set label "N" ; Replace with actual node IDs from graphML
]
]
end
to setup-vehicles
ask edges with [label ?] [ ; Extract edgeIDs from GraphML
let edgeID label
hatch-vehicles 1 [
set xcor source-node-xcor
set ycor source-node-ycor
set color color-from-name (item 0 (get edgeID "veh_type"))
]
]
end
How Senior Engineers Fix It
- Step 1: Validate GraphML structure using XML validators to ensure all attributes (
edgeID,source,target,veh_type,end_time) are correctly serialized. - Step 2: Map multiplex attributes (e.g.,
veh_type) to turtle colors/breeds using NetLogo’sitemandgetprimitives. - Step 3: Aggregate temporal edges by
edgeID, converting each to a single vehicle turtle with multiplenextedges in aset-current-directionloop. - Step 4: Synchronize time via
end_timeby iterating through time slices post-import.
Why Juniors Miss It
- Overlooking attribute parsing: Assuming
nw:load-graphmlauto-generates breeds ignores requireditem/getcalls. - Patch/node misuse: Nodes must be turtles to enable pathfinding (e.g.,
forwardalong edges). - Timing mismatches: Failing to align
end_timewith NetLogo’stickscauses agents to abandon paths mid-simulation.