コード例 #1
0
 def testUnitDiskGraph(self):
     # prosty test na stwierdzenie czy macierz wyglada tak jak trzeba
     
     n = 150
     matrix = getUnitDiskGraph(n)
     
     # tworzenie sieci
     network = Network(matrix)
     
     alg = LogStar(network)
     
     
     nodes = network.ndList
     
     for node in nodes:
         alg.initiateNode(node)
         
     alg.execute()
     
     # sprawdzanie faili
     for node in nodes:
         # sprawdzanie mozliwosci faila #1
         neighIndices = node.neighbors
         
         if node.memory['state'] == 'dominator':
             for neighIndex in neighIndices:
                 self.failIf(nodes[neighIndex].memory['state'] == 'dominator')
         
         elif node.memory['state'] == 'dominated':
             dominatedList = [nodes[n].memory['state'] == 'dominated' for n in neighIndices]
             self.failIf(all(dominatedList))
         else:
             self.fail(''.join(['incorrect state after algorithm execution:', node.memory['state']]))
コード例 #2
0
 def testGetYaoGraph(self):
     # test algorytmu log star MIS dla grafu Yao
     
     n = 200
     k = 10
     
     matrix = getYaoGraph(n, k)
     
     # tworzenie sieci
     network = Network(matrix)
     
     alg = LogStar(network)
     
     
     nodes = network.ndList
     
     for node in nodes:
         alg.initiateNode(node)
         
     alg.execute()
     
     # sprawdzanie faili
     for node in nodes:
         # sprawdzanie mozliwosci faila #1
         neighIndices = node.neighbors
         
         if node.memory['state'] == 'dominator':
             for neighIndex in neighIndices:
                 self.failIf(nodes[neighIndex].memory['state'] == 'dominator')
         
         elif node.memory['state'] == 'dominated':
             dominatedList = [nodes[n].memory['state'] == 'dominated' for n in neighIndices]
             self.failIf(all(dominatedList))
         else:
             self.fail(''.join(['incorrect state after algorithm execution:', node.memory['state']]))
コード例 #3
0
 def testProperMIScomputation(self):
     # test sprawdza czy algorytm wylicza MIS bez zadnych faili:
     # fail #1 - jesli dwa wezly kolo siebie sa w MIS (sa dominatorami)
     # fail #2 - jesli wezel jest otoczony wezlami zdominowanymi i sam jest zdominowany
     
     adjacencyMatrix = getUnitDiskGraph(200)
     
     # tworzenie sieci
     network = Network(adjacencyMatrix)
     
     alg = LogStar(network)
     
     
     nodes = network.ndList
     
     for node in nodes:
         alg.initiateNode(node)
     
     
     alg.execute()
     
     for node in nodes:
         # sprawdzanie mozliwosci faila #1
         neighIndices = node.neighbors
         
         if node.memory['state'] == 'dominator':
             for neighIndex in neighIndices:
                 self.failIf(nodes[neighIndex].memory['state'] == 'dominator')
         
         elif node.memory['state'] == 'dominated':
             dominatedList = [nodes[n].memory['state'] == 'dominated' for n in neighIndices]
             self.failIf(all(dominatedList))
         else:
             self.fail(''.join(['incorrect state after algorithm execution:', node.memory['state']]))
コード例 #4
0
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 = getYaoGraph(n, 8)
            network = Network(adjMatrix)
            
            alg = LogStar(network)
            
            for node in network.ndList:
                alg.initiateNode(node)
            
            alg.execute()
            print k
            tempAlgSum += alg.roundCounter
            tempCommSum += network.algCommRoundCounter
            
        print n, 'time: ', datetime.now()
            
        algTimes.append(tempAlgSum/float(repetitions))
        commTimes.append(tempCommSum/float(repetitions))
        
    # print times
        
    fileName = '/home/julka/100_reps/log_star_MIS_yao_graph_comm.txt'
    save(commTimes, fileName)
    
    fileName = '/home/julka/100_reps/log_star_MIS_yao_graph_alg.txt'
    save(algTimes, fileName)
コード例 #5
0
 def testRoundForNode_part1(self):
     adjacencyMatrix = [[0, 1, 1, 1],
                        [1, 0, 1, 1],
                        [1, 1, 0, 1],
                        [1, 1, 1, 0]]
     
     # tworzenie sieci
     network = Network(adjacencyMatrix)
     
     alg = LogStar(network)
     nodes = network.ndList
     
     # 1 - sprawdzenie czy inicjalizacja sie powiodla
     
     network.algorithm = alg
     
     for node in nodes:
         alg.initiateNode(node)
         
     for node in nodes:
         self.failUnless(node.memory['state'] == 'competitor')
         self.failUnless(node.memory['activity'] == 'initiate loop')
コード例 #6
0
n = 30
adjacencyMatrix = getUnitDiskGraph(n)

# tworzenie sieci
network = Network(adjacencyMatrix)

alg = LogStar()

network.algorithm = alg
alg.network = network

nodes = network.ndList

for node in nodes:
    alg.initiateNode(node)

network.executeAlgorithm()

# czesc rysujaca
g = Graph(directed=False)

# dodawanie wezlow - indeksowanie bedzie sie zgadzalo
for node in nodes:
    g.add_vertex()

# dodawanie krawedzi - tu trzeba isc po macierzy incydencji
# i - wiersze macierzy
# j - kolumny macierzy
# n - ilosc wezlow