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 {
38 namespace DistanceGeometry {
41 class DistanceBoundsMatrix;
145 using VertexDescriptor =
unsigned long;
146 using EdgeDescriptor = std::pair<VertexDescriptor, VertexDescriptor>;
149 [[gnu::const]]
inline static VertexDescriptor left(
const VertexDescriptor a) noexcept {
153 [[gnu::const]]
inline static VertexDescriptor right(
const VertexDescriptor a) noexcept {
157 [[gnu::const]]
inline static VertexDescriptor
internal(
const VertexDescriptor i) noexcept {
172 static void explainContradictionPaths_(
175 const std::vector<VertexDescriptor>& predecessors,
176 const std::vector<double>& distances
180 using BoundsMatrix = Eigen::MatrixXd;
213 std::pair<EdgeDescriptor, bool>
edge(VertexDescriptor i, VertexDescriptor j)
const;
226 [[gnu::const]]
inline static bool isLeft(
const VertexDescriptor i) noexcept {
230 [[gnu::const]]
inline static bool sameSide(
const VertexDescriptor i,
const VertexDescriptor j) noexcept {
231 return i % 2 == j % 2;
268 inline VertexDescriptor
source(const EdgeDescriptor& e)
const {
276 inline VertexDescriptor
target(
const EdgeDescriptor& e)
const {
292 VertexDescriptor
out_degree(VertexDescriptor i)
const;
295 double& lowerBound(VertexDescriptor a, VertexDescriptor b);
296 double& upperBound(VertexDescriptor a, VertexDescriptor b);
298 double lowerBound(VertexDescriptor a, VertexDescriptor b)
const;
299 double upperBound(VertexDescriptor a, VertexDescriptor b)
const;
308 struct EdgeWeightMap :
public boost::put_get_helper<double, EdgeWeightMap> {
309 using value_type = double;
310 using reference = double;
311 using key_type = EdgeDescriptor;
316 double operator [] (
const EdgeDescriptor& e)
const;
317 double operator () (
const EdgeDescriptor& e)
const;
324 struct VertexIndexMap :
public boost::put_get_helper<VertexDescriptor, VertexIndexMap> {
325 using value_type = VertexDescriptor;
326 using key_type = VertexDescriptor;
327 using reference = VertexDescriptor;
329 inline VertexDescriptor operator [] (
const VertexDescriptor v)
const {
return v; }
330 inline VertexDescriptor operator () (
const VertexDescriptor v)
const {
return v; }
335 VertexDescriptor index = 0;
338 using iterator_category = std::random_access_iterator_tag;
339 using value_type = VertexDescriptor;
340 using difference_type = int;
341 using pointer = VertexDescriptor*;
342 using reference =
const VertexDescriptor&;
367 VertexDescriptor operator * ()
const;
382 VertexDescriptor i_, b_;
388 using iterator_category = std::forward_iterator_tag;
389 using value_type = EdgeDescriptor;
390 using difference_type = int;
391 using pointer = EdgeDescriptor*;
392 using reference =
const EdgeDescriptor&;
412 std::string state()
const;
414 EdgeDescriptor operator * ()
const;
416 double weight()
const;
417 VertexDescriptor target()
const;
440 using iterator_category = std::forward_iterator_tag;
441 using value_type = EdgeDescriptor;
442 using difference_type = int;
443 using pointer = EdgeDescriptor*;
444 using reference =
const EdgeDescriptor&;
469 b_ < static_cast<VertexDescriptor>(basePtr_->
distances_.outerSize())
470 && (basePtr_->
distances_(
internal(i_), b_) == 0.0)
485 isLeft_ == other.isLeft_
488 && basePtr_ == other.basePtr_
492 return !(*
this == other);
495 inline EdgeDescriptor operator *()
const {
496 return {i_, target()};
499 inline VertexDescriptor target()
const {
507 inline double weight()
const {
508 return basePtr_->upperBound(
internal(i_), b_);
516 inline in_group_edge_iterator in_group_edges_end(
const VertexDescriptor i)
const {
517 return {*
this, i,
true};
VertexDescriptor num_edges() const
Returns the number of edges currently simulated by the graph.
Result< Eigen::MatrixXd > makeDistanceMatrix(Random::Engine &engine) noexcept
Generates a distance matrix by randomly fixing distances within triangle inequality bounds...
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:324
Result< Eigen::MatrixXd > makeDistanceBounds() const noexcept
Generates a bare distance bounds matrix by repeated shortest-paths calculations.
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:284
Simulates a graph from which triangle inequality bounds can be calculated by shortest-paths.
Definition: ImplicitBoundsGraph.h:143
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:276
A helper struct permitting read-access to an edge weight via an edge descriptor.
Definition: ImplicitBoundsGraph.h:308
Data struct for storing a numeric interval.
Library internal graph class wrapping BGL types.
Definition: PrivateGraph.h:26
VertexDescriptor source(const EdgeDescriptor &e) const
Returns the source vertex from an edge descriptor.
Definition: ImplicitBoundsGraph.h:268
An iterator to enumerate all edges in a graph.
Definition: ImplicitBoundsGraph.h:379
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:167
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:170
static bool isLeft(const VertexDescriptor i) noexcept
Check if a vertex descriptor is part of the left subgraph.
Definition: ImplicitBoundsGraph.h:226
A random access iterator through all vertex descriptors of the graph.
Definition: ImplicitBoundsGraph.h:334
An iterator to enumerate only edges to the same part of the graph from specific vertices.
Definition: ImplicitBoundsGraph.h:433
EdgeWeightMap getEdgeWeightPropertyMap() const
Returns an instance of EdgeWeightMap.
const PrivateGraph * innerGraphPtr_
Pointer to molecule from which the bounds come from.
Definition: ImplicitBoundsGraph.h:164
edge_iterator ebegin() const
Returns a begin edge iterator.
Partiality
Limit triangle inequality bounds smoothing to a subset of all atoms.
Definition: Conformers.h:42
double maximalImplicitLowerBound(VertexDescriptor i) const
Returns the length of the maximal implicit lower bound outgoing from a left vertex.