Import Temporal Multilayer Networks into NetLogo without Data Loss

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 edgeID requires 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 list rows with timestamps, requiring aggregation by edgeID.
  • 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_time and NetLogo ticks breaks 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’s item and get primitives.
  • Step 3: Aggregate temporal edges by edgeID, converting each to a single vehicle turtle with multiple next edges in a set-current-direction loop.
  • Step 4: Synchronize time via end_time by iterating through time slices post-import.

Why Juniors Miss It

  • Overlooking attribute parsing: Assuming nw:load-graphml auto-generates breeds ignores required item/get calls.
  • Patch/node misuse: Nodes must be turtles to enable pathfinding (e.g., forward along edges).
  • Timing mismatches: Failing to align end_time with NetLogo’s ticks causes agents to abandon paths mid-simulation.

Leave a Comment