当前位置: 首页>>代码示例>>Python>>正文


Python Graph.remove_node方法代码示例

本文整理汇总了Python中Graph.Graph.remove_node方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.remove_node方法的具体用法?Python Graph.remove_node怎么用?Python Graph.remove_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph.Graph的用法示例。


在下文中一共展示了Graph.remove_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Node

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import remove_node [as 别名]
node1 = Node('darkstar.wi.mit.edu')
node2 = Node('fang.harvard.edu')
node3 = Node('www.wi.mit.edu')
edge1 = Edge('t3')
edge2 = Edge('t1')

network = Graph()
network.add_node(node1)
network.add_node(node2)
network.add_node(node3)
network.add_edge(edge1, node1, node2)
network.add_edge(edge2, node1, node3)

print "*"*44
print "current graph"
network.dump()

print
print "*"*44
print "now removing", edge2
network.remove_edge(edge2)

network.dump()

print "*"*44
print "now removing", node1
network.remove_node(node1)
network.dump()

开发者ID:MasaruFukuie,项目名称:Frog2,代码行数:30,代码来源:test_graph.py

示例2: __init__

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import remove_node [as 别名]
class Molecules:

  # constructor sets up the class
  # It takes an event queue that will contain the posey assembly events, an
  # initial list of molecule graphs and two hooks into the gui, one to set the
  # list of elements displayed when a new posey graph is produced, and one to force
  # update of the currently displayed molecule.
  def __init__ (self, event_queue, isomorphism_list, set_gui_list, update_display):
    # initialize various fields
    # list of possible molecules
    self.isomorphism_list = isomorphism_list
    # a copy of the original possible molecules for backtracking on
    # destroy or disconnect events
    self.original_isomorphism_list = isomorphism_list[:]
    # part data
    self.part_library = Part_Library( hub_class=Hub,
                                     strut_class=Strut )

    # posey graph
    self.iso_graph = Graph()
    # information on currently connected pieces to help update the graph
    self.node_dict = {}
    self.socket_dict = {}
    self.strut_dict = {}

    #setting gui hook
    self.set_gui_list = set_gui_list
    self.update_display = update_display

    # print initial moledcules
    print "Initial possible molecules (%d):" % len(self.isomorphism_list)
    self.isomorphism_list.sort(key=self.molecule_key)
    self.set_gui_list(self.isomorphism_list)
    for el in self.isomorphism_list:
      print "%s,"% el[0],
    print ""
    print "\n"

    #start thread to process assembly events
    t = threading.Thread(target=self.event_wait,args=(event_queue,))
    t.setDaemon(1)
    t.start()
   
  # We sort molecules by size
  def molecule_key (self, m):
    return m[1].adj_matrix.shape[0]

  # Used with map: for each graph in our list, try to
  # match the posey graph to it.
  def map_isomorphisms( self, large ):
    if self.iso_graph.adj_matrix.shape[0] == 0:
      # the graph is empty
      return (large[0], large[1], {})
    if self.iso_graph.adj_matrix.shape[0] > large[1].adj_matrix.shape[0]:
      # return if we are larger than the molecule we are testing against
      return (large[0], large[1], None)
    gm = GM.Graph_Matcher(large[1], self.iso_graph)
    iso_map = gm.get_isomorphism()
    return (large[0], large[1], iso_map)


  # Used with filter to get rid of failed matches.
  def filter_isomorphisms( self, triple ):
    return triple[2] is not None


  # wait for events, update the iso graph
  def event_wait (self, event_queue):
    while 1:
      self.update_isomorphisms(event_queue.get())


  # process assembly events; update graph; update list of molecules
  def update_isomorphisms( self, event ):

    #create event
    if event["type"] == "create":
      #find out what node this is
      gn = Graph_Node(self.part_library[event["hub"]].label)
      print "Received create event: %s(%d)." % (gn.label, gn.unique)
      # add it to dictionary of nodes in our graph
      self.node_dict[event["hub"]] = gn
      # add it to the graph
      self.iso_graph.add_node(gn)

    #destroy
    elif event["type"] == "destroy":
      # find out what node it is
      try:
        gn = self.node_dict[event["hub"]]
        print "Received destroy event: %s(%d)" % (gn.label, gn.unique)
        # remove node from graph
        self.iso_graph.remove_node(gn)
        # remove node from dictionary
        del self.node_dict[event["hub"]]
        # replace molecule list with original list
        # This requires some explanation. Since we filter out unmatching graphs,
        # our list of matching molecules gets smaller monotonically.  When we
        # need to make our list larger on destroy or disconnect, we refilter the
        # whole list.
#.........这里部分代码省略.........
开发者ID:philetus,项目名称:molecule_graph_matcher,代码行数:103,代码来源:Molecules.py


注:本文中的Graph.Graph.remove_node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。