Exemplo n.º 1
0
 def testGetYaoGraph(self):
     
     # prosty test na stwierdzenie czy macierz wyglada tak jak trzeba
     
     n = 200
     k = 8
     
     matrix = getYaoGraph(n, k)
     
     for row in matrix:
         print row
     
     for row in matrix:
         self.failIf(all([el == 0 for el in row]))
         
         
     # drugi test - sprawdzamy czy wszystkie wierzcholki sa dostepne
     reachable = [0]
 
     # teraz dla kazdego obiektu z listy patrzymy na wezly z nim sasiadujace
     for v in reachable:
     
         neighbors = [i for i in matrix[v]]
         neighbors = [i for i in range(n) if (neighbors[i] > 0)]
         neighbors = [i for i in neighbors if (i not in reachable)]
         
         reachable.extend(neighbors)
         
     # sprawdzenie czego brakuje:
     # jesli wszystkie wezly sa osiagalne
     print reachable
     self.failUnless(len(reachable) == n)
 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']]))
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)
Exemplo n.º 4
0
    def test_execute(self):
        adjacencyMatrix = getUnitDiskGraph(200)
        
        network = Network(adjacencyMatrix)
        
        alg = FastMIS_v2(network)
        
        alg.execute()
        
        
#         self.drawGraph(network.ndList, adjacencyMatrix)
        # sprawdzenie wlasnosci wyliczonego MIS
        self.checkIfMISisCorrect(network.ndList)
#         
        # graf Yao
        adjacencyMatrix = getYaoGraph(15, 6)
         
        network = Network(adjacencyMatrix)
         
        alg = FastMIS_v2(network)
         
        alg.execute()
         
         
#         self.drawGraph(network.ndList, adjacencyMatrix)
        # sprawdzenie wlasnosci wyliczonego MIS
        self.checkIfMISisCorrect(network.ndList)
         
        # graf planarny
        adjacencyMatrix = getPlanarGraph(10)
         
        network = Network(adjacencyMatrix)
         
        alg = FastMIS_v2(network)
         
        alg.execute()
         
         
#         self.drawGraph(network.ndList, adjacencyMatrix)
        # sprawdzenie wlasnosci wyliczonego MIS
        self.checkIfMISisCorrect(network.ndList)
Exemplo n.º 5
0
from algorithm.log_star_MIS import LogStar
from network.network import Network
from graph_tool.all import *
from graph_generators.n_yao_graph import getYaoGraph


adjacencyMatrix = getYaoGraph(15, 6)

# 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