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;
51 std::vector<AtomIndex> path(
AtomIndex target)
const;
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>>;
Type for non-zero cost edge edits in the result set.
Definition: GraphAlgorithms.h:198
std::unordered_map< ComponentIndexPair, ComponentIndexPair, boost::hash< ComponentIndexPair > > indexMap
Vertex and component mapping.
Definition: GraphAlgorithms.h:217
std::vector< EdgeEdit > edgeEdits
List of non-zero-cost edge edits.
Definition: GraphAlgorithms.h:159
std::vector< VertexEdit > vertexEdits
List of non-zero-cost vertex edits.
Definition: GraphAlgorithms.h:219
Defines basic types widely shared across the project.
Fuzzy-matching cost function that prefers element substitutions to alterations.
Definition: GraphAlgorithms.h:91
std::vector< EdgeEdit > edgeEdits
List of non-zero-cost edge edits.
Definition: GraphAlgorithms.h:221
std::string reactionGraphvizSvg(const GraphList &lhs, const GraphList &rhs, const MinimalReactionEdits &edits)
MinimalReactionEdits reactionEdits(const GraphList &lhsGraphs, const GraphList &rhsGraphs)
Graph edit distance calculation for reactions.
Type for non-zero cost edge edits in the result set.
Definition: GraphAlgorithms.h:137
ComponentIndexPair first
Left graph index and component.
Definition: GraphAlgorithms.h:190
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:211
Type for non-zero cost vertex edits in the result set.
Definition: GraphAlgorithms.h:124
Represents the connectivity of atoms of a molecule.
Definition: Graph.h:54
std::vector< unsigned > distance(AtomIndex source, const Graph &graph)
Calculates the graph distance from a single atom index to all others.
MinimalGraphEdits minimalEdits(const Graph &a, const Graph &b, const EditCost &cost=FuzzyCost{})
Graph edit distance calculation.
Result type for single-pair graph edit distance calculation.
Definition: GraphAlgorithms.h:119
ComponentBondIndex second
Right bond.
Definition: GraphAlgorithms.h:209
std::vector< VertexEdit > vertexEdits
List of non-zero-cost vertex edits.
Definition: GraphAlgorithms.h:157
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:194
constexpr Get< 1 > second
Calls std::get<1> on any argument it is invoked with.
Definition: Functor.h:125
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:146
unsigned distance
Total distance between graphs according to cost function.
Definition: GraphAlgorithms.h:153
std::pair< unsigned, AtomIndex > ComponentIndexPair
Input component and atom index therein.
Definition: GraphAlgorithms.h:181
std::size_t AtomIndex
Unsigned integer atom index type. Used to refer to particular atoms.
Definition: Types.h:51
AtomIndex first
Left graph index (possibly epsilon)
Definition: GraphAlgorithms.h:129
BondType
Discrete bond type numeration.
Definition: Types.h:26
Element type conserving cost function, really allowing only edge alterations.
Definition: GraphAlgorithms.h:109
Type for non-zero cost vertex edits in the result set.
Definition: GraphAlgorithms.h:184
BondIndex second
Right graph bond index (possibly containing epsilon values)
Definition: GraphAlgorithms.h:144
constexpr Get< 0 > first
Calls std::get<0> on any argument it is invoked with.
Definition: Functor.h:123
Type used to refer to particular bonds. Orders first < second.
Definition: Types.h:54
unsigned cost
Cost of the edit per the cost function.
Definition: GraphAlgorithms.h:133
Definition: GraphAlgorithms.h:40
ComponentBondIndex first
Left bond.
Definition: GraphAlgorithms.h:207
Base class for edit cost functors for graph edit distance methods.
Definition: GraphAlgorithms.h:74
std::pair< ComponentIndexPair, ComponentIndexPair > ComponentBondIndex
Type for two component and index pairs.
Definition: GraphAlgorithms.h:200
unsigned distance
Minimal edit cost between graphs.
Definition: GraphAlgorithms.h:215
Aggregate for multiple-graph graph edit distance.
Definition: GraphAlgorithms.h:179
IndexMap indexMap
Vertex mapping, possibly including epsilon values.
Definition: GraphAlgorithms.h:155
BondIndex first
Left graph bond index (possibly containing epsilon values)
Definition: GraphAlgorithms.h:142
std::vector< std::reference_wrapper< Graph >> GraphList
Input type for multiple graphs.
Definition: GraphAlgorithms.h:225
ComponentIndexPair second
Right graph index and component.
Definition: GraphAlgorithms.h:192
std::vector< AtomIndex > IndexMap
Flat vertex index map between the graphs.
Definition: GraphAlgorithms.h:121
PredecessorMap shortestPaths(AtomIndex source, const Graph &graph)
Generates shortest paths to each vertex in a graph.
AtomIndex second
Right graph index (possibly epsilon)
Definition: GraphAlgorithms.h:131