Browse Source

Merge branch 'master' of https://sselab.de/lab9/private/git/storm

Former-commit-id: 9a24cdd3e6
tempestpy_adaptions
dehnert 9 years ago
parent
commit
53524c3c6e
  1. 41
      src/utility/vector.h
  2. 19
      test/functional/utility/VectorTest.cpp

41
src/utility/vector.h

@ -366,6 +366,47 @@ namespace storm {
return sum;
}
/**
* Computes the maximum of the entries from the values that are set to one in the filter vector
* @param values
* @param filter
* @param smallestPossibleValue A value which is not larger than any value in values. If the filter is empty, this value is returned.
* @return The maximum over the subset of the values and the smallestPossibleValue.
*/
template<typename VT>
VT max_if(std::vector<VT> const& values, storm::storage::BitVector const& filter, VT const& smallestPossibleValue) {
assert(values.size() >= filter.size());
VT max = smallestPossibleValue;
for(uint_fast64_t i : filter) {
if(values[i] > max) {
max = values[i];
}
}
return max;
}
/**
* Computes the minimum of the entries from the values that are set to one in the filter vector
* @param values
* @param filter
* @param largestPossibleValue A value which is not smaller than any value in values. If the filter is empty, this value is returned.
* @return The minimum over the subset of the values and the largestPossibleValue.
*/
template<typename VT>
VT min_if(std::vector<VT> const& values, storm::storage::BitVector const& filter, VT const& largestPossibleValue) {
assert(values.size() >= filter.size());
VT min = largestPossibleValue;
for(uint_fast64_t i : filter) {
if(values[i] < min) {
min = values[i];
}
}
return min;
}
/*!
* Reduces the given source vector by selecting an element according to the given filter out of each row group.
*

19
test/functional/utility/VectorTest.cpp

@ -12,3 +12,22 @@ TEST(VectorTest, sum_if) {
ASSERT_EQ(24.0, storm::utility::vector::sum_if(a, f2));
}
TEST(VectorTest, max_if) {
std::vector<double> a = {1.0, 2.0, 34.0, 8.0, 16.0};
storm::storage::BitVector f1(5, {2,4});
storm::storage::BitVector f2(5, {3,4});
ASSERT_EQ(34.0, storm::utility::vector::max_if(a,f1,0.0));
ASSERT_EQ(16.0, storm::utility::vector::max_if(a,f2,0.0));
}
TEST(VectorTest, min_if) {
std::vector<double> a = {1.0, 2.0, 34.0, 8.0, 16.0};
storm::storage::BitVector f1(5, {2,4});
storm::storage::BitVector f2(5, {3,4});
ASSERT_EQ(16.0, storm::utility::vector::min_if(a,f1,100.0));
ASSERT_EQ(8.0, storm::utility::vector::min_if(a,f2,100.0));
}
Loading…
Cancel
Save