當前位置: 首頁>>代碼示例>>Python>>正文


Python Pool.from_file方法代碼示例

本文整理匯總了Python中pool.Pool.from_file方法的典型用法代碼示例。如果您正苦於以下問題:Python Pool.from_file方法的具體用法?Python Pool.from_file怎麽用?Python Pool.from_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pool.Pool的用法示例。


在下文中一共展示了Pool.from_file方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: go

# 需要導入模塊: from pool import Pool [as 別名]
# 或者: from pool.Pool import from_file [as 別名]
def go(filename, max_size, use_donor_weight):
    def edge_score_fun(e):
        return 1# + (e.patient.weight - e.donor.weight)/999.0

    sys.stdout.write(filename + "\t")
    sys.stdout.write("1\t" if use_donor_weight else "0\t")

    pool = Pool.from_file(filename)
    pool.create_donor_patient_arcs(use_donor_weight)
    sys.stdout.write(str(len(pool.patients)) + "\t")

    unrestricted_obj_val, optimal_exchanges = pool.solve_uef(edge_score_fun)
    sys.stdout.write(str(unrestricted_obj_val) + "\t")

    obj_val = None
    for i in range(2, max_size+1):
        if obj_val==unrestricted_obj_val:
            pass
        elif i < 6:
            obj_val, optimal_exchanges = pool.solve_cycle_formulation(i, edge_score_fun)
        else:
            obj_val, optimal_exchanges = pool.solve_eef(i, edge_score_fun)

        sys.stdout.write(str(obj_val) + "\t")
        sys.stdout.flush()

    sys.stdout.write(str(pool.n_patients_with_2_compat_donors()) + "\n")
開發者ID:jamestrimble,項目名稱:lungexchange,代碼行數:29,代碼來源:optimise.py

示例2: start

# 需要導入模塊: from pool import Pool [as 別名]
# 或者: from pool.Pool import from_file [as 別名]
def start(filename, max_size):
    pool = Pool.from_file(filename)

    pool.create_donor_patient_arcs(True)

    pool.show()

    exchanges = pool.find_exchanges(max_size)
    for exch in exchanges:
        exch.show()

    print "Number of exchanges: ", len(exchanges)

    # Find out how many exchanges there are if two exchanges with the same
    # set of patients are considered equal
    unique_exch = set()
    for exch in exchanges:
        unique_exch.add(frozenset(e.patient for e in exch.edges))
    print "....", len(unique_exch)

    def edge_score_fun(e):
        return 1  # + (e.patient.weight - e.donor.weight)/999.0

    print "Optimal exchanges with restricted cycle size (cycle formulation):"
    obj_val, optimal_exchanges = pool.solve_cycle_formulation(max_size, edge_score_fun)
    print obj_val
    for exch in optimal_exchanges:
        exch.show()

    print "Optimal exchanges with restricted cycle size:"
    obj_val, optimal_exchanges = pool.solve_eef(max_size, edge_score_fun)
    print obj_val
    for exch in optimal_exchanges:
        exch.show()

    print "Optimal exchanges with unrestricted cycle size:"
    obj_val, optimal_exchanges = pool.solve_uef(edge_score_fun)
    print obj_val
    for exch in optimal_exchanges:
        exch.show()

    print "Number of patients with 2 compatible paired donors:"
    print pool.n_patients_with_2_compat_donors()
    # TODO: put this in a unit test
    print pool.solve_eef(1, lambda e: 1)[0] / 2
開發者ID:jamestrimble,項目名稱:lungexchange,代碼行數:47,代碼來源:optimise_verbose.py


注:本文中的pool.Pool.from_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。