RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
BoundsMatrix.h
Go to the documentation of this file.
1//
2// Copyright (C) 2004-2006 Greg Landrum and other RDKit contributors
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10#include <RDGeneral/export.h>
11#ifndef RD_BOUNDS_MATRIX_H
12#define RD_BOUNDS_MATRIX_H
13
14#include <RDGeneral/Invariant.h>
15#include <boost/smart_ptr.hpp>
16#include <iomanip>
18
19namespace DistGeom {
20//! Class to store the distance bound
21/*!
22 Basically a N by N matrix
23 with lower distance bounds on the lower traingle and upper bounds in the upper
24 triangle
25*/
27 : public RDNumeric::SquareMatrix<double> {
28 public:
29 typedef boost::shared_array<double> DATA_SPTR;
30
31 explicit BoundsMatrix(unsigned int N)
32 : RDNumeric::SquareMatrix<double>(N, 0.0) {}
33 BoundsMatrix(unsigned int N, DATA_SPTR data)
34 : RDNumeric::SquareMatrix<double>(N, data) {}
35
36 //! Get the upper bound between points i and j
37 inline double getUpperBound(unsigned int i, unsigned int j) const {
38 if (i < j) {
39 return getVal(i, j);
40 } else {
41 return getVal(j, i);
42 }
43 }
44
45 //! Set the lower bound between points i and j
46 inline void setUpperBound(unsigned int i, unsigned int j, double val) {
47 CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
48 if (i < j) {
49 setVal(i, j, val);
50 } else {
51 setVal(j, i, val);
52 }
53 }
54
55 //! Set the upper bound between points i and j only if it is better than
56 //! previously existing value (i.e. the new value is smaller)
57 inline void setUpperBoundIfBetter(unsigned int i, unsigned int j,
58 double val) {
59 if ((val < getUpperBound(i, j)) && (val > getLowerBound(i, j))) {
60 setUpperBound(i, j, val);
61 }
62 }
63
64 //! Set the lower bound between points i and j
65 inline void setLowerBound(unsigned int i, unsigned int j, double val) {
66 CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
67 if (i < j) {
68 setVal(j, i, val);
69 } else {
70 setVal(i, j, val);
71 }
72 }
73
74 //! Set the lower bound between points i and j only if it is better than
75 //! previously existing value (i.e. the new value is larger)
76 inline void setLowerBoundIfBetter(unsigned int i, unsigned int j,
77 double val) {
78 if ((val > getLowerBound(i, j)) && (val < getUpperBound(i, j))) {
79 setLowerBound(i, j, val);
80 }
81 }
82
83 //! Get the lower bound between points i and j
84 inline double getLowerBound(unsigned int i, unsigned int j) const {
85 if (i < j) {
86 return getVal(j, i);
87 } else {
88 return getVal(i, j);
89 }
90 }
91
92 //! Do a simple check of the current bounds - i.e. all lower bounds are
93 //! smaller than the existing upper bounds
94 inline bool checkValid() const {
95 unsigned int i, j;
96 for (i = 1; i < d_nRows; i++) {
97 for (j = 0; j < i; j++) {
98 if (getUpperBound(i, j) < getLowerBound(i, j)) {
99 return false;
100 }
101 }
102 }
103 return true;
104 }
105};
106
107typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
108} // namespace DistGeom
109
110#endif
#define CHECK_INVARIANT(expr, mess)
Definition Invariant.h:100
void setUpperBound(unsigned int i, unsigned int j, double val)
Set the lower bound between points i and j.
double getUpperBound(unsigned int i, unsigned int j) const
Get the upper bound between points i and j.
double getLowerBound(unsigned int i, unsigned int j) const
Get the lower bound between points i and j.
BoundsMatrix(unsigned int N)
BoundsMatrix(unsigned int N, DATA_SPTR data)
void setLowerBoundIfBetter(unsigned int i, unsigned int j, double val)
void setUpperBoundIfBetter(unsigned int i, unsigned int j, double val)
boost::shared_array< double > DATA_SPTR
void setLowerBound(unsigned int i, unsigned int j, double val)
Set the lower bound between points i and j.
bool checkValid() const
virtual double getVal(unsigned int i, unsigned int j) const
Definition Matrix.h:86
virtual void setVal(unsigned int i, unsigned int j, double val)
Definition Matrix.h:94
#define RDKIT_DISTGEOMETRY_EXPORT
Definition export.h:137
boost::shared_ptr< BoundsMatrix > BoundsMatPtr