8 #ifndef INCLUDE_MOLASSEMBLER_OUTER_GRAPH_ALGORITHMS_H
9 #define INCLUDE_MOLASSEMBLER_OUTER_GRAPH_ALGORITHMS_H
13 #include "boost/functional/hash.hpp"
15 #include <unordered_map>
21 namespace Molassembler {
41 std::vector<AtomIndex> predecessors;
78 virtual unsigned vertexAlteration()
const = 0;
79 virtual unsigned edgeAlteration()
const = 0;
80 virtual unsigned elementSubstitution(Utils::ElementType from, Utils::ElementType to)
const = 0;
92 unsigned vertexAlteration()
const override {
return 1; }
93 unsigned edgeAlteration()
const override {
return 1; }
94 unsigned elementSubstitution(Utils::ElementType from, Utils::ElementType to)
const override {
95 return (from != to) ? 1 : 0;
98 return (from != to) ? 1 : 0;
110 unsigned vertexAlteration()
const override {
return 100; }
111 unsigned elementSubstitution(Utils::ElementType from, Utils::ElementType to)
const override {
112 return (from != to) ? 100 : 0;
150 static constexpr
AtomIndex epsilon = std::numeric_limits<AtomIndex>::max();
187 :
first(std::move(i)),
second(std::move(j)), cost(c) {}
204 :
first(std::move(i)),
second(std::move(j)), cost(c) {}
217 std::unordered_map<ComponentIndexPair, ComponentIndexPair, boost::hash<ComponentIndexPair>>
indexMap;
225 using GraphList = std::vector<std::reference_wrapper<Graph>>;
Defines basic types widely shared across the project.
Represents the connectivity of atoms of a molecule.
Definition: Graph.h:54
constexpr Get< 0 > first
Calls std::get<0> on any argument it is invoked with.
Definition: Functor.h:123
constexpr Get< 1 > second
Calls std::get<1> on any argument it is invoked with.
Definition: Functor.h:125
MinimalReactionEdits reactionEdits(const GraphList &lhsGraphs, const GraphList &rhsGraphs)
Graph edit distance calculation for reactions.
BondType
Discrete bond type numeration.
Definition: Types.h:26
MinimalGraphEdits minimalEdits(const Graph &a, const Graph &b, const EditCost &cost=FuzzyCost {})
Graph edit distance calculation.
std::size_t AtomIndex
Unsigned integer atom index type. Used to refer to particular atoms.
Definition: Types.h:51
std::vector< std::reference_wrapper< Graph > > GraphList
Input type for multiple graphs.
Definition: GraphAlgorithms.h:225
std::vector< unsigned > distance(AtomIndex source, const Graph &graph)
Calculates the graph distance from a single atom index to all others.
std::string reactionGraphvizSvg(const GraphList &lhs, const GraphList &rhs, const MinimalReactionEdits &edits)
PredecessorMap shortestPaths(AtomIndex source, const Graph &graph)
Generates shortest paths to each vertex in a graph.
Type used to refer to particular bonds. Orders first < second.
Definition: Types.h:54
Base class for edit cost functors for graph edit distance methods.
Definition: GraphAlgorithms.h:74
Element type conserving cost function, really allowing only edge alterations.
Definition: GraphAlgorithms.h:109
Fuzzy-matching cost function that prefers element substitutions to alterations.
Definition: GraphAlgorithms.h:91
Type for non-zero cost edge edits in the result set.
Definition: GraphAlgorithms.h:137
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:146
BondIndex second
Right graph bond index (possibly containing epsilon values)
Definition: GraphAlgorithms.h:144
BondIndex first
Left graph bond index (possibly containing epsilon values)
Definition: GraphAlgorithms.h:142
Type for non-zero cost vertex edits in the result set.
Definition: GraphAlgorithms.h:124
AtomIndex first
Left graph index (possibly epsilon)
Definition: GraphAlgorithms.h:129
AtomIndex second
Right graph index (possibly epsilon)
Definition: GraphAlgorithms.h:131
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:133
Result type for single-pair graph edit distance calculation.
Definition: GraphAlgorithms.h:119
std::vector< AtomIndex > IndexMap
Flat vertex index map between the graphs.
Definition: GraphAlgorithms.h:121
std::vector< VertexEdit > vertexEdits
List of non-zero-cost vertex edits.
Definition: GraphAlgorithms.h:157
IndexMap indexMap
Vertex mapping, possibly including epsilon values.
Definition: GraphAlgorithms.h:155
unsigned distance
Total distance between graphs according to cost function.
Definition: GraphAlgorithms.h:153
std::vector< EdgeEdit > edgeEdits
List of non-zero-cost edge edits.
Definition: GraphAlgorithms.h:159
Type for non-zero cost edge edits in the result set.
Definition: GraphAlgorithms.h:198
ComponentBondIndex first
Left bond.
Definition: GraphAlgorithms.h:207
ComponentBondIndex second
Right bond.
Definition: GraphAlgorithms.h:209
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:211
std::pair< ComponentIndexPair, ComponentIndexPair > ComponentBondIndex
Type for two component and index pairs.
Definition: GraphAlgorithms.h:200
Type for non-zero cost vertex edits in the result set.
Definition: GraphAlgorithms.h:184
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:194
ComponentIndexPair second
Right graph index and component.
Definition: GraphAlgorithms.h:192
ComponentIndexPair first
Left graph index and component.
Definition: GraphAlgorithms.h:190
Aggregate for multiple-graph graph edit distance.
Definition: GraphAlgorithms.h:179
std::unordered_map< ComponentIndexPair, ComponentIndexPair, boost::hash< ComponentIndexPair > > indexMap
Vertex and component mapping.
Definition: GraphAlgorithms.h:217
std::vector< VertexEdit > vertexEdits
List of non-zero-cost vertex edits.
Definition: GraphAlgorithms.h:219
std::vector< EdgeEdit > edgeEdits
List of non-zero-cost edge edits.
Definition: GraphAlgorithms.h:221
unsigned distance
Minimal edit cost between graphs.
Definition: GraphAlgorithms.h:215
std::pair< unsigned, AtomIndex > ComponentIndexPair
Input component and atom index therein.
Definition: GraphAlgorithms.h:181
Definition: GraphAlgorithms.h:40
std::vector< AtomIndex > path(AtomIndex target) const
Generate path from source to target vertex.