class documentation

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_adjacency_matrix 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_bitmask 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_flattened 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_matrix_binary 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_matrix_colors 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_loops 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_size 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_in 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_out 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_colors 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_clockwise_binary 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_clockwise_colors 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_row_major_binary 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_row_major_colors 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_order 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_directed 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_graph_format 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_matrix_binary 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_matrix_colors 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_loops 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_size 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_in 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_out 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_colors The number of proper edge colors, i.e., k, given as a positive int that is at least 2.
Instance Variable __flattened_clockwise_binary 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_clockwise_colors 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_row_major_binary 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_row_major_colors 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_order The graph order or the common order of all graphs in the batch, given as a positive int.
Instance Variable __is_directed 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.
def from_adjacency_matrix(cls, adjacency_matrix: 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
adjacency_matrix:np.ndarrayA 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.
color_representation:ColorRepresentationAn 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.
edge_colors:intA 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.
is_directed:boolA 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.
allow_loops:boolA 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
GraphThe 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.
def from_bitmask(cls, bitmask: 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.ndarrayA 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.
bitmask_type:BitmaskTypeAn 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.
edge_colors:intA 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.
is_directed:boolA 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.
allow_loops:boolA 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
GraphThe 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.
def from_flattened(cls, flattened: 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.ndarrayA 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.
flattened_ordering:FlattenedOrderingAn 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.
color_representation:ColorRepresentationAn 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.
edge_colors:intA 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.
is_directed:boolA 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.
allow_loops:boolA 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
GraphThe 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.
def __getitem__(self, index: int) -> Graph:

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:intA nonnegative int below the batch size specifying which graph to extract.
Returns
GraphThe graph at the given index, as a Graph object.
def __init__(self, edge_colors: 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):

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 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
edge_colors:intA 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.
is_directed:boolA 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.
allow_loops:boolA 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.
bitmask_out:np.ndarray | NoneEither 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.
bitmask_in:np.ndarray | NoneEither 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.
adjacency_matrix_colors:np.ndarray | NoneEither 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.
adjacency_matrix_binary:np.ndarray | NoneEither 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.
flattened_row_major_colors:np.ndarray | NoneEither 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.
flattened_row_major_binary:np.ndarray | NoneEither 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.
flattened_clockwise_colors:np.ndarray | NoneEither 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.
flattened_clockwise_binary:np.ndarray | NoneEither 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.
adjacency_matrix_binary: np.ndarray =

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.

adjacency_matrix_colors: np.ndarray =

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.

allow_loops: bool =

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.

batch_size: int | None =

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.e., the number of graphs in the batch, as a positive int.

bitmask_in: np.ndarray =

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.

bitmask_out: np.ndarray =

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.

edge_colors: int =

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.

flattened_clockwise_binary: np.ndarray =

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.

flattened_clockwise_colors: np.ndarray =

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.

flattened_row_major_binary: np.ndarray =

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.

flattened_row_major_colors: np.ndarray =

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.

graph_order: int =

This property returns the order of the given graph or the common order of all graphs in the batch, as a positive int.

is_directed: bool =

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.

def __convert_graph_format(self, input_format: GraphFormat, output_format: GraphFormat):

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:

  1. bitmask format for the out-neighborhoods ↔ adjacency matrix format with binary slices;
  2. bitmask format for the in-neighborhoods ↔ adjacency matrix format with binary slices;
  3. adjacency matrix format with binary slices ↔ flattened row-major format with binary slices;
  4. adjacency matrix format with binary slices ↔ flattened clockwise format with binary slices;
  5. adjacency matrix format with color numbers ↔ flattened row-major format with color numbers;
  6. adjacency matrix format with color numbers ↔ flattened clockwise format with color numbers;
  7. adjacency matrix format with binary slices ↔ adjacency matrix format with color numbers;
  8. flattened row-major format with binary slices ↔ flattened row-major format with color numbers; and
  9. flattened clockwise format with binary slices ↔ flattened clockwise format with color numbers.

A NotImplementedError is raised if any other direct conversion is attempted.

Parameters
input_format:GraphFormatThe selected input format, given as an item of the GraphFormat enumeration.
output_format:GraphFormatThe selected output format, given as an item of the GraphFormat enumeration.
__adjacency_matrix_binary: np.ndarray | None =

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.

__adjacency_matrix_colors: np.ndarray | None =

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.

__allow_loops: bool =

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.

__batch_size: int | None =

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.

__bitmask_in: np.ndarray | None =

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.

__bitmask_out: np.ndarray | None =

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.

__edge_colors: int =

The number of proper edge colors, i.e., k, given as a positive int that is at least 2.

__flattened_clockwise_binary: np.ndarray | None =

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.

__flattened_clockwise_colors: np.ndarray | None =

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.

__flattened_row_major_binary: np.ndarray | None =

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.

__flattened_row_major_colors: np.ndarray | None =

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.

__graph_order: int =

The graph order or the common order of all graphs in the batch, given as a positive int.

__is_directed: bool =

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.