synkit 1.6.5__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- synkit/CRN/Benchmark/__init__.py +53 -0
- synkit/CRN/Benchmark/crosschecks.py +13 -0
- synkit/CRN/Benchmark/kegg.py +12 -0
- synkit/CRN/Benchmark/networks.py +13 -0
- synkit/CRN/Benchmark/scaling.py +13 -0
- synkit/CRN/Benchmark/validate.py +13 -0
- synkit/CRN/Construct/__init__.py +16 -0
- synkit/CRN/Construct/abstract.py +668 -0
- synkit/CRN/Construct/arity.py +36 -0
- synkit/CRN/Construct/builder.py +619 -0
- synkit/CRN/Construct/derivation.py +63 -0
- synkit/CRN/Construct/flattener.py +100 -0
- synkit/CRN/Construct/keys.py +14 -0
- synkit/CRN/Construct/mixtures.py +117 -0
- synkit/CRN/Construct/rdkit_worker.py +69 -0
- synkit/CRN/Construct/smiles.py +99 -0
- synkit/CRN/Construct/state.py +31 -0
- synkit/CRN/Construct/strategy.py +75 -0
- synkit/CRN/Construct/worker.py +42 -0
- synkit/CRN/IO/__init__.py +36 -0
- synkit/CRN/IO/sbml.py +925 -0
- synkit/CRN/Pathway/__init__.py +72 -0
- synkit/CRN/Pathway/_adapter.py +333 -0
- synkit/CRN/Pathway/pathfinder.py +500 -0
- synkit/CRN/Pathway/reachability.py +796 -0
- synkit/CRN/Pathway/realizability.py +1322 -0
- synkit/CRN/Petrinet/__init__.py +93 -0
- synkit/CRN/Petrinet/analyzer.py +486 -0
- synkit/CRN/Petrinet/minimal_semiflows.py +436 -0
- synkit/CRN/Petrinet/net.py +1041 -0
- synkit/CRN/Petrinet/persistence.py +97 -0
- synkit/CRN/Petrinet/semiflows.py +483 -0
- synkit/CRN/Petrinet/siphon_search.py +402 -0
- synkit/CRN/Petrinet/structure.py +286 -0
- synkit/CRN/Props/__init__.py +130 -0
- synkit/CRN/Props/_rank.py +29 -0
- synkit/CRN/Props/deficiency.py +953 -0
- synkit/CRN/Props/dynamics.py +832 -0
- synkit/CRN/Props/helper.py +151 -0
- synkit/CRN/Props/stoich.py +751 -0
- synkit/CRN/Props/thermo.py +584 -0
- synkit/CRN/Query/__init__.py +66 -0
- synkit/CRN/Query/cache.py +41 -0
- synkit/CRN/Query/kegg_api.py +99 -0
- synkit/CRN/Query/kegg_extract.py +714 -0
- synkit/CRN/Query/kegg_impute.py +707 -0
- synkit/CRN/Query/kegg_parse.py +480 -0
- synkit/CRN/Query/to_syncrn.py +290 -0
- synkit/CRN/README.md +234 -0
- synkit/CRN/Structure/__init__.py +12 -0
- synkit/CRN/Structure/_graph_io.py +713 -0
- synkit/CRN/Structure/_matrices.py +88 -0
- synkit/CRN/Structure/_parse.py +544 -0
- synkit/CRN/Structure/reaction.py +237 -0
- synkit/CRN/Structure/rule.py +55 -0
- synkit/CRN/Structure/species.py +46 -0
- synkit/CRN/Structure/syncrn.py +929 -0
- synkit/CRN/Symmetry/__init__.py +20 -0
- synkit/CRN/Symmetry/_common.py +1059 -0
- synkit/CRN/Symmetry/_ir.py +940 -0
- synkit/CRN/Symmetry/automorphism.py +472 -0
- synkit/CRN/Symmetry/canon.py +441 -0
- synkit/CRN/Symmetry/isomorphism.py +412 -0
- synkit/CRN/Symmetry/symmetry.py +61 -0
- synkit/CRN/Symmetry/wl_canon.py +967 -0
- synkit/CRN/Visualize/__init__.py +11 -0
- synkit/CRN/Visualize/labels.py +113 -0
- synkit/CRN/Visualize/layout.py +708 -0
- synkit/CRN/Visualize/palette.py +292 -0
- synkit/CRN/Visualize/validation.py +122 -0
- synkit/CRN/Visualize/vis.py +1152 -0
- synkit/CRN/__init__.py +233 -0
- synkit/CRN/_build.py +50 -0
- synkit/CRN/_native_build.py +175 -0
- synkit/CRN/analysis.py +629 -0
- synkit/CRN/backend.py +74 -0
- synkit/CRN/cpp/CMakeLists.txt +58 -0
- synkit/CRN/cpp/algebra.cpp +46 -0
- synkit/CRN/cpp/closure.cpp +29 -0
- synkit/CRN/cpp/exact.h +55 -0
- synkit/CRN/cpp/pathway.cpp +46 -0
- synkit/CRN/cpp/semiflows.cpp +209 -0
- synkit/CRN/cpp/structural.cpp +240 -0
- synkit/CRN/cpp/symmetry.cpp +45 -0
- synkit/CRN/cpp/write_manifest.cmake +28 -0
- synkit/CRN/kinds.py +137 -0
- synkit/CRN/lib/synkit_crn.dll +0 -0
- synkit/CRN/lib/synkit_crn.json +33 -0
- synkit/CRN/native.py +388 -0
- synkit/CRN/native_analysis.py +459 -0
- synkit/Chem/Cluster/__init__.py +0 -0
- synkit/Chem/Cluster/butina.py +140 -0
- synkit/Chem/Fingerprint/__init__.py +0 -0
- synkit/Chem/Fingerprint/fp_calculator.py +155 -0
- synkit/Chem/Fingerprint/smiles_featurizer.py +258 -0
- synkit/Chem/Fingerprint/transformation_fp.py +139 -0
- synkit/Chem/Mapper/README.rst +43 -0
- synkit/Chem/Mapper/__init__.py +255 -0
- synkit/Chem/Mapper/_compat.py +130 -0
- synkit/Chem/Mapper/adapters/__init__.py +1 -0
- synkit/Chem/Mapper/adapters/prediction.py +126 -0
- synkit/Chem/Mapper/adapters/template.py +412 -0
- synkit/Chem/Mapper/chem/__init__.py +52 -0
- synkit/Chem/Mapper/chem/aam.py +673 -0
- synkit/Chem/Mapper/chem/blind.py +160 -0
- synkit/Chem/Mapper/chem/its.py +309 -0
- synkit/Chem/Mapper/chem/smiles.py +564 -0
- synkit/Chem/Mapper/graph/__init__.py +66 -0
- synkit/Chem/Mapper/graph/automorphism.py +395 -0
- synkit/Chem/Mapper/graph/blockcut.py +98 -0
- synkit/Chem/Mapper/graph/labeled_graph.py +104 -0
- synkit/Chem/Mapper/graph/refine.py +176 -0
- synkit/Chem/Mapper/graph/synkit_adapter.py +110 -0
- synkit/Chem/Mapper/io/__init__.py +13 -0
- synkit/Chem/Mapper/io/idxmapstr.py +82 -0
- synkit/Chem/Mapper/mapper.py +685 -0
- synkit/Chem/Mapper/reaction_search.py +554 -0
- synkit/Chem/Mapper/reporting/__init__.py +1 -0
- synkit/Chem/Mapper/reporting/alternatives.py +451 -0
- synkit/Chem/Mapper/reporting/analysis.py +681 -0
- synkit/Chem/Mapper/reporting/native_analysis.py +485 -0
- synkit/Chem/Mapper/reporting/spectrum.py +642 -0
- synkit/Chem/Mapper/solvers/__init__.py +1 -0
- synkit/Chem/Mapper/solvers/exact/__init__.py +141 -0
- synkit/Chem/Mapper/solvers/exact/assignment/__init__.py +1 -0
- synkit/Chem/Mapper/solvers/exact/assignment/assignment_certificate.py +113 -0
- synkit/Chem/Mapper/solvers/exact/assignment/assignment_domains.py +162 -0
- synkit/Chem/Mapper/solvers/exact/assignment/assignment_verification.py +58 -0
- synkit/Chem/Mapper/solvers/exact/assignment/incremental_assignment.py +247 -0
- synkit/Chem/Mapper/solvers/exact/certificate.py +128 -0
- synkit/Chem/Mapper/solvers/exact/core.py +183 -0
- synkit/Chem/Mapper/solvers/exact/distance_search/__init__.py +1 -0
- synkit/Chem/Mapper/solvers/exact/distance_search/bounds.py +319 -0
- synkit/Chem/Mapper/solvers/exact/distance_search/exhaustive.py +179 -0
- synkit/Chem/Mapper/solvers/exact/distance_search/inputs.py +283 -0
- synkit/Chem/Mapper/solvers/exact/distance_search/records.py +242 -0
- synkit/Chem/Mapper/solvers/exact/distance_search/search.py +1025 -0
- synkit/Chem/Mapper/solvers/exact/distance_search/verify.py +378 -0
- synkit/Chem/Mapper/solvers/exact/edit_support.py +375 -0
- synkit/Chem/Mapper/solvers/exact/hybrid.py +224 -0
- synkit/Chem/Mapper/solvers/exact/hydrogen.py +264 -0
- synkit/Chem/Mapper/solvers/exact/kernel_solvers/__init__.py +1 -0
- synkit/Chem/Mapper/solvers/exact/kernel_solvers/branching.py +499 -0
- synkit/Chem/Mapper/solvers/exact/kernel_solvers/enumerate.py +1050 -0
- synkit/Chem/Mapper/solvers/exact/kernel_solvers/enumeration_result.py +30 -0
- synkit/Chem/Mapper/solvers/exact/kernel_solvers/kernel.py +256 -0
- synkit/Chem/Mapper/solvers/exact/kernel_solvers/milp.py +194 -0
- synkit/Chem/Mapper/solvers/exact/native/__init__.py +1 -0
- synkit/Chem/Mapper/solvers/exact/native/build.py +154 -0
- synkit/Chem/Mapper/solvers/exact/native/candidates.py +593 -0
- synkit/Chem/Mapper/solvers/exact/native/canonical.py +396 -0
- synkit/Chem/Mapper/solvers/exact/native/disk_frontier.py +415 -0
- synkit/Chem/Mapper/solvers/exact/native/frontier.py +390 -0
- synkit/Chem/Mapper/solvers/exact/native/hydrogen_quotient.py +213 -0
- synkit/Chem/Mapper/solvers/exact/native/its.py +528 -0
- synkit/Chem/Mapper/solvers/exact/native/native_distance.cpp +2803 -0
- synkit/Chem/Mapper/solvers/exact/native/orbit_aggregation.py +328 -0
- synkit/Chem/Mapper/solvers/exact/native/parallel.py +205 -0
- synkit/Chem/Mapper/solvers/exact/native/pmcd.py +203 -0
- synkit/Chem/Mapper/solvers/exact/native/runtime.py +40 -0
- synkit/Chem/Mapper/solvers/exact/native/search.py +294 -0
- synkit/Chem/Mapper/solvers/exact/native/separator.py +224 -0
- synkit/Chem/Mapper/solvers/exact/native_build.py +12 -0
- synkit/Chem/Mapper/solvers/exact/pabs/__init__.py +1 -0
- synkit/Chem/Mapper/solvers/exact/pabs/cost_lattice.py +43 -0
- synkit/Chem/Mapper/solvers/exact/pabs/factor_spectrum.py +110 -0
- synkit/Chem/Mapper/solvers/exact/pabs/multi_shell.py +368 -0
- synkit/Chem/Mapper/solvers/exact/pabs/propagation.py +679 -0
- synkit/Chem/Mapper/solvers/exact/pabs/propagation_bounds.py +436 -0
- synkit/Chem/Mapper/solvers/exact/pabs/propagation_limits.py +13 -0
- synkit/Chem/Mapper/solvers/exact/pabs/propagation_search.py +856 -0
- synkit/Chem/Mapper/solvers/exact/pabs/propagation_symmetry.py +66 -0
- synkit/Chem/Mapper/solvers/exact/pabs/residual_typed_bonds.py +136 -0
- synkit/Chem/Mapper/solvers/exact/pabs/reward_frontier.py +201 -0
- synkit/Chem/Mapper/solvers/exact/pabs/separator_bound.py +258 -0
- synkit/Chem/Mapper/solvers/exact/pabs/separator_spectrum.py +308 -0
- synkit/Chem/Mapper/solvers/exact/pabs/sparse_reward_bound.py +207 -0
- synkit/Chem/Mapper/solvers/exact/pabs/suffix_spectrum.py +299 -0
- synkit/Chem/Mapper/solvers/exact/search.py +55 -0
- synkit/Chem/Mapper/solvers/exact/seeds/__init__.py +1 -0
- synkit/Chem/Mapper/solvers/exact/seeds/seed.py +104 -0
- synkit/Chem/Mapper/solvers/exact/seeds/seed_fragments.py +148 -0
- synkit/Chem/Mapper/solvers/exact/seeds/seed_relaxation.py +181 -0
- synkit/Chem/Mapper/solvers/exact/symmetry.py +223 -0
- synkit/Chem/Mapper/solvers/native/__init__.py +4 -0
- synkit/Chem/Mapper/solvers/native/assignment.py +99 -0
- synkit/Chem/Mapper/solvers/native/astar.py +22 -0
- synkit/Chem/Mapper/solvers/native/build.py +385 -0
- synkit/Chem/Mapper/solvers/native/classification.py +641 -0
- synkit/Chem/Mapper/solvers/native/core.py +378 -0
- synkit/Chem/Mapper/solvers/native/cpp/CMakeLists.txt +120 -0
- synkit/Chem/Mapper/solvers/native/cpp/examples/map_reaction.cpp +29 -0
- synkit/Chem/Mapper/solvers/native/cpp/examples/slap_graph.cpp +63 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/assignment/assignment.h +18 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/astar/astar.h +18 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/astar/bound.h +33 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/core/pmcd_witness.h +16 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/core/runtime.h +130 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/hydrogen/hydrogen.h +73 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/mapper.h +175 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/mces/mces.h +9 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/pabs/seed.h +34 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/reaction/reaction.h +30 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/sepdp/sepdp.h +21 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/slap.h +72 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/solvers/solvers.h +16 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/symmetry/classification.h +140 -0
- synkit/Chem/Mapper/solvers/native/cpp/include/synkit_mapper/symmetry/cpabs.h +33 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/assignment/abb.cpp +302 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/astar/CMakeLists.txt +12 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/astar/README.md +47 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/astar/astar.cpp +228 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/astar/astar_graph.cpp +37 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/astar/bound.cpp +212 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/core/dispatch.cpp +272 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/core/pmcd_witness.cpp +36 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/hydrogen/hydrogen.cpp +380 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/mces/README.md +57 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/mces/mces.cpp +287 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/bridge.cpp +334 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/chemical_floor.inc +181 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/endpoint_symmetry.inc +104 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/exact_helpers.h +20 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/lp_assignment_certificate.h +165 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/lp_certificate.h +125 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/lp_model.h +365 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/lp_provider.inc +319 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/lp_rounding.inc +170 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/lp_test_hooks.h +342 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/objective_reduction.inc +137 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/overlap_dual.inc +351 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/profile_seed.inc +214 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/seed_heuristics.inc +640 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/sparse_embedding.cpp +430 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/sparse_root_lp.h +176 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/pabs/test_hooks.inc +262 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/reaction/reaction.cpp +611 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/sepdp/README.md +61 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/sepdp/sepdp.cpp +253 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/slap.cpp +810 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/solvers/formulation.h +138 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/solvers/maxsat.cpp +526 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/solvers/ortools.cpp +475 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/solvers/seed.h +80 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/solvers/weighted_cnf.h +256 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/supporting/README.md +43 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/supporting/dfs.cpp +123 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/supporting/edit_support.cpp +224 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/classification.cpp +553 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/classification_pipeline.cpp +124 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/classification_stream.h +13 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/cpabs.cpp +455 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/edge_deck.cpp +743 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/COPYRIGHT +44 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/LICENSE-2.0.txt +202 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/naugraph.c +732 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/naurng.c +94 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/naurng.h +49 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/nausparse.c +1771 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/nausparse.h +133 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/nautil.c +750 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/naututil.h +355 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/nauty.c +1256 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/nauty.h +1544 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/schreier.c +1131 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/schreier.h +70 -0
- synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/sorttemplates.c +580 -0
- synkit/Chem/Mapper/solvers/native/hydrogen.py +711 -0
- synkit/Chem/Mapper/solvers/native/implicit.py +506 -0
- synkit/Chem/Mapper/solvers/native/implicit_certificate.py +187 -0
- synkit/Chem/Mapper/solvers/native/implicit_preparation.py +309 -0
- synkit/Chem/Mapper/solvers/native/lib/synkit_mapper.dll +0 -0
- synkit/Chem/Mapper/solvers/native/mces.py +16 -0
- synkit/Chem/Mapper/solvers/native/reaction.py +179 -0
- synkit/Chem/Mapper/solvers/native/reaction_build.py +277 -0
- synkit/Chem/Mapper/solvers/native/reaction_text.py +26 -0
- synkit/Chem/Mapper/solvers/native/runtime.py +242 -0
- synkit/Chem/Mapper/solvers/native/sepdp.py +47 -0
- synkit/Chem/Mapper/solvers/native/slap.py +266 -0
- synkit/Chem/Mapper/solvers/native/solvers.py +67 -0
- synkit/Chem/Mapper/solvers/native/stereo.py +86 -0
- synkit/Chem/Mapper/solvers/native/supporting.py +34 -0
- synkit/Chem/Mapper/solvers/native/symmetry.py +91 -0
- synkit/Chem/Mapper/solvers/slap/__init__.py +29 -0
- synkit/Chem/Mapper/solvers/slap/lap.py +174 -0
- synkit/Chem/Mapper/solvers/slap/sequential.py +696 -0
- synkit/Chem/Mapper/validation/__init__.py +1 -0
- synkit/Chem/Mapper/validation/aam_validator.py +442 -0
- synkit/Chem/Mapper/validation/annotations.py +274 -0
- synkit/Chem/Mapper/validation/bonds.py +124 -0
- synkit/Chem/Mapper/validation/cohorts.py +72 -0
- synkit/Chem/Mapper/validation/identifiability.py +150 -0
- synkit/Chem/Mapper/validation/numerical_scope.py +36 -0
- synkit/Chem/Mapper/validation/orbits.py +137 -0
- synkit/Chem/Molecule/__init__.py +0 -0
- synkit/Chem/Molecule/_chirality_loci.py +165 -0
- synkit/Chem/Molecule/_chirality_types.py +231 -0
- synkit/Chem/Molecule/_helical_loci.py +167 -0
- synkit/Chem/Molecule/_stereo_axis_evidence.py +202 -0
- synkit/Chem/Molecule/_stereo_element_detection.py +193 -0
- synkit/Chem/Molecule/_stereo_orientation_constraints.py +511 -0
- synkit/Chem/Molecule/_tetrahedral_carriers.py +63 -0
- synkit/Chem/Molecule/atom_features.py +379 -0
- synkit/Chem/Molecule/chirality.py +1041 -0
- synkit/Chem/Molecule/cip_assignment.py +569 -0
- synkit/Chem/Molecule/cip_ranking.py +843 -0
- synkit/Chem/Molecule/coordinate_stereo.py +503 -0
- synkit/Chem/Molecule/derived_stereo_naming.py +165 -0
- synkit/Chem/Molecule/descriptors.py +452 -0
- synkit/Chem/Molecule/formula.py +249 -0
- synkit/Chem/Molecule/global_stereo.py +175 -0
- synkit/Chem/Molecule/graph_annotator.py +300 -0
- synkit/Chem/Molecule/standardize.py +817 -0
- synkit/Chem/Molecule/stereo_evidence.py +179 -0
- synkit/Chem/Molecule/stereo_perception.py +1032 -0
- synkit/Chem/Molecule/valence.py +123 -0
- synkit/Chem/Reaction/Mapper/__init__.py +44 -0
- synkit/Chem/Reaction/__init__.py +20 -0
- synkit/Chem/Reaction/aam_validator.py +5 -0
- synkit/Chem/Reaction/balance_check.py +138 -0
- synkit/Chem/Reaction/canon_rsmi.py +249 -0
- synkit/Chem/Reaction/cleaning.py +58 -0
- synkit/Chem/Reaction/deionize.py +199 -0
- synkit/Chem/Reaction/explicit_h_audit.py +232 -0
- synkit/Chem/Reaction/fix_aam.py +64 -0
- synkit/Chem/Reaction/neutralize.py +207 -0
- synkit/Chem/Reaction/radical_wildcard.py +224 -0
- synkit/Chem/Reaction/standardize.py +203 -0
- synkit/Chem/Reaction/tautomerize.py +205 -0
- synkit/Chem/__init__.py +1 -0
- synkit/Chem/utils.py +315 -0
- synkit/Data/__init__.py +0 -0
- synkit/Data/aldol.json.gz +1 -0
- synkit/Data/gen_partial_aam.py +147 -0
- synkit/Data/paracetamol.json.gz +1 -0
- synkit/Graph/Canon/__init__.py +16 -0
- synkit/Graph/Canon/_native/__init__.py +13 -0
- synkit/Graph/Canon/_native/build.py +93 -0
- synkit/Graph/Canon/_native/lib/synkit_canon.dll +0 -0
- synkit/Graph/Canon/_native/prepare.py +49 -0
- synkit/Graph/Canon/_native/runtime.py +140 -0
- synkit/Graph/Canon/_native/search.py +137 -0
- synkit/Graph/Canon/canon_algs.py +228 -0
- synkit/Graph/Canon/canon_graph.py +531 -0
- synkit/Graph/Canon/cpp/CMakeLists.txt +42 -0
- synkit/Graph/Canon/cpp/README.md +123 -0
- synkit/Graph/Canon/cpp/examples/canonical_graph.cpp +16 -0
- synkit/Graph/Canon/cpp/include/synkit_canon/canon.h +85 -0
- synkit/Graph/Canon/cpp/src/canonical.cpp +391 -0
- synkit/Graph/Canon/cpp/src/symmetry.h +83 -0
- synkit/Graph/Canon/cpp/tests/symmetry.cpp +93 -0
- synkit/Graph/Canon/exact.py +1020 -0
- synkit/Graph/Canon/exact_refinement.py +368 -0
- synkit/Graph/Canon/nauty.py +143 -0
- synkit/Graph/Context/__init__.py +0 -0
- synkit/Graph/Context/hier_context.py +244 -0
- synkit/Graph/Context/radius_expand.py +252 -0
- synkit/Graph/FG/__init__.py +19 -0
- synkit/Graph/FG/api.py +39 -0
- synkit/Graph/FG/audit.py +155 -0
- synkit/Graph/FG/catalog.py +919 -0
- synkit/Graph/FG/detector.py +288 -0
- synkit/Graph/FG/model.py +97 -0
- synkit/Graph/FG/recognizers.py +274 -0
- synkit/Graph/FG/ring_system.py +154 -0
- synkit/Graph/Feature/Descriptors/topology.py +857 -0
- synkit/Graph/Feature/Fingerprint/__init__.py +0 -0
- synkit/Graph/Feature/Fingerprint/wl_rxn_fps.py +222 -0
- synkit/Graph/Feature/__init__.py +5 -0
- synkit/Graph/Feature/graph_descriptors.py +323 -0
- synkit/Graph/Feature/graph_fps.py +96 -0
- synkit/Graph/Feature/graph_signature.py +239 -0
- synkit/Graph/Feature/hash_fps.py +133 -0
- synkit/Graph/Feature/morgan_fps.py +88 -0
- synkit/Graph/Feature/path_fps.py +81 -0
- synkit/Graph/Feature/wl_hash.py +134 -0
- synkit/Graph/Fusion/__init__.py +85 -0
- synkit/Graph/Fusion/candidate.py +559 -0
- synkit/Graph/Fusion/constructor.py +877 -0
- synkit/Graph/Fusion/identity.py +184 -0
- synkit/Graph/Fusion/interface.py +700 -0
- synkit/Graph/Fusion/search.py +241 -0
- synkit/Graph/Hyrogen/__init__.py +6 -0
- synkit/Graph/Hyrogen/_misc.py +591 -0
- synkit/Graph/Hyrogen/hcomplete.py +995 -0
- synkit/Graph/Hyrogen/hcomplete_legacy.py +368 -0
- synkit/Graph/Hyrogen/hcompletion_algorithms.py +713 -0
- synkit/Graph/Hyrogen/hextend.py +570 -0
- synkit/Graph/Hyrogen/hextend_legacy.py +215 -0
- synkit/Graph/ITS/__init__.py +4 -0
- synkit/Graph/ITS/its_builder.py +120 -0
- synkit/Graph/ITS/its_construction.py +719 -0
- synkit/Graph/ITS/its_decompose.py +572 -0
- synkit/Graph/ITS/its_destruction.py +331 -0
- synkit/Graph/ITS/its_expand.py +1251 -0
- synkit/Graph/ITS/its_relabel.py +187 -0
- synkit/Graph/ITS/its_reverter.py +356 -0
- synkit/Graph/ITS/normalize_aam.py +145 -0
- synkit/Graph/ITS/partial_its.py +238 -0
- synkit/Graph/ITS/rc_extractor.py +656 -0
- synkit/Graph/ITS/stereo.py +74 -0
- synkit/Graph/MTG/__init__.py +107 -0
- synkit/Graph/MTG/gluing.py +451 -0
- synkit/Graph/MTG/history.py +928 -0
- synkit/Graph/MTG/inventory.py +118 -0
- synkit/Graph/MTG/local.py +447 -0
- synkit/Graph/MTG/mcs_matcher.py +246 -0
- synkit/Graph/MTG/mtg.py +611 -0
- synkit/Graph/MTG/mtg_explore.py +74 -0
- synkit/Graph/MTG/observation.py +209 -0
- synkit/Graph/MTG/process.py +577 -0
- synkit/Graph/MTG/queries.py +66 -0
- synkit/Graph/MTG/realization.py +95 -0
- synkit/Graph/MTG/series_parallel.py +107 -0
- synkit/Graph/MTG/utils.py +424 -0
- synkit/Graph/Matcher/__init__.py +10 -0
- synkit/Graph/Matcher/approx_mcs.py +1264 -0
- synkit/Graph/Matcher/auto_est.py +736 -0
- synkit/Graph/Matcher/automorphism.py +314 -0
- synkit/Graph/Matcher/batch_cluster.py +224 -0
- synkit/Graph/Matcher/dedup_matches.py +247 -0
- synkit/Graph/Matcher/graph_cluster.py +191 -0
- synkit/Graph/Matcher/graph_matcher.py +312 -0
- synkit/Graph/Matcher/graph_morphism.py +421 -0
- synkit/Graph/Matcher/mcs_matcher.py +804 -0
- synkit/Graph/Matcher/multi_turbo_iso.py +186 -0
- synkit/Graph/Matcher/orbit.py +284 -0
- synkit/Graph/Matcher/partial_matcher.py +694 -0
- synkit/Graph/Matcher/sing.py +544 -0
- synkit/Graph/Matcher/subgraph_matcher.py +812 -0
- synkit/Graph/Matcher/turbo_iso.py +272 -0
- synkit/Graph/Matcher/wl_sel.py +537 -0
- synkit/Graph/Mech/__init__.py +26 -0
- synkit/Graph/Mech/conversion.py +1466 -0
- synkit/Graph/Mech/conversion_debug.py +237 -0
- synkit/Graph/Mech/electron_accounting.py +200 -0
- synkit/Graph/Mech/lwg_editor.py +406 -0
- synkit/Graph/Mech/lwg_ops.py +313 -0
- synkit/Graph/Morphism/__init__.py +99 -0
- synkit/Graph/Morphism/constraints.py +460 -0
- synkit/Graph/Morphism/llg.py +999 -0
- synkit/Graph/Morphism/morphism.py +349 -0
- synkit/Graph/Morphism/stereo.py +258 -0
- synkit/Graph/Morphism/stereo_morphism.py +383 -0
- synkit/Graph/Morphism/stereo_morphism_helpers.py +957 -0
- synkit/Graph/Morphism/stereo_morphism_types.py +117 -0
- synkit/Graph/Stereo/__init__.py +376 -0
- synkit/Graph/Stereo/_descriptor_core.py +207 -0
- synkit/Graph/Stereo/_descriptor_serialization.py +138 -0
- synkit/Graph/Stereo/canonical.py +648 -0
- synkit/Graph/Stereo/changes.py +964 -0
- synkit/Graph/Stereo/composition.py +391 -0
- synkit/Graph/Stereo/configured.py +946 -0
- synkit/Graph/Stereo/couplings.py +245 -0
- synkit/Graph/Stereo/descriptors.py +1030 -0
- synkit/Graph/Stereo/enumeration.py +597 -0
- synkit/Graph/Stereo/extended_descriptors.py +406 -0
- synkit/Graph/Stereo/global_configured.py +152 -0
- synkit/Graph/Stereo/global_stereo.py +304 -0
- synkit/Graph/Stereo/identity.py +648 -0
- synkit/Graph/Stereo/interchange.py +496 -0
- synkit/Graph/Stereo/legacy.py +460 -0
- synkit/Graph/Stereo/matching.py +899 -0
- synkit/Graph/Stereo/native.py +154 -0
- synkit/Graph/Stereo/orbits.py +668 -0
- synkit/Graph/Stereo/outcomes.py +99 -0
- synkit/Graph/Stereo/pairwise.py +350 -0
- synkit/Graph/Stereo/rdkit_adapter.py +662 -0
- synkit/Graph/Stereo/rdkit_identity.py +118 -0
- synkit/Graph/Stereo/rdkit_resonance.py +140 -0
- synkit/Graph/Stereo/reaction_interchange.py +266 -0
- synkit/Graph/Stereo/semantics.py +296 -0
- synkit/Graph/Stereo/supports.py +257 -0
- synkit/Graph/Stereo/wire.py +339 -0
- synkit/Graph/Wildcard/__init__.py +0 -0
- synkit/Graph/Wildcard/fuse_graph.py +156 -0
- synkit/Graph/Wildcard/graph_wc.py +303 -0
- synkit/Graph/Wildcard/its_merge.py +857 -0
- synkit/Graph/Wildcard/radwc.py +114 -0
- synkit/Graph/Wildcard/wc_matcher.py +576 -0
- synkit/Graph/Wildcard/wildcard.py +225 -0
- synkit/Graph/__init__.py +17 -0
- synkit/Graph/canon_graph.py +14 -0
- synkit/Graph/syn_graph.py +199 -0
- synkit/Graph/utils.py +324 -0
- synkit/IO/__init__.py +4 -0
- synkit/IO/chem_converter.py +1059 -0
- synkit/IO/combinatorial/__init__.py +8 -0
- synkit/IO/combinatorial/gml_to_graph.py +223 -0
- synkit/IO/combinatorial/graph_to_gml.py +280 -0
- synkit/IO/combinatorial/graph_to_smarts.py +186 -0
- synkit/IO/combinatorial/smarts_expander.py +147 -0
- synkit/IO/combinatorial/smarts_generalizer.py +133 -0
- synkit/IO/combinatorial/smarts_to_graph.py +179 -0
- synkit/IO/conversion.py +42 -0
- synkit/IO/data_io.py +269 -0
- synkit/IO/data_process.py +143 -0
- synkit/IO/debug.py +73 -0
- synkit/IO/gml_to_nx.py +150 -0
- synkit/IO/graph_to_mol.py +199 -0
- synkit/IO/mol_to_graph.py +1105 -0
- synkit/IO/mol_to_graph_chemistry.py +545 -0
- synkit/IO/nx_to_gml.py +209 -0
- synkit/IO/smiles_to_id.py +123 -0
- synkit/Mechanism/__init__.py +151 -0
- synkit/Mechanism/adapters.py +136 -0
- synkit/Mechanism/audit.py +323 -0
- synkit/Mechanism/benchmark.py +638 -0
- synkit/Mechanism/compatibility.py +13 -0
- synkit/Mechanism/drawing.py +85 -0
- synkit/Mechanism/electron_models.py +725 -0
- synkit/Mechanism/equivalence.py +521 -0
- synkit/Mechanism/evidence.py +262 -0
- synkit/Mechanism/interchange.py +141 -0
- synkit/Mechanism/model.py +918 -0
- synkit/Mechanism/neighbor_stereo.py +312 -0
- synkit/Mechanism/radical_data.py +740 -0
- synkit/Mechanism/replay.py +986 -0
- synkit/Mechanism/schema.py +264 -0
- synkit/Mechanism/stereo_state.py +416 -0
- synkit/Mechanism/symbols.py +91 -0
- synkit/Rule/Apply/__init__.py +35 -0
- synkit/Rule/Apply/conditions.py +45 -0
- synkit/Rule/Apply/dpo.py +998 -0
- synkit/Rule/Apply/rule_matcher.py +218 -0
- synkit/Rule/Apply/validation.py +354 -0
- synkit/Rule/Compose/__init__.py +106 -0
- synkit/Rule/Compose/_identity.py +43 -0
- synkit/Rule/Compose/composition.py +976 -0
- synkit/Rule/Compose/laws.py +439 -0
- synkit/Rule/Compose/search.py +771 -0
- synkit/Rule/Compose/synrule.py +170 -0
- synkit/Rule/Modify/__init__.py +0 -0
- synkit/Rule/Modify/implict_rule.py +56 -0
- synkit/Rule/Modify/longest_path.py +92 -0
- synkit/Rule/Modify/molecule_rule.py +115 -0
- synkit/Rule/Modify/prune_templates.py +78 -0
- synkit/Rule/Modify/rule_utils.py +194 -0
- synkit/Rule/Modify/strip_rule.py +97 -0
- synkit/Rule/__init__.py +28 -0
- synkit/Rule/generic_stereo.py +884 -0
- synkit/Rule/stereo_identity.py +271 -0
- synkit/Rule/syn_rule.py +1090 -0
- synkit/Synthesis/MSR/__init__.py +0 -0
- synkit/Synthesis/MSR/path_finder.py +239 -0
- synkit/Synthesis/Metrics/__init__.py +0 -0
- synkit/Synthesis/Metrics/_base.py +52 -0
- synkit/Synthesis/Metrics/_plot.py +129 -0
- synkit/Synthesis/Metrics/_ranking.py +179 -0
- synkit/Synthesis/RBL/__init__.py +80 -0
- synkit/Synthesis/RBL/engine.py +1249 -0
- synkit/Synthesis/RBL/matching.py +652 -0
- synkit/Synthesis/RBL/overlap.py +336 -0
- synkit/Synthesis/RBL/pipeline.py +376 -0
- synkit/Synthesis/RBL/policy.py +139 -0
- synkit/Synthesis/RBL/proof.py +370 -0
- synkit/Synthesis/RBL/reaction.py +506 -0
- synkit/Synthesis/RBL/state.py +169 -0
- synkit/Synthesis/RBL/validation.py +1060 -0
- synkit/Synthesis/Reactor/__init__.py +60 -0
- synkit/Synthesis/Reactor/core/__init__.py +1 -0
- synkit/Synthesis/Reactor/core/engine.py +967 -0
- synkit/Synthesis/Reactor/core/product.py +621 -0
- synkit/Synthesis/Reactor/core/rewrite.py +561 -0
- synkit/Synthesis/Reactor/core/strategy.py +44 -0
- synkit/Synthesis/Reactor/matching/__init__.py +1 -0
- synkit/Synthesis/Reactor/matching/mixin.py +920 -0
- synkit/Synthesis/Reactor/matching/policy.py +345 -0
- synkit/Synthesis/Reactor/matching/symmetry.py +309 -0
- synkit/Synthesis/Reactor/output/__init__.py +1 -0
- synkit/Synthesis/Reactor/output/deduplication.py +703 -0
- synkit/Synthesis/Reactor/output/policy.py +16 -0
- synkit/Synthesis/Reactor/output/serialization.py +485 -0
- synkit/Synthesis/Reactor/output/structural.py +893 -0
- synkit/Synthesis/Reactor/stereo/__init__.py +1 -0
- synkit/Synthesis/Reactor/stereo/assignment.py +35 -0
- synkit/Synthesis/Reactor/stereo/mixin.py +780 -0
- synkit/Synthesis/Reactor/variants/__init__.py +1 -0
- synkit/Synthesis/Reactor/variants/imbalanced.py +180 -0
- synkit/Synthesis/Reactor/variants/partial.py +84 -0
- synkit/Synthesis/Reactor/workflow/__init__.py +1 -0
- synkit/Synthesis/Reactor/workflow/batch.py +550 -0
- synkit/Synthesis/Reactor/workflow/benchmark.py +143 -0
- synkit/Synthesis/Reactor/workflow/postprocess.py +267 -0
- synkit/Synthesis/Reactor/workflow/rule_filter.py +210 -0
- synkit/Synthesis/__init__.py +0 -0
- synkit/Synthesis/reactor_utils.py +316 -0
- synkit/Utils/__init__.py +0 -0
- synkit/Utils/utils.py +172 -0
- synkit/Vis/__init__.py +91 -0
- synkit/Vis/crn/__init__.py +40 -0
- synkit/Vis/epd/__init__.py +20 -0
- synkit/Vis/epd/arrows.py +425 -0
- synkit/Vis/epd/chem.py +197 -0
- synkit/Vis/epd/constants.py +83 -0
- synkit/Vis/epd/layout.py +283 -0
- synkit/Vis/epd/mapping.py +51 -0
- synkit/Vis/epd/models.py +136 -0
- synkit/Vis/epd/render.py +543 -0
- synkit/Vis/epd/utils.py +108 -0
- synkit/Vis/epd/visualizer.py +811 -0
- synkit/Vis/graph_visualizer.py +375 -0
- synkit/Vis/its/__init__.py +19 -0
- synkit/Vis/its/drawer.py +615 -0
- synkit/Vis/its_drawer.py +35 -0
- synkit/Vis/molecule/__init__.py +31 -0
- synkit/Vis/molecule/drawer.py +563 -0
- synkit/Vis/molecule/reaction.py +285 -0
- synkit/Vis/molecule_drawer.py +33 -0
- synkit/Vis/mtg/__init__.py +17 -0
- synkit/Vis/mtg/drawer.py +769 -0
- synkit/Vis/mtg_drawer.py +34 -0
- synkit/Vis/pdf_writer.py +146 -0
- synkit/Vis/reaction/__init__.py +19 -0
- synkit/Vis/reaction/rule.py +141 -0
- synkit/Vis/reaction/rxn.py +532 -0
- synkit/Vis/reaction_drawer.py +41 -0
- synkit/Vis/space/__init__.py +17 -0
- synkit/Vis/space/chemical.py +80 -0
- synkit/Vis/space/embedding.py +87 -0
- synkit/Vis/vis_synedu/Vis/__init__.py +7 -0
- synkit/Vis/vis_synedu/Vis/dpo.py +862 -0
- synkit/Vis/vis_synedu/rxn_vis.py +377 -0
- synkit/Vis/vis_synedu/vis.py +501 -0
- synkit/Vis/visual_drawer.py +215 -0
- synkit/Vis/visual_model.py +520 -0
- synkit/__init__.py +3 -0
- synkit/_native.py +91 -0
- synkit/examples.py +50 -0
- synkit/version.py +23 -0
- synkit-1.6.5.dist-info/METADATA +156 -0
- synkit-1.6.5.dist-info/RECORD +636 -0
- synkit-1.6.5.dist-info/WHEEL +4 -0
- synkit-1.6.5.dist-info/licenses/LICENSE +21 -0
- synkit-1.6.5.dist-info/licenses/synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/COPYRIGHT +44 -0
- synkit-1.6.5.dist-info/licenses/synkit/Chem/Mapper/solvers/native/cpp/src/symmetry/vendor/nauty/LICENSE-2.0.txt +202 -0
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
#include "synkit_mapper/slap.h"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <chrono>
|
|
5
|
+
#include <cmath>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <iterator>
|
|
8
|
+
#include <limits>
|
|
9
|
+
#include <map>
|
|
10
|
+
#include <memory>
|
|
11
|
+
#include <numeric>
|
|
12
|
+
#include <set>
|
|
13
|
+
#include <stdexcept>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <utility>
|
|
16
|
+
#include <vector>
|
|
17
|
+
|
|
18
|
+
namespace {
|
|
19
|
+
|
|
20
|
+
using Clock = std::chrono::steady_clock;
|
|
21
|
+
using Label = int64_t;
|
|
22
|
+
using Signature = std::vector<int64_t>;
|
|
23
|
+
constexpr int64_t INF = std::numeric_limits<int64_t>::max() / 8;
|
|
24
|
+
thread_local std::string last_error;
|
|
25
|
+
|
|
26
|
+
struct Stop {
|
|
27
|
+
int reason;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class Budget {
|
|
31
|
+
public:
|
|
32
|
+
Budget(Clock::time_point start, double seconds)
|
|
33
|
+
: start_(start), seconds_(seconds) {}
|
|
34
|
+
bool expired() const { return seconds_ >= 0 && elapsed() >= seconds_; }
|
|
35
|
+
double elapsed() const {
|
|
36
|
+
return std::chrono::duration<double>(Clock::now() - start_).count();
|
|
37
|
+
}
|
|
38
|
+
void check() const {
|
|
39
|
+
if (expired())
|
|
40
|
+
throw Stop{1};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private:
|
|
44
|
+
Clock::time_point start_;
|
|
45
|
+
double seconds_;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
struct Block {
|
|
49
|
+
Label label;
|
|
50
|
+
std::vector<int> atoms;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
struct Side {
|
|
54
|
+
std::vector<Label> labels;
|
|
55
|
+
// Insertion order matters to the sequential heuristic and is kept explicit.
|
|
56
|
+
std::vector<Block> blocks;
|
|
57
|
+
std::shared_ptr<const std::vector<Label>> initial_wl;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
using Neighbors = std::map<Label, std::vector<int64_t>>;
|
|
61
|
+
struct NeighborhoodClass {
|
|
62
|
+
Label token;
|
|
63
|
+
std::vector<int> atoms;
|
|
64
|
+
Neighbors neighbors;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
struct Solution {
|
|
68
|
+
int64_t value;
|
|
69
|
+
std::vector<int> fingerprint;
|
|
70
|
+
std::vector<int> groups_r, groups_p;
|
|
71
|
+
bool proper = true;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
struct BlockData {
|
|
75
|
+
std::vector<NeighborhoodClass> classes_r, classes_p;
|
|
76
|
+
std::vector<Solution> solutions;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
struct State {
|
|
80
|
+
Side r, p;
|
|
81
|
+
std::map<Label, std::shared_ptr<const BlockData>> irreducible;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
struct Record {
|
|
85
|
+
State state;
|
|
86
|
+
int64_t value;
|
|
87
|
+
std::map<Label, std::shared_ptr<const BlockData>> lap_solutions;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
class Slap {
|
|
91
|
+
public:
|
|
92
|
+
Slap(int n, const int64_t *a, const int64_t *b, const int32_t *lr,
|
|
93
|
+
const int32_t *lp, const int32_t *stop, int fingerprints, int64_t states,
|
|
94
|
+
int64_t mappings, Budget &budget, SlapStatistics &statistics)
|
|
95
|
+
: n_(n), a_(a), b_(b), original_r_(lr, lr + n), original_p_(lp, lp + n),
|
|
96
|
+
stop_(stop, stop + n), fingerprint_cap_(fingerprints),
|
|
97
|
+
state_cap_(states), mapping_cap_(mappings), budget_(budget),
|
|
98
|
+
stats_(statistics) {
|
|
99
|
+
std::map<int32_t, Label> initial;
|
|
100
|
+
auto labels = [&](const int32_t *source) {
|
|
101
|
+
std::vector<Label> values;
|
|
102
|
+
for (int i = 0; i < n_; ++i) {
|
|
103
|
+
auto found = initial.find(source[i]);
|
|
104
|
+
if (found == initial.end())
|
|
105
|
+
found = initial.emplace(source[i], fresh()).first;
|
|
106
|
+
values.push_back(found->second);
|
|
107
|
+
}
|
|
108
|
+
return values;
|
|
109
|
+
};
|
|
110
|
+
initial_.r = side(labels(lr));
|
|
111
|
+
initial_.p = side(labels(lp));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
void run() {
|
|
115
|
+
std::vector<State> pending;
|
|
116
|
+
pending.push_back(initial_);
|
|
117
|
+
while (!pending.empty()) {
|
|
118
|
+
budget_.check();
|
|
119
|
+
std::vector<State> stack = std::move(pending);
|
|
120
|
+
pending.clear();
|
|
121
|
+
std::vector<Record> results;
|
|
122
|
+
int64_t phase_minimum = INF;
|
|
123
|
+
while (!stack.empty()) {
|
|
124
|
+
budget_.check();
|
|
125
|
+
if (state_cap_ >= 0 && stats_.states >= state_cap_)
|
|
126
|
+
throw Stop{2};
|
|
127
|
+
State current = std::move(stack.back());
|
|
128
|
+
stack.pop_back();
|
|
129
|
+
++stats_.states;
|
|
130
|
+
solve_path(std::move(current), stack, results, phase_minimum);
|
|
131
|
+
}
|
|
132
|
+
// The sequential heuristic deliberately retains only the best proxy
|
|
133
|
+
// partition states reached in this round, matching the Python structure.
|
|
134
|
+
results.erase(std::remove_if(results.begin(), results.end(),
|
|
135
|
+
[&](const Record &r) {
|
|
136
|
+
return r.value != phase_minimum;
|
|
137
|
+
}),
|
|
138
|
+
results.end());
|
|
139
|
+
while (!results.empty()) {
|
|
140
|
+
budget_.check();
|
|
141
|
+
Record record = std::move(results.back());
|
|
142
|
+
results.pop_back();
|
|
143
|
+
const auto order = ordered_labels(record.state.r);
|
|
144
|
+
Label label = -1;
|
|
145
|
+
for (auto it = order.rbegin(); it != order.rend(); ++it) {
|
|
146
|
+
if (block(record.state.r, *it).atoms.size() > 1) {
|
|
147
|
+
label = *it;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (label < 0) {
|
|
152
|
+
remember(record);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
split(record, label, pending);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (completed_.empty())
|
|
159
|
+
throw std::runtime_error("SLAP produced no full bijection");
|
|
160
|
+
stats_.completed = 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
void emit(SlapMappingCallback callback, void *userdata) {
|
|
164
|
+
for (const auto &entry : completed_) {
|
|
165
|
+
if (budget_.expired()) {
|
|
166
|
+
stats_.completed = 0;
|
|
167
|
+
if (!stats_.reason)
|
|
168
|
+
stats_.reason = 1;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
const auto started = Clock::now();
|
|
172
|
+
int stop =
|
|
173
|
+
callback ? callback(entry.first.data(), entry.second, userdata) : 0;
|
|
174
|
+
stats_.callback_seconds +=
|
|
175
|
+
std::chrono::duration<double>(Clock::now() - started).count();
|
|
176
|
+
++stats_.candidates;
|
|
177
|
+
if (stop) {
|
|
178
|
+
stats_.completed = 0;
|
|
179
|
+
stats_.reason = 4;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private:
|
|
186
|
+
int n_;
|
|
187
|
+
const int64_t *a_, *b_;
|
|
188
|
+
std::vector<int32_t> original_r_, original_p_, stop_;
|
|
189
|
+
int fingerprint_cap_;
|
|
190
|
+
int64_t state_cap_, mapping_cap_;
|
|
191
|
+
Budget &budget_;
|
|
192
|
+
SlapStatistics &stats_;
|
|
193
|
+
Label next_label_ = 0;
|
|
194
|
+
std::map<Signature, Label> interned_;
|
|
195
|
+
State initial_;
|
|
196
|
+
std::set<std::vector<int>> visited_;
|
|
197
|
+
std::map<std::vector<int32_t>, int64_t> completed_;
|
|
198
|
+
|
|
199
|
+
Label fresh() { return next_label_++; }
|
|
200
|
+
|
|
201
|
+
Label intern(Signature signature) {
|
|
202
|
+
const auto found = interned_.find(signature);
|
|
203
|
+
if (found != interned_.end())
|
|
204
|
+
return found->second;
|
|
205
|
+
const Label label = fresh();
|
|
206
|
+
interned_.emplace(std::move(signature), label);
|
|
207
|
+
return label;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static Side side(std::vector<Label> labels) {
|
|
211
|
+
Side result;
|
|
212
|
+
result.labels = std::move(labels);
|
|
213
|
+
std::map<Label, size_t> positions;
|
|
214
|
+
for (size_t i = 0; i < result.labels.size(); ++i) {
|
|
215
|
+
const Label label = result.labels[i];
|
|
216
|
+
auto found = positions.find(label);
|
|
217
|
+
if (found == positions.end()) {
|
|
218
|
+
positions.emplace(label, result.blocks.size());
|
|
219
|
+
result.blocks.push_back({label, {static_cast<int>(i)}});
|
|
220
|
+
} else {
|
|
221
|
+
result.blocks[found->second].atoms.push_back(static_cast<int>(i));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static const Block &block(const Side &value, Label label) {
|
|
228
|
+
const auto found =
|
|
229
|
+
std::find_if(value.blocks.begin(), value.blocks.end(),
|
|
230
|
+
[&](const Block &b) { return b.label == label; });
|
|
231
|
+
if (found == value.blocks.end())
|
|
232
|
+
throw std::runtime_error("Unknown SLAP label block");
|
|
233
|
+
return *found;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
static std::vector<Label> ordered_labels(const Side &value) {
|
|
237
|
+
auto blocks = value.blocks;
|
|
238
|
+
std::stable_sort(blocks.begin(), blocks.end(),
|
|
239
|
+
[](const Block &x, const Block &y) {
|
|
240
|
+
return x.atoms.size() > y.atoms.size();
|
|
241
|
+
});
|
|
242
|
+
std::vector<Label> result;
|
|
243
|
+
for (const auto &b : blocks)
|
|
244
|
+
result.push_back(b.label);
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static std::vector<int> state_key(const State &state) {
|
|
249
|
+
std::map<Label, int> colors;
|
|
250
|
+
std::vector<int> result;
|
|
251
|
+
for (const Side *value : {&state.r, &state.p}) {
|
|
252
|
+
for (Label label : value->labels) {
|
|
253
|
+
auto found = colors.find(label);
|
|
254
|
+
if (found == colors.end())
|
|
255
|
+
found = colors.emplace(label, static_cast<int>(colors.size())).first;
|
|
256
|
+
result.push_back(found->second);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
std::vector<NeighborhoodClass> classes(const Side &value, Label label,
|
|
263
|
+
const int64_t *matrix) {
|
|
264
|
+
std::vector<NeighborhoodClass> result;
|
|
265
|
+
std::map<Label, size_t> positions;
|
|
266
|
+
for (int atom : block(value, label).atoms) {
|
|
267
|
+
budget_.check();
|
|
268
|
+
Neighbors neighbors;
|
|
269
|
+
for (int j = 0; j < n_; ++j)
|
|
270
|
+
if (matrix[atom * n_ + j])
|
|
271
|
+
neighbors[value.labels[j]].push_back(matrix[atom * n_ + j]);
|
|
272
|
+
Signature signature{label, static_cast<int64_t>(neighbors.size())};
|
|
273
|
+
for (auto &entry : neighbors) {
|
|
274
|
+
std::sort(entry.second.begin(), entry.second.end(),
|
|
275
|
+
std::greater<int64_t>());
|
|
276
|
+
signature.push_back(entry.first);
|
|
277
|
+
signature.push_back(static_cast<int64_t>(entry.second.size()));
|
|
278
|
+
signature.insert(signature.end(), entry.second.begin(),
|
|
279
|
+
entry.second.end());
|
|
280
|
+
}
|
|
281
|
+
const Label token = intern(std::move(signature));
|
|
282
|
+
const auto found = positions.find(token);
|
|
283
|
+
if (found == positions.end()) {
|
|
284
|
+
positions.emplace(token, result.size());
|
|
285
|
+
result.push_back({token, {atom}, std::move(neighbors)});
|
|
286
|
+
} else {
|
|
287
|
+
result[found->second].atoms.push_back(atom);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
static int64_t weight_cost(const std::vector<int64_t> &a,
|
|
294
|
+
const std::vector<int64_t> &b) {
|
|
295
|
+
int64_t cost = 0;
|
|
296
|
+
const size_t common = std::min(a.size(), b.size());
|
|
297
|
+
for (size_t i = 0; i < common; ++i)
|
|
298
|
+
cost += std::abs(a[i] - b[i]);
|
|
299
|
+
for (size_t i = common; i < a.size(); ++i)
|
|
300
|
+
cost += a[i];
|
|
301
|
+
for (size_t i = common; i < b.size(); ++i)
|
|
302
|
+
cost += b[i];
|
|
303
|
+
return cost;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
static int64_t neighborhood_cost(const Neighbors &a, const Neighbors &b) {
|
|
307
|
+
static const std::vector<int64_t> empty;
|
|
308
|
+
int64_t cost = 0;
|
|
309
|
+
for (const auto &entry : a) {
|
|
310
|
+
const auto found = b.find(entry.first);
|
|
311
|
+
cost +=
|
|
312
|
+
weight_cost(entry.second, found == b.end() ? empty : found->second);
|
|
313
|
+
}
|
|
314
|
+
for (const auto &entry : b)
|
|
315
|
+
if (a.find(entry.first) == a.end())
|
|
316
|
+
cost += weight_cost(empty, entry.second);
|
|
317
|
+
return cost;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
std::vector<int> lap(const std::vector<int64_t> &cost, int n) {
|
|
321
|
+
budget_.check();
|
|
322
|
+
++stats_.lap_calls;
|
|
323
|
+
std::vector<int64_t> u(n + 1), v(n + 1);
|
|
324
|
+
std::vector<int> p(n + 1), way(n + 1);
|
|
325
|
+
for (int i = 1; i <= n; ++i) {
|
|
326
|
+
budget_.check();
|
|
327
|
+
p[0] = i;
|
|
328
|
+
int j0 = 0;
|
|
329
|
+
std::vector<int64_t> minimum(n + 1, INF);
|
|
330
|
+
std::vector<bool> used(n + 1, false);
|
|
331
|
+
do {
|
|
332
|
+
budget_.check();
|
|
333
|
+
used[j0] = true;
|
|
334
|
+
const int i0 = p[j0];
|
|
335
|
+
int64_t delta = INF;
|
|
336
|
+
int j1 = 0;
|
|
337
|
+
for (int j = 1; j <= n; ++j) {
|
|
338
|
+
if (used[j])
|
|
339
|
+
continue;
|
|
340
|
+
const int64_t current = cost[(i0 - 1) * n + j - 1] - u[i0] - v[j];
|
|
341
|
+
if (current < minimum[j]) {
|
|
342
|
+
minimum[j] = current;
|
|
343
|
+
way[j] = j0;
|
|
344
|
+
}
|
|
345
|
+
if (minimum[j] < delta) {
|
|
346
|
+
delta = minimum[j];
|
|
347
|
+
j1 = j;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (j1 == 0)
|
|
351
|
+
throw std::runtime_error("Infeasible internal LAP");
|
|
352
|
+
for (int j = 0; j <= n; ++j) {
|
|
353
|
+
if (used[j]) {
|
|
354
|
+
u[p[j]] += delta;
|
|
355
|
+
v[j] -= delta;
|
|
356
|
+
} else
|
|
357
|
+
minimum[j] -= delta;
|
|
358
|
+
}
|
|
359
|
+
j0 = j1;
|
|
360
|
+
} while (p[j0] != 0);
|
|
361
|
+
do {
|
|
362
|
+
const int previous = way[j0];
|
|
363
|
+
p[j0] = p[previous];
|
|
364
|
+
j0 = previous;
|
|
365
|
+
} while (j0);
|
|
366
|
+
}
|
|
367
|
+
std::vector<int> assignment(n);
|
|
368
|
+
for (int j = 1; j <= n; ++j)
|
|
369
|
+
assignment[p[j] - 1] = j - 1;
|
|
370
|
+
return assignment;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
static std::pair<std::vector<int>, std::vector<int>>
|
|
374
|
+
components(const std::vector<int> &fingerprint, int nr, int np) {
|
|
375
|
+
std::vector<int> left(nr, -1), right(np, -1);
|
|
376
|
+
int group = 0;
|
|
377
|
+
for (int start = 0; start < nr; ++start) {
|
|
378
|
+
if (left[start] >= 0)
|
|
379
|
+
continue;
|
|
380
|
+
std::vector<int> pending{start};
|
|
381
|
+
left[start] = group;
|
|
382
|
+
while (!pending.empty()) {
|
|
383
|
+
const int i = pending.back();
|
|
384
|
+
pending.pop_back();
|
|
385
|
+
for (int j = 0; j < np; ++j) {
|
|
386
|
+
if (!fingerprint[i * np + j] || right[j] >= 0)
|
|
387
|
+
continue;
|
|
388
|
+
right[j] = group;
|
|
389
|
+
for (int k = 0; k < nr; ++k)
|
|
390
|
+
if (fingerprint[k * np + j] && left[k] < 0) {
|
|
391
|
+
left[k] = group;
|
|
392
|
+
pending.push_back(k);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
++group;
|
|
397
|
+
}
|
|
398
|
+
for (int &value : right)
|
|
399
|
+
if (value < 0)
|
|
400
|
+
value = group++;
|
|
401
|
+
return {left, right};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
static bool one_group(const std::vector<int> &groups) {
|
|
405
|
+
return std::all_of(groups.begin(), groups.end(),
|
|
406
|
+
[&](int group) { return group == groups.front(); });
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
static void mark_proper(std::vector<Solution> &solutions) {
|
|
410
|
+
for (size_t i = 0; i < solutions.size(); ++i) {
|
|
411
|
+
for (size_t j = 0; j < solutions.size(); ++j) {
|
|
412
|
+
if (i == j || !solutions[j].proper)
|
|
413
|
+
continue;
|
|
414
|
+
std::map<int, std::set<int>> image;
|
|
415
|
+
for (size_t k = 0; k < solutions[i].groups_r.size(); ++k)
|
|
416
|
+
image[solutions[i].groups_r[k]].insert(solutions[j].groups_r[k]);
|
|
417
|
+
for (size_t k = 0; k < solutions[i].groups_p.size(); ++k)
|
|
418
|
+
image[solutions[i].groups_p[k]].insert(solutions[j].groups_p[k]);
|
|
419
|
+
if (std::all_of(image.begin(), image.end(), [](const auto &entry) {
|
|
420
|
+
return entry.second.size() == 1;
|
|
421
|
+
})) {
|
|
422
|
+
solutions[i].proper = false;
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
std::shared_ptr<const BlockData> build_block(const State &state,
|
|
430
|
+
Label label) {
|
|
431
|
+
auto data = std::make_shared<BlockData>();
|
|
432
|
+
data->classes_r = classes(state.r, label, a_);
|
|
433
|
+
data->classes_p = classes(state.p, label, b_);
|
|
434
|
+
const int size = static_cast<int>(block(state.r, label).atoms.size());
|
|
435
|
+
if (size != static_cast<int>(block(state.p, label).atoms.size()))
|
|
436
|
+
throw std::runtime_error("Unbalanced refined SLAP block");
|
|
437
|
+
std::vector<int> row_class, column_class;
|
|
438
|
+
for (size_t i = 0; i < data->classes_r.size(); ++i)
|
|
439
|
+
row_class.insert(row_class.end(), data->classes_r[i].atoms.size(),
|
|
440
|
+
static_cast<int>(i));
|
|
441
|
+
for (size_t j = 0; j < data->classes_p.size(); ++j)
|
|
442
|
+
column_class.insert(column_class.end(), data->classes_p[j].atoms.size(),
|
|
443
|
+
static_cast<int>(j));
|
|
444
|
+
std::vector<int64_t> cost(size * size);
|
|
445
|
+
for (int i = 0; i < size; ++i) {
|
|
446
|
+
budget_.check();
|
|
447
|
+
for (int j = 0; j < size; ++j)
|
|
448
|
+
cost[i * size + j] =
|
|
449
|
+
neighborhood_cost(data->classes_r[row_class[i]].neighbors,
|
|
450
|
+
data->classes_p[column_class[j]].neighbors);
|
|
451
|
+
}
|
|
452
|
+
const int nr = static_cast<int>(data->classes_r.size());
|
|
453
|
+
const int np = static_cast<int>(data->classes_p.size());
|
|
454
|
+
std::vector<int64_t> perturbed(cost);
|
|
455
|
+
for (auto &value : perturbed)
|
|
456
|
+
value *= 100;
|
|
457
|
+
std::set<std::vector<int>> seen;
|
|
458
|
+
int64_t best = INF;
|
|
459
|
+
for (int iteration = 0; iteration < fingerprint_cap_; ++iteration) {
|
|
460
|
+
budget_.check();
|
|
461
|
+
const auto assignment = lap(perturbed, size);
|
|
462
|
+
int64_t value = 0;
|
|
463
|
+
for (int i = 0; i < size; ++i)
|
|
464
|
+
value += cost[i * size + assignment[i]];
|
|
465
|
+
if (!iteration)
|
|
466
|
+
best = value;
|
|
467
|
+
if (value != best)
|
|
468
|
+
break;
|
|
469
|
+
Solution solution;
|
|
470
|
+
solution.value = value;
|
|
471
|
+
if (nr == 1 || np == 1) {
|
|
472
|
+
solution.groups_r.assign(nr, 0);
|
|
473
|
+
solution.groups_p.assign(np, 0);
|
|
474
|
+
data->solutions.push_back(std::move(solution));
|
|
475
|
+
++stats_.fingerprints;
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
solution.fingerprint.assign(nr * np, 0);
|
|
479
|
+
for (int i = 0; i < size; ++i)
|
|
480
|
+
++solution.fingerprint[row_class[i] * np + column_class[assignment[i]]];
|
|
481
|
+
if (!seen.insert(solution.fingerprint).second)
|
|
482
|
+
break;
|
|
483
|
+
auto groups = components(solution.fingerprint, nr, np);
|
|
484
|
+
solution.groups_r = std::move(groups.first);
|
|
485
|
+
solution.groups_p = std::move(groups.second);
|
|
486
|
+
for (int i = 0; i < size; ++i) {
|
|
487
|
+
budget_.check();
|
|
488
|
+
for (int j = 0; j < size; ++j)
|
|
489
|
+
if (solution.fingerprint[row_class[i] * np + column_class[j]])
|
|
490
|
+
perturbed[i * size + j] += 2;
|
|
491
|
+
}
|
|
492
|
+
data->solutions.push_back(std::move(solution));
|
|
493
|
+
++stats_.fingerprints;
|
|
494
|
+
}
|
|
495
|
+
if (data->solutions.empty())
|
|
496
|
+
throw std::runtime_error("SLAP found no block assignment");
|
|
497
|
+
mark_proper(data->solutions);
|
|
498
|
+
return data;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
static void replace_block(
|
|
502
|
+
Side &side, Label old_label,
|
|
503
|
+
const std::vector<std::pair<Label, std::vector<int>>> &replacements) {
|
|
504
|
+
side.blocks.erase(
|
|
505
|
+
std::remove_if(side.blocks.begin(), side.blocks.end(),
|
|
506
|
+
[&](const Block &b) { return b.label == old_label; }),
|
|
507
|
+
side.blocks.end());
|
|
508
|
+
for (const auto &entry : replacements) {
|
|
509
|
+
auto atoms = entry.second;
|
|
510
|
+
std::sort(atoms.begin(), atoms.end());
|
|
511
|
+
side.blocks.push_back({entry.first, atoms});
|
|
512
|
+
for (int atom : atoms)
|
|
513
|
+
side.labels[atom] = entry.first;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
void clear_cache(State &state, const std::vector<Label> &parents) {
|
|
518
|
+
std::map<Label, std::set<Label>> neighbors;
|
|
519
|
+
for (Label parent : parents) {
|
|
520
|
+
for (int side_index = 0; side_index < 2; ++side_index) {
|
|
521
|
+
const Side &value = side_index ? state.p : state.r;
|
|
522
|
+
const auto *matrix = side_index ? b_ : a_;
|
|
523
|
+
const auto found =
|
|
524
|
+
std::find_if(value.blocks.begin(), value.blocks.end(),
|
|
525
|
+
[&](const Block &b) { return b.label == parent; });
|
|
526
|
+
if (found == value.blocks.end())
|
|
527
|
+
continue;
|
|
528
|
+
for (int atom : found->atoms)
|
|
529
|
+
for (int j = 0; j < n_; ++j)
|
|
530
|
+
if (matrix[atom * n_ + j])
|
|
531
|
+
neighbors[parent].insert(value.labels[j]);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
std::set<Label> dirty(parents.begin(), parents.end());
|
|
535
|
+
for (auto left = neighbors.begin(); left != neighbors.end(); ++left)
|
|
536
|
+
for (auto right = neighbors.begin(); right != left; ++right)
|
|
537
|
+
std::set_intersection(left->second.begin(), left->second.end(),
|
|
538
|
+
right->second.begin(), right->second.end(),
|
|
539
|
+
std::inserter(dirty, dirty.end()));
|
|
540
|
+
for (Label label : dirty)
|
|
541
|
+
state.irreducible.erase(label);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
State refine(const State &state, Label label, const Solution &solution,
|
|
545
|
+
const BlockData &data) {
|
|
546
|
+
State result = state;
|
|
547
|
+
std::map<int, Label> group_labels;
|
|
548
|
+
for (size_t j = 0; j < data.classes_p.size(); ++j)
|
|
549
|
+
group_labels[solution.groups_p[j]] = data.classes_p[j].token;
|
|
550
|
+
for (int group : solution.groups_r)
|
|
551
|
+
if (group_labels.find(group) == group_labels.end())
|
|
552
|
+
group_labels[group] = fresh();
|
|
553
|
+
auto replacements = [&](const std::vector<NeighborhoodClass> &classes,
|
|
554
|
+
const std::vector<int> &groups) {
|
|
555
|
+
std::vector<std::pair<Label, std::vector<int>>> merged;
|
|
556
|
+
std::map<Label, size_t> positions;
|
|
557
|
+
for (size_t i = 0; i < classes.size(); ++i) {
|
|
558
|
+
const Label next = group_labels.at(groups[i]);
|
|
559
|
+
auto found = positions.find(next);
|
|
560
|
+
if (found == positions.end()) {
|
|
561
|
+
positions.emplace(next, merged.size());
|
|
562
|
+
merged.push_back({next, classes[i].atoms});
|
|
563
|
+
} else {
|
|
564
|
+
auto &atoms = merged[found->second].second;
|
|
565
|
+
atoms.insert(atoms.end(), classes[i].atoms.begin(),
|
|
566
|
+
classes[i].atoms.end());
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return merged;
|
|
570
|
+
};
|
|
571
|
+
replace_block(result.r, label,
|
|
572
|
+
replacements(data.classes_r, solution.groups_r));
|
|
573
|
+
replace_block(result.p, label,
|
|
574
|
+
replacements(data.classes_p, solution.groups_p));
|
|
575
|
+
std::vector<Label> parents;
|
|
576
|
+
for (const auto &entry : group_labels)
|
|
577
|
+
parents.push_back(entry.second);
|
|
578
|
+
clear_cache(result, parents);
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
void solve_path(State state, std::vector<State> &stack,
|
|
583
|
+
std::vector<Record> &results, int64_t &minimum) {
|
|
584
|
+
int64_t total = 0;
|
|
585
|
+
std::map<Label, std::shared_ptr<const BlockData>> lap_solutions;
|
|
586
|
+
for (Label label : ordered_labels(state.r)) {
|
|
587
|
+
budget_.check();
|
|
588
|
+
const auto cached = state.irreducible.find(label);
|
|
589
|
+
auto data = cached == state.irreducible.end() ? build_block(state, label)
|
|
590
|
+
: cached->second;
|
|
591
|
+
total += data->solutions.front().value;
|
|
592
|
+
if (total > minimum)
|
|
593
|
+
return;
|
|
594
|
+
const int atom = block(state.r, label).atoms.front();
|
|
595
|
+
const auto proper_count =
|
|
596
|
+
std::count_if(data->solutions.begin(), data->solutions.end(),
|
|
597
|
+
[](const Solution &s) { return s.proper; });
|
|
598
|
+
bool irreducible = cached != state.irreducible.end() ||
|
|
599
|
+
(stop_[atom] && proper_count > 1);
|
|
600
|
+
if (!irreducible) {
|
|
601
|
+
for (const auto &solution : data->solutions) {
|
|
602
|
+
budget_.check();
|
|
603
|
+
if (!solution.proper)
|
|
604
|
+
continue;
|
|
605
|
+
if (one_group(solution.groups_r)) {
|
|
606
|
+
irreducible = true;
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
auto child = refine(state, label, solution, *data);
|
|
610
|
+
if (visited_.insert(state_key(child)).second)
|
|
611
|
+
stack.push_back(std::move(child));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
lap_solutions[label] = data;
|
|
615
|
+
if (irreducible)
|
|
616
|
+
state.irreducible[label] = data;
|
|
617
|
+
else
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
results.push_back({std::move(state), total, std::move(lap_solutions)});
|
|
621
|
+
minimum = std::min(minimum, total);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
std::shared_ptr<const std::vector<Label>> wl_colors(const Side &side) {
|
|
625
|
+
if (side.initial_wl)
|
|
626
|
+
return side.initial_wl;
|
|
627
|
+
std::vector<Label> colors = side.labels;
|
|
628
|
+
for (int round = 0; round < n_; ++round) {
|
|
629
|
+
budget_.check();
|
|
630
|
+
std::vector<Label> next;
|
|
631
|
+
for (int i = 0; i < n_; ++i) {
|
|
632
|
+
std::vector<std::pair<Label, int64_t>> incident;
|
|
633
|
+
for (int j = 0; j < n_; ++j)
|
|
634
|
+
if (b_[i * n_ + j])
|
|
635
|
+
incident.emplace_back(colors[j], b_[i * n_ + j]);
|
|
636
|
+
std::sort(incident.begin(), incident.end());
|
|
637
|
+
// Separate tag distinguishes these signatures from class signatures.
|
|
638
|
+
Signature signature{-1, colors[i],
|
|
639
|
+
static_cast<int64_t>(incident.size())};
|
|
640
|
+
for (auto [color, weight] : incident) {
|
|
641
|
+
signature.push_back(color);
|
|
642
|
+
signature.push_back(weight);
|
|
643
|
+
}
|
|
644
|
+
next.push_back(intern(std::move(signature)));
|
|
645
|
+
}
|
|
646
|
+
if (std::set<Label>(next.begin(), next.end()).size() ==
|
|
647
|
+
std::set<Label>(colors.begin(), colors.end()).size())
|
|
648
|
+
break;
|
|
649
|
+
colors = std::move(next);
|
|
650
|
+
}
|
|
651
|
+
return std::make_shared<const std::vector<Label>>(std::move(colors));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
static void assign_singleton(Side &side, Label label, int atom, Label next) {
|
|
655
|
+
auto found = std::find_if(side.blocks.begin(), side.blocks.end(),
|
|
656
|
+
[&](const Block &b) { return b.label == label; });
|
|
657
|
+
if (found == side.blocks.end())
|
|
658
|
+
throw std::runtime_error("Cannot split missing SLAP block");
|
|
659
|
+
const auto position =
|
|
660
|
+
std::find(found->atoms.begin(), found->atoms.end(), atom);
|
|
661
|
+
if (position == found->atoms.end())
|
|
662
|
+
throw std::runtime_error("Cannot split missing SLAP atom");
|
|
663
|
+
found->atoms.erase(position);
|
|
664
|
+
side.labels[atom] = next;
|
|
665
|
+
side.blocks.push_back({next, {atom}});
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
void split(Record &record, Label label, std::vector<State> &pending) {
|
|
669
|
+
const Label next = fresh();
|
|
670
|
+
const auto &data = *record.lap_solutions.at(label);
|
|
671
|
+
record.state.p.initial_wl = wl_colors(record.state.p);
|
|
672
|
+
for (const auto &solution : data.solutions) {
|
|
673
|
+
budget_.check();
|
|
674
|
+
if (!one_group(solution.groups_r))
|
|
675
|
+
continue;
|
|
676
|
+
const int source = *std::min_element(data.classes_r.front().atoms.begin(),
|
|
677
|
+
data.classes_r.front().atoms.end());
|
|
678
|
+
int target_class = 0;
|
|
679
|
+
if (!solution.fingerprint.empty()) {
|
|
680
|
+
while (target_class < static_cast<int>(data.classes_p.size()) &&
|
|
681
|
+
solution.fingerprint[target_class] == 0)
|
|
682
|
+
++target_class;
|
|
683
|
+
if (target_class == static_cast<int>(data.classes_p.size()))
|
|
684
|
+
throw std::runtime_error("Empty SLAP fingerprint row");
|
|
685
|
+
}
|
|
686
|
+
// This is the SLAP heuristic's WL-based split representative policy,
|
|
687
|
+
// not an assertion that equal WL colors prove graph automorphism.
|
|
688
|
+
std::set<Label> seen_wl;
|
|
689
|
+
for (int target : data.classes_p[target_class].atoms) {
|
|
690
|
+
budget_.check();
|
|
691
|
+
if (!seen_wl.insert((*record.state.p.initial_wl)[target]).second)
|
|
692
|
+
continue;
|
|
693
|
+
State child = record.state;
|
|
694
|
+
assign_singleton(child.r, label, source, next);
|
|
695
|
+
assign_singleton(child.p, label, target, next);
|
|
696
|
+
clear_cache(child, {label, next});
|
|
697
|
+
if (visited_.insert(state_key(child)).second)
|
|
698
|
+
pending.push_back(std::move(child));
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
void remember(const Record &record) {
|
|
704
|
+
std::vector<int32_t> mapping(n_, -1);
|
|
705
|
+
std::vector<bool> used(n_, false);
|
|
706
|
+
for (const auto &left : record.state.r.blocks) {
|
|
707
|
+
const auto &right = block(record.state.p, left.label);
|
|
708
|
+
if (left.atoms.size() != 1 || right.atoms.size() != 1)
|
|
709
|
+
throw std::runtime_error("SLAP output is not fully resolved");
|
|
710
|
+
const int i = left.atoms.front(), j = right.atoms.front();
|
|
711
|
+
if (used[j] || original_r_[i] != original_p_[j])
|
|
712
|
+
throw std::runtime_error("SLAP output violates atom compatibility");
|
|
713
|
+
mapping[i] = j;
|
|
714
|
+
used[j] = true;
|
|
715
|
+
}
|
|
716
|
+
if (std::find(mapping.begin(), mapping.end(), -1) != mapping.end())
|
|
717
|
+
throw std::runtime_error("SLAP output omits atoms");
|
|
718
|
+
int64_t cost = 0;
|
|
719
|
+
for (int i = 0; i < n_; ++i)
|
|
720
|
+
for (int j = i + 1; j < n_; ++j)
|
|
721
|
+
cost += std::abs(a_[i * n_ + j] - b_[mapping[i] * n_ + mapping[j]]);
|
|
722
|
+
if (record.value != 2 * cost)
|
|
723
|
+
throw std::runtime_error(
|
|
724
|
+
"SLAP proxy disagrees with independent full-mapping rescoring");
|
|
725
|
+
if (stats_.best_proxy2 < 0 || record.value < stats_.best_proxy2) {
|
|
726
|
+
stats_.best_proxy2 = record.value;
|
|
727
|
+
completed_.clear();
|
|
728
|
+
}
|
|
729
|
+
if (record.value == stats_.best_proxy2)
|
|
730
|
+
completed_.emplace(std::move(mapping), cost);
|
|
731
|
+
if (mapping_cap_ >= 0 &&
|
|
732
|
+
static_cast<int64_t>(completed_.size()) >= mapping_cap_)
|
|
733
|
+
throw Stop{3};
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
} // namespace
|
|
738
|
+
|
|
739
|
+
extern "C" {
|
|
740
|
+
|
|
741
|
+
int synkit_mapper_abi(void) { return 1; }
|
|
742
|
+
|
|
743
|
+
const char *synkit_mapper_error(void) { return last_error.c_str(); }
|
|
744
|
+
|
|
745
|
+
int synkit_slap_solve(int n, const int64_t *a, const int64_t *b,
|
|
746
|
+
const int32_t *lr, const int32_t *lp, const int32_t *stop,
|
|
747
|
+
int max_fingerprints, double seconds, int64_t max_states,
|
|
748
|
+
int64_t max_mappings, SlapMappingCallback callback,
|
|
749
|
+
void *userdata, SlapStatistics *statistics) {
|
|
750
|
+
last_error.clear();
|
|
751
|
+
if (!statistics) {
|
|
752
|
+
last_error = "Missing SLAP statistics output";
|
|
753
|
+
return -1;
|
|
754
|
+
}
|
|
755
|
+
*statistics = {};
|
|
756
|
+
statistics->best_proxy2 = -1;
|
|
757
|
+
Budget budget(Clock::now(), seconds);
|
|
758
|
+
try {
|
|
759
|
+
if (n < 1 || n > 512 || !a || !b || !lr || !lp || !stop ||
|
|
760
|
+
max_fingerprints < 1 || !std::isfinite(seconds) || seconds < -1 ||
|
|
761
|
+
(seconds < 0 && seconds != -1) || max_states == 0 || max_states < -1 ||
|
|
762
|
+
max_mappings == 0 || max_mappings < -1)
|
|
763
|
+
throw std::invalid_argument("Invalid SLAP ABI arguments");
|
|
764
|
+
std::map<int32_t, int> inventories;
|
|
765
|
+
std::map<int32_t, int32_t> policies;
|
|
766
|
+
for (int i = 0; i < n; ++i) {
|
|
767
|
+
budget.check();
|
|
768
|
+
++inventories[lr[i]];
|
|
769
|
+
--inventories[lp[i]];
|
|
770
|
+
if (stop[i] != 0 && stop[i] != 1)
|
|
771
|
+
throw std::invalid_argument("SLAP stop flags must be 0 or 1");
|
|
772
|
+
const auto policy = policies.emplace(lr[i], stop[i]);
|
|
773
|
+
if (!policy.second && policy.first->second != stop[i])
|
|
774
|
+
throw std::invalid_argument(
|
|
775
|
+
"SLAP stop flags must agree within each initial label");
|
|
776
|
+
if (a[i * n + i] || b[i * n + i])
|
|
777
|
+
throw std::invalid_argument("SLAP matrices must be loop free");
|
|
778
|
+
for (int j = 0; j < n; ++j)
|
|
779
|
+
if (a[i * n + j] < 0 || b[i * n + j] < 0 || a[i * n + j] > 1000000 ||
|
|
780
|
+
b[i * n + j] > 1000000 || a[i * n + j] != a[j * n + i] ||
|
|
781
|
+
b[i * n + j] != b[j * n + i])
|
|
782
|
+
throw std::invalid_argument(
|
|
783
|
+
"SLAP matrices must be bounded nonnegative symmetric integers");
|
|
784
|
+
}
|
|
785
|
+
for (auto [label, count] : inventories)
|
|
786
|
+
if (count)
|
|
787
|
+
throw std::invalid_argument(
|
|
788
|
+
"SLAP requires equal atom-label inventories");
|
|
789
|
+
Slap solver(n, a, b, lr, lp, stop, max_fingerprints, max_states,
|
|
790
|
+
max_mappings, budget, *statistics);
|
|
791
|
+
try {
|
|
792
|
+
solver.run();
|
|
793
|
+
} catch (const Stop &limit) {
|
|
794
|
+
statistics->completed = 0;
|
|
795
|
+
statistics->reason = limit.reason;
|
|
796
|
+
}
|
|
797
|
+
solver.emit(callback, userdata);
|
|
798
|
+
} catch (const Stop &limit) {
|
|
799
|
+
statistics->completed = 0;
|
|
800
|
+
statistics->reason = limit.reason;
|
|
801
|
+
} catch (const std::exception &error) {
|
|
802
|
+
statistics->elapsed_seconds = budget.elapsed();
|
|
803
|
+
last_error = error.what();
|
|
804
|
+
return -1;
|
|
805
|
+
}
|
|
806
|
+
statistics->elapsed_seconds = budget.elapsed();
|
|
807
|
+
return 0;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
} // extern "C"
|