Skip to content

Commit

Permalink
[rule] Fix isomorphicLeftRight
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobandersen committed Nov 13, 2024
1 parent f1010fc commit 7eed61f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ New Features
a name for the rule as a second positional argument.


Bugs Fixed
----------

- Fix :py:meth:`Rule.isomorphicLeftRight`/:cpp:func:`rule::Rule::isomorphicLeftRight`,
it was completely broken.


v0.16.0 (2024-06-18)
====================

Expand Down
9 changes: 5 additions & 4 deletions libs/libmod/src/mod/lib/Rules/Real.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <mod/lib/GraphMorphism/LabelledMorphism.hpp>
#include <mod/lib/GraphMorphism/VF2Finder.hpp>
#include <mod/lib/LabelledGraph.hpp>
#include <mod/lib/LabelledFilteredGraph.hpp>
#include <mod/lib/IO/IO.hpp>
#include <mod/lib/Rules/IO/DepictionData.hpp>
#include <mod/lib/Rules/Properties/Molecule.hpp>
Expand Down Expand Up @@ -194,15 +195,15 @@ std::size_t Real::monomorphism(const Real &rDom,
bool Real::isomorphicLeftRight(const Real &rDom, const Real &rCodom, LabelSettings labelSettings) {
auto mrLeft = jla_boost::GraphMorphism::makeLimit(1);
lib::GraphMorphism::morphismSelectByLabelSettings(
get_labelled_left(rDom.getDPORule()),
get_labelled_left(rCodom.getDPORule()),
LabelledFilteredGraph(get_labelled_left(rDom.getDPORule())),
LabelledFilteredGraph(get_labelled_left(rCodom.getDPORule())),
labelSettings,
lib::GraphMorphism::VF2Isomorphism(), std::ref(mrLeft));
if(mrLeft.getNumHits() == 0) return false;
auto mrRight = jla_boost::GraphMorphism::makeLimit(1);
lib::GraphMorphism::morphismSelectByLabelSettings(
get_labelled_right(rDom.getDPORule()),
get_labelled_right(rCodom.getDPORule()),
LabelledFilteredGraph(get_labelled_right(rDom.getDPORule())),
LabelledFilteredGraph(get_labelled_right(rCodom.getDPORule())),
labelSettings,
lib::GraphMorphism::VF2Isomorphism(), std::ref(mrRight));
return mrRight.getNumHits() == 1;
Expand Down
29 changes: 11 additions & 18 deletions test/py/rule/850_isomorphismLeftRight.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
include("xxx_helpers.py")

rId = Rule.fromGMLString("""rule [
ruleID "id"
context [
node [ id 0 label "A" ]
node [ id 1 label "B" ]
]
]""")
rSwap = Rule.fromGMLString("""rule [
ruleID "id"
left [
node [ id 0 label "A" ]
node [ id 1 label "B" ]
]
right [
node [ id 0 label "B" ]
node [ id 1 label "A" ]
]
]""")
rId = Rule.fromDFS("[A]0.[B]1>>[A]0.[B]1", "ID")
rSwap = Rule.fromDFS("[A]0.[B]1>>[A]1.[B]0", "swap")
assert rId.isomorphism(rSwap) == 0
assert rId.isomorphicLeftRight(rSwap)

commonChecks(rId)
commonChecks(rSwap)


rId = Rule.fromDFS("[A]0-[A]1.[A]10-[A]11>>[A]0-[A]1.[A]10-[A]11", "ID")
rSwap = Rule.fromDFS("[A]0-[A]1.[A]10-[A]11>>[A]0-[A]10.[A]1-[A]11", "swap")
assert rId.isomorphism(rSwap) == 0
assert rId.isomorphicLeftRight(rSwap)

Expand Down

0 comments on commit 7eed61f

Please sign in to comment.