def test_checkIfUndecidedExists(self): adjacencyMatrix = getUnitDiskGraph(50) network = Network(adjacencyMatrix) alg = SlowMIS() alg.network = network alg.initiate() result = alg.checkIfUndecidedExists() self.failUnless(result == True) # zmiana stanow wezlow for node in network.ndList: node.memory["state"] = "in_MIS" result = alg.checkIfUndecidedExists() self.failUnless(result == False) network.ndList[38].memory["state"] = "undecided" result = alg.checkIfUndecidedExists() self.failUnless(result == True)
def test_checkIfUndecidedExists(self): adjacencyMatrix = getUnitDiskGraph(10) network = Network(adjacencyMatrix) alg = FastMIS_v2(network) alg.initiate() result = alg.checkIfUndecidedExists() self.failUnless(result == True) # zmiana stanow wezlow for node in network.ndList: node.memory['state'] = 'in_MIS' result = alg.checkIfUndecidedExists() self.failUnless(result == False) network.ndList[8].memory['state'] = 'undecided' result = alg.checkIfUndecidedExists() self.failUnless(result == True)
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']]))
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 testGetUnitDiskGraph(self): # prosty test na stwierdzenie czy macierz wyglada tak jak trzeba n = 200 matrix = getUnitDiskGraph(n) 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 self.failUnless(len(reachable) == n)
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']]))
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 = getUnitDiskGraph(n) 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_unit_disk_graph_comm.txt' save(commTimes, fileName) fileName = '/home/julka/100_reps/log_star_MIS_unit_disk_graph_alg.txt' save(algTimes, fileName)
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.log_star_MIS import LogStar from network.network import Network from graph_tool.all import * from graph_generators.n_unit_disk_graph import getUnitDiskGraph 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