| 1 | /*
|
|---|
| 2 | * FunctionArgument.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: 02.10.2012
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef FUNCTIONARGUMENT_HPP_
|
|---|
| 9 | #define FUNCTIONARGUMENT_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | #include <utility>
|
|---|
| 17 | #include <iosfwd>
|
|---|
| 18 |
|
|---|
| 19 | /** This class encapsulates all information with respect to a single argument
|
|---|
| 20 | * for a high-dimensional model function.
|
|---|
| 21 | *
|
|---|
| 22 | * We restrict ourselves here to a function that dependent on a set of
|
|---|
| 23 | * three-dimensional vectors, i.e. a set of positions in space. And for
|
|---|
| 24 | * the moment to distances in between these sets.
|
|---|
| 25 | *
|
|---|
| 26 | */
|
|---|
| 27 | struct argument_t
|
|---|
| 28 | {
|
|---|
| 29 | //!> grant operator access to private parts
|
|---|
| 30 | friend std::ostream& operator<<(std::ostream &ost, const argument_t &arg);
|
|---|
| 31 |
|
|---|
| 32 | //!> typedef for the two indices of the argument
|
|---|
| 33 | typedef std::pair<size_t, size_t> indices_t;
|
|---|
| 34 | //!> typedef for the underlying type of the particle
|
|---|
| 35 | typedef unsigned int ParticleType_t;
|
|---|
| 36 | //!> typedef for the two particle types of the argument
|
|---|
| 37 | typedef std::pair<ParticleType_t, ParticleType_t> types_t;
|
|---|
| 38 |
|
|---|
| 39 | /** Default constructor for class argument_t.
|
|---|
| 40 | *
|
|---|
| 41 | */
|
|---|
| 42 | argument_t() :
|
|---|
| 43 | indices( std::make_pair(0,1) ),
|
|---|
| 44 | types( std::make_pair(0,0) ),
|
|---|
| 45 | distance(0.),
|
|---|
| 46 | globalid(-1),
|
|---|
| 47 | bonded(false)
|
|---|
| 48 | {}
|
|---|
| 49 |
|
|---|
| 50 | /** Constructor for class argument_t.
|
|---|
| 51 | *
|
|---|
| 52 | * This constructors uses the index pair (0,1) as default.
|
|---|
| 53 | *
|
|---|
| 54 | * \param _distance distance argument
|
|---|
| 55 | * \param _bonded is this a distance between bonded (true) or nonbonded (false) atoms
|
|---|
| 56 | */
|
|---|
| 57 | argument_t(const double &_distance, const bool _bonded = false) :
|
|---|
| 58 | indices( std::make_pair(0,1) ),
|
|---|
| 59 | types( std::make_pair(0,0) ),
|
|---|
| 60 | distance(_distance),
|
|---|
| 61 | globalid(-1),
|
|---|
| 62 | bonded(_bonded)
|
|---|
| 63 | {}
|
|---|
| 64 |
|
|---|
| 65 | /** Constructor for class argument_t.
|
|---|
| 66 | *
|
|---|
| 67 | * \param _indices pair of indices associated with the \a _distance
|
|---|
| 68 | * \param _distance distance argument
|
|---|
| 69 | * \param _bonded is this a distance between bonded (true) or nonbonded (false) atoms
|
|---|
| 70 | */
|
|---|
| 71 | argument_t(const indices_t &_indices, const double &_distance, const bool _bonded = false) :
|
|---|
| 72 | indices( _indices ),
|
|---|
| 73 | types( std::make_pair(0,0) ),
|
|---|
| 74 | distance(_distance),
|
|---|
| 75 | globalid(-1),
|
|---|
| 76 | bonded(_bonded)
|
|---|
| 77 | {}
|
|---|
| 78 |
|
|---|
| 79 | /** Constructor for class argument_t.
|
|---|
| 80 | *
|
|---|
| 81 | * \param _indices pair of indices associated with the \a _distance
|
|---|
| 82 | * \param _types pair of particle type
|
|---|
| 83 | * \param _distance distance argument
|
|---|
| 84 | * \param _bonded is this a distance between bonded (true) or nonbonded (false) atoms
|
|---|
| 85 | */
|
|---|
| 86 | argument_t(
|
|---|
| 87 | const indices_t &_indices,
|
|---|
| 88 | const types_t &_types,
|
|---|
| 89 | const double &_distance,
|
|---|
| 90 | const bool _bonded = false) :
|
|---|
| 91 | indices( _indices ),
|
|---|
| 92 | types( _types ),
|
|---|
| 93 | distance(_distance),
|
|---|
| 94 | globalid(-1),
|
|---|
| 95 | bonded(_bonded)
|
|---|
| 96 | {}
|
|---|
| 97 |
|
|---|
| 98 | /** Comparator with respect to the distance.
|
|---|
| 99 | *
|
|---|
| 100 | * \note We'll have this as static function to allow usage in e.g. STL's sort.
|
|---|
| 101 | *
|
|---|
| 102 | * \param one first argument
|
|---|
| 103 | * \param other other argument to compare to \a one to
|
|---|
| 104 | * \return true - first distance is less
|
|---|
| 105 | */
|
|---|
| 106 | static bool DistanceComparator(const argument_t &one, const argument_t &other)
|
|---|
| 107 | {
|
|---|
| 108 | return one.distance < other.distance;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | /** Comparator with respect to the pair of types.
|
|---|
| 112 | *
|
|---|
| 113 | * \note We'll have this as static function to allow usage in e.g. STL's sort.
|
|---|
| 114 | *
|
|---|
| 115 | * \param one first argument
|
|---|
| 116 | * \param other other argument to compare to \a one to
|
|---|
| 117 | * \return true - first type is less or if equal, second type is less, else
|
|---|
| 118 | */
|
|---|
| 119 | bool static TypeComparator(const argument_t &one, const argument_t &other)
|
|---|
| 120 | {
|
|---|
| 121 | if (one.types.first < other.types.first)
|
|---|
| 122 | return true;
|
|---|
| 123 | else if (one.types.first > other.types.first)
|
|---|
| 124 | return false;
|
|---|
| 125 | else
|
|---|
| 126 | return one.types.second < other.types.second;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /** Comparator with respect to the pair of indices.
|
|---|
| 130 | *
|
|---|
| 131 | * \note We'll have this as static function to allow usage in e.g. STL's sort.
|
|---|
| 132 | *
|
|---|
| 133 | * \param one first argument
|
|---|
| 134 | * \param other other argument to compare to \a one to
|
|---|
| 135 | * \return true - first index is less or if equal, second index is less, else
|
|---|
| 136 | */
|
|---|
| 137 | bool static IndexComparator(const argument_t &one, const argument_t &other)
|
|---|
| 138 | {
|
|---|
| 139 | if (one.indices.first < other.indices.first)
|
|---|
| 140 | return true;
|
|---|
| 141 | else if (one.indices.first > other.indices.first)
|
|---|
| 142 | return false;
|
|---|
| 143 | else
|
|---|
| 144 | return one.indices.second < other.indices.second;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | /** Less comparator for FunctionArgument.
|
|---|
| 148 | *
|
|---|
| 149 | * @param other other argument to compare to
|
|---|
| 150 | * @return true - this argument is less than \a other, false - else
|
|---|
| 151 | */
|
|---|
| 152 | bool operator<(const argument_t &other) const
|
|---|
| 153 | {
|
|---|
| 154 | if (types.first < other.types.first)
|
|---|
| 155 | return true;
|
|---|
| 156 | else if (types.first > other.types.first)
|
|---|
| 157 | return false;
|
|---|
| 158 | else if (types.second < other.types.second)
|
|---|
| 159 | return true;
|
|---|
| 160 | else if (types.second > other.types.second)
|
|---|
| 161 | return false;
|
|---|
| 162 | else {
|
|---|
| 163 | if (indices.first < other.indices.first)
|
|---|
| 164 | return true;
|
|---|
| 165 | else if (indices.first > other.indices.first)
|
|---|
| 166 | return false;
|
|---|
| 167 | else
|
|---|
| 168 | return indices.second < other.indices.second;
|
|---|
| 169 | }
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | /** Equality operator for FunctionArgument.
|
|---|
| 173 | *
|
|---|
| 174 | * \note This compares only types and indices.
|
|---|
| 175 | *
|
|---|
| 176 | * @param other other argument to compare to
|
|---|
| 177 | * @return true - this argument is equal to \a other, false - else
|
|---|
| 178 | */
|
|---|
| 179 | bool operator==(const argument_t &other) const
|
|---|
| 180 | {
|
|---|
| 181 | if (types.first != other.types.first)
|
|---|
| 182 | return false;
|
|---|
| 183 | else if (types.second != other.types.second)
|
|---|
| 184 | return false;
|
|---|
| 185 | if (indices.first != other.indices.first)
|
|---|
| 186 | return false;
|
|---|
| 187 | else if (indices.second != other.indices.second)
|
|---|
| 188 | return false;
|
|---|
| 189 | else
|
|---|
| 190 | return true;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | //!> indices between which the distance is given
|
|---|
| 194 | indices_t indices;
|
|---|
| 195 | //!> indices between which the distance is given
|
|---|
| 196 | types_t types;
|
|---|
| 197 | //!> distance
|
|---|
| 198 | double distance;
|
|---|
| 199 | //!> global id refers to some global index, e.g. the configuration id in training set
|
|---|
| 200 | size_t globalid;
|
|---|
| 201 | //!> states whether this argument is between bonded (true) or nonbonded (false) atoms
|
|---|
| 202 | bool bonded;
|
|---|
| 203 | };
|
|---|
| 204 |
|
|---|
| 205 | /** Print given \a arg to stream \a ost.
|
|---|
| 206 | *
|
|---|
| 207 | * \param ost output stream to print to
|
|---|
| 208 | * \param arg argument to print
|
|---|
| 209 | * \return output stream for concatenation
|
|---|
| 210 | */
|
|---|
| 211 | std::ostream& operator<<(std::ostream &ost, const argument_t &arg);
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 | #endif /* FUNCTIONARGUMENT_HPP_ */
|
|---|