class Graph:
Known subclasses: rlgt.graphs.special_graphs.AlmostCompleteGraph, rlgt.graphs.special_graphs.BookGraph, rlgt.graphs.special_graphs.CompleteBipartiteGraph, rlgt.graphs.special_graphs.CompleteGraph, rlgt.graphs.special_graphs.CompleteKPartiteGraph, rlgt.graphs.special_graphs.CycleGraph, rlgt.graphs.special_graphs.EmptyGraph, rlgt.graphs.special_graphs.FriendshipGraph, rlgt.graphs.special_graphs.MonochromaticGraph, rlgt.graphs.special_graphs.PathGraph, rlgt.graphs.special_graphs.StarGraph, rlgt.graphs.special_graphs.WheelGraph
Constructors: Graph.from_adjacency_matrix(adjacency_matrix, color_representation, edge_colors, is_directed, ...), Graph.from_bitmask(bitmask, bitmask_type, edge_colors, is_directed, ...), Graph.from_flattened(flattened, flattened_ordering, color_representation, edge_colors, ...), Graph(edge_colors, is_directed, allow_loops, bitmask_out, ...)
This class encapsulates the concept of a k-edge-colored looped complete graph or a batch of
k-edge-colored looped complete graphs of the same order, with k being at least 2. If a
single graph is modeled, then it is represented as a quintuple (edge_colors, is_directed,
allow_loops, graph_format, format_representation), as explained in the GraphFormat
enumeration. If a batch of graphs is modeled, then the graphs in the batch must be consistent
in the sense that they all have the same number of proper edge colors and the same order, they
are either all directed or all undirected, and they either all allow loops or all disallow
them. Accordingly, a batch of graphs can be analogously represented by a quintuple
(edge_colors, is_directed, allow_loops, graph_format, format_representation), where the
only difference is that all numpy.ndarray objects used as format representations have one
additional leading dimension. More precisely, if a is the numpy.ndarray describing the
structure of a batch of graphs in a given graph format, then a[i] is the structural
representation of the i-th graph in the batch in that format.
The structure of the graph or batch of graphs can be represented in any of the eight graph
formats defined in the GraphFormat enumeration. The structure is initialized in at least one
of these formats so that the corresponding format_representation numpy.ndarray objects
are internally stored. Afterwards, the graph or batch of graphs can be accessed in any of the
eight formats, with all required graph format conversions being performed automatically. Each
time a conversion is performed, the resulting numpy.ndarray corresponding to the target graph
format is internally stored. The class provides support for all reduced formats, and when
converting to a bitmask format or to a format with binary slices, the corresponding reduced
format is always used whenever possible, i.e., whenever the graph or batch of graphs is fully
colored.
| Class Method | from |
This class method initializes a Graph object in either the adjacency matrix format with color numbers or the adjacency matrix format with binary slices. |
| Class Method | from |
This class method initializes a Graph object in either the bitmask format for the out-neighborhoods or the bitmask format for the in-neighborhoods. |
| Class Method | from |
This class method initializes a Graph object in exactly one of the four possible flattened graph formats. |
| Method | __getitem__ |
This method returns the graph at the given index if this object models a batch of graphs. If this object models a single graph, it raises an IndexError. |
| Method | __init__ |
This method initializes an instance of the class, which models either a single graph or a batch of graphs in at least one of the eight graph formats defined in the GraphFormat enumeration. In other words, at least one graph format must be selected, and the graph or batch of graphs is initialized in each selected format using the corresponding provided ... |
| Property | adjacency |
This property returns the numpy.ndarray of type numpy.uint8 representing the given graph or batch of graphs in the adjacency matrix format with binary slices. |
| Property | adjacency |
This property returns the numpy.ndarray of type numpy.uint8 representing the given graph or batch of graphs in the adjacency matrix format with color numbers. |
| Property | allow |
This property returns a bool indicating whether loops are allowed in the given graph or in each graph in the batch. The value True indicates that loops are allowed. |
| Property | batch |
This property returns None if the object represents a single k-edge-colored looped complete graph. If the object represents a batch of k-edge-colored looped complete graphs of the same order, then this property returns the batch size, i... |
| Property | bitmask |
This property returns the numpy.ndarray of type numpy.uint64 representing the given graph or batch of graphs in the bitmask format for the the in-neighborhoods. |
| Property | bitmask |
This property returns the numpy.ndarray of type numpy.uint64 representing the given graph or batch of graphs in the bitmask format for the out-neighborhoods. |
| Property | edge |
This property returns the number of proper edge colors in the given graph or batch of graphs, i.e., k, as a positive int that is at least 2. |
| Property | flattened |
This property returns the numpy.ndarray of type numpy.uint8 representing the given graph or batch of graphs in the flattened clockwise format with binary slices. |
| Property | flattened |
This property returns the numpy.ndarray of type numpy.uint8 representing the given graph or batch of graphs in the flattened clockwise format with color numbers. |
| Property | flattened |
This property returns the numpy.ndarray of type numpy.uint8 representing the given graph or batch of graphs in the flattened row-major format with binary slices. |
| Property | flattened |
This property returns the numpy.ndarray of type numpy.uint8 representing the given graph or batch of graphs in the flattened row-major format with color numbers. |
| Property | graph |
This property returns the order of the given graph or the common order of all graphs in the batch, as a positive int. |
| Property | is |
This property returns a bool indicating whether the given graph or each graph in the batch is directed. The value True indicates that the graph or graphs are directed. |
| Method | __convert |
This private method performs a direct conversion from the format representation of the given graph or batch of graphs in a selected input format to the format representation of that graph or batch of graphs in a selected output format... |
| Instance Variable | __adjacency |
Either a numpy.ndarray of type numpy.uint8 representing the graph structure in the adjacency matrix format with binary slices, if this format was used during initialization or computed afterwards, or None... |
| Instance Variable | __adjacency |
Either a numpy.ndarray of type numpy.uint8 representing the graph structure in the adjacency matrix format with color numbers, if this format was used during initialization or computed afterwards, or None... |
| Instance Variable | __allow |
A bool indicating whether the graph or each graph in the batch is allowed to have loops. If loops are not allowed, then all loops are removed from the considered looped complete graph or graphs and therefore do not exist. |
| Instance Variable | __batch |
Either None, if the object models a single graph, or a positive int, if the object models a batch of graphs, specifying the batch size, i.e., the number of graphs in the batch. |
| Instance Variable | __bitmask |
Either a numpy.ndarray of type numpy.uint64 representing the graph structure in the bitmask format for the in-neighborhoods, if this format was used during initialization or computed afterwards, or None... |
| Instance Variable | __bitmask |
Either a numpy.ndarray of type numpy.uint64 representing the graph structure in the bitmask format for the out-neighborhoods, if this format was used during initialization or computed afterwards, or None... |
| Instance Variable | __edge |
The number of proper edge colors, i.e., k, given as a positive int that is at least 2. |
| Instance Variable | __flattened |
Either a numpy.ndarray of type numpy.uint8 representing the graph structure in the flattened clockwise format with binary slices, if this format was used during initialization or computed afterwards, or ... |
| Instance Variable | __flattened |
Either a numpy.ndarray of type numpy.uint8 representing the graph structure in the flattened clockwise format with color numbers, if this format was used during initialization or computed afterwards, or ... |
| Instance Variable | __flattened |
Either a numpy.ndarray of type numpy.uint8 representing the graph structure in the flattened row-major format with binary slices, if this format was used during initialization or computed afterwards, or ... |
| Instance Variable | __flattened |
Either a numpy.ndarray of type numpy.uint8 representing the graph structure in the flattened row-major format with color numbers, if this format was used during initialization or computed afterwards, or ... |
| Instance Variable | __graph |
The graph order or the common order of all graphs in the batch, given as a positive int. |
| Instance Variable | __is |
A bool indicating whether the graph or each graph in the batch is a k-edge-colored looped complete directed graph or a k-edge-colored looped complete undirected graph. |
np.ndarray, color_representation: ColorRepresentation = ColorRepresentation.COLOR_NUMBERS, edge_colors: int = 2, is_directed: bool = False, allow_loops: bool = False) -> Graph:
¶
This class method initializes a Graph object in either the adjacency matrix format with
color numbers or the adjacency matrix format with binary slices.
| Parameters | |
adjacencynp.ndarray | A numpy.ndarray of type numpy.uint8 that describes the format
representation of the graph or batch of graphs to be initialized, either in the
adjacency matrix format with color numbers or in the adjacency matrix format with
binary slices. |
colorColorRepresentation | An item of the ColorRepresentation enumeration that
determines whether the graph or batch of graphs is initialized in the adjacency matrix
format with color numbers or in the adjacency matrix format with binary slices. The
default value is ColorRepresentation.COLOR_NUMBERS, meaning that the graph or batch
of graphs is initialized in the adjacency matrix format with color numbers by default. |
edgeint | A positive int that represents the number of proper edge colors,
i.e., k, and that must be at least 2. The default value is 2. |
isbool | A bool indicating whether the graph or each graph in the batch is a
k-edge-colored looped complete directed graph or a k-edge-colored looped complete
undirected graph. The default value is False, meaning that the graph or batch of
graphs is undirected by default. |
allowbool | A bool indicating whether the graph or each graph in the batch is
allowed to have loops. If loops are not allowed, then all loops are removed from the
considered looped complete graph or graphs and therefore do not exist. The default
value is False, meaning that loops are not allowed by default. |
| Returns | |
Graph | The initialized Graph object. |
| Note | |
| This class method supports the reduced adjacency matrix format with binary slices, meaning that the reduced variant is also accepted when initializing the graph or batch of graphs in this format. |
np.ndarray, bitmask_type: BitmaskType = BitmaskType.OUT_NEIGHBORS, edge_colors: int = 2, is_directed: bool = False, allow_loops: bool = False) -> Graph:
¶
This class method initializes a Graph object in either the bitmask format for the
out-neighborhoods or the bitmask format for the in-neighborhoods.
| Parameters | |
bitmask:np.ndarray | A numpy.ndarray of type numpy.uint64 that describes the format
representation of the graph or batch of graphs to be initialized, either in the bitmask
format for the out-neighborhoods or in the bitmask format for the in-neighborhoods. |
bitmaskBitmaskType | An item of the BitmaskType enumeration that determines whether the
graph or batch of graphs is initialized in the bitmask format for the out-neighborhoods
or in the bitmask format for the in-neighborhoods. The default value is
BitmaskType.OUT_NEIGHBORS, meaning that the graph or batch of graphs is initialized
in the bitmask format for the out-neighborhoods by default. |
edgeint | A positive int that represents the number of proper edge colors,
i.e., k, and that must be at least 2. The default value is 2. |
isbool | A bool indicating whether the graph or each graph in the batch is a
k-edge-colored looped complete directed graph or a k-edge-colored looped complete
undirected graph. The default value is False, meaning that the graph or batch of
graphs is undirected by default. |
allowbool | A bool indicating whether the graph or each graph in the batch is
allowed to have loops. If loops are not allowed, then all loops are removed from the
considered looped complete graph or graphs and therefore do not exist. The default
value is False, meaning that loops are not allowed by default. |
| Returns | |
Graph | The initialized Graph object. |
| Note | |
| This class method supports the reduced bitmask formats, meaning that the graph or batch of graphs can also be initialized using either of the reduced bitmask format representations. |
np.ndarray, flattened_ordering: FlattenedOrdering = FlattenedOrdering.ROW_MAJOR, color_representation: ColorRepresentation = ColorRepresentation.COLOR_NUMBERS, edge_colors: int = 2, is_directed: bool = False, allow_loops: bool = False) -> Graph:
¶
This class method initializes a Graph object in exactly one of the four possible
flattened graph formats.
| Parameters | |
flattened:np.ndarray | A numpy.ndarray of type numpy.uint8 that describes the format
representation of the graph or batch of graphs to be initialized, in one of the four
possible flattened formats. |
flattenedFlattenedOrdering | An item of the FlattenedOrdering enumeration that determines
whether the graph or batch of graphs is initialized in a flattened row-major format or
in a flattened clockwise format. The default value is FlattenedOrdering.ROW_MAJOR,
meaning that the graph or batch of graphs is initialized in a flattened row-major
format by default. |
colorColorRepresentation | An item of the ColorRepresentation enumeration that
determines whether the graph or batch of graphs is initialized in a flattened format
with color numbers or in a flattened format with binary slices. The default value is
ColorRepresentation.COLOR_NUMBERS, meaning that the graph or batch of graphs is
initialized in a flattened format with color numbers by default. |
edgeint | A positive int that represents the number of proper edge colors,
i.e., k, and that must be at least 2. The default value is 2. |
isbool | A bool indicating whether the graph or each graph in the batch is a
k-edge-colored looped complete directed graph or a k-edge-colored looped complete
undirected graph. The default value is False, meaning that the graph or batch of
graphs is undirected by default. |
allowbool | A bool indicating whether the graph or each graph in the batch is
allowed to have loops. If loops are not allowed, then all loops are removed from the
considered looped complete graph or graphs and therefore do not exist. The default
value is False, meaning that loops are not allowed by default. |
| Returns | |
Graph | The initialized Graph object. |
| Note | |
| This class method supports the reduced flattened formats with binary slices, meaning that the reduced variants are also accepted when initializing the graph or batch of graphs in these formats. |
This method returns the graph at the given index if this object models a batch of graphs.
If this object models a single graph, it raises an IndexError.
| Parameters | |
index:int | A nonnegative int below the batch size specifying which graph to extract. |
| Returns | |
Graph | The graph at the given index, as a Graph object. |
int = 2, is_directed: bool = False, allow_loops: bool = False, bitmask_out: np.ndarray | None = None, bitmask_in: np.ndarray | None = None, adjacency_matrix_colors: np.ndarray | None = None, adjacency_matrix_binary: np.ndarray | None = None, flattened_row_major_colors: np.ndarray | None = None, flattened_row_major_binary: np.ndarray | None = None, flattened_clockwise_colors: np.ndarray | None = None, flattened_clockwise_binary: np.ndarray | None = None):
¶
rlgt.graphs.special_graphs.AlmostCompleteGraph, rlgt.graphs.special_graphs.BookGraph, rlgt.graphs.special_graphs.CompleteBipartiteGraph, rlgt.graphs.special_graphs.CompleteGraph, rlgt.graphs.special_graphs.CompleteKPartiteGraph, rlgt.graphs.special_graphs.CycleGraph, rlgt.graphs.special_graphs.EmptyGraph, rlgt.graphs.special_graphs.FriendshipGraph, rlgt.graphs.special_graphs.MonochromaticGraph, rlgt.graphs.special_graphs.PathGraph, rlgt.graphs.special_graphs.StarGraph, rlgt.graphs.special_graphs.WheelGraphThis method initializes an instance of the class, which models either a single graph or a
batch of graphs in at least one of the eight graph formats defined in the GraphFormat
enumeration. In other words, at least one graph format must be selected, and the graph or
batch of graphs is initialized in each selected format using the corresponding provided
numpy.ndarray objects. If the instance is initialized in more than one graph format, then
the provided numpy.ndarray objects must be mutually consistent, meaning that they must
all represent the same graph or the same batch of graphs.
| Parameters | |
edgeint | A positive int that represents the number of proper edge colors,
i.e., k, and that must be at least 2. The default value is 2. |
isbool | A bool indicating whether the graph or each graph in the batch is a
k-edge-colored looped complete directed graph or a k-edge-colored looped complete
undirected graph. The default value is False, meaning that the graph or batch of
graphs is undirected by default. |
allowbool | A bool indicating whether the graph or each graph in the batch is
allowed to have loops. If loops are not allowed, then all loops are removed from the
considered looped complete graph or graphs and therefore do not exist. The default
value is False, meaning that loops are not allowed by default. |
bitmasknp.ndarray | None | Either a numpy.ndarray of type numpy.uint64 describing the graph
structure in the bitmask format for the out-neighborhoods, if the graph or batch of
graphs should be initialized in this format, or None otherwise. The default value is
None. |
bitmasknp.ndarray | None | Either a numpy.ndarray of type numpy.uint64 describing the graph
structure in the bitmask format for the in-neighborhoods, if the graph or batch of
graphs should be initialized in this format, or None otherwise. The default value is
None. |
adjacencynp.ndarray | None | Either a numpy.ndarray of type numpy.uint8 describing
the graph structure in the adjacency matrix format with color numbers, if the graph or
batch of graphs should be initialized in this format, or None otherwise. The default
value is None. |
adjacencynp.ndarray | None | Either a numpy.ndarray of type numpy.uint8 describing
the graph structure in the adjacency matrix format with binary slices, if the graph or
batch of graphs should be initialized in this format, or None otherwise. The default
value is None. |
flattenednp.ndarray | None | Either a numpy.ndarray of type numpy.uint8
describing the graph structure in the flattened row-major format with color numbers, if
the graph or batch of graphs should be initialized in this format, or None otherwise.
The default value is None. |
flattenednp.ndarray | None | Either a numpy.ndarray of type numpy.uint8
describing the graph structure in the flattened row-major format with binary slices, if
the graph or batch of graphs should be initialized in this format, or None otherwise.
The default value is None. |
flattenednp.ndarray | None | Either a numpy.ndarray of type numpy.uint8
describing the graph structure in the flattened clockwise format with color numbers, if
the graph or batch of graphs should be initialized in this format, or None otherwise.
The default value is None. |
flattenednp.ndarray | None | Either a numpy.ndarray of type numpy.uint8
describing the graph structure in the flattened clockwise format with binary slices, if
the graph or batch of graphs should be initialized in this format, or None otherwise.
The default value is None. |
This property returns the numpy.ndarray of type numpy.uint8 representing the given
graph or batch of graphs in the adjacency matrix format with binary slices.
This property returns the numpy.ndarray of type numpy.uint8 representing the given
graph or batch of graphs in the adjacency matrix format with color numbers.
This property returns the numpy.ndarray of type numpy.uint64 representing the given
graph or batch of graphs in the bitmask format for the the in-neighborhoods.
This property returns the numpy.ndarray of type numpy.uint64 representing the given
graph or batch of graphs in the bitmask format for the out-neighborhoods.
This property returns the number of proper edge colors in the given graph or batch of
graphs, i.e., k, as a positive int that is at least 2.
This property returns the numpy.ndarray of type numpy.uint8 representing the given
graph or batch of graphs in the flattened clockwise format with binary slices.
This property returns the numpy.ndarray of type numpy.uint8 representing the given
graph or batch of graphs in the flattened clockwise format with color numbers.
This property returns the numpy.ndarray of type numpy.uint8 representing the given
graph or batch of graphs in the flattened row-major format with binary slices.
This property returns the numpy.ndarray of type numpy.uint8 representing the given
graph or batch of graphs in the flattened row-major format with color numbers.
This property returns the order of the given graph or the common order of all graphs in the
batch, as a positive int.
This private method performs a direct conversion from the format representation of the given graph or batch of graphs in a selected input format to the format representation of that graph or batch of graphs in a selected output format. The following direct conversions are supported:
- bitmask format for the out-neighborhoods ↔ adjacency matrix format with binary slices;
- bitmask format for the in-neighborhoods ↔ adjacency matrix format with binary slices;
- adjacency matrix format with binary slices ↔ flattened row-major format with binary slices;
- adjacency matrix format with binary slices ↔ flattened clockwise format with binary slices;
- adjacency matrix format with color numbers ↔ flattened row-major format with color numbers;
- adjacency matrix format with color numbers ↔ flattened clockwise format with color numbers;
- adjacency matrix format with binary slices ↔ adjacency matrix format with color numbers;
- flattened row-major format with binary slices ↔ flattened row-major format with color numbers; and
- flattened clockwise format with binary slices ↔ flattened clockwise format with color numbers.
A NotImplementedError is raised if any other direct conversion is attempted.
| Parameters | |
inputGraphFormat | The selected input format, given as an item of the GraphFormat
enumeration. |
outputGraphFormat | The selected output format, given as an item of the GraphFormat
enumeration. |
Either a numpy.ndarray of type numpy.uint8 representing
the graph structure in the adjacency matrix format with binary slices, if this format was
used during initialization or computed afterwards, or None otherwise.
Either a numpy.ndarray of type numpy.uint8 representing
the graph structure in the adjacency matrix format with color numbers, if this format was
used during initialization or computed afterwards, or None otherwise.
A bool indicating whether the graph or each graph in the batch is
allowed to have loops. If loops are not allowed, then all loops are removed from the
considered looped complete graph or graphs and therefore do not exist.
Either a numpy.ndarray of type numpy.uint64 representing the graph
structure in the bitmask format for the in-neighborhoods, if this format was used during
initialization or computed afterwards, or None otherwise.
Either a numpy.ndarray of type numpy.uint64 representing the graph
structure in the bitmask format for the out-neighborhoods, if this format was used during
initialization or computed afterwards, or None otherwise.
Either a numpy.ndarray of type numpy.uint8 representing
the graph structure in the flattened clockwise format with binary slices, if this format
was used during initialization or computed afterwards, or None otherwise.
Either a numpy.ndarray of type numpy.uint8 representing
the graph structure in the flattened clockwise format with color numbers, if this format
was used during initialization or computed afterwards, or None otherwise.
Either a numpy.ndarray of type numpy.uint8 representing
the graph structure in the flattened row-major format with binary slices, if this format
was used during initialization or computed afterwards, or None otherwise.
Either a numpy.ndarray of type numpy.uint8 representing
the graph structure in the flattened row-major format with color numbers, if this format
was used during initialization or computed afterwards, or None otherwise.