Abstract Base Classes
Abstract base classes for user-defined coordinates.
The base classes in this module form an interface for using the
functions in pygrates.moves. The user creates a coordinate class
by explicitly subclassing one of the bases and implementing its
abstract methods, or implicitly by implementing all of its methods.
All coordinates need to be hashable and to define equality with
coordinates of the same type: this can easily achieved with a named
tuple or dataclass implementation.
Examples
>>> from dataclasses import dataclass
>>> @dataclass(frozen=True)
... class Point2D(pg.abc.DGCoords):
... x: int
... y: int
...
... def children(self):
... return Point2D(self.x + 1, self.y), Point2D(self.x, self.y + 1)
...
... def parents(self):
... return Point2D(self.x - 1, self.y), Point2D(self.x, self.y - 1)
...
>>> origin = Point2D(0, 0)
>>> isinstance(origin, pg.abc.DGCoords)
True
- class pygrates.abc.GCoords[source]
Bases:
ABCBase class for graph coordinates.
Interface for using the functions in
pygrates.moves. User-created coordinate class implicitly defines an undirected or directed graph.Methods to implement are
__eq__,__hash__andadjacent.- abstract __eq__(other: object) bool[source]
Return True if self is equal to other coordinate.
- Parameters:
other (Self) – Coordinate object of the same type as self.
- Returns:
True if passed coordinate is equal to self.
- Return type:
- abstract __hash__() int[source]
Return hash value of self.
- Returns:
Hash value of self.
- Return type:
- class pygrates.abc.DGCoords[source]
-
Base class for directed graph coordinates.
Interface for using the functions in
pygrates.moves. User-created coordinate class implicitly defines a directed graph.Methods to implement are
__eq__,__hash__,children, andparents.- abstract __eq__(other: object) bool
Return True if self is equal to other coordinate.
- Parameters:
other (Self) – Coordinate object of the same type as self.
- Returns:
True if passed coordinate is equal to self.
- Return type:
- adjacent() Iterable[Self][source]
Return iterable containing adjacent coordinates.
- Returns:
Iterable containing coordinates adjacent to self, of the same type.
- Return type:
Iterable[Self]
- abstract children() Iterable[Self][source]
Return iterable containing child coordinates.
- Returns:
Iterable containing child coordinates of self, of the same type.
- Return type:
Iterable[Self]
- is_adjacent(other: Self) bool
Return True if self is adjacent to other coordinate.
- Parameters:
other (Self) – Coordinate object of the same type as self.
- Returns:
True if self is adjacent to passed coordinate.
- Return type:
- is_child(other: Self) bool[source]
Return True if self is a child of other coordinate.
- Parameters:
other (Self) – Coordinate object of the same type as self.
- Returns:
True if self is a child of passed coordinate.
- Return type: