示例#1
0
def main():
    covid19 = covid19_Simulation()
    al = DLList.DLList()
    for population in range(covid19.people):
        person = Person()
        al.append(person)
    #With lockdown
    g1 = AdjacencyList.AdjacencyList(covid19.people)
    #Without lockdown
    g2 = AdjacencyList.AdjacencyList(covid19.people)

    covid19.getInteractionGraph(g1, al)
    covid19.initialInfectedNodes(g1, al)
    covid19.simulation(g1, 0, al)
    matplot.show()
示例#2
0
 def __init__(self):
     self.bookCatalog = ArrayList.ArrayList()
     self.shoppingCart = ArrayQueue.ArrayQueue()
     self.indexKey = ChainedHashTable.ChainedHashTable()
     self.indexSortedPrefix = BinarySearchTree.BinarySearchTree()
     self.bookSortedCatalog = ArrayList.ArrayList()
     self.similaGraph = AdjacencyList.AdjacencyList(0)
示例#3
0
    def test_graph(self):
        points = 0.5
        q = AdjacencyMatrix.AdjacencyMatrix(4)
        try:
            q.remove_edge(1, 2)
            q.has_edge(2, 3)
            q.add_edge(0, 1)
            q.add_edge(1, 2)
            q.add_edge(2, 3)
            q.add_edge(3, 0)
            q.add_edge(0, 2)

            self.assertAlmostEqual(q.has_edge(0, 1), True)
            self.assertAlmostEqual(q.has_edge(1, 3), False)
            print("AdjacencyMatrix in_edges(2)", q.in_edges(2))
            print("AdjacencyMatrix out_edges(0)", q.out_edges(0))
            points += 0.5

        except:
            print("AdjacencyMatrix is not correct")

        q = AdjacencyList.AdjacencyList(4)
        try:
            q.remove_edge(1, 2)
            q.has_edge(2, 3)
            q.add_edge(0, 1)
            q.add_edge(1, 2)
            q.add_edge(2, 3)
            q.add_edge(3, 0)
            q.add_edge(0, 2)
            self.assertAlmostEqual(q.has_edge(0, 1), True)
            self.assertAlmostEqual(q.has_edge(1, 3), False)
            print("AdjacencyList in_edges(2)", q.in_edges(2))
            print("AdjacencyList out_edges(0)", q.out_edges(0))
            points += 0.5
            print("BFS(0)")
            q.bfs(0)
            print("DFS(0)")
            q.dfs(0)
            points += 0.5
        except:
            print("AdjacencyList is not correct")

        print(f"Graph: {points} Points")
示例#4
0
    def loadCatalog(self, fileName: str):
        #Graphs
        self.indexKeys = ChainedHashTable.ChainedHashTable()
        self.bookCatalog = DLList.DLList()  #or arraylist

        with open(fileName, encoding='utf-8') as f:
            start_time = time.time()
            count = 0  #line number
            for line in f:
                (key, title, group, rank, similar) = line.split("^")
                b = Book.Book(key, title, group, rank, similar)
                self.bookCatalog.append(b)

                self.indexKeys.add(b.key, count)
                #self.indexKeys.add(key, line)
                count += 1
            elapsed_time = time.time() - start_time
            print(
                f"Loaded {self.bookCatalog.size()} books into bookCatalog in {elapsed_time} seconds"
            )
        #self.similar_graph()

    #def similar_graph(self,k : int):
        self.similarGraph = AdjacencyList.AdjacencyList(
            self.bookCatalog.size())

        with open(fileName, encoding='utf-8') as f:
            start_time = time.time()
            count = 0
            for line in f:
                (key, title, group, rank, similar) = line.split("^")
                l = similar.split()
                for k in range(1, len(l)):
                    j = self.indexKeys.find(l[k])
                    #print(j)
                    if j != None:  #is not
                        self.similarGraph.add_edge(count, j)
                count += 1
            elapsed_time = time.time() - start_time
            print(
                f"Loaded {self.similarGraph.n} books into Graph in {elapsed_time} seconds"
            )
示例#5
0
print(a)
'''
'''
print(c)
algorithms.quick_sort(c)
print(c)
'''
#Lab 7 Larry Delgado
import AdjacencyMatrix
import AdjacencyList
import ArrayQueue

q = ArrayQueue.ArrayQueue()
q.add(0)
print(q)
al = AdjacencyList.AdjacencyList(5)

al.add_edge(1, 2)
al.add_edge(2, 3)
al.add_edge(3, 4)
al.add_edge(4, 1)
al.add_edge(1, 3)
print(al.out_edges(1))
'''
am = AdjacencyMatrix.AdjacencyMatrix(5)
am.add_edge(1,2)
am.add_edge(2,3)
am.add_edge(3,4)
am.add_edge(4,1)
am.add_edge(1,3)
print(am.has_edge(1,2))
 def __init__(self):
     self.graph = AdjacencyList(True)
     self.graphPrepare()
示例#7
0
 def __init__(self, startVertex=1):
     self.graph = AdjacencyList(False)
     self.graphPrepare()
     self.startVertex = startVertex