Ejemplo n.º 1
0
    def _DFS(self, g: Graph, v):

        self._unexploredV.remove(v)

        for e in g.incident_edges(v):
            if self._unexploredE.__contains__(e):
                self._unexploredE.remove(e)
                for w in e.endpoints():
                    if w != v and self._unexploredV.__contains__(w):
                        self._DFS(g, w)
Ejemplo n.º 2
0
    def _DFS(self, g: Graph, v):

        self._unexploredV.remove(v)

        for e in g.incident_edges(v):
            if self._unexploredE.__contains__(e):
                self._unexploredE.remove(e)
                if self._unexploredV.__contains__(e.toVertex()):
                    if e.toVertex == g.end():
                        self._counter = self._counter + 1
                    else:
                        self._DFS(g, e.toVertex())
Ejemplo n.º 3
0
g.insert_edge(2, v66, v38)
g.insert_edge(76, v66, v123)
g.insert_edge(7, v123, v6)
g.insert_edge(55, v123, v38)

g2 = Graph()

g2.insert_vertex(15)
g2.insert_vertex(6)

d = dfs_iterator()
for i in d.iterator_dfs(g, 15):
    print(i)

print(d.is_connected(g2))

print(d.is_path(g2, 15, 6))

for i in g.incident_edges(15):
    print(i)

d.DFS(g)

print("Unexplored Edge")
for i in d._unexploredE:
    print(i)

print("Unexplored Vertex")
for i in d._unexploredV:
    print(i)