|
@ -1,10 +1,3 @@ |
|
|
/* |
|
|
|
|
|
* vector.h |
|
|
|
|
|
* |
|
|
|
|
|
* Created on: 06.12.2012 |
|
|
|
|
|
* Author: Christian Dehnert |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#ifndef STORM_UTILITY_VECTOR_H_ |
|
|
#ifndef STORM_UTILITY_VECTOR_H_ |
|
|
#define STORM_UTILITY_VECTOR_H_ |
|
|
#define STORM_UTILITY_VECTOR_H_ |
|
|
|
|
|
|
|
@ -14,75 +7,68 @@ |
|
|
#include <algorithm> |
|
|
#include <algorithm> |
|
|
#include <functional> |
|
|
#include <functional> |
|
|
|
|
|
|
|
|
#include "log4cplus/logger.h" |
|
|
|
|
|
#include "log4cplus/loggingmacros.h" |
|
|
|
|
|
|
|
|
|
|
|
extern log4cplus::Logger logger; |
|
|
|
|
|
|
|
|
|
|
|
namespace storm { |
|
|
namespace storm { |
|
|
|
|
|
namespace utility { |
|
|
|
|
|
namespace vector { |
|
|
|
|
|
|
|
|
namespace utility { |
|
|
|
|
|
|
|
|
|
|
|
namespace vector { |
|
|
|
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Sets the provided values at the provided positions in the given vector. |
|
|
* Sets the provided values at the provided positions in the given vector. |
|
|
* |
|
|
* |
|
|
* @param vector The vector in which the values are to be set. |
|
|
* @param vector The vector in which the values are to be set. |
|
|
* @param positions The positions at which the values are to be set. |
|
|
* @param positions The positions at which the values are to be set. |
|
|
* @param values The values that are to be set. |
|
|
* @param values The values that are to be set. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void setVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<T> const& values) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void setVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<T> const& values) { |
|
|
uint_fast64_t oldPosition = 0; |
|
|
uint_fast64_t oldPosition = 0; |
|
|
for (auto position : positions) { |
|
|
for (auto position : positions) { |
|
|
vector[position] = values[oldPosition++]; |
|
|
vector[position] = values[oldPosition++]; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Sets the provided value at the provided positions in the given vector. |
|
|
* Sets the provided value at the provided positions in the given vector. |
|
|
* |
|
|
* |
|
|
* @param vector The vector in which the value is to be set. |
|
|
* @param vector The vector in which the value is to be set. |
|
|
* @param positions The positions at which the value is to be set. |
|
|
* @param positions The positions at which the value is to be set. |
|
|
* @param value The value that is to be set. |
|
|
* @param value The value that is to be set. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void setVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, T value) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void setVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, T value) { |
|
|
for (auto position : positions) { |
|
|
for (auto position : positions) { |
|
|
vector[position] = value; |
|
|
vector[position] = value; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Sets the provided value at the provided positions in the given vector. |
|
|
* Sets the provided value at the provided positions in the given vector. |
|
|
* |
|
|
* |
|
|
* @param vector The vector in which the value is to be set. |
|
|
* @param vector The vector in which the value is to be set. |
|
|
* @param positions The positions at which the value is to be set. |
|
|
* @param positions The positions at which the value is to be set. |
|
|
* @param value The value that is to be set. |
|
|
* @param value The value that is to be set. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void setVectorValues(Eigen::Matrix<T, -1, 1, 0, -1, 1>& eigenVector, storm::storage::BitVector const& positions, T value) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void setVectorValues(Eigen::Matrix<T, -1, 1, 0, -1, 1>& eigenVector, storm::storage::BitVector const& positions, T value) { |
|
|
for (auto position : positions) { |
|
|
for (auto position : positions) { |
|
|
eigenVector(position, 0) = value; |
|
|
eigenVector(position, 0) = value; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Selects the elements from a vector at the specified positions and writes them consecutively into another vector. |
|
|
* Selects the elements from a vector at the specified positions and writes them consecutively into another vector. |
|
|
* @param vector The vector into which the selected elements are to be written. |
|
|
* @param vector The vector into which the selected elements are to be written. |
|
|
* @param positions The positions at which to select the elements from the values vector. |
|
|
* @param positions The positions at which to select the elements from the values vector. |
|
|
* @param values The vector from which to select the elements. |
|
|
* @param values The vector from which to select the elements. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<T> const& values) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<T> const& values) { |
|
|
uint_fast64_t oldPosition = 0; |
|
|
uint_fast64_t oldPosition = 0; |
|
|
for (auto position : positions) { |
|
|
for (auto position : positions) { |
|
|
vector[oldPosition++] = values[position]; |
|
|
vector[oldPosition++] = values[position]; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Selects groups of elements from a vector at the specified positions and writes them consecutively into another vector. |
|
|
* Selects groups of elements from a vector at the specified positions and writes them consecutively into another vector. |
|
|
* |
|
|
* |
|
|
* @param vector The vector into which the selected elements are to be written. |
|
|
* @param vector The vector into which the selected elements are to be written. |
|
@ -90,17 +76,17 @@ void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the values vector. |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the values vector. |
|
|
* @param values The vector from which to select groups of elements. |
|
|
* @param values The vector from which to select groups of elements. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<uint_fast64_t> const& rowGrouping, std::vector<T> const& values) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<uint_fast64_t> const& rowGrouping, std::vector<T> const& values) { |
|
|
uint_fast64_t oldPosition = 0; |
|
|
uint_fast64_t oldPosition = 0; |
|
|
for (auto position : positions) { |
|
|
for (auto position : positions) { |
|
|
for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i) { |
|
|
for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i) { |
|
|
vector[oldPosition++] = values[i]; |
|
|
vector[oldPosition++] = values[i]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Selects one element out of each row group and writes it to the target vector. |
|
|
* Selects one element out of each row group and writes it to the target vector. |
|
|
* |
|
|
* |
|
|
* @param vector The target vector to which the values are written. |
|
|
* @param vector The target vector to which the values are written. |
|
@ -109,15 +95,15 @@ void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the values vector. |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the values vector. |
|
|
* @param values The vector from which to select the values. |
|
|
* @param values The vector from which to select the values. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void selectVectorValues(std::vector<T>& vector, std::vector<uint_fast64_t> const& rowGroupToRowIndexMapping, std::vector<uint_fast64_t> const& rowGrouping, std::vector<T> const& values) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void selectVectorValues(std::vector<T>& vector, std::vector<uint_fast64_t> const& rowGroupToRowIndexMapping, std::vector<uint_fast64_t> const& rowGrouping, std::vector<T> const& values) { |
|
|
uint_fast64_t oldPosition = 0; |
|
|
uint_fast64_t oldPosition = 0; |
|
|
for (uint_fast64_t i = 0; i < vector.size(); ++i) { |
|
|
for (uint_fast64_t i = 0; i < vector.size(); ++i) { |
|
|
vector[i] = values[rowGrouping[i] + rowGroupToRowIndexMapping[i]]; |
|
|
vector[i] = values[rowGrouping[i] + rowGroupToRowIndexMapping[i]]; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Selects values from a vector at the specified positions and writes them into another vector as often as given by |
|
|
* Selects values from a vector at the specified positions and writes them into another vector as often as given by |
|
|
* the size of the corresponding group of elements. |
|
|
* the size of the corresponding group of elements. |
|
|
* |
|
|
* |
|
@ -126,45 +112,45 @@ void selectVectorValues(std::vector<T>& vector, std::vector<uint_fast64_t> const |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the values vector. This |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the values vector. This |
|
|
* implicitly defines the number of times any element is written to the output vector. |
|
|
* implicitly defines the number of times any element is written to the output vector. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void selectVectorValuesRepeatedly(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<uint_fast64_t> const& rowGrouping, std::vector<T> const& values) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void selectVectorValuesRepeatedly(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<uint_fast64_t> const& rowGrouping, std::vector<T> const& values) { |
|
|
uint_fast64_t oldPosition = 0; |
|
|
uint_fast64_t oldPosition = 0; |
|
|
for (auto position : positions) { |
|
|
for (auto position : positions) { |
|
|
for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i) { |
|
|
for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i) { |
|
|
vector[oldPosition++] = values[position]; |
|
|
vector[oldPosition++] = values[position]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Subtracts the given vector from the constant one-vector and writes the result to the input vector. |
|
|
* Subtracts the given vector from the constant one-vector and writes the result to the input vector. |
|
|
* |
|
|
* |
|
|
* @param vector The vector that is to be subtracted from the constant one-vector. |
|
|
* @param vector The vector that is to be subtracted from the constant one-vector. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void subtractFromConstantOneVector(std::vector<T>& vector) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void subtractFromConstantOneVector(std::vector<T>& vector) { |
|
|
for (auto& element : vector) { |
|
|
for (auto& element : vector) { |
|
|
element = storm::utility::constGetOne<T>() - element; |
|
|
element = storm::utility::constGetOne<T>() - element; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Adds the two given vectors and writes the result into the first operand. |
|
|
* Adds the two given vectors and writes the result into the first operand. |
|
|
* |
|
|
* |
|
|
* @param target The first summand and target vector. |
|
|
* @param target The first summand and target vector. |
|
|
* @param summand The second summand. |
|
|
* @param summand The second summand. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void addVectorsInPlace(std::vector<T>& target, std::vector<T> const& summand) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void addVectorsInPlace(std::vector<T>& target, std::vector<T> const& summand) { |
|
|
if (target.size() != summand.size()) { |
|
|
if (target.size() != summand.size()) { |
|
|
LOG4CPLUS_ERROR(logger, "Lengths of vectors do not match, which makes operation impossible."); |
|
|
LOG4CPLUS_ERROR(logger, "Lengths of vectors do not match, which makes operation impossible."); |
|
|
throw storm::exceptions::InvalidArgumentException() << "Length of vectors do not match, which makes operation impossible."; |
|
|
throw storm::exceptions::InvalidArgumentException() << "Length of vectors do not match, which makes operation impossible."; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::transform(target.begin(), target.end(), summand.begin(), target.begin(), std::plus<T>()); |
|
|
std::transform(target.begin(), target.end(), summand.begin(), target.begin(), std::plus<T>()); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Reduces the given source vector by selecting an element according to the given filter out of each row group. |
|
|
* Reduces the given source vector by selecting an element according to the given filter out of each row group. |
|
|
* |
|
|
* |
|
|
* @param source The source vector which is to be reduced. |
|
|
* @param source The source vector which is to be reduced. |
|
@ -174,8 +160,8 @@ void addVectorsInPlace(std::vector<T>& target, std::vector<T> const& summand) { |
|
|
* return true iff v1 is supposed to be taken instead of v2. |
|
|
* return true iff v1 is supposed to be taken instead of v2. |
|
|
* @param choices If non-null, this vector is used to store the choices made during the selection. |
|
|
* @param choices If non-null, this vector is used to store the choices made during the selection. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void reduceVector(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping, std::function<bool (T const&, T const&)> filter, std::vector<uint_fast64_t>* choices = nullptr) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void reduceVector(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping, std::function<bool (T const&, T const&)> filter, std::vector<uint_fast64_t>* choices = nullptr) { |
|
|
uint_fast64_t currentSourceRow = 0; |
|
|
uint_fast64_t currentSourceRow = 0; |
|
|
uint_fast64_t currentTargetRow = -1; |
|
|
uint_fast64_t currentTargetRow = -1; |
|
|
uint_fast64_t currentLocalRow = 0; |
|
|
uint_fast64_t currentLocalRow = 0; |
|
@ -199,9 +185,9 @@ void reduceVector(std::vector<T> const& source, std::vector<T>& target, std::vec |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Reduces the given source vector by selecting the smallest element out of each row group. |
|
|
* Reduces the given source vector by selecting the smallest element out of each row group. |
|
|
* |
|
|
* |
|
|
* @param source The source vector which is to be reduced. |
|
|
* @param source The source vector which is to be reduced. |
|
@ -209,12 +195,12 @@ void reduceVector(std::vector<T> const& source, std::vector<T>& target, std::vec |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the source vector. |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the source vector. |
|
|
* @param choices If non-null, this vector is used to store the choices made during the selection. |
|
|
* @param choices If non-null, this vector is used to store the choices made during the selection. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void reduceVectorMin(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping, std::vector<uint_fast64_t>* choices = nullptr) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void reduceVectorMin(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping, std::vector<uint_fast64_t>* choices = nullptr) { |
|
|
reduceVector<T>(source, target, rowGrouping, std::less<T>(), choices); |
|
|
reduceVector<T>(source, target, rowGrouping, std::less<T>(), choices); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Reduces the given source vector by selecting the largest element out of each row group. |
|
|
* Reduces the given source vector by selecting the largest element out of each row group. |
|
|
* |
|
|
* |
|
|
* @param source The source vector which is to be reduced. |
|
|
* @param source The source vector which is to be reduced. |
|
@ -222,12 +208,12 @@ void reduceVectorMin(std::vector<T> const& source, std::vector<T>& target, std:: |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the source vector. |
|
|
* @param rowGrouping A vector that specifies the begin and end of each group of elements in the source vector. |
|
|
* @param choices If non-null, this vector is used to store the choices made during the selection. |
|
|
* @param choices If non-null, this vector is used to store the choices made during the selection. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
void reduceVectorMax(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping, std::vector<uint_fast64_t>* choices = nullptr) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
void reduceVectorMax(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping, std::vector<uint_fast64_t>* choices = nullptr) { |
|
|
reduceVector<T>(source, target, rowGrouping, std::greater<T>(), choices); |
|
|
reduceVector<T>(source, target, rowGrouping, std::greater<T>(), choices); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Compares the given elements and determines whether they are equal modulo the given precision. The provided flag |
|
|
* Compares the given elements and determines whether they are equal modulo the given precision. The provided flag |
|
|
* additionaly specifies whether the error is computed in relative or absolute terms. |
|
|
* additionaly specifies whether the error is computed in relative or absolute terms. |
|
|
* |
|
|
* |
|
@ -237,17 +223,17 @@ void reduceVectorMax(std::vector<T> const& source, std::vector<T>& target, std:: |
|
|
* @param relativeError If set, the error is computed relative to the second value. |
|
|
* @param relativeError If set, the error is computed relative to the second value. |
|
|
* @return True iff the elements are considered equal. |
|
|
* @return True iff the elements are considered equal. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
bool equalModuloPrecision(T const& val1, T const& val2, T precision, bool relativeError = true) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
bool equalModuloPrecision(T const& val1, T const& val2, T precision, bool relativeError = true) { |
|
|
if (relativeError) { |
|
|
if (relativeError) { |
|
|
if (std::abs(val1 - val2)/val2 > precision) return false; |
|
|
if (std::abs(val1 - val2)/val2 > precision) return false; |
|
|
} else { |
|
|
} else { |
|
|
if (std::abs(val1 - val2) > precision) return false; |
|
|
if (std::abs(val1 - val2) > precision) return false; |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Compares the two vectors and determines whether they are equal modulo the provided precision. Depending on whether the |
|
|
* Compares the two vectors and determines whether they are equal modulo the provided precision. Depending on whether the |
|
|
* flag is set, the difference between the vectors is computed relative to the value or in absolute terms. |
|
|
* flag is set, the difference between the vectors is computed relative to the value or in absolute terms. |
|
|
* |
|
|
* |
|
@ -256,8 +242,8 @@ bool equalModuloPrecision(T const& val1, T const& val2, T precision, bool relati |
|
|
* @param precision The precision up to which the vectors are to be checked for equality. |
|
|
* @param precision The precision up to which the vectors are to be checked for equality. |
|
|
* @param relativeError If set, the difference between the vectors is computed relative to the value or in absolute terms. |
|
|
* @param relativeError If set, the difference between the vectors is computed relative to the value or in absolute terms. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight, T precision, bool relativeError) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight, T precision, bool relativeError) { |
|
|
if (vectorLeft.size() != vectorRight.size()) { |
|
|
if (vectorLeft.size() != vectorRight.size()) { |
|
|
LOG4CPLUS_ERROR(logger, "Lengths of vectors do not match, which makes comparison impossible."); |
|
|
LOG4CPLUS_ERROR(logger, "Lengths of vectors do not match, which makes comparison impossible."); |
|
|
throw storm::exceptions::InvalidArgumentException() << "Lengths of vectors do not match, which makes comparison impossible."; |
|
|
throw storm::exceptions::InvalidArgumentException() << "Lengths of vectors do not match, which makes comparison impossible."; |
|
@ -270,9 +256,9 @@ bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
|
|
|
/*! |
|
|
* Compares the two vectors at the specified positions and determines whether they are equal modulo the provided |
|
|
* Compares the two vectors at the specified positions and determines whether they are equal modulo the provided |
|
|
* precision. Depending on whether the flag is set, the difference between the vectors is computed relative to the value |
|
|
* precision. Depending on whether the flag is set, the difference between the vectors is computed relative to the value |
|
|
* or in absolute terms. |
|
|
* or in absolute terms. |
|
@ -283,8 +269,8 @@ bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const |
|
|
* @param positions A vector representing a set of positions at which the vectors are compared. |
|
|
* @param positions A vector representing a set of positions at which the vectors are compared. |
|
|
* @param relativeError If set, the difference between the vectors is computed relative to the value or in absolute terms. |
|
|
* @param relativeError If set, the difference between the vectors is computed relative to the value or in absolute terms. |
|
|
*/ |
|
|
*/ |
|
|
template<class T> |
|
|
|
|
|
bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight, std::vector<uint_fast64_t> const& positions, T precision, bool relativeError) { |
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight, std::vector<uint_fast64_t> const& positions, T precision, bool relativeError) { |
|
|
if (vectorLeft.size() != vectorRight.size()) { |
|
|
if (vectorLeft.size() != vectorRight.size()) { |
|
|
LOG4CPLUS_ERROR(logger, "Lengths of vectors do not match, which makes comparison impossible."); |
|
|
LOG4CPLUS_ERROR(logger, "Lengths of vectors do not match, which makes comparison impossible."); |
|
|
throw storm::exceptions::InvalidArgumentException() << "Lengths of vectors do not match, which makes comparison impossible."; |
|
|
throw storm::exceptions::InvalidArgumentException() << "Lengths of vectors do not match, which makes comparison impossible."; |
|
@ -297,12 +283,42 @@ bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*! |
|
|
|
|
|
* Takes the given offset vector and applies the given contraint. That is, it produces another offset vector that contains |
|
|
|
|
|
* the relative offsets of the entries given by the constraint. |
|
|
|
|
|
* |
|
|
|
|
|
* @param offsetVector The offset vector to constrain. |
|
|
|
|
|
* @param constraint The constraint to apply to the offset vector. |
|
|
|
|
|
* @return An offset vector that contains all selected relative offsets. |
|
|
|
|
|
*/ |
|
|
|
|
|
template<class T> |
|
|
|
|
|
std::vector<T> getConstrainedOffsetVector(std::vector<T> const& offsetVector, storm::storage::BitVector const& constraint) { |
|
|
|
|
|
// Reserve the known amount of slots for the resulting vector. |
|
|
|
|
|
std::vector<uint_fast64_t> subVector(constraint.getNumberOfSetBits() + 1); |
|
|
|
|
|
uint_fast64_t currentRowCount = 0; |
|
|
|
|
|
uint_fast64_t currentIndexCount = 1; |
|
|
|
|
|
|
|
|
|
|
|
// Set the first element as this will clearly begin at offset 0. |
|
|
|
|
|
subVector[0] = 0; |
|
|
|
|
|
|
|
|
|
|
|
// Loop over all states that need to be kept and copy the relative indices of the nondeterministic choices over |
|
|
|
|
|
// to the resulting vector. |
|
|
|
|
|
for (auto index : constraint) { |
|
|
|
|
|
subVector[currentIndexCount] = currentRowCount + offsetVector[index + 1] - offsetVector[index]; |
|
|
|
|
|
currentRowCount += offsetVector[index + 1] - offsetVector[index]; |
|
|
|
|
|
++currentIndexCount; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} // namespace vector |
|
|
|
|
|
|
|
|
// Put a sentinel element at the end. |
|
|
|
|
|
subVector[constraint.getNumberOfSetBits()] = currentRowCount; |
|
|
|
|
|
|
|
|
} // namespace utility |
|
|
|
|
|
|
|
|
return subVector; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace vector |
|
|
|
|
|
} // namespace utility |
|
|
} // namespace storm |
|
|
} // namespace storm |
|
|
|
|
|
|
|
|
#endif /* STORM_UTILITY_VECTOR_H_ */ |
|
|
#endif /* STORM_UTILITY_VECTOR_H_ */ |