コード例 #1
0
    def test_dfs(self):
        graph = g.newGraph(7, self.comparenames)

        g.insertVertex(graph, 'Bogota')
        g.insertVertex(graph, 'Yopal')
        g.insertVertex(graph, 'Cali')
        g.insertVertex(graph, 'Medellin')
        g.insertVertex(graph, 'Pasto')
        g.insertVertex(graph, 'Barranquilla')
        g.insertVertex(graph, 'Manizales')

        g.addEdge(graph, 'Bogota', 'Yopal')
        g.addEdge(graph, 'Yopal', 'Cali')

        search = dfs.newDFS(graph, 'Bogota')
        response = ''
        path = dfs.pathTo(search, 'Cali')
        pathsize = 0
        if path:
            iteraPath = it.newIterator(path)
            while it.hasNext(iteraPath):
                Vertex = it.next(iteraPath)
                response += Vertex + '\n'
                pathsize += 1
            print(response)
        self.assertEqual(pathsize, 3)

        path2 = dfs.pathTo(search, 'Pasto')
        self.assertIsNone(path2)
コード例 #2
0
ファイル: model.py プロジェクト: susme2020/Lab9_202010
def newCatalog():
    """
    Inicializa el catálogo y retorna el catalogo inicializado.
    """
    libgraph = g.newGraph(7235, compareByKey, directed=True)
    catalog = {'librariesGraph': libgraph}
    return catalog
コード例 #3
0
ファイル: test_graph.py プロジェクト: andresR0410/Lab7_202010
    def test_connectedcomponents1(self):

        graph = g.newGraph(1, self.comparenames)

        g.insertVertex(graph, 'Laura')

        cc = dfs.countCC(graph)
        self.assertEqual(cc, 1)
コード例 #4
0
ファイル: test_graph.py プロジェクト: dlmanrique/Lab7_202010
    def test_numVertex(self):
        graph = g.newGraph(7,self.comparenames)

        g.insertVertex (graph, 'Bogota')
        g.insertVertex (graph, 'Yopal')
        g.insertVertex (graph, 'Cali')
        n=g.numVertex(graph)
        lst = g.vertices (graph)
        self.assertEqual (lt.size (lst), n)
コード例 #5
0
ファイル: test_graph.py プロジェクト: dlmanrique/Lab7_202010
    def test_containsVertex(self):
        graph = g.newGraph(7,self.comparenames)

        g.insertVertex (graph, 'Bogota')
        g.insertVertex (graph, 'Yopal')
        g.insertVertex (graph, 'Cali')
        v1 = g.containsVertex(graph,'Cali')
        self.assertEqual (True, v1)
        v2=g.containsVertex(graph,'Tunja')
        self.assertEqual(False,v2)
コード例 #6
0
def newCatalog():
    """
    Inicializa el catálogo y retorna el catalogo inicializado.
    """
    capacityMap = map.newMap(maptype='PROBING',comparefunction=compareByKey)
    stationMap = map.newMap(97,maptype='CHAINING',comparefunction=compareByKey)
    tree = oms.newMap('RBT')
    gdir = g.newGraph(97, compareByKey, directed=True)
    tempHash = map.newMap(179, maptype='CHAINING', comparefunction=compareByKey)
    tempList = lt.newList('ARRAY_LIST')
    catalog = {'capacityMap':capacityMap, 'stationMap': stationMap,"dateTree": tree, 
    "GraphDirected":gdir, 'temperatureHash': tempHash, 'tempList':tempList}
    return catalog
コード例 #7
0
ファイル: test_graph.py プロジェクト: dlmanrique/Lab7_202010
    def test_insertVertex (self):
        graph = g.newGraph(7,self.comparenames)

        g.insertVertex (graph, 'Bogota')
        g.insertVertex (graph, 'Yopal')
        g.insertVertex (graph, 'Cali')
        g.insertVertex (graph, 'Medellin')
        g.insertVertex (graph, 'Pasto')
        g.insertVertex (graph, 'Barranquilla')
        g.insertVertex (graph, 'Manizales')

        self.assertEqual (g.numVertex(graph), 7)
        lst = g.vertices (graph)
        self.assertEqual (lt.size (lst), 7)
コード例 #8
0
    def reverse(self, graph):
        """
         Retornar el reverso del grafo graph
        """
        greverse = g.newGraph(12, self.comparenames, directed=True)

        lstvert = g.vertices(graph)
        itervert = it.newIterator(lstvert)
        while it.hasNext(itervert):
            vert = it.next(itervert)
            g.insertVertex(greverse, vert)

        itervert = it.newIterator(lstvert)
        while it.hasNext(itervert):
            vert = it.next(itervert)
            lstadj = g.adjacents(graph, vert)
            iteradj = it.newIterator(lstadj)
            while it.hasNext(iteradj):
                adj = it.next(iteradj)
                g.addEdge(greverse, adj, vert)
        return greverse
コード例 #9
0
ファイル: test_graph.py プロジェクト: dlmanrique/Lab7_202010
    def test_removeVertex(self):
        graph = g.newGraph(7,self.comparenames)
        
        g.insertVertex (graph, 'Bogota')
        g.insertVertex (graph, 'Yopal')
        g.insertVertex (graph, 'Cali')
        g.insertVertex (graph, 'Medellin')
        g.insertVertex (graph, 'Pasto')
        g.insertVertex (graph, 'Barranquilla')
        g.insertVertex (graph, 'Manizales')

        

        g.removeVertex(graph,'Bogota')
        g.removeVertex(graph,'Cali')

        n=g.containsVertex(graph, 'Bogota')
        o=g.containsVertex(graph, 'Cali')

        self.assertEqual(False,n)
        self.assertEqual(False,o)
コード例 #10
0
ファイル: test_graph.py プロジェクト: dlmanrique/Lab7_202010
    def test_adjacents(self):
        graph = g.newGraph(7,self.comparenames)

        g.insertVertex (graph, 'Bogota')
        g.insertVertex (graph, 'Yopal')
        g.insertVertex (graph, 'Cali')
        g.insertVertex (graph, 'Medellin')
        g.insertVertex (graph, 'Pasto')
        g.insertVertex (graph, 'Barranquilla')
        g.insertVertex (graph, 'Manizales')

        g.addEdge (graph, 'Bogota', 'Yopal')
        g.addEdge (graph, 'Bogota', 'Medellin')
        g.addEdge (graph, 'Bogota', 'Pasto')
        g.addEdge (graph, 'Bogota', 'Cali')
        g.addEdge (graph, 'Yopal', 'Medellin')
        g.addEdge (graph, 'Medellin', 'Pasto')
        g.addEdge (graph, 'Cali', 'Pasto')
        g.addEdge (graph, 'Cali', 'Barranquilla')
        g.addEdge (graph, 'Barranquilla','Manizales')
        g.addEdge (graph, 'Pasto','Manizales')

        lst=g.adjacents(graph,'Bogota')
        self.assertEqual(lt.size(lst),4)
コード例 #11
0
def resultado(pila):
    if pila == 'No hay camino' or pila == 'No existen los vértices':
        print(pila)
    else:
        print("El camino de menor costo entre los vertices es:")
        totalDist = 0
        while not stk.isEmpty(pila):
            step = stk.pop(pila)
            totalDist += step['weight']
            print(step['vertexA'] + "-->" + step['vertexB'] + " costo: " +
                  str(step['weight']))
        print("Total: " + str(totalDist))


if __name__ == "__main__":
    graph = g.newGraph(7, comparenames)

    g.insertVertex(graph, 'Bogota')
    g.insertVertex(graph, 'Yopal')
    g.insertVertex(graph, 'Cali')
    g.insertVertex(graph, 'Medellin')
    g.insertVertex(graph, 'Pasto')
    g.insertVertex(graph, 'Barranquilla')
    g.insertVertex(graph, 'Manizales')
    g.insertVertex(graph, 'Cucuta')
    g.insertVertex(graph, 'Bucaramanga')

    g.addEdge(graph, 'Bogota', 'Yopal', 1.0)
    g.addEdge(graph, 'Bogota', 'Medellin', 1.0)
    g.addEdge(graph, 'Bogota', 'Pasto', 1.0)
    g.addEdge(graph, 'Bogota', 'Cali', 1.0)
コード例 #12
0
ファイル: test_graph.py プロジェクト: andresR0410/Lab7_202010
    def test_connectedcomponents0(self):

        graph = g.newGraph(1, self.comparenames)

        cc = dfs.countCC(graph)
        self.assertEqual(cc, 0)