Repository navigation
Add vf2pp subgraph isomorphism and monomorphism - #8506
Conversation
Not sure why this is firing - perhaps a mypy regex bug? Either way - the simple thing to do is disable it!
|
Excellent @dschult ! I will try to get at this this week! I went ahead and tweaked the
This is great! The described abstraction seems like an excellent addition to me, especially since it makes more clear exactly which things are being compared and by which checks for sub/mono morphism! It's always nice when abstractions "just work" :)
This is great news - worthwhile cleanup even if the diffs are huge!
Excellent!
This too seems like a good idea - it's much easier to reason about checks being passed than one check and one filter. |
rossbar
left a comment
There was a problem hiding this comment.
Okay - I had a chance to work my way through everything! I left a few minor comments but on the whole this PR represents a very nice improvement, both in terms of new functionality (vf2pp SG isomorphism/monomorphism) as well as clean-up/readability improvements for the isomorphism package as a whole! Thanks @dschult for undertaking this herculean effort!
Update vf2pp code to support subgraph isomorphism and subgraph monomorphism.
Adding subgraph isomorphism required checking
<=instead of==in a number of places. I pass around an operator calledsubgraph_fitswhich is eithereqorledepending on the problem type. The name is because we are testing whether the subgraph fits into the full graph. I was pleasantly surprised to find that very few places needed more complicated logic. And there I just checkedif subgraph_fits == operator.eq.That strategy worked well for monomorphism too. I defined a
mono_fitsoperator (againeqorle). All of thesubgraph_fitschecks have to be the same as for "subgraph iso", and the additional checks that need to change from==to<=callmono_fits. That way the subgraph_fits is used to see if the node counts fit. For ISO, we need all countseq. For IND (induced subgraph iso) we uselefor node counts but edge counts on nodes must still beeq. For MONO we need thelefor node counts and also for edge counts. So the two operators are enough to handle the three problem types.I added a couple of tests, but mostly the tests are
test_common.pywhich covers all 3 problem types by all three algorithms. Thevf2pp_helperstests were a bear though... So I spent the time to clean it up. Reduction of duplications across Graph/DiGraph reduced thousands of lines from thetest_vf2pp_helpers.pyfile. All tests are still there -- most of the Graph and DiGraph class tests were the same except for tweaks to make it DiGraph instead of Graph.The main features still coming are:
Notes/Questions:
FG&SGfor "full graph" and "smaller graph" (or subgraph if you prefer).cutandconsistentbecause one returnsTrueto continue and the other returnsFalse. And its not clear why there are 2 criteria just based on the names. I named themfeasible_node_pairfor the one that looks at the candidate node pair itself, andfeasible_look_aheadfor the one that looks at the neighbors and neighbors neighbors to see if any contradictions arise that would block all future node pairs. They both return True to continue exploring this node pair.Review: There is way too much for one PR here. Sorry about that. Especially when some changes (like G1, G2 -> FG, SG touching almost every line of some tests). I suggest looking at the commits rather than the full diff. The first commit has the changes to the algorithm. The rest are mostly clean-up and renaming, etc.