graphit/graph_helpers.py
def renumber_id(graph, start):
    """
    Renumber all node ID's in the graph from a new start ID and adjust edges
    accordingly. Useful when duplicating a graph substructure.
    If the graph uses auto_nid, the node nid is also changed.
    
    #TODO: this one failes if run on a subgraph. Probably need to make changes
    #to nids in place instead of registering new storage
    
    :param graph:   Graph object to renumber
    :type graph:    Graph object
    :param start:   New start number to renumber from
    :type start:    :py:int
    :return:        Renumber graph and mapping of old to new ID
    :rtype:         Graph object, :py:dict
    """
    
    start = copy.copy(start)
    mapper = {}
    for nid, value in sorted(graph.nodes.items()):
        mapper[value['_id']] = start
        
        # Renumber
        value['_id'] = start
        start += 1

    # Update root and auto_nid
    graph._nodeid = start
    if graph.root:
        graph.root = mapper[graph.root]

    # Update nid if auto_nid
    newnodes = {}
    if graph.auto_nid:
        newnodes = {v: graph.nodes[k] for k, v in mapper.items()}

    # Update edges.
    newedges = {}
    for eid, edge in graph.edges.items():
        newedges[(mapper.get(eid[0], eid[0]), mapper.get(eid[1], eid[1]))] = edge

    graph.nodes, graph.edges, graph.adjacency = graph.storagedriver(newnodes, newedges)

    return graph, mapper

    Renumber all node ID's in the graph from a new start ID and adjust edges
    accordingly. Useful when duplicating a graph substructure.
    If the graph uses auto_nid, the node nid is also changed.
    
    #TODO: this one failes if run on a subgraph. Probably need to make changes
    #to nids in place instead of registering new storage
    
    :param graph:   Graph object to renumber
    :type graph:    Graph object
    :param start:   New start number to renumber from
    :type start:    :py:int
    :return:        Renumber graph and mapping of old to new ID
    :rtype:         Graph object, :py:dict
    
Renumber all node ID's in the graph from a new start ID and adjust edges
accordingly. Useful when duplicating a graph substructure.
If the graph uses auto_nid, the node nid is also changed.

this one failes if run on a subgraph. Probably need to make changes
to nids in place instead of registering new storage
Renumber all node ID ' s in the graph from a new start ID and adjust edges accordingly . Useful when duplicating a graph substructure . If the graph uses auto_nid the node nid is also changed . this one failes if run on a subgraph . Probably need to make changes to nids in place instead of registering new storage
def renumber_id(graph, start):
    start = copy.copy(start)
    mapper = {}
    for nid, value in sorted(graph.nodes.items()):
        mapper[value['_id']] = start
        value['_id'] = start
        start += 1
    graph._nodeid = start
    if graph.root:
        graph.root = mapper[graph.root]
    newnodes = {}
    if graph.auto_nid:
        newnodes = {v: graph.nodes[k] for k, v in mapper.items()}
    newedges = {}
    for eid, edge in graph.edges.items():
        newedges[(mapper.get(eid[0], eid[0]), mapper.get(eid[1], eid[1]))] = edge
    graph.nodes, graph.edges, graph.adjacency = graph.storagedriver(newnodes, newedges)
    return graph, mapper
def renumber_id ( graph , start ) : start = copy . copy ( start ) mapper = { } for nid , value in sorted ( graph . nodes . items ( ) ) : mapper [ value [ '_id' ] ] = start value [ '_id' ] = start start += 1 graph . _nodeid = start if graph . root : graph . root = mapper [ graph . root ] newnodes = { } if graph . auto_nid : newnodes = { v : graph . nodes [ k ] for k , v in mapper . items ( ) } newedges = { } for eid , edge in graph . edges . items ( ) : newedges [ ( mapper . get ( eid [ 0 ] , eid [ 0 ] ) , mapper . get ( eid [ 1 ] , eid [ 1 ] ) ) ] = edge graph . nodes , graph . edges , graph . adjacency = graph . storagedriver ( newnodes , newedges ) return graph , mapper
Renumber all node ID's in the graph from a new start ID and adjust edges
accordingly.
Renumber all node ID ' s in the graph from a new start ID and adjust edges accordingly .
"""
    Renumber all node ID's in the graph from a new start ID and adjust edges
    accordingly. Useful when duplicating a graph substructure.
    If the graph uses auto_nid, the node nid is also changed.
    
    #TODO: this one failes if run on a subgraph. Probably need to make changes
    #to nids in place instead of registering new storage
    
    :param graph:   Graph object to renumber
    :type graph:    Graph object
    :param start:   New start number to renumber from
    :type start:    :py:int
    :return:        Renumber graph and mapping of old to new ID
    :rtype:         Graph object, :py:dict
    """ # Renumber # Update root and auto_nid # Update nid if auto_nid # Update edges.
Renumber graph and mapping of old to new ID
Renumber graph and mapping of old to new ID
Graph object, :py:dict
graph
Graph object to renumber
Graph object to renumber
start
New start number to renumber from
New start number to renumber from