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>
17
18namespace DistGeom {
19//! Class to store the distance bound
20/*!
21 Basically a N by N matrix
22 with lower distance bounds on the lower traingle and upper bounds in the upper
23 triangle
24*/
26 : public RDNumeric::SquareMatrix<double> {
27 public:
28 typedef boost::shared_array<double> DATA_SPTR;
29
30 explicit BoundsMatrix(unsigned int N)
31 : RDNumeric::SquareMatrix<double>(N, 0.0) {}
32 BoundsMatrix(unsigned int N, DATA_SPTR data)
33 : RDNumeric::SquareMatrix<double>(N, data) {}
34
35 //! Get the upper bound between points i and j
36 inline double getUpperBound(unsigned int i, unsigned int j) const {
37 if (i < j) {
38 return getVal(i, j);
39 } else {
40 return getVal(j, i);
41 }
42 }
43
44 //! Set the lower bound between points i and j
45 inline void setUpperBound(unsigned int i, unsigned int j, double val) {
46 CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
47 if (i < j) {
48 setVal(i, j, val);
49 } else {
50 setVal(j, i, val);
51 }
52 }
53
54 //! Set the upper bound between points i and j only if it is better than
55 //! previously existing value (i.e. the new value is smaller)
56 inline void setUpperBoundIfBetter(unsigned int i, unsigned int j,
57 double val) {
58 if ((val < getUpperBound(i, j)) && (val > getLowerBound(i, j))) {
59 setUpperBound(i, j, val);
60 }
61 }
62
63 //! Set the lower bound between points i and j
64 inline void setLowerBound(unsigned int i, unsigned int j, double val) {
65 CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
66 if (i < j) {
67 setVal(j, i, val);
68 } else {
69 setVal(i, j, val);
70 }
71 }
72
73 //! Set the lower bound between points i and j only if it is better than
74 //! previously existing value (i.e. the new value is larger)
75 inline void setLowerBoundIfBetter(unsigned int i, unsigned int j,
76 double val) {
77 if ((val > getLowerBound(i, j)) && (val < getUpperBound(i, j))) {
78 setLowerBound(i, j, val);
79 }
80 }
81
82 //! Get the lower bound between points i and j
83 inline double getLowerBound(unsigned int i, unsigned int j) const {
84 if (i < j) {
85 return getVal(j, i);
86 } else {
87 return getVal(i, j);
88 }
89 }
90
91 //! Do a simple check of the current bounds - i.e. all lower bounds are
92 //! smaller than the existing upper bounds
93 inline bool checkValid() const {
94 unsigned int i, j;
95 for (i = 1; i < d_nRows; i++) {
96 for (j = 0; j < i; j++) {
97 if (getUpperBound(i, j) < getLowerBound(i, j)) {
98 return false;
99 }
100 }
101 }
102 return true;
103 }
104};
105
106typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
107} // namespace DistGeom
108
109#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:94
virtual void setVal(unsigned int i, unsigned int j, double val)
Definition Matrix.h:102
#define RDKIT_DISTGEOMETRY_EXPORT
Definition export.h:171
boost::shared_ptr< BoundsMatrix > BoundsMatPtr