assignment_prob_hungarian.py 文件源码

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

项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码
def CreateGraph():
    B = nx.DiGraph();
    f = open('input.txt')
    n = int(f.readline())
    cost = []

    for i in range(n):
        list1 = map(int, (f.readline()).split())
        cost.append(list1)
    people = []
    for i in range(n):
        people.append(i)
    job = [] 
    for c in ascii_lowercase[:n]:
        job.append(c)
    B.add_nodes_from(people, bipartite=0) # Add the node attribute "bipartite"
    B.add_nodes_from(job, bipartite=1)
    for i in range(n) :
        for c in ascii_lowercase[:n] :
            if cost[i][ord(c)-97] > 0 :
                B.add_edge(i, c, length = cost[i][ord(c)-97])  
    return B,cost
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号