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