12 #ifndef INCLUDE_DISTANCE_GEOMETRY_IMPLICIT_BOUNDS_GRAPH_H
13 #define INCLUDE_DISTANCE_GEOMETRY_IMPLICIT_BOUNDS_GRAPH_H
17 #include "boost/property_map/property_map.hpp"
29 namespace Molassembler {
35 namespace outcome = OUTCOME_V2_NAMESPACE;
40 namespace DistanceGeometry {
43 class DistanceBoundsMatrix;
147 using VertexDescriptor =
unsigned long;
148 using EdgeDescriptor = std::pair<VertexDescriptor, VertexDescriptor>;
151 [[gnu::const]]
inline static VertexDescriptor left(
const VertexDescriptor a) noexcept {
155 [[gnu::const]]
inline static VertexDescriptor right(
const VertexDescriptor a) noexcept {
159 [[gnu::const]]
inline static VertexDescriptor
internal(
const VertexDescriptor i) noexcept {
174 static void explainContradictionPaths_(
177 const std::vector<VertexDescriptor>& predecessors,
178 const std::vector<double>& distances
182 using BoundsMatrix = Eigen::MatrixXd;
215 std::pair<EdgeDescriptor, bool>
edge(VertexDescriptor i, VertexDescriptor j)
const;
228 [[gnu::const]]
inline static bool isLeft(
const VertexDescriptor i) noexcept {
232 [[gnu::const]]
inline static bool sameSide(
const VertexDescriptor i,
const VertexDescriptor j) noexcept {
233 return i % 2 == j % 2;
270 inline VertexDescriptor
source(const EdgeDescriptor& e)
const {
278 inline VertexDescriptor
target(
const EdgeDescriptor& e)
const {
294 VertexDescriptor
out_degree(VertexDescriptor i)
const;
297 double& lowerBound(VertexDescriptor a, VertexDescriptor b);
298 double& upperBound(VertexDescriptor a, VertexDescriptor b);
300 double lowerBound(VertexDescriptor a, VertexDescriptor b)
const;
301 double upperBound(VertexDescriptor a, VertexDescriptor b)
const;
310 struct EdgeWeightMap :
public boost::put_get_helper<double, EdgeWeightMap> {
311 using value_type = double;
312 using reference = double;
313 using key_type = EdgeDescriptor;
318 double operator [] (
const EdgeDescriptor& e)
const;
319 double operator () (
const EdgeDescriptor& e)
const;
326 struct VertexIndexMap :
public boost::put_get_helper<VertexDescriptor, VertexIndexMap> {
327 using value_type = VertexDescriptor;
328 using key_type = VertexDescriptor;
329 using reference = VertexDescriptor;
331 inline VertexDescriptor operator [] (
const VertexDescriptor v)
const {
return v; }
332 inline VertexDescriptor operator () (
const VertexDescriptor v)
const {
return v; }
337 VertexDescriptor index = 0;
340 using iterator_category = std::random_access_iterator_tag;
341 using value_type = VertexDescriptor;
342 using difference_type = int;
343 using pointer = VertexDescriptor*;
344 using reference =
const VertexDescriptor&;
369 VertexDescriptor operator * ()
const;
384 VertexDescriptor i_, b_;
390 using iterator_category = std::forward_iterator_tag;
391 using value_type = EdgeDescriptor;
392 using difference_type = int;
393 using pointer = EdgeDescriptor*;
394 using reference =
const EdgeDescriptor&;
414 std::string state()
const;
416 EdgeDescriptor operator * ()
const;
418 double weight()
const;
419 VertexDescriptor target()
const;
442 using iterator_category = std::forward_iterator_tag;
443 using value_type = EdgeDescriptor;
444 using difference_type = int;
445 using pointer = EdgeDescriptor*;
446 using reference =
const EdgeDescriptor&;
471 b_ < static_cast<VertexDescriptor>(basePtr_->
distances_.outerSize())
472 && (basePtr_->
distances_(
internal(i_), b_) == 0.0)
487 isLeft_ == other.isLeft_
490 && basePtr_ == other.basePtr_
494 return !(*
this == other);
497 inline EdgeDescriptor operator *()
const {
498 return {i_, target()};
501 inline VertexDescriptor target()
const {
509 inline double weight()
const {
510 return basePtr_->upperBound(
internal(i_), b_);
518 inline in_group_edge_iterator in_group_edges_end(
const VertexDescriptor i)
const {
519 return {*
this, i,
true};
VertexDescriptor num_edges() const
Returns the number of edges currently simulated by the graph.
VertexDescriptor num_vertices() const
Returns the number of vertices simulated by the graph, which is 2N.
A helper struct to turn vertex descriptors into numeric indices.
Definition: ImplicitBoundsGraph.h:326
VertexDescriptor out_degree(VertexDescriptor i) const
Returns the number of out-edges for a particular vertex.
std::pair< EdgeDescriptor, bool > edge(VertexDescriptor i, VertexDescriptor j) const
Fetches an edge descriptor for a speculative edge from i to j.
const Eigen::MatrixXd & getMatrix() const
Allows const-ref access to the underlying matrix for debug purposes.
Definition: ImplicitBoundsGraph.h:286
Simulates a graph from which triangle inequality bounds can be calculated by shortest-paths.
Definition: ImplicitBoundsGraph.h:145
outcome::result< Eigen::MatrixXd > makeDistanceMatrix(Random::Engine &engine) noexcept
Generates a distance matrix by randomly fixing distances within triangle inequality bounds...
edge_iterator eend() const
Returns an end edge iterator.
vertex_iterator vbegin() const
Returns a begin-iterator for vertices.
VertexDescriptor target(const EdgeDescriptor &e) const
Returns the target vertex from an edge descriptor.
Definition: ImplicitBoundsGraph.h:278
A helper struct permitting read-access to an edge weight via an edge descriptor.
Definition: ImplicitBoundsGraph.h:310
Data struct for storing a numeric interval.
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:24
VertexDescriptor source(const EdgeDescriptor &e) const
Returns the source vertex from an edge descriptor.
Definition: ImplicitBoundsGraph.h:270
An iterator to enumerate all edges in a graph.
Definition: ImplicitBoundsGraph.h:381
edge_iterator oend(VertexDescriptor i) const
Returns an end edge iterator for the out-edges of a specific vertex.
bool hasExplicit(const EdgeDescriptor &edge) const
Checks if there is explicit information present for a left-to-right edge.
edge_iterator obegin(VertexDescriptor i) const
Returns a begin edge iterator for the out-edges of a specific vertex.
std::array< Utils::ElementType, 2 > heaviestAtoms_
Stores the two heaviest element types.
Definition: ImplicitBoundsGraph.h:169
vertex_iterator vend() const
Returns an end-iterator for vertices.
Eigen::MatrixXd distances_
Dense adjacency matrix for O(1) access to fixed distances.
Definition: ImplicitBoundsGraph.h:172
static bool isLeft(const VertexDescriptor i) noexcept
Check if a vertex descriptor is part of the left subgraph.
Definition: ImplicitBoundsGraph.h:228
A random access iterator through all vertex descriptors of the graph.
Definition: ImplicitBoundsGraph.h:336
An iterator to enumerate only edges to the same part of the graph from specific vertices.
Definition: ImplicitBoundsGraph.h:435
EdgeWeightMap getEdgeWeightPropertyMap() const
Returns an instance of EdgeWeightMap.
const PrivateGraph * innerGraphPtr_
Pointer to molecule from which the bounds come from.
Definition: ImplicitBoundsGraph.h:166
edge_iterator ebegin() const
Returns a begin edge iterator.
Partiality
Limit triangle inequality bounds smoothing to a subset of all atoms.
Definition: Conformers.h:44
outcome::result< Eigen::MatrixXd > makeDistanceBounds() const noexcept
Generates a bare distance bounds matrix by repeated shortest-paths calculations.
double maximalImplicitLowerBound(VertexDescriptor i) const
Returns the length of the maximal implicit lower bound outgoing from a left vertex.