File: BoundsMatrix.h

package info (click to toggle)
rdkit 201203-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 37,840 kB
  • sloc: cpp: 93,902; python: 51,897; java: 5,192; ansic: 3,497; xml: 2,499; sql: 1,641; yacc: 1,518; lex: 1,076; makefile: 325; fortran: 183; sh: 153; cs: 51
file content (117 lines) | stat: -rw-r--r-- 3,513 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
//  Copyright (C) 2004-2006 Rational Discovery LLC
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#ifndef __RD_BOUNDS_MATRIX_H__
#define __RD_BOUNDS_MATRIX_H__

#include <RDGeneral/Invariant.h>
#include <boost/smart_ptr.hpp>
#include <iostream>
#include <iomanip>
#include <Numerics/SquareMatrix.h>

namespace DistGeom {
  //! Class to store the distance bound
  /*! 
    Basically a N by N matrix 
    with lower distance bounds on the lower traingle and upper bounds in the upper 
    triangle
  */
  class BoundsMatrix : public RDNumeric::SquareMatrix<double> {
  public:
    typedef boost::shared_array<double> DATA_SPTR;

    explicit BoundsMatrix(unsigned int N) : RDNumeric::SquareMatrix<double>(N,0.0) {}; 
    BoundsMatrix(unsigned int N, DATA_SPTR data) : 
      RDNumeric::SquareMatrix<double>(N,data) {}; 

    //! Get the upper bound between points i and j
    inline double getUpperBound(unsigned int i, unsigned int j) const {
      RANGE_CHECK(0, i, d_nRows-1);
      RANGE_CHECK(0, j, d_nCols-1);

      if (i < j) {
        return getVal(i,j);
      } else {
        return getVal(j,i);
      }
    }
    
    //! Set the lower bound between points i and j
    inline void setUpperBound(unsigned int i, unsigned int j, double val) {
      RANGE_CHECK(0, i, d_nRows-1);
      RANGE_CHECK(0, j, d_nCols-1);
      CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
      if (i < j) {
        setVal(i,j,val);
      } else {
        setVal(j,i,val);
      }
    }
    
    //! Set the upper bound between points i and j only if it is better than 
    //! previously existing value (i.e. the new value is smaller)
    inline void setUpperBoundIfBetter(unsigned int i, unsigned int j, double val) {
      if ((val < getUpperBound(i, j)) && (val > getLowerBound(i, j)) ) {
        setUpperBound(i, j, val);
      }
    }

    //! Set the lower bound between points i and j 
    inline void setLowerBound(unsigned int i, unsigned int j, double val) {
      RANGE_CHECK(0, i, d_nRows-1);
      RANGE_CHECK(0, j, d_nCols-1);
      CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
      if (i < j) {
        setVal(j,i,val);
      } else {
        setVal(i,j,val);
      }
    }
    
    //! Set the lower bound between points i and j only if it is better than 
    //! previously existing value (i.e. the new value is larger)
    inline void setLowerBoundIfBetter(unsigned int i, unsigned int j, double val) {
      if ((val > getLowerBound(i,j)) && (val < getUpperBound(i,j))) {
        setLowerBound(i,j, val);
      } 
    } 
    
    //! Get the lower bound between points i and j
    inline double getLowerBound(unsigned int i, unsigned int j) const {
      RANGE_CHECK(0, i, d_nRows-1);
      RANGE_CHECK(0, j, d_nCols-1);

      if (i < j) {
        return getVal(j,i);
      } else {
        return getVal(i,j);
      }
    }

    //! Do a simple check of the current bounds - i.e. all lower bounds are
    //! smaller than the existing upper bounds
    inline bool checkValid() const {
      unsigned int i, j;
      for (i = 1; i < d_nRows; i++) {
        for (j = 0; j < i; j++) {
          if (getUpperBound(i,j) < getLowerBound(i,j)) {
            return false;
          }
        }
      }
      return true;
    }
  }; 

  typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
}

#endif