• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python graph.graph函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygraph.classes.graph.graph函数的典型用法代码示例。如果您正苦于以下问题:Python graph函数的具体用法?Python graph怎么用?Python graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __init__

    def __init__(self):

        self.original_dungeon = []
        self.dungeon = []
        self.size = 0
        self.LoopGraph = graph()
        self.FullGraph = graph()
        self.DistanceGraphOriginal = graph()
        self.DistanceGraph = graph()
        self.MonsterChar = "A"
        self.monster_location = '12'
        self.rogue_location = '12'
        self.is_infinitive = False
        self.all_the_moves = []
开发者ID:aliahmet,项目名称:rogue,代码行数:14,代码来源:Rogue.py


示例2: merge_graphs

def merge_graphs(g1, g2):
    """
    Merge two graphs to a new graph (V, E) with V = g1.nodes \union g2.nodes
    and Edge e \in g1 or e \in g2 -> e \in E.
    """

    if g1.DIRECTED or g2.DIRECTED:
        g = digraph()
    else:
        g = graph()

    for n in g1.nodes():
        g.add_node(n)
    for n in g2.nodes():
        if not n in g.nodes():
            g.add_node(n)
    for e in g1.edges():
        try:
            g.add_edge(e, g1.edge_weight(e))
        except:
            logging.info("merge_graphs: adding edge %d %d failed" % (e[0], e[1]))
    for e in g2.edges():
        try:
            g.add_edge(e, g2.edge_weight(e))
        except:
            logging.info("merge_graphs: adding edge %d %d failed" % (e[0], e[1]))
    return g
开发者ID:libsmelt,项目名称:Simulator,代码行数:27,代码来源:algorithms.py


示例3: teo_1

def teo_1(g, k):
  if k > len(g.nodes()):
    raise ValueError('FORBIDDEN: K > |V|')
  if k <= 0:
    raise ValueError('FORBIDDEN: K <= 0')

  # Caso base
  if k == 1:
    tree = graph()
    tree.add_node(1)
    return tree

  # Hipotese indutiva
  tree = teo_1(g, k-1)

  all_nodes = g.nodes()
  used_nodes = tree.nodes()
  external_nodes = [node for node in all_nodes if node not in used_nodes]

  r = []
  for used_node in used_nodes:
    for external_node in external_nodes:
      if g.has_edge((used_node, external_node)):
        r.append((used_node, external_node))

  new_edge = max(r, key=lambda e: g.edge_weight(e))

  a, b = new_edge
  tree.add_node(b)

  tree.add_edge(new_edge)

  return tree
开发者ID:lucashardman,项目名称:INF1631,代码行数:33,代码来源:teorema1.py


示例4: build_graph

def build_graph():
	gr = graph()

	for i in range(1,11):
		gr.add_node(i)
		gr.add_node_attribute(i, ('level', 0) )

	gr.add_edge((1,3))
	gr.add_edge((1,4))
	gr.add_edge((2,3))
	gr.add_edge((2,5))
	gr.add_edge((5,3))
	gr.add_edge((5,6))
	gr.add_edge((6,3))
	gr.add_edge((4,6))
	gr.add_edge((6,7))
	gr.add_edge((7,8))
	gr.add_edge((7,10))
	gr.add_edge((8,9))
	gr.add_edge((9,10))

	#gr.add_edge((2,8))

	gr.add_node_attribute(3, ('in', 10))

	return gr
开发者ID:cloudozer,项目名称:color_the_graph,代码行数:26,代码来源:pumping.py


示例5: drawGraph

 def drawGraph(self, inputs):
     
     fileName = 'planetModel.png'
     gr = graph()
     self.addGraphNode(1,gr, inputs)
 # Draw as PNG
     #with open("./planetModel.viz", 'wb') as f:
         #dot = write(gr,f)
         #f.write(dot)
         #gvv = gv.readstring(dot)
         #gv.layout(gvv,'dot')
         #gv.render(gvv,'png', fileName)
         #f.close()
         
     gst = digraph()
     self.addGraphNode(1,gst, inputs)            
     with open("./planetModel.viz", 'wb') as f:            
         #st, order = breadth_first_search(gst, root=1)
         #gst2 = digraph()
         #gst2.add_spanning_tree(gst.nodes())
         #gst2.(1, 'post')
         dot = write(gst,f)
         f.write(dot)
         gvv = gv.readstring(dot)
         gv.layout(gvv,'dot')
         gv.render(gvv,'png', fileName)   
         f.close()         
         
         
          
     return fileName
开发者ID:jsrawan-mobo,项目名称:mrbigdata,代码行数:31,代码来源:planetModel.py


示例6: __init__

 def __init__(self):
     """
     Initialize a hypergraph.
     """
     self.node_links = {}    # Pairing: Node -> Hyperedge
     self.edge_links = {}     # Pairing: Hyperedge -> Node
     self.graph = graph()    # Ordinary graph
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:hypergraph.py


示例7: import_network_erl

def import_network_erl(data_file,eps):
    gr = graph()
    
    with open(data_file) as f:
        line = f.readline()
        while line != '':
            
            if not coin(eps): 
                line = f.readline()
                continue

            link = line.split('"')
            #print link
            #_ = raw_input()
            n1 = link[1]
            n2 = link[3]
            #print n1,n2
            if not gr.has_node(n1): 
                gr.add_node(n1)
                gr.add_node_attribute(n1, ('col', n1))
            if not gr.has_node(n2): 
                gr.add_node(n2)
                gr.add_node_attribute(n2, ('col', n2))

            if not gr.has_edge((n1,n2)): 
                gr.add_edge((n1,n2))
            #s = raw_input()
            line = f.readline()

    f.close()
    print "Graph has %i nodes and %i edges\n" % (len(gr.nodes()), len(gr.edges()) )
    return gr
开发者ID:cloudozer,项目名称:color_the_graph,代码行数:32,代码来源:color_the_graph.py


示例8: make_graph

def make_graph(data):
    gr = graph()

    with open(data) as f:
        line = f.readline()
        while line != '':
            link = line.split()
            n1 = int(link[0])
            n2 = int(link[1])
            #print n1,n2
            if not gr.has_node(n1): 
                gr.add_node(n1)
                gr.add_node_attribute(n1, ('col', n1))
            if not gr.has_node(n2): 
                gr.add_node(n2)
                gr.add_node_attribute(n2, ('col', n2))

            if not gr.has_edge((n1,n2)): 
                gr.add_edge((n1,n2))
            #s = raw_input()
            line = f.readline()
    f.close()
    print "Graph has %i nodes and %i edges\n" % (len(gr.nodes()), len(gr.edges()) ) 

    return gr
开发者ID:sarojinigarapati,项目名称:community-detection,代码行数:25,代码来源:main1.py


示例9: getSSAroundSS

    def getSSAroundSS(self, solarSystemID, jumps):
        ss = self.getSSInfo(solarSystemID)

        color = 0
        if ss[2] > 0.5:
            color = "green"
        else:
            color = "red"

        ssRegion = colored(ss[0], color)
        ssName = colored(ss[1], color)
        ssSecruity = colored("%.1f" % ss[2], color)

        if self.ssgraph:
            gr = self.ssgraph
        else:
            gr = graph()
            nodes = self.getAllSS()
            gr.add_nodes(nodes)
            for edge in self.getAllSSEdges():
                gr.add_edge(edge)

        print "Searching for Solar Systems around %s: %s(%s) in %d jumps." % (ssRegion, ssName, ssSecruity, jumps)

        ssinrad = breadth_first_search(gr, solarSystemID, radius(jumps))
        ssinrad = ssinrad[1]

        text = "Found %d systems" % len(ssinrad)
        text = colored(text, "cyan")
        print "Done. %s, including current one." % text

        return ssinrad
开发者ID:aspcartman,项目名称:EVE-Market,代码行数:32,代码来源:eve.py


示例10: test_graph_equality_attributes

 def test_graph_equality_attributes(self):
     """
     Graph equality test. This one checks node equality. 
     """
     gr = graph()
     gr.add_nodes([0,1,2])
     gr.add_edge((0,1))
     gr.add_node_attribute(1, ('a','x'))
     gr.add_node_attribute(2, ('b','y'))
     gr.add_edge_attribute((0,1), ('c','z'))
     
     gr2 = deepcopy(gr)
     
     gr3 = deepcopy(gr)
     gr3.del_edge((0,1))
     gr3.add_edge((0,1))
     
     gr4 = deepcopy(gr)
     gr4.del_edge((0,1))
     gr4.add_edge((0,1))
     gr4.add_edge_attribute((0,1), ('d','k'))
     
     gr5 = deepcopy(gr)
     gr5.del_node(2)
     gr5.add_node(2)
     gr5.add_node_attribute(0, ('d','k'))
     
     assert gr == gr2
     assert gr2 == gr
     assert gr != gr3
     assert gr3 != gr
     assert gr != gr4
     assert gr4 != gr
     assert gr != gr5
     assert gr5 != gr
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:35,代码来源:unittests-graph.py


示例11: drawGraphFromSM

def drawGraphFromSM(SM, names, outFile):
	fig = plt.figure(1)
	plot1 = plt.imshow(SM, origin='upper', cmap=cm.gray, interpolation='nearest')
	plt.show()
		
	gr = graph()

	namesNew = []
	for i,f in enumerate(names):	
		if sum(SM[i,:])>0:
			gr.add_nodes([f])
			namesNew.append(f)
			
	Max = SM.max()
	Mean = mean(SM)

	Threshold = Mean * 1.5
	for i in range(len(names)):
		for j in range(len(names)):
			if i<j:
				if SM[i][j] > 0:
					gr.add_edge((names[i], names[j]))
	# Draw as PNG
	dot = write(gr)
	gvv = gv.readstring(dot)
	gv.layout(gvv,'dot')
	gv.render(gvv,'png', outFile)
开发者ID:tyiannak,项目名称:pyOpenAireTextClassifier,代码行数:27,代码来源:textFeatureExtraction.py


示例12: test_complete_graph

 def test_complete_graph(self):
     gr = graph()
     gr.add_nodes(xrange(10))
     gr.complete()
     for i in xrange(10):
         for j in range(10):
             self.assertTrue((i, j) in gr.edges() or i == j)
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-graph.py


示例13: create_graph

def create_graph():
    g = graph()
    g.add_node("1")
    g.add_node("2")
    g.add_node("3")
    g.add_node("4")
    g.add_node("5")
    g.add_node("6")
    g.add_node("7")
    g.add_node("8")
    g.add_node("9")

    g.add_edge(("1", "2"))
    g.add_edge(("1", "4"))
    g.add_edge(("1", "5"))
    g.add_edge(("2", "3"))
    g.add_edge(("2", "4"))
    g.add_edge(("2", "5"))
    g.add_edge(("2", "6"))
    g.add_edge(("3", "5"))
    g.add_edge(("3", "6"))
    g.add_edge(("4", "5"))
    g.add_edge(("4", "7"))
    g.add_edge(("4", "8"))
    g.add_edge(("5", "6"))
    g.add_edge(("5", "7"))
    g.add_edge(("5", "8"))
    g.add_edge(("5", "9"))
    g.add_edge(("6", "8"))
    g.add_edge(("6", "9"))
    g.add_edge(("7", "8"))
    g.add_edge(("8", "9"))
    return g
开发者ID:slhurst,项目名称:goblet-kings,代码行数:33,代码来源:ideal_graph.py


示例14: __init__

 def __init__(self):
     # graph that holds the street network
     self._graph = graph()
     self.bounds = None
     # give every street a sequential index (used for perfomance optimization)
     self.street_index = 0
     self.streets_by_index = dict()
开发者ID:NeziheSozen,项目名称:Streets4MPI,代码行数:7,代码来源:streetnetwork.py


示例15: __init__

    def __init__(self, point_free_cb, line_free_cb, dimensions):
        """
        Construct a randomized roadmap planner.

        'point_free_cb' is a function that accepts a point (two-tuple) and
        outputs a boolean value indicating whether the point is in free space.

        'line_free_cb' is a function that accepts two points (the start and the
        end of a line segment) and outputs a boolen value indicating whether
        the line segment is free from obstacles.

        'dimensions' is a tuple of tuples that define the x and y dimensions of
        the world, e.g. ((-8, 8), (-8, 8)). It should be used when generating
        random points.
        """
        self.point_free_cb = point_free_cb
        self.line_free_cb = line_free_cb
        self.dimensions = dimensions

        self.search_algorithm = euclidean()
        self.number_of_trials = 500
        self.search_result = False
        self.output_path = None
        self.id_generator = 10000
        self.graph = graph()
开发者ID:minhnh,项目名称:hbrs_courses,代码行数:25,代码来源:randomized_roadmap_planner.py


示例16: test_add_spanning_tree

 def test_add_spanning_tree(self):
     gr = graph()
     st = {0: None, 1: 0, 2:0, 3: 1, 4: 2, 5: 3}
     gr.add_spanning_tree(st)
     for each in st:
         self.assertTrue((each, st[each]) in gr.edges() or (each, st[each]) == (0, None))
         self.assertTrue((st[each], each) in gr.edges() or (each, st[each]) == (0, None))
开发者ID:svn2github,项目名称:python-graph2,代码行数:7,代码来源:unittests-graph.py


示例17: _update_hyki_graph

 def _update_hyki_graph(self):
     import re
     from pygraph.classes.graph import graph
     pattern = re.compile(LINK_RE)
     articles = HykiArticle.objects.all()
     gr = graph()
     if len(articles) > 0:
         for article in articles:
             if article.id not in gr.nodes():
                 self.create_node(gr, article)
             article_text = self._get_revision_text(article)
             results = pattern.findall(article_text)
             for link in results:
                 _source = link[7].split('/')[1]
                 _link = link[7].split('/')[2]
                 if _source == 'hyki':
                     #adjacency article links
                     for _article in articles:
                         #match link with article
                         if _article.slug == _link:
                             #doesnt point to itself
                             if _article != article:
                                 #target node doesn't exist yet
                                 if _article.id not in gr.nodes():
                                     self.create_node(gr, _article)
                                     gr.add_edge((article.id, _article.id))
                                 else:
                                     if not gr.has_edge((_article.id,article.id)):
                                         gr.add_edge((article.id, _article.id))
         self.graph_info = self.format_graph_to_thejit_tree(gr)
     else:
         self.graph_info = False
开发者ID:mmetzmac,项目名称:hwios,代码行数:32,代码来源:hyki.py


示例18: plot_graph

def plot_graph(gr):
    """
    draws the graph to file
    """
    p = 100.0 / (len(gr.nodes())+1)
    gr_ext = graph()

    
    for node in gr.nodes():
        if coin(p):
            if not gr_ext.has_node(node):
                gr_ext.add_node(node,attrs=gr.node_attributes(node))
            for n in [ ed[0] for ed in gr.edges() if ed[1] == node ]:
                if coin(0.3):
                    if not gr_ext.has_node(n):
                        gr_ext.add_node(n,attrs=gr.node_attributes(n))
                    #print "Edges:",gr_ext.edges()
                    if not gr_ext.has_edge((node,n)):
                        gr_ext.add_edge((node,n)) 
    dot = write(gr_ext)
    gvv = gv.readstring(dot)
    gv.layout(gvv,'dot')    
    if args[1]== 'karate.txt':
        gv.render(gvv,'png','community1.png') 
    elif args[1] == 'email.txt':
        gv.render(gvv,'png','community2.png')
    elif args[1] == 'hep-th-citations.txt':
        gv.render(gvv,'png','community3.png')
    elif args[1] == 'amazon1.txt':
        gv.render(gvv,'png','community4.png')
    elif args[1] == 'p2p-Gnutella30.txt':
        gv.render(gvv,'png','community5.png')
开发者ID:sarojinigarapati,项目名称:community-detection,代码行数:32,代码来源:main1.py


示例19: test_graph_equality_labels

 def test_graph_equality_labels(self):
     """
     Graph equality test. This one checks node equality. 
     """
     gr = graph()
     gr.add_nodes([0,1,2])
     gr.add_edge((0,1), label="l1")
     gr.add_edge((1,2), label="l2")
     
     gr2 = deepcopy(gr)
     
     gr3 = deepcopy(gr)
     gr3.del_edge((0,1))
     gr3.add_edge((0,1))
     
     gr4 = deepcopy(gr)
     gr4.del_edge((0,1))
     gr4.add_edge((0,1), label="l3")
          
     assert gr == gr2
     assert gr2 == gr
     assert gr != gr3
     assert gr3 != gr
     assert gr != gr4
     assert gr4 != gr
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:25,代码来源:unittests-graph.py


示例20: calGraph

 def calGraph(self):
     grafo = graph()
     for item in self.items:
         grafo.add_node(item, attrs = [("splines",  "")])
     for key, stream in self.streams.iteritems():
         grafo.add_edge((stream[0], stream[1]), attrs = [("splines",  "")])
     return grafo
开发者ID:edusegzy,项目名称:pychemqt,代码行数:7,代码来源:project.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python hypergraph.hypergraph函数代码示例发布时间:2022-05-25
下一篇:
Python digraph.digraph函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap