-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40850f7
commit 3636e8a
Showing
3 changed files
with
120 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import networkx as nx | ||
|
||
class EMBED_TOOLS: | ||
def __init__(self, G): | ||
SHALLOW_COPY = nx.Graph() | ||
SHALLOW_COPY.add_nodes_from(G.nodes()) | ||
SHALLOW_COPY.add_edges_from(G.edges()) | ||
self.SHALLOW_COPY = SHALLOW_COPY | ||
|
||
def GET_COPY(self): | ||
return self.SHALLOW_COPY | ||
|
||
def DELETE_NODES(self, nodes): | ||
# make another copy | ||
TEMP = nx.Graph() | ||
TEMP.add_nodes_from(self.SHALLOW_COPY.nodes()) | ||
TEMP.add_edges_from(self.SHALLOW_COPY.edges()) | ||
# usable version | ||
for n in nodes: | ||
n1 = list(TEMP.neighbors(n)) | ||
toRestore = [] | ||
for nn in n1: | ||
if len(list(TEMP.neighbors(nn))) == 1: | ||
toRestore.append(nn) | ||
TEMP.remove_node(n) | ||
for nn in toRestore: | ||
TEMP.add_node(nn) | ||
return TEMP | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters