예제 #1
0
    def test_execute(self):
        adjacencyMatrix = getUnitDiskGraph(200)

        network = Network(adjacencyMatrix)

        alg = SlowMIS()
        alg.network = network

        alg.execute()

        # sprawdzenie wlasnosci wyliczonego MIS

        for node in network.ndList:

            # stany wszystkich sasiadow
            states = [network.ndList[neigh].memory["state"] for neigh in node.neighbors]

            if node.memory["state"] == "not_in_MIS":
                # fail jesli wszystkie wezly tez nie sa w MIS
                self.failIf(all([state == "not_in_MIS" for state in states]))

            elif node.memory["state"] == "in_MIS":
                self.failIf(any([state == "in_MIS" for state in states]))
            else:
                self.fail("nieprawidlowy stan")
def compute():
    
    MIN = 50
    MAX =5000
    step = 500
    
    repetitions = 100
    
    adjMatrix = []
    alg = None
    network = None
    
    tempCommSum = 0
    commTimes = []
    
    tempAlgSum = 0
    algTimes = []
    
    
    for n in range(MIN, MAX, step):
        tempCommSum = 0
        tempAlgSum = 0
        
        for k in range(repetitions):
            adjMatrix = getPlanarGraph(n)
            network = Network(adjMatrix)
            
            alg = SlowMIS(network)
            
            alg.execute()
            
            print k
            tempCommSum += network.algCommRoundCounter
            tempAlgSum += alg.roundCounter
            
            
        print n, 'time: ', datetime.now()
            
        commTimes.append(tempCommSum/float(repetitions))
        algTimes.append(tempAlgSum/float(repetitions))
        
    # print times
        
    fileName = '/home/julka/100_reps/slow_MIS_planar_graph_comm.txt'
    save(commTimes, fileName)
    
    fileName = '/home/julka/100_reps/slow_MIS_planar_graph_alg.txt'
    save(algTimes, fileName)