Source code for campy.datastructures.basicgraph

# TODO(sredmond): Implement hash.

[docs]class Vertex(): """Canonical Vertex (Node) structure used by :class:`BasicGraph`. """ # TODO(sredmond): Investigate whether VertexGen in the C++ library is meaningful. def __init__(self, name): = name self.reset_data() ## TODO Copy constructor
[docs] def reset_data(self): self.arcs = set() # {Edge} self.visited = False self.previous = None self.cost = 0.0 self._color = 0 # UNCOLORED
@property def color(self): """Return the color of this vertex.""" return self._m_color @color.setter def color(self, c): self._color = c # self.notify_observers() ## TODO Add observables # Convenient aliases @property def edges(self): return self.arcs @property def weight(self): return self.cost def __repr__(self): return "Vertex(name={}, cost={}, visited={}, previous={}, neighbors={{}})".format(, self.cost, self.visited, if self.previous else 'None', ', '.join( for edge in self.edges) )
## TODO equality override # Node = Vertex # Should we allow class-level aliasing like Marty?
[docs]class Edge(): def __init__(self, start=None, finish=None, cost=0.0): self.start = start self.finish = finish self.cost = cost self.reset_data()
[docs] def reset_data(self): self.visited = False
# Convenient aliases @property def end(self): return self.finish @end.setter def end(self, value): self.finish = value @end.deleter def end(self): del self.end @property def weight(self): return self.cost def __repr__(self): return "Edge(start={}, finish={}, cost={}, visited={})".format( if self.start else 'None', if self.finish else 'None', self.cost, self.visited )
# Arc = Edge # Should we alias this too?
[docs]class BasicGraph(): def __init__(self): self._reset_enabled = True