rustworkx.cartesian_product#

cartesian_product(first, second)[source]#

Return a new graph by forming the cartesian product from two input graph objects

Parameters:
  • first – The first graph object

  • second – The second graph object

Returns:

A new graph object that is the union of second and first. It’s worth noting the weight/data payload objects are passed by reference from first and second to this new object. A read-only dictionary of the product of nodes is also returned. The keys are a tuple where the first element is a node of the first graph and the second element is a node of the second graph, and the values are the map of those elements to node indices in the product graph. For example:

{
    (0, 0): 0,
    (0, 1): 1,
}

Return type:

Tuple[PyGraph or PyDiGraph, ProductNodeMap]