def find_retracts(G, results_limit=-1, only_count=False, max_depth=-1, partmap=None): """ Run retract search on undirected graph `G`, return list of maps or their number (acc. to `only_count`), starting with `partmap` G-H-map if given. NOTE: always finds the identity. """ assert not G.is_directed() hs = HomsearchInterface(graph_to_adjlist(G), graph_to_adjlist(G), results_limit, (not only_count), True, max_depth=max_depth) if partmap is None: hs.search() else: hs.search_from(graphmap_to_fmap(G, G, partmap)) if only_count: return hs.result_count() else: return [fmap_to_graphmap(G, G, f) for f in hs.result_list()]
def find_homomorphisms(G, H, results_limit=-1, only_count=False, max_depth=-1, partmap=None): """ Run G->H homomorphism search on undirected graphs `G` and `H`, return list of maps or their number (acc. to `only_count`), starting with `partmap` G-H-map if given. """ assert not G.is_directed() assert not H.is_directed() hs = HomsearchInterface(graph_to_adjlist(G), graph_to_adjlist(H), results_limit, (not only_count), False, max_depth=max_depth) if partmap is None: hs.search() else: hs.search_from(graphmap_to_fmap(G, H, partmap)) if only_count: return hs.result_count() else: return [fmap_to_graphmap(G, H, f) for f in hs.result_list()]