예제 #1
0
 def testAssignSet7(self):
     nodes_7 = []
     node_7_1 = Node(1)
     node_7_1.communication_set = [1, 2, 3]
     nodes_7.append(node_7_1)
     
     node_7_4 = Node(4)
     node_7_4.communication_set = [1, 4, 5]
     nodes_7.append(node_7_4)
     
     node_7_6 = Node(6)
     node_7_6.communication_set = [1, 6, 7]
     nodes_7.append(node_7_6)
     
     node_7_2 = Node(2)
     node_7_2.communication_set = [2, 4, 6]
     nodes_7.append(node_7_2)
     
     node_7_5 = Node(5)
     node_7_5.communication_set = [2, 5, 7]
     nodes_7.append(node_7_5)
     
     node_7_7 = Node(7)
     node_7_7.communication_set = [3, 4, 7]
     nodes_7.append(node_7_7)
     
     node_7_3 = Node(3)
     node_7_3.communication_set = [3, 5, 6]
     nodes_7.append(node_7_3)
     
     self.assertEqual(assign_set(self.sets_7), nodes_7)
예제 #2
0
def assign_set(sets):
    ''' Core method, assign the communication set to the appropriate site.
        refer to report for detail. '''
    K = len(sets[0]) - 1
    nodes = []
    
    node_1 = Node(sets[0][0][0])
    tmp = sets[0][0][:]
    tmp.remove(sets[0][0][0])
    node_1.communication_set = unique_list(tmp)
    nodes.append(node_1)
    
    # assign the rows
    for i in sets[0][1:]:
        n = Node(i[1])
        if n in nodes:
            continue
        # Lazy attachment, in order to save the memory,
        # if site is not in the list, attaching the neighbour sites.
        tmp = i[:]
        tmp.remove(i[1])
        n.communication_set = unique_list(tmp)
        nodes.append(n)
        
    # assign the columns
    node_2 = Node(sets[1][0][0])
    tmp = sets[1][0][:]
    tmp.remove(sets[1][0][0])
    node_2.communication_set = unique_list(tmp)
    nodes.append(node_2)
    
    for i in sets[1][1:]:
        n = Node(i[1])
        if n in nodes:
            continue
        tmp = i[:]
        tmp.remove(i[1])
        n.communication_set = unique_list(tmp)
        nodes.append(n)
        
    # assign the diagonals
    jump = 0
    loop = 0
    for i in sets[2]:
        loop += 1
        n = Node(i[jump + 2])
        if n in nodes:
            for t in i:
                no = Node(t)
                if no not in nodes:
                    tmp = i[:]
                    tmp.remove(t)
                    no.communication_set = unique_list(tmp)
                    nodes.append(no)
                    break
            else:
                o_index = nodes.index(n)
                origin = nodes[o_index]
                tmp = i[:]
                tmp.remove(n.value)
                origin.communication_set = unique_list(origin.communication_set + tmp)
        else:
            tmp = i[:]
            tmp.remove(i[jump + 2])
            n.communication_set = unique_list(tmp)
            nodes.append(n)
        if (loop % K) == 0:
            jump += 1
        
    return nodes
예제 #3
0
 def testAssignSet13(self):
     
     nodes_13 = []
     node_13_1 = Node(1)
     node_13_1.communication_set = [1, 2, 3, 4]
     nodes_13.append(node_13_1)
     
     node_13_5 = Node(5)
     node_13_5.communication_set = [1, 5, 6, 7]
     nodes_13.append(node_13_5)
     
     node_13_8 = Node(8)
     node_13_8.communication_set = [1, 8, 9, 10]
     nodes_13.append(node_13_8)
     
     node_13_11 = Node(11)
     node_13_11.communication_set = [1, 11, 12, 13]
     nodes_13.append(node_13_11)
     
     node_13_2 = Node(2)
     node_13_2.communication_set = [2, 5, 8, 11]
     nodes_13.append(node_13_2)
     
     node_13_6 = Node(6)
     node_13_6.communication_set = [2, 6, 9, 12]
     nodes_13.append(node_13_6)
     
     node_13_7 = Node(7)
     node_13_7.communication_set = [2, 7, 10, 13]
     nodes_13.append(node_13_7)
     
     node_13_9 = Node(9)
     node_13_9.communication_set = [3, 5, 9, 13]
     nodes_13.append(node_13_9)
     
     node_13_10 = Node(10)
     node_13_10.communication_set = [3, 6, 10, 11]
     nodes_13.append(node_13_10)
     
     node_13_3 = Node(3)
     node_13_3.communication_set = [3, 6, 10, 11]
     nodes_13.append(node_13_3)
     
     node_13_12 = Node(12)
     node_13_12.communication_set = [4, 5, 10, 12]
     nodes_13.append(node_13_12)
     
     node_13_13 = Node(13)
     node_13_13.communication_set = [4, 6, 8, 13]
     nodes_13.append(node_13_13)
     
     node_13_4 = Node(4)
     node_13_13.communication_set = [4, 7, 9, 11]
     nodes_13.append(node_13_4)
     
     self.assertEqual(assign_set(self.sets_13), nodes_13)