[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Does igraph support node ports/records?
From: |
Tamás Nepusz |
Subject: |
Re: [igraph] Does igraph support node ports/records? |
Date: |
Fri, 20 Jan 2012 23:43:31 +0100 |
> In my case, it's not the visualization I need so much as the concept.
Oh, right, sorry, I misunderstood what you want then.
In this case, you can probably simply use node and edge attributes to achieve
what you want. For instance, you can attach a node attribute called "counters"
to every node. The attribute value could be a Python dict for every node that
maps the name of the port to its corresponding counter. (If you use a
defaultdict(int) then you don't even have to worry about nonexistent port
names, they will be created automagically). Besides that, you can add a tuple
named "ports" to every edge, which contains the name of the source and the
target port the edge is connected to. The downside of this solution is that you
cannot save your graph into GraphML or DOT format without losing the attributes
since most igraph exporters handle string and numeric attributes only -- the
only exception being the "pickled" format, which saves everything in Python's
native pickle format so it preserves all the attributes.
So, basically I'm thinking about something like this:
# Attach a defaultdict to the "counters" attribute of every vertex
graph.vs["counters"] = [defaultdict(int) for v in graph.vs]
for packet in my_list_of_packets:
graph.vs[packet.source]["counters"][packet.source_port] += 1
graph.vs[packet.target]["counters"][packet.target_port] += 1
where "packet" is a custom class representing Ethernet packets in your example
with attributes like source, target, source_port and target_port (where source
and target are numeric indices from zero), and my_list_of_packets is the list
of packets to process.
Cheers,
Tamas