本文整理汇总了Python中networkx.Graph.subgraph方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.subgraph方法的具体用法?Python Graph.subgraph怎么用?Python Graph.subgraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.subgraph方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subnetwork
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import subgraph [as 别名]
def subnetwork(self, nbunch, pos=None):
""" Returns Network instance with nbunch nodes, see subgraph. """
if not pos:
pos = self.pos
H = Graph.subgraph(self, nbunch)
for node in H:
H.pos.update({node: pos[node][:2]})
if len(pos[node]) > 2:
H.ori.update({node: pos[node][2]})
else:
H.ori.update({node: self.ori[node]})
H.labels.update({node: self.labels[node]})
H._environment = deepcopy(self._environment)
assert(isinstance(H, Network))
return H
示例2: _get_fbvs
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import subgraph [as 别名]
def _get_fbvs(self, graph: Graph):
# get the list of cycles
cycles = cycle_basis(graph)
# if the graph is already acyclic, there's nothing to remove, so return an empty set
if len(cycles) == 0:
return set()
# get the set of nodes that is in at least one cycle
nodes_in_cycles = set([item for sublist in cycles for item in sublist])
min_num_to_remove = sys.maxsize
min_nodes_to_remove = set()
for node in nodes_in_cycles:
# make an induced subgraph with the current node removed
nodes = graph.nodes()
nodes.remove(node)
nodes_set = frozenset(nodes)
if nodes_set in self.cacheDict:
# if we have previously calculated the min fbvs for this induced subgraph, get that
# fbvs from the cache dict
nodes_to_remove = self.cacheDict[nodes_set]
else:
# otherwise we have to calculate it
new_graph = graph.subgraph(nodes)
nodes_to_remove = self._get_fbvs(new_graph)
# add the newly calculated fbvs to the cache dict
self.cacheDict[nodes_set] = nodes_to_remove
if len(nodes_to_remove) < min_num_to_remove:
min_num_to_remove = len(nodes_to_remove)
nodes_to_remove.add(node)
min_nodes_to_remove = nodes_to_remove
return min_nodes_to_remove
示例3: Network
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import subgraph [as 别名]
#.........这里部分代码省略.........
""" Creates the datasource manager instance if not yet available """
if self.active:
if self.datasourcemanager is None:
logger.debug('Create a DatasourceManager instance')
self.datasourcemanager = DatasourceManager(network=self)
else:
logger.debug('DatasourceManager instance already running. This is an error.')
def _render_matrix(self):
""" Invokes the connectivity matrix viewer """
# assume the network is activated (i.e. data source generated)
# we need the edge parameter instance initialized
if self._edge_para is None:
self._edge_para = EdgeParameters(self, self.rendermanager.attract.point_scalars_name)
logger.debug('Invoke Matrix Viewer...')
self.rendermanager.invoke_matrix_viewer()
def _trackvis_launch(self):
""" Generates scene file and launch Trackvis on the selected nodes """
import tempfile
logger.debug('Starting TrackVis ...')
# extract selected subgraph
selectionlist = self.get_selectiongraph_list()
if len(selectionlist) == 0:
# message
from enthought.traits.ui.message import message
message(message = 'No nodes selected for ROI creation!', title = 'Infomessage', buttons = [ 'OK' ], parent = None)
tmpgraph = self.graph.subgraph(selectionlist)
# extract trackfile temporarily
if len(self.tracks) == 0:
logger.info('No trackfile found to invoke Trackvis.')
return
else:
# load the first trackfile
trackfname = self.tracks[0].load_trackfile_to_file()
# find the first valid segmentation volume in the self.volumes list
for vol in self.volumes:
if vol.segmentation:
logger.debug('Found a segmentation volume file. Assume labels are corresponding.')
volumefname = vol.load_volume_to_file()
break
# generate the scene file in the temporary folder
tmpscenefile=tempfile.mkstemp(prefix='tmp', suffix='.scene')
# generate trackfile
generate_scene_file(scenefname=tmpscenefile[1], \
trackfname = trackfname, \
volumefname = volumefname, \
selectiongraph = tmpgraph)
# execute trackvis in a thread
pref = preference_manager.preferences
action = ThreadedTrackvis(tvpath = pref.get('cviewer.plugins.ui.trackvispath'), \
fname = tmpscenefile[1], \
trkfname = trackfname,\
volfname = volumefname)