I am studying about graph theory, more specifically about the vertices that are units representing a given node of a graph. However, there are still some questions about the vertices.
See this illustration graph in Python:
graph = {
'A': ['B', 'C', 'D'],
'B': ['A'],
'C': ['A', 'D'],
'D': ['A', 'C']
}
Notice that it is a non-directed graph, the dictionary saves the path for each vertex.
My question is related to the vertex, if it is possible to make it represent an object or a class . And the object I would like my vertex to represent would be of the type of class Ambiente
:
class Ambiente:
def __init__(self, titulo, descricao, id):
self.titulo = titulo
self.descricao = descricao
self.id = id
I tried to associate the index in the dictionary:
ambientes = {
'A': Ambiente('Sala de maquinas',
"A sala contém várias maquinas industriais, todas parecem não funcionar por anos. O som que é emitido dela é fantasmagórico e causa um estado de panico e alerta, como se a qualquer momento alguma entidade fosse emergir daquela pilha de metal amaldiçoada. Há poucos ruídos, no entanto, não há sinal de vida alguma.",
'A'
)
}
But I do not seem to be effective in this way, especially when I need to navigate the paths of the graph. So, I'd like my question to be answered below.
Question
How could I associate objects with the vertices of the graph?