LinkPrediction.py 文件源码

python
阅读 45 收藏 0 点赞 0 评论 0

项目:PhD 作者: wutaoadeny 项目源码 文件源码
def Create_Graph(fname = None):
    '''
    G = nx.Graph()
    G.add_edge(0, 1, weight = 2.0,timestamp = 1.0)
    G.add_edge(0, 2, weight = 2.0,timestamp = 1.0)
    G.add_edge(0, 3, weight = 2.0,timestamp = 1.0)
    G.add_edge(0, 4, weight = 2.0,timestamp = 1.0)
    G.add_edge(0, 5, weight = 2.0,timestamp = 1.0)
    G.add_edge(4, 6, weight = 2.0,timestamp = 1.0)
    G.add_edge(4, 7, weight = 2.0,timestamp = 1.0)
    G.add_edge(4, 8, weight = 2.0,timestamp = 1.0)
    G.add_edge(7, 8, weight = 2.0,timestamp = 1.0)
    G.add_edge(5, 9, weight = 2.0,timestamp = 1.0)
    G.add_edge(2, 3, weight = 2.0,timestamp = 1.0)
    G.add_edge(2, 13, weight = 2.0,timestamp = 1.0)
    G.add_edge(2, 11, weight = 2.0,timestamp = 1.0)
    G.add_edge(2, 12, weight = 2.0,timestamp = 1.0)
    G.add_edge(11, 12, weight = 2.0,timestamp = 1.0)
    G.add_edge(3, 11, weight = 2.0,timestamp = 1.0)
    G.add_edge(3, 10, weight = 2.0,timestamp = 1.0)
    '''

    #fname = 'F:/Link_Prediction_Code/Dataset/6-Wireless_contact_Train_Regular.txt'
    #Get edge from txt type data
    try:
        fdobj = open(fname,'r')
    except IOError as e:
        print "***file open error:",e
    else:
        G = nx.Graph()
        eline = fdobj.readline()
        eline = fdobj.readline()
        eline = fdobj.readline()
        eline = fdobj.readline()
        eline = fdobj.readline()
        eline = fdobj.readline()
        eline = fdobj.readline()
        eline = fdobj.readline()
        eline = fdobj.readline()
        while eline:
            line = eline.strip('\n').split()
            G.add_edge(string.atoi(line[0]),string.atoi(line[1]),weight=string.atof(line[3]),timestamp=string.atof(line[4]))#weight=string.atof(line[3])
            eline = fdobj.readline()
        #end while

    #Data_Prepare.Drawcomgraph(G)
    return G








##==========================================================================================
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号