Skip to content

Commit

Permalink
Sort nodes and edges in GraphML output
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Dec 11, 2024
1 parent f702059 commit a99ace9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crimson_forge/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def size(self):

class DiGraphBase(networkx.DiGraph):
def _graph_edges(self):
return self.edges
yield from sorted(self.edges, key=lambda nodes: (nodes[0].address, nodes[1].address))

def _graphml_id(self, node):
return node
Expand All @@ -164,7 +164,7 @@ def _graphml_node_attributes(self, node):
def _graphml_graph(self, parent, id_prefix=''):
graph = ElementTree.SubElement(parent, 'graph', attrib={'edgedefault': 'directed'})
self.__graphml_add_attributes(graph)
for node in self.nodes:
for node in sorted(self.nodes, key=lambda node: node.address):
xml_node_id = id_prefix + self._graphml_id(node)
element = ElementTree.SubElement(graph, 'node', attrib={'id': xml_node_id})
self.__graphml_add_attributes(element, node)
Expand Down

0 comments on commit a99ace9

Please sign in to comment.