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


Python Graph.remove_edge方法代码示例

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


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

示例1: generate_small_world_graph

# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import remove_edge [as 别名]
 def generate_small_world_graph(self):
     max_edges = self.NODE_COUNT*(self.NODE_COUNT-1)/2
     if self.EDGE_COUNT > max_edges:
         return complete_graph(self.NODE_COUNT)
     graph = Graph()
     graph.add_nodes_from(range(self.NODE_COUNT))
     edges = performer.edge_indices.flatten()
     probabilities = performer.probabilities.flatten()
     for trial in range(len(edges)-9):
         edge_index = numpy.random.choice(edges, p=probabilities)
         source, destination = self.edge_nodes(edge_index)
         graph.add_edge(source, destination, length = self.link_length(source, destination),
                        weight = self.edge_weight(source, destination))
         probabilities[edge_index] = 0
         probabilities /= sum(probabilities)
         if max(graph.degree().values()) > self.DEGREE_MAX:
             graph.remove_edge(source, destination)
         if graph.number_of_edges() > self.EDGE_COUNT:
             victim = random.choice(graph.edges())
             graph.remove_edge(victim[0], victim[1])
         if self.constraints_satisfied(graph):
             print 'performer.generate_small_world_graph:',
             print self.BENCHMARK, self.NODE_COUNT, self.EDGE_COUNT, trial
             self.process_graph(graph)
             return graph
开发者ID:yuchenhou,项目名称:artificial-architect,代码行数:27,代码来源:architect.py

示例2: recalculate_edges

# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import remove_edge [as 别名]
 def recalculate_edges(self, nodes=[]):
     """ Recalculate edges for given nodes or for all self.nodes().
     Edge between nodes n1 and n2 are added if both are
     ChannelType.in_comm_range of each other"""
     if(not nodes):
         nodes = self.nodes()
     for n1 in nodes:
         for n2 in self.nodes():
             if (n1 != n2):
                 if (self.channelType.in_comm_range(self, n1, n2)):
                     Graph.add_edge(self, n1, n2)
                 elif (Graph.has_edge(self, n1, n2)):
                     Graph.remove_edge(self, n1, n2)
开发者ID:engalex,项目名称:pymote,代码行数:15,代码来源:network.py

示例3: remove_edge

# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import remove_edge [as 别名]
 def remove_edge(self, u, v): 
     Graph.remove_edge(self,u,v)
     self.fh.write("Remove edge: %s-%s\n"%(u,v))
开发者ID:Jverma,项目名称:networkx,代码行数:5,代码来源:printgraph.py

示例4: LangGraph

# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import remove_edge [as 别名]

#.........这里部分代码省略.........
		"""
		Makes the mapping from instances to their narrative index
		"""
		return {inst:i for i,inst in enumerate(self.temporal)}

	def addNode(self, node):
		"""
		Adds a node to the graph
		"""
		self.graph.add_node(node)

	def addEdge(self, start, end, type):
		"""
		Adds an edge between the two instances
		"""
		#if the edge exists, just add the type
		if self.graph.has_edge(start, end):
			self.addType(start, end, type)
		else:
			self.graph.add_edge(start, end, TYPES=set([type]))

	def removeEdge(self, start, end, edgeType):
		"""
		Removes an edge with a given type from the edge type
		"""
		#remove the type
		self.removeType(start, end, edgeType)

		#if there are no types, remove the edge itself
		types = self.edgeTypes(start, end)

		#remove the edge
		if not len(types) and self.graph.has_edge(start, end):
			self.graph.remove_edge(start, end)

	def addType(self, start, end, type):
		"""
		Adds a type between the edges
		"""
		#look for existing types
		types = self.graph[start][end].get(TYPES, set())

		#add the new type
		types.add(type)

		self.graph[start][end][TYPES] = types

	def removeType(self, start, end, edgeType):
		"""
		Removes the type on the edge
		"""
		for prefix in [PARENT, CHILD]:
			edgeType = removePrefix(prefix, edgeType)

		types = self.graph[start][end][TYPES]

		#if the types contains the edge, remove
		if edgeType in types:
			types.remove(edgeType)

	def hasType(self, start, end, type):
		"""
		Returns true if the edge between the two nodes has the given
		type
		"""
		return type in self.edgeTypes(start, end)
开发者ID:jworr,项目名称:ml_tools,代码行数:70,代码来源:docgraph.py


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