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


Python Graph.get_edgelist方法代码示例

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


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

示例1: Graph

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

foster = Graph().LCF(90, [17, -9, 37, -37, 9, -17], 15)
foster.to_directed()

print "Is Directed? " + str(foster.is_directed())

for start in range(0, 90):
    for end in range(0, 90):
        # Don't delete this. Delete opposite direction edge
        if start + 1 == end:
            opposite_ID = foster.get_eid(end, start, True, False)
            if opposite_ID != 1:
                foster.delete_edges([opposite_ID])
        else:
            opposite_ID = foster.get_eid(end, start, True, False)
            if opposite_ID != -1:
                current_ID = foster.get_eid(start, end, True, False)
                if current_ID != -1:
                    foster.delete_edges([current_ID])

print "Number of Edges: " + str(len(foster.get_edgelist()))
print (foster.is_connected())

foster_list = foster.get_adjacency()

for sublist in foster_list:
    sublist = map(str, sublist)
    sublist_string = " ".join(sublist)
    print (sublist_string)
开发者ID:afrancis13,项目名称:MAS-Solver,代码行数:32,代码来源:fosters.py

示例2: str

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import get_edgelist [as 别名]
    FromNodeIDtoVerticeID[vertice] = count
    # In gr.vs, each vertice has two characters.
    gr.vs[count]['verticeID'] = count
    gr.vs[count]['NodeID'] = str(vertice)
    count += 1
#print 'map from NodeID to verticeID: '
#print FromNodeIDtoVerticeID
#Now we map long NodeID into VerticeID.

for rawlikedata_line in rawlikedata:
    gr.add_edges((
        FromNodeIDtoVerticeID[rawlikedata_line['LikeFromID']],
        FromNodeIDtoVerticeID[rawlikedata_line['LikeToID']]))
#print summary(gr)

edgelist = gr.get_edgelist()
#Now we finish building edges.

length = len(NodeList)
#print 'nodelist: ' + str(length)


OneGroup = {}
AnotherGroup = {}
#We should make sure that there is at least one node in the list.
if not NodeList:
    status['message'] = "Empty NodeList"
    print json.dumps({'status': status})
    exit(1)

#print '-----------------'
开发者ID:dslfaithdev,项目名称:Data-organizer,代码行数:33,代码来源:comments.py

示例3: doClustering

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import get_edgelist [as 别名]
def doClustering(likes):

    NodeList = []
    
    for like in likes:
        if like[0] not in NodeList:
            NodeList.append(like[0])
        if like[1] not in NodeList:
            NodeList.append(like[1])

#    print NodeList

    gr = Graph(0)

    gr.add_vertices(len(NodeList))
    #Now, we finish adding nodes.
#    print 'num of node: '
#    print len(NodeList)
    #-------------------------------------
    count = 0
    FromNodeIDtoVerticeID = {}
    for vertice in NodeList:
        FromNodeIDtoVerticeID[vertice] = count
        # In gr.vs, each vertice has two characters.
        gr.vs[count]['verticeID'] = count
        gr.vs[count]['NodeID'] = str(vertice)
        count += 1
#    print 'map from NodeID to verticeID: '
#    print FromNodeIDtoVerticeID 
    #Now we map long NodeID into VerticeID.
    #-------------------------------------
    count = 0
    for line in FromNodeIDtoVerticeID:
        count = count + 1
    #print count
    #-------------------------------------

    for like in likes:
        igraphEdgePair = (FromNodeIDtoVerticeID[like[0]],FromNodeIDtoVerticeID[like[1]])
        gr.add_edges(igraphEdgePair)
    #print summary(gr)

    edgelist = gr.get_edgelist()
    #Now we finish building edges.

    length = len(NodeList)
#    print 'nodelist: ' + str(length)

    #Here we are dealing with special situations in final results.
    if length == 0:
        ClusterResultWithUserID = []
        ClusterResultWithUserID.append('0')

        return ClusterResultWithUserID


    #print '-----------------'
    #Now we are building adjacent matrix for later clustering.
    b = np.arange(0,length*length,1)

    for i in range(0,length*length):
        b[i] = 0
    #print b

    b.shape = length,length

    for i in range(0,len(edgelist)):
        b[edgelist[i][0]][edgelist[i][1]] = b[edgelist[i][0]][edgelist[i][1]] + 1
        b[edgelist[i][1]][edgelist[i][0]] = b[edgelist[i][1]][edgelist[i][0]] + 1
    #Now we finished building adjacent matrix.

    a = [sum(bi) for bi in b]

    G = np.diag(a)  
    L = G - b  
#---------------------------------------------------------------------------------------------------------------------------------
#    for w in range(0,200):
#        evals, Y, idx = cluster_points(L) 
    
#        membership = []

#        for i in range(0,len(idx)):
#            membership.append(str(idx[i]))
#            membership[i] = int(membership[i])

#--------------------------------------------
    checkmodularity = -100
    savemembership = []

    for w in range(0,200):
        evals, Y, idx = cluster_points(L) 
    
        membership = []

        for i in range(0,len(idx)):
            membership.append(str(idx[i]))
            membership[i] = int(membership[i])

        if gr.modularity(membership) > checkmodularity:
            checkmodularity = gr.modularity(membership)
#.........这里部分代码省略.........
开发者ID:blublud,项目名称:shdp,代码行数:103,代码来源:comment_cluster_red.py

示例4: Topo

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import get_edgelist [as 别名]
class Topo( object ):

    def __init__( self, *args, **params ):
        """Topo object.
           Optional named parameters:
           hinfo: default host options
           sopts: default switch options
           lopts: default link options
           calls build()"""
        self.g = Graph()
        self.hopts = params.pop( 'hopts', {} )
        self.sopts = params.pop( 'sopts', {} )
        self.lopts = params.pop( 'lopts', {} )
        # ports[src][dst][sport] is port on dst that connects to src
        self.ports = {}
        self.build( *args, **params )

    def build( self, *args, **params ):
        "Override this method to build your topology."
        pass

    def addNode( self, name, **opts ):
        """Add Node to graph.
           name: name
           opts: node options
           returns: node name"""
        self.g.add_vertex( name, **opts )
        return name

    def addHost( self, name, **opts ):
        """Convenience method: Add host to graph.
           name: host name
           opts: host options
           returns: host name"""
        if not opts and self.hopts:
            opts = self.hopts
        return self.addNode( name, isSwitch=False, **opts )

    def addSwitch( self, name, **opts ):
        """Convenience method: Add switch to graph.
           name: switch name
           opts: switch options
           returns: switch name"""
        if not opts and self.sopts:
            opts = self.sopts
        return self.addNode( name, isSwitch=True, **opts )

    def addLink( self, node1, node2, port1=None, port2=None, key=None, **opts ):
        """node1, node2: nodes to link together
           port1, port2: ports (optional)
           opts: link options (optional)
           key: useless, kept for compatibility with mininet"""
        if not opts and self.lopts:
            opts = self.lopts
        port1, port2 = self.addPort( node1, node2, port1, port2 )
        opts = dict( opts )
        opts.update( node1=node1, node2=node2, port1=port1, port2=port2 )
        self.g.add_edge(node1, node2, **opts)

    def nodes( self, sort=True ):
        """Return a list of nodes in graph"""
        nodes = self.g.vs["name"]
        if sort:
            nodes.sort()
        return nodes

    def isSwitch( self, n ):
        """Return true if node is a switch."""
        return self.g.vs.find(name=n)['isSwitch']

    def switches( self, sort=True ):
        """Return a list of switches."""
        #return [ n for n in self.nodes() if self.isSwitch( n ) ]
        switches = self.g.vs.select(isSwitch=True)["name"]
        if sort:
            switches.sort()
        return switches

    def hosts( self, sort=True ):
        """Return a list of hosts."""
        hosts =  self.g.vs.select(isSwitch=False)["name"]
        if sort:
            hosts.sort()
        return hosts

    def links( self, sort=False, withKeys=False, withInfo=False ):
        """Return a list of links
           sort: sort links alphabetically, preserving (src, dst) order
           withKeys: return link keys
           withInfo: return link info
           returns: list of ( src, dst [,key, info ] )"""
        
        if withKeys:
            if withInfo:
                links = [(self.g.vs[e[0]]["name"], self.g.vs[e[1]]["name"], e, self.g.es[self.g.get_eid(e[0],e[1])].attributes()) for e in self.g.get_edgelist()]
            else:
                links = [(self.g.vs[e[0]]["name"], self.g.vs[e[1]]["name"], e) for e in self.g.get_edgelist()]
        else:
            if withInfo:
                links = [(self.g.vs[e[0]]["name"], self.g.vs[e[1]]["name"], self.g.es[self.g.get_eid(e[0],e[1])].attributes()) for e in self.g.get_edgelist()]
#.........这里部分代码省略.........
开发者ID:ravel-net,项目名称:ravel,代码行数:103,代码来源:topolib.py


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