本文整理汇总了Python中graph_tool.Graph.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.copy方法的具体用法?Python Graph.copy怎么用?Python Graph.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import copy [as 别名]
class GraphClass:
#------------#
# Initialize #
#------------#
def __init__ (self, dicProp={"Name": "Graph", "Type": "None", "Weighted": False}, graph=None):
''' init from properties '''
self.dicProperties = deepcopy(dicProp)
self.dicGetProp = { "Reciprocity": get_reciprocity, "Clustering": get_clustering, "Assortativity": get_assortativity,
"Diameter": get_diameter, "SCC": get_num_scc, #"Spectral radius": get_spectral_radius,
"WCC": get_num_wcc, "InhibFrac": get_inhib_frac }
self.dicGenGraph = { "Erdos-Renyi": gen_er, "Free-scale": gen_fs, "EDR": gen_edr }
# create a graph
if graph != None:
# use the one furnished
self.__graph = graph
self.update_prop()
self.bPropToDate = True
elif dicProp["Type"] == "None":
# create an empty graph
self.__graph = Graph()
self.bPropToDate = False
else:
# generate a graph of the requested type
self.__graph = self.dicGenGraph[dicProp["Type"]](self.dicProperties)
self.update_prop()
self.set_name()
self.bPropToDate = True
@classmethod
def from_graph_class(cls, graphToCopy):
''' create new GraphClass instance as a deepcopy of another '''
dicProperties = deepcopy(graphToCopy.get_dict_properties())
gtGraph = graphToCopy.get_graph().copy()
# create
graphClass = cls(dicProperties, gtGraph)
# set state of properties
bPropToDate = deepcopy(graphToCopy.bPropToDate)
bBetwToDate = deepcopy(graphToCopy.bBetwToDate)
graphClass.bPropToDate = bPropToDate
graphClass.bBetwToDate = bBetwToDate
return graphClass
def copy(self):
''' returns a deepcopy of the graphClass instance '''
graphCopy = GraphClass()
graphCopy.set_graph(self.__graph.copy())
graphCopy.update_prop()
graphCopy.set_name(self.dicProperties["Name"]+'_copy')
return graphCopy
#---------------------------#
# Manipulating the gt graph #
#---------------------------#
def set_graph(self, gtGraph):
''' acquire a graph_tool graph as its own '''
if gtGraph.__class__ == Graph:
self.__graph = gtGraph
else:
raise TypeError("The object passed to 'copy_gt_graph' is not a < class 'graph_tool.Graph' > but a {}".format(gtGraph.__class__))
def inhibitory_subgraph(self):
''' create a GraphClass instance which graph contains only
the inhibitory connections of the current instance's graph '''
graph = self.graph.copy()
epropType = graph.new_edge_property("bool",-graph.edge_properties["type"].a+1)
graph.set_edge_filter(epropType)
inhibGraph = GraphClass()
inhibGraph.set_graph(Graph(graph,prune=True))
inhibGraph.set_prop("Weighted", True)
return inhibGraph
def excitatory_subgraph(self):
''' create a GraphClass instance which graph contains only
the excitatory connections of the current instance's graph '''
graph = self.graph.copy()
epropType = graph.new_edge_property("bool",graph.edge_properties["type"].a+1)
graph.set_edge_filter(epropType)
excGraph = GraphClass()
excGraph.set_graph(Graph(graph,prune=True))
excGraph.set_prop("Weighted", True)
return excGraph
#-------------------------#
# Set or update functions #
#-------------------------#
def set_name(self,name=""):
''' set graph name '''
if name != "":
self.dicProperties["Name"] = name
else:
strName = self.dicProperties["Type"]
tplUse = ("Nodes", "Edges", "Distribution")
for key,value in self.dicProperties.items():
if key in tplUse and (value.__class__ != dict):
strName += '_' + key[0] + str(value)
if key == "Clustering":
#.........这里部分代码省略.........