RepastHPC
2.3.1
|
A RelativeLocation is a vector of integers that express a relative location in a coordinate system; this is generally used in an MPI Cartesian Topology. More...
#include <RelativeLocation.h>
Public Member Functions | |
RelativeLocation (int dimensions) | |
Default constructor; min values are all -1, max values are all 1, for the specified number of dimensions. | |
RelativeLocation (vector< int > minima, vector< int > maxima) | |
Constructor that takes specific minima and maxima. More... | |
RelativeLocation (const RelativeLocation &original) | |
Copy Constructor. | |
void | translate (vector< int > displacement) |
bool | increment () |
bool | increment (bool skipZero) |
bool | set (vector< int > newValues) |
Set the current value. More... | |
bool | equals (RelativeLocation other) |
Returns true if the current value for the other instance is equal to this one; does NOT compare minima or maxima. More... | |
vector< int > | getCurrentValue () |
Gets the array of current values. | |
int | operator[] (int index) |
Gets the current value at the specified index. | |
int | getCountOfDimensions () |
Returns the count of dimensions. | |
int | getMaxIndex () |
Gets the maximum index value; this will be one less than the total number of values. | |
int | getTotalValues () |
Gets the total number of relative location values (including the center spot) | |
int | getIndex (vector< int > value) |
Gets the index value associated with the specified position. | |
int | getIndex () |
Gets the index value associated with the current position. | |
int | getIndexOfCenter () |
Gets the index value of the 0,0,0... More... | |
bool | validNonCenter () |
Returns false when the values are all zeroes, true otherwise. | |
int | getMinimumAt (int index) |
Gets the lower bound in the specified dimension. | |
int | getMaximumAt (int index) |
Gets the upper bound in the specified dimension. More... | |
RelativeLocation | trim (RelativeLocation toBeTrimmed) |
Returns a new RelativeLocation object based on the one passed, but trimmed so that it fits within the boundaries of this one. More... | |
std::string | report () |
Gets a string describing this object for human-readable output. | |
Static Public Member Functions | |
static int | getDirectionIndex (vector< int > dirVec) |
Assumes that the vector given can be reduced to a 'unit' vector (in which all values are either -1, 0, or 1); returns the index value of this vector assuming a RelativeLocation with minima of -1, -,1 -1, ... More... | |
static int | getReverseDirectionIndex (vector< int > dirVec) |
Assumes that the vector given can be reduced to a 'unit' vector (in which all values are either -1, 0, or 1); returns the index value of the negative of this vector (all values multiplied by -1), assuming a RelativeLocation with minima of -1, -,1 -1, ... More... | |
A RelativeLocation is a vector of integers that express a relative location in a coordinate system; this is generally used in an MPI Cartesian Topology.
A vector might look like:
[ -1, -1, 1 ]
which would indicate one unit to the 'left' in the x dimension, one to the 'left' in the y dimension, and one to the 'right' in the z dimension.
This class can be 'incremented' so that it advances through a series of relative locations in a fixed and predictable order. The boundaries can be customized so that the range of possible values in any dimension is settable; by default it is [-1, 1] (inclusive) in all dimensions, meaning, roughly, 'left, center, right'. However, different values can be used, e.g.:
minima: [-2, -1, -2] maxima: [1, 2, 3]
This would describe a volume of space ranging from -2 to 1 in the x dimension, -1 to 2 in the y dimension, and -2 to 3 in the z dimension. A typical use when incrementing would be to start at the lowest value [-2, -1, -2] and loop through all possible variants:
[ -2, -1, -2 ] [ -1, -1, -2 ] [ 0, -1, -2 ] [ 1, -1, -2 ] [ -2, 0, -2 ] [ -1, 0, -2 ] [ 0, 0, -2 ] [ 1, 0, -2 ] [ -2, 1, -2 ] [ -1, 1, -2 ] [ 0, 1, -2 ] [ 1, 1, -2 ] [ -2, 2, -2 ] [ -1, 2, -2 ] [ 0, 2, -2 ] [ 1, 2, -2 ] [ -2, -1, -1 ] [ -1, -1, -1 ] [ 0, -1, -1 ] [ 1, -1, -1 ] ... [ 0, 2, 3 ] [ 1, 2, 3 ]
repast::RelativeLocation::RelativeLocation | ( | vector< int > | minima, |
vector< int > | maxima | ||
) |
Constructor that takes specific minima and maxima.
Current Value is set to the minima Note that if any maximum value is less than the corresponding minimum value, it will be reset to match the minimum value. If the minima and maxima vectors are of different sizes, the shorter vector size is used and the extra values in the longer one are ignored.
bool repast::RelativeLocation::equals | ( | RelativeLocation | other | ) |
Returns true if the current value for the other instance is equal to this one; does NOT compare minima or maxima.
Note: if the two instances are different sizes, only the first N values are compared, where N is the size of the shorter instance.
|
static |
Assumes that the vector given can be reduced to a 'unit' vector (in which all values are either -1, 0, or 1); returns the index value of this vector assuming a RelativeLocation with minima of -1, -,1 -1, ...
and maxima of 1, 1, 1.
int repast::RelativeLocation::getIndexOfCenter | ( | ) |
Gets the index value of the 0,0,0...
position
int repast::RelativeLocation::getMaximumAt | ( | int | index | ) |
Gets the upper bound in the specified dimension.
|
static |
Assumes that the vector given can be reduced to a 'unit' vector (in which all values are either -1, 0, or 1); returns the index value of the negative of this vector (all values multiplied by -1), assuming a RelativeLocation with minima of -1, -,1 -1, ...
and maxima of 1, 1, 1.
bool repast::RelativeLocation::set | ( | vector< int > | newValues | ) |
Set the current value.
Will return false if the number of dimensions does not match the existing value, or if any of the new values are out of the ranges defined by the minima and maxima vectors.
RelativeLocation repast::RelativeLocation::trim | ( | RelativeLocation | toBeTrimmed | ) |
Returns a new RelativeLocation object based on the one passed, but trimmed so that it fits within the boundaries of this one.
If the result would be invalid (because the one to be trimmed falls outside of this one) the return value will be a RelativeLocation with the original number of dimensions, but all zeroes in the values.
Trimming is done only on the first N dimensions, where N is the smaller of the number of dimensions in this or the passed RelativeLocation; extra dimensions are ignored