def testGetPlanarGraph(self):
        
        n = 200
        
        matrix = getPlanarGraph(n)
        
#         for row in matrix:
#             print row
        
        # 1 - sprawdzanie czy wszystkie punkty sa osiagalne
        reachable = [0]
    
        # teraz dla kazdego obiektu z listy patrzymy na wezly z nim sasiadujace
        for v in reachable:
            
            row = matrix[v]
            neigh = [i for i in range(n) if (row[i] > 0) and (i not in reachable)]
#             print 'neigh:'
#             print neigh
            reachable.extend(neigh)
#             print reachable
            
        # sprawdzenie czego brakuje:
        # jesli wszystkie wezly sa osiagalne
#         print 'pod koniec testu'
#         print reachable
        self.failUnless(len(reachable) == n)
 def test_execute(self):
     n = 50
     adjacencyMatrix = getPlanarGraph(n)
     
     network = Network(adjacencyMatrix)
     
     # sprawdzenie metody
     alg = PlanarMIS(network)
     alg.execute()
     
     # sprawdzanie:
     # standardowo jak w MIS
     for node in network.ndList:
         if node.memory['is_in_final_MIS'] == True:
             for neigh in node.neighbors:
                 self.failIf(network.ndList[neigh].memory['is_in_final_MIS'] == True)
                 
         # jesli wezel jest zdominowany, to fail jesli ma w swoim otoczeniu same zdominowane wezly
         elif node.memory['is_in_final_MIS'] == False:
             neigh_states = [network.ndList[neigh].memory['is_in_final_MIS'] for neigh in node.neighbors]
             
             self.failIf(all([state == False for state in neigh_states]))
         # jesli wezel nie jest ani dominatorem ani zdominownay, to fail
         else:
             self.fail("nieprawidlowy stan wezla")
    def test_executeWithoutJoiningSubgraphs(self):
        n = 10
        adjacencyMatrix = getPlanarGraph(n)
        
        network = Network(adjacencyMatrix)
        
        # sprawdzenie metody
        alg = PlanarMIS(network)
        alg._executeWithoutJoiningSubgraphs()
        
        # sprawdzanie:
        # po kolei dla kazdego poddrzewa
        # poddrzew bedzie mniej niz n/2
        for i in range(n/2):
            for node in network.ndList:
                
                
                # fail jesli wezel nie ma nadal przydzielonego poddrzewa
                self.failIf(not node.memory.has_key('tree_num'))
                
                # wybieranie tylko wezlow z podgrafu nr i
                if node.memory['tree_num'] != i:
                    continue
                
                # fail jesli sasiedzi wezla sa z innego poddrzewa
                neighbors = node.memory['neighbors_cp']
                
                for neigh in neighbors:
                    sub = network.ndList[neigh].memory['tree_num']
                    
                    if sub != i:
                        print 'wezel: ', node.ID, 'sasiad:', neigh
                        self.drawGraph(network.ndList, adjacencyMatrix)
                        self.fail('podgraf mial byc nr ' + str(i)+ ' a jest '+ str(sub))
                    
#                     self.failIf(sub != i)
                    
                # jesli wezel jest dominatorem, to fail jesli jego sasiad tez jest
                if node.memory['state_subgraph'] == 'dominator':
                    for neigh in neighbors:
                        self.failIf(network.ndList[neigh].memory['state_subgraph'] == 'dominator')
                        
                # jesli wezel jest zdominowany, to fail jesli ma w swoim otoczeniu same zdominowane wezly
                elif node.memory['state_subgraph'] == 'dominated':
                    neigh_states = [network.ndList[neigh].memory['state_subgraph'] for neigh in neighbors]
                    
                    self.failIf(all([state == 'dominated' for state in neigh_states]))
                # jesli wezel nie jest ani dominatorem ani zdominownay, to fail
                else:
                    self.fail("nieprawidlowy stan wezla:", node.memory['state_subgraph'])
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 = FastMIS_v2(network)
            
            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/fast_MIS_v2_planar_graph_comm.txt'
    save(commTimes, fileName)
    
    fileName = '/home/julka/100_reps/fast_MIS_v2_planar_graph_alg.txt'
    save(algTimes, fileName)
 def test_divideIntoSubgraphsv2(self):
     # 1 - tworzenie macierzy
     adjacencyMatrix = getPlanarGraph(10)
     
     network = Network(adjacencyMatrix)
     
     # sprawdzenie metody
     alg = PlanarMIS(network)
     
     
     alg.divideIntoSubgraphs()
     
     
     # wezly z podgrafu i musza miec jako sasiadow tylko inne wezly z podgrafu i - albo zadnych
     for node in network.ndList:
         if node.memory.has_key('tree_num'):
             i = node.memory['tree_num']
             neigh_cp = node.memory['neighbors_cp']
             
             for neigh in neigh_cp:
                 if not network.ndList[neigh].memory.has_key('tree_num'):
                     self.fail("sasiad nie jest w tym zadnym podgrafie")
                 else:
                     self.failIf(network.ndList[neigh].memory['tree_num'] != i)
                     
         else:
             # wszystkie wezly musza byc w jakims podgrafie
                 self.fail("sasiad nie jest w zadnym podgrafie")
                 
     # sprawdzanie ilosci sasiadow
     for node in network.ndList:
             neigh_len = len(node.memory['neighbors_cp'])
             self.failIf(neigh_len > 6)
             
     # wypisywanie pogrfaow
     for i in range(7):
         print 'wezly z podgrafu', i, ':'
         for node in network.ndList:
             if node.memory['tree_num'] == i:
                 print node.ID, 
                 
         print ' '
Beispiel #6
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)
from algorithm.MIS_for_planar_graphs import PlanarMIS
from network.network import Network
from graph_generators.n_planar_graph import getPlanarGraph

from graph_tool.all import *

adjacencyMatrix = getPlanarGraph(70)

# tworzenie sieci
network = Network(adjacencyMatrix)

alg = PlanarMIS()

network.algorithm = alg
alg.network = network

nodes = network.ndList

alg.divideIntoSubgraphs()

# 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