From 5a31b2804703e7338892651bfcf01a2f01592422 Mon Sep 17 00:00:00 2001 From: Kris Brown Date: Fri, 24 May 2024 11:36:31 +0100 Subject: [PATCH] Epic backtracking constraint --- src/categorical_algebra/HomSearch.jl | 39 ++++++++++++++++++++++++--- test/categorical_algebra/HomSearch.jl | 18 +++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/categorical_algebra/HomSearch.jl b/src/categorical_algebra/HomSearch.jl index 0c9028ac1..acc8f23f4 100644 --- a/src/categorical_algebra/HomSearch.jl +++ b/src/categorical_algebra/HomSearch.jl @@ -177,7 +177,7 @@ been bound. struct BacktrackingState{ Dom <: ACSet, Codom <: ACSet, Assign <: NamedTuple, PartialAssign <: NamedTuple, LooseFun <: NamedTuple, - Predicates <: NamedTuple + Predicates <: NamedTuple,Image <: NamedTuple, Unassign<: NamedTuple } assignment::Assign assignment_depth::Assign @@ -186,10 +186,13 @@ struct BacktrackingState{ codom::Codom type_components::LooseFun predicates::Predicates + image::Image # Negative of image for epic components or if finding an epimorphism + unassigned::Unassign # "# of unassigned elems in domain of a component + end function backtracking_search(f, X::ACSet, Y::ACSet; - monic=false, iso=false, random=false, predicates=(;), + monic=false, epic=false, iso=false, random=false, predicates=(;), type_components=(;), initial=(;), error_failures=false) S, Sy = acset_schema.([X,Y]) S == Sy || error("Schemas must match for morphism search") @@ -212,15 +215,21 @@ function backtracking_search(f, X::ACSet, Y::ACSet; if monic isa Bool monic = monic ? ObAttr : () end + if epic isa Bool + epic = epic ? Ob : () + end iso_failures = Iterators.filter(c->nparts(X,c)!=nparts(Y,c),iso) mono_failures = Iterators.filter(c->nparts(X,c)>nparts(Y,c),monic) - if (!isempty(iso_failures) || !isempty(mono_failures)) + epi_failures = Iterators.filter(c->nparts(X,c)