Esempio n. 1
0
def lq_count(G):
    count = 0
    lq_sum = 0
    for h in G.B:
        if graph.lower_quota(G, h) > 0:
            lq_sum += graph.lower_quota(G, h)
            count += 1
    return count, lq_sum
def hreduction(G):
    for r in G.A:
        pref_list = []
        for h in G.E[r]:
            if graph.lower_quota(G, h) > 0:
                pref_list.append(h)
        G.E[r] = pref_list

    B = set(h for h in G.B if graph.lower_quota(G, h) > 0)
    for h in B:
        G.capacities[h] = (0, graph.lower_quota(G, h))
    return graph.BipartiteGraph(G.A, B, G.E, G.capacities)
Esempio n. 3
0
def hreduction(G):
    for r in G.A:
        pref_list = []
        for h in G.E[r]:
            if graph.lower_quota(G, h) > 0:
                pref_list.append(h)
        G.E[r] = pref_list

    B = set(h for h in G.B if graph.lower_quota(G, h) > 0)
    for h in B:
        G.capacities[h] = (0, graph.lower_quota(G, h))
    return graph.BipartiteGraph(G.A, B, G.E, G.capacities)
Esempio n. 4
0
def checkForLQHosp(G):

    for h in G.B:
        if graph.lower_quota(h, G) > 0:
            if len(G.E[h]) != len(G.A):

                return False

    return True
def checkForLQHosp(G):
	
	for h in G.B:
	    if graph.lower_quota(h,G)>0:
                if len(G.E[h])!=len(G.A) :
                    
                    return False
	
	return True
Esempio n. 6
0
def feasibility_check(G):
    G1 = graph.copy_graph(G)
    #G = mahadian_k_model_generator_hospital_residents(n1, n2, k, max_capacity)

    for h in G.B:
        if graph.lower_quota(G, h) == 0:
            G1.B.remove(h)

            for r in G.E[h]:
                G1.E[r].remove(h)
            del G1.E[h]
            del G1.capacities[h]
        else:
            G1.capacities[h] = (graph.lower_quota(G,
                                                  h), graph.lower_quota(G, h))
    #print("---------- G1-----------\n")
    #print(G1)
    #print("---------- G-----------\n")
    #print(G)
    #print("-------------max_card_mat----------\n")

    Max_M = matching_algos.max_card_hospital_residents(graph.copy_graph(G1))
    #print(graph.to_easy_format(G1, Max_M))

    if check_on_max_card_matching(G1, Max_M):
        M = matching_algos.stable_matching_hospital_residents(
            graph.copy_graph(G))
        #print("-------------stable_mat----------\n")
        #print(graph.to_easy_format(G, M))
        for h in G.B:
            if h not in M:
                if graph.lower_quota(G, h) > 0:
                    return True
            else:
                if len(M[h]) < graph.lower_quota(G, h):
                    return True
        return False

    else:
        return False
def feasibility_check(G):
        G1 = graph.copy_graph(G)
        #G = mahadian_k_model_generator_hospital_residents(n1, n2, k, max_capacity)
        
        for h in G.B:
             if graph.lower_quota(G, h)==0:
                   G1.B.remove(h)
                   
                   for r in G.E[h]:
                          G1.E[r].remove(h)
                   del G1.E[h]
                   del G1.capacities[h]
             else:
                   G1.capacities[h] = (graph.lower_quota(G, h), graph.lower_quota(G, h))
        #print("---------- G1-----------\n")
        #print(G1)
        #print("---------- G-----------\n")
        #print(G)
        #print("-------------max_card_mat----------\n")
        
        Max_M = matching_algos.max_card_hospital_residents(graph.copy_graph(G1))
        #print(graph.to_easy_format(G1, Max_M))
      
        if check_on_max_card_matching(G1, Max_M):
            M = matching_algos.stable_matching_hospital_residents(graph.copy_graph(G))
            #print("-------------stable_mat----------\n")
            #print(graph.to_easy_format(G, M))
            for h in G.B:
                if h not in M:
                    if graph.lower_quota(G, h)>0:
                        return True
                else:
                    if len(M[h])<graph.lower_quota(G,h):
                        return True
            return False
 
        else: 
            return False
Esempio n. 8
0
def total_deficiency(G, M):
    """
    return total deficiency of the lower quota hospitals
    :param G: graph
    :param M: matching in G
    """
    sum_def = 0
    for h in G.B:
        lq = graph.lower_quota(G, h)
        if lq > 0:
            nmatched = len(matching_utils.partners_iterable(G, M, h))
            deficiency = lq - nmatched
            sum_def += deficiency if deficiency > 0 else 0
    return sum_def
Esempio n. 9
0
def total_deficiency(G, M):
    """
    return total deficiency of the lower quota hospitals
    :param G: graph
    :param M: matching in G
    """
    sum_def = 0
    for h in G.B:
        lq = graph.lower_quota(G, h)
        if lq > 0:
            nmatched = len(matching_utils.partners_iterable(G, M, h))
            deficiency = lq - nmatched
            sum_def += deficiency if deficiency > 0 else 0
    return sum_def
Esempio n. 10
0
def check_on_max_card_matching(G1, M):
    for h in G1.B:
        if len(M[h]) != graph.lower_quota(G1, h):
            return False
    return True
Esempio n. 11
0
def NRcheck(G):
    sum = 0

    for h in G.B:
        sum += graph.lower_quota(h, G)
    return len(G.A) >= sum
def check_on_max_card_matching(G1, M):
        for h in G1.B:
             if len(M[h])!=graph.lower_quota(G1, h):
                   return False
        return True
def NRcheck(G):
        sum=0
        
        for h in G.B:
            sum+=graph.lower_quota(h,G)
        return len(G.A)>=sum