1#ifndef STORM_UTILITY_VECTOR_H_
2#define STORM_UTILITY_VECTOR_H_
10#include <boost/optional.hpp>
23template<
typename ValueType>
25 size_t operator()(std::vector<ValueType>
const& vec)
const {
26 std::hash<ValueType> hasher;
28 for (ValueType
const& element : vec) {
29 seed ^= hasher(element) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
49 std::size_t position = std::find(vector.begin(), vector.end(), element) - vector.begin();
50 if (position == vector.size()) {
51 vector.emplace_back(std::move(element));
58 T
const& negativeValue = storm::utility::zero<T>()) {
60 vec.resize(positions.
size(), positiveValue);
62 while (index < positions.
size()) {
63 vec[index] = negativeValue;
67 vec.resize(positions.
size(), negativeValue);
68 for (uint64_t index : positions) {
69 vec[index] = positiveValue;
83 STORM_LOG_ASSERT(positions.
size() <= vector.size(),
"We cannot set positions that have not been initialized");
85 <<
") exceeds the size of the input vector ("
86 << values.size() <<
").");
87 uint_fast64_t oldPosition = 0;
88 for (
auto position : positions) {
89 vector[position] = values[oldPosition++];
103 STORM_LOG_ASSERT(positions.
size() <= vector.size(),
"We cannot set positions that have not been initialized");
104 for (
auto position : positions) {
105 vector[position] = value;
112 for (uint64_t i = 0; i < vec.size(); ++i) {
124template<
class OutputIterator,
class Size,
class Assignable>
125void iota_n(OutputIterator first, Size n, Assignable value) {
126 std::generate_n(first, n, [&value]() {
return value++; });
138 iota_n(std::back_inserter(v), diff,
min);
149 std::vector<uint_fast64_t> res = buildVectorForRange<uint_fast64_t>(0, v.size());
150 std::sort(res.begin(), res.end(), [&v](uint_fast64_t index1, uint_fast64_t index2) { return v[index1] > v[index2]; });
163 auto indexIt = sortedIndices.begin();
164 T
const* previous = &v[*indexIt];
165 for (++indexIt; indexIt != sortedIndices.end(); ++indexIt) {
166 T
const& current = v[*indexIt];
167 if (current == *previous) {
175template<
typename T,
typename Comparator>
176bool compareElementWise(std::vector<T>
const& left, std::vector<T>
const& right, Comparator comp = std::less<T>()) {
177 STORM_LOG_ASSERT(left.size() == right.size(),
"Expected that vectors for comparison have equal size");
178 return std::equal(left.begin(), left.end(), right.begin(), comp);
190 <<
") exceeds the size of the target vector ("
191 << vector.size() <<
").");
193 "Size mismatch of the positions vector (" << positions.
size() <<
") and the values vector (" << values.size() <<
").");
194 auto targetIt = vector.begin();
195 for (
auto position : positions) {
196 *targetIt = values[position];
211 std::vector<T>
const& values) {
212 auto targetIt = vector.begin();
213 for (
auto position : positions) {
214 for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i, ++targetIt) {
215 *targetIt = values[i];
230void selectVectorValues(std::vector<T>& vector, std::vector<uint_fast64_t>
const& rowGroupToRowIndexMapping, std::vector<uint_fast64_t>
const& rowGrouping,
231 std::vector<T>
const& values) {
232 auto targetIt = vector.begin();
233 for (uint_fast64_t i = 0; i < vector.size(); ++i, ++targetIt) {
234 *targetIt = values[rowGrouping[i] + rowGroupToRowIndexMapping[i]];
246void selectVectorValues(std::vector<T>& vector, std::vector<uint_fast64_t>
const& indexSequence, std::vector<T>
const& values) {
248 "The number of selected positions (" << indexSequence.size() <<
") exceeds the size of the target vector (" << vector.size() <<
").");
250 for (uint_fast64_t vectorIndex = 0; vectorIndex < vector.size(); ++vectorIndex) {
251 vector[vectorIndex] = values[indexSequence[vectorIndex]];
266 std::vector<T>
const& values) {
267 auto targetIt = vector.begin();
268 for (
auto position : positions) {
269 for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i, ++targetIt) {
270 *targetIt = values[position];
282 for (
auto& element : vector) {
283 element = storm::utility::one<T>() - element;
289 std::vector<uint_fast64_t>
const& rowGroupIndices) {
290 auto targetIt = target.begin();
291 for (
auto group :
filter) {
292 auto it = source.cbegin() + rowGroupIndices[group];
293 auto ite = source.cbegin() + rowGroupIndices[group + 1];
294 for (; it != ite; ++targetIt, ++it) {
309void addVectorToGroupedVector(std::vector<T>& target, std::vector<T>
const& source, std::vector<uint_fast64_t>
const& rowGroupIndices) {
310 auto targetIt = target.begin();
311 auto sourceIt = source.cbegin();
312 auto sourceIte = source.cend();
313 auto rowGroupIt = rowGroupIndices.cbegin();
315 for (; sourceIt != sourceIte; ++sourceIt) {
316 uint_fast64_t current = *rowGroupIt;
318 uint_fast64_t next = *rowGroupIt;
319 for (; current < next; ++targetIt, ++current) {
320 *targetIt += *sourceIt;
335 std::vector<uint_fast64_t>
const& rowGroupIndices) {
336 auto targetIt = target.begin();
337 for (
auto group :
filter) {
338 uint_fast64_t current = rowGroupIndices[group];
339 uint_fast64_t next = rowGroupIndices[group + 1];
340 for (; current < next; ++current, ++targetIt) {
341 *targetIt += source[group];
354template<
class InValueType1,
class InValueType2,
class OutValueType,
class Operation>
355void applyPointwiseTernary(std::vector<InValueType1>
const& firstOperand, std::vector<InValueType2>
const& secondOperand, std::vector<OutValueType>& target,
356 Operation f = Operation()) {
357 auto firstIt = firstOperand.begin();
358 auto firstIte = firstOperand.end();
359 auto secondIt = secondOperand.begin();
360 auto targetIt = target.begin();
361 while (firstIt != firstIte) {
362 *targetIt = f(*firstIt, *secondIt, *targetIt);
377template<
class InValueType1,
class InValueType2,
class OutValueType,
class Operation>
378void applyPointwise(std::vector<InValueType1>
const& firstOperand, std::vector<InValueType2>
const& secondOperand, std::vector<OutValueType>& target,
379 Operation f = Operation()) {
380 std::transform(firstOperand.begin(), firstOperand.end(), secondOperand.begin(), target.begin(), f);
390template<
class InValueType,
class OutValueType,
class Operation>
391void applyPointwise(std::vector<InValueType>
const& operand, std::vector<OutValueType>& target, Operation f = Operation()) {
392 std::transform(operand.begin(), operand.end(), target.begin(), f);
402template<
class InValueType1,
class InValueType2,
class OutValueType>
403void addVectors(std::vector<InValueType1>
const& firstOperand, std::vector<InValueType2>
const& secondOperand, std::vector<OutValueType>& target) {
404 applyPointwise<InValueType1, InValueType2, OutValueType, std::plus<>>(firstOperand, secondOperand, target);
414template<
class InValueType1,
class InValueType2,
class OutValueType>
415void subtractVectors(std::vector<InValueType1>
const& firstOperand, std::vector<InValueType2>
const& secondOperand, std::vector<OutValueType>& target) {
416 applyPointwise<InValueType1, InValueType2, OutValueType, std::minus<>>(firstOperand, secondOperand, target);
426template<
class InValueType1,
class InValueType2,
class OutValueType>
428 std::vector<OutValueType>& target) {
429 applyPointwise<InValueType1, InValueType2, OutValueType, std::multiplies<>>(firstOperand, secondOperand, target);
439template<
class InValueType1,
class InValueType2,
class OutValueType>
440void divideVectorsPointwise(std::vector<InValueType1>
const& firstOperand, std::vector<InValueType2>
const& secondOperand, std::vector<OutValueType>& target) {
441 applyPointwise<InValueType1, InValueType2, OutValueType, std::divides<>>(firstOperand, secondOperand, target);
450template<
class ValueType1,
class ValueType2>
452 applyPointwise<ValueType1, ValueType1>(target, target, [&](ValueType1
const& argument) -> ValueType1 {
return argument * factor; });
463template<
class InValueType1,
class InValueType2,
class InValueType3>
464void addScaledVector(std::vector<InValueType1>& firstOperand, std::vector<InValueType2>
const& secondOperand, InValueType3
const& factor) {
465 applyPointwise<InValueType1, InValueType2, InValueType1>(
466 firstOperand, secondOperand, firstOperand, [&](InValueType1
const& val1, InValueType2
const& val2) -> InValueType1 {
return val1 + (factor * val2); });
477T
dotProduct(std::vector<T>
const& firstOperand, std::vector<T>
const& secondOperand) {
478 return std::inner_product(firstOperand.begin(), firstOperand.end(), secondOperand.begin(), storm::utility::zero<T>());
493 uint_fast64_t currentIndex = 0;
494 for (
auto const& value : values) {
495 if (function(value)) {
496 result.
set(currentIndex,
true);
513 return filter<T>(values, [](T
const& value) ->
bool {
return value > storm::utility::zero<T>(); });
524 return filter<T>(values, storm::utility::isZero<T>);
535 return filter<T>(values, storm::utility::isOne<T>);
546 return filter<T>(values, storm::utility::isInfinity<T>);
558 VT sum = storm::utility::zero<VT>();
579 VT current = values[*it];
582 for (; it != ite; ++it) {
583 current = std::max(values[*it], current);
602 VT current = values[*it];
605 for (; it != ite; ++it) {
606 current = std::min(values[*it], current);
621template<
class T,
class Filter>
622void reduceVector(std::vector<T>
const& source, std::vector<T>& target, std::vector<uint_fast64_t>
const& rowGrouping, std::vector<uint_fast64_t>* choices) {
624 typename std::vector<T>::iterator targetIt = target.begin();
625 typename std::vector<T>::iterator targetIte = target.end();
626 typename std::vector<uint_fast64_t>::const_iterator rowGroupingIt = rowGrouping.begin();
627 typename std::vector<T>::const_iterator sourceIt = source.begin();
628 typename std::vector<T>::const_iterator sourceIte;
629 typename std::vector<uint_fast64_t>::iterator choiceIt;
631 choiceIt = choices->begin();
635 T oldSelectedChoiceValue;
636 uint64_t selectedChoice;
638 uint64_t currentRow = 0;
639 for (; targetIt != targetIte; ++targetIt, ++rowGroupingIt, ++choiceIt) {
641 if (*rowGroupingIt != *(rowGroupingIt + 1)) {
642 *targetIt = *sourceIt;
646 if (*choiceIt == 0) {
647 oldSelectedChoiceValue = *targetIt;
654 for (sourceIte = source.begin() + *(rowGroupingIt + 1); sourceIt != sourceIte; ++sourceIt, ++currentRow) {
655 if (choices && *rowGroupingIt + *choiceIt == currentRow) {
656 oldSelectedChoiceValue = *sourceIt;
659 if (f(*sourceIt, *targetIt)) {
660 *targetIt = *sourceIt;
662 selectedChoice = std::distance(source.begin(), sourceIt) - *rowGroupingIt;
667 if (choices && f(*targetIt, oldSelectedChoiceValue)) {
668 *choiceIt = selectedChoice;
672 *targetIt = storm::utility::zero<T>();
686void reduceVectorMin(std::vector<T>
const& source, std::vector<T>& target, std::vector<uint_fast64_t>
const& rowGrouping,
687 std::vector<uint_fast64_t>* choices =
nullptr) {
688 reduceVector<T, storm::utility::ElementLess<T>>(source, target, rowGrouping, choices);
700void reduceVectorMax(std::vector<T>
const& source, std::vector<T>& target, std::vector<uint_fast64_t>
const& rowGrouping,
701 std::vector<uint_fast64_t>* choices =
nullptr) {
702 reduceVector<T, storm::utility::ElementGreater<T>>(source, target, rowGrouping, choices);
716 std::vector<uint_fast64_t>
const& rowGrouping, std::vector<uint_fast64_t>* choices =
nullptr) {
717 if (dir == storm::solver::OptimizationDirection::Minimize) {
737 if (storm::utility::isZero<T>(val1)) {
740 T relDiff = (val1 - val2) / val1;
745 T diff = val1 - val2;
755inline bool equalModuloPrecision(
double const& val1,
double const& val2,
double const& precision,
bool relativeError) {
760 double relDiff = (val1 - val2) / val1;
765 double diff = val1 - val2;
783bool equalModuloPrecision(std::vector<T>
const& vectorLeft, std::vector<T>
const& vectorRight, T
const& precision,
bool relativeError) {
784 STORM_LOG_ASSERT(vectorLeft.size() == vectorRight.size(),
"Lengths of vectors does not match.");
786 auto leftIt = vectorLeft.begin();
787 auto leftIte = vectorLeft.end();
788 auto rightIt = vectorRight.begin();
789 for (; leftIt != leftIte; ++leftIt, ++rightIt) {
811 bool relativeError) {
812 STORM_LOG_ASSERT(vectorLeft.size() == vectorRight.size(),
"Lengths of vectors does not match.");
814 for (
auto position : positions) {
815 if (!
equalModuloPrecision(vectorLeft[position], vectorRight[position], precision, relativeError)) {
835bool equalModuloPrecision(std::vector<T>
const& vectorLeft, std::vector<T>
const& vectorRight, std::vector<uint_fast64_t>
const& positions, T
const& precision,
836 bool relativeError) {
837 STORM_LOG_ASSERT(vectorLeft.size() == vectorRight.size(),
"Lengths of vectors does not match.");
839 for (uint_fast64_t position : positions) {
840 if (!
equalModuloPrecision(vectorLeft[position], vectorRight[position], precision, relativeError)) {
850 T res = storm::utility::zero<T>();
851 for (
auto const& element : vector) {
859 T maxDiff = storm::utility::zero<T>();
860 auto leftIt = vectorLeft.begin();
861 auto leftIte = vectorLeft.end();
862 auto rightIt = vectorRight.begin();
863 for (; leftIt != leftIte; ++leftIt, ++rightIt) {
864 T diff = *leftIt - *rightIt;
866 maxDiff = maxDiff < possDiff ? possDiff : maxDiff;
875 T result = storm::utility::zero<T>();
877 auto b1It = b1.begin();
878 auto b1Ite = b1.end();
879 auto b2It = b2.begin();
881 for (; b1It != b1Ite; ++b1It, ++b2It) {
882 result += storm::utility::pow<T>(*b1It - *b2It, 2);
891template<
typename ValueType>
892void clip(std::vector<ValueType>& x, boost::optional<ValueType>
const& lowerBound, boost::optional<ValueType>
const& upperBound) {
893 for (
auto& entry : x) {
894 if (lowerBound && entry < lowerBound.get()) {
895 entry = lowerBound.get();
896 }
else if (upperBound && entry > upperBound.get()) {
897 entry = upperBound.get();
905template<
typename ValueType>
906void clip(std::vector<ValueType>& x, ValueType
const& bound,
bool boundFromBelow) {
907 for (
auto& entry : x) {
908 if (boundFromBelow && entry < bound) {
910 }
else if (!boundFromBelow && entry > bound) {
919template<
typename ValueType>
920void clip(std::vector<ValueType>& x, std::vector<ValueType>
const& bounds,
bool boundFromBelow) {
921 auto boundsIt = bounds.begin();
922 for (
auto& entry : x) {
923 if (boundFromBelow && entry < *boundsIt) {
925 }
else if (!boundFromBelow && entry > *boundsIt) {
944 uint_fast64_t currentRowCount = 0;
945 uint_fast64_t currentIndexCount = 1;
952 for (
auto index : constraint) {
953 subVector[currentIndexCount] = currentRowCount + offsetVector[index + 1] - offsetVector[index];
954 currentRowCount += offsetVector[index + 1] - offsetVector[index];
969template<
typename TargetType,
typename SourceType>
971 std::vector<TargetType> resultVector;
972 resultVector.reserve(oldVector.size());
973 for (
auto const& oldValue : oldVector) {
974 resultVector.push_back(storm::utility::convertNumber<TargetType>(oldValue));
988template<
typename TargetType,
typename SourceType>
990 assert(inputVector.size() == targetVector.size());
991 applyPointwise(inputVector, targetVector, [](SourceType
const& v) {
return storm::utility::convertNumber<TargetType>(v); });
997template<
typename NewValueType,
typename ValueType>
998std::vector<NewValueType>
toValueType(std::vector<ValueType>
const& oldVector) {
999 std::vector<NewValueType> resultVector;
1000 resultVector.reserve(oldVector.size());
1001 for (
auto const& oldValue : oldVector) {
1002 resultVector.push_back(
static_cast<NewValueType
>(oldValue));
1004 return resultVector;
1007template<
typename ValueType,
typename TargetValueType>
1008typename std::enable_if<std::is_same<ValueType, storm::RationalNumber>::value, std::pair<std::vector<TargetValueType>, ValueType>>::type
toIntegralVector(
1009 std::vector<ValueType>
const& vec) {
1011 std::set<ValueType> occurringNonZeroNumbers;
1012 for (
auto const& v : vec) {
1014 occurringNonZeroNumbers.insert(v);
1020 if (occurringNonZeroNumbers.empty()) {
1021 factor = storm::utility::one<ValueType>();
1022 }
else if (occurringNonZeroNumbers.size() == 1) {
1023 factor = *occurringNonZeroNumbers.begin();
1027 auto numberIt = occurringNonZeroNumbers.begin();
1029 for (++numberIt; numberIt != occurringNonZeroNumbers.end(); ++numberIt) {
1033 numberIt = occurringNonZeroNumbers.begin();
1034 ValueType gcd = *numberIt * lcm;
1035 for (++numberIt; numberIt != occurringNonZeroNumbers.end(); ++numberIt) {
1036 gcd = carl::gcd(gcd,
static_cast<ValueType
>(*numberIt * lcm));
1043 std::vector<TargetValueType> result;
1044 result.reserve(vec.size());
1045 for (
auto const& v : vec) {
1046 ValueType vScaled = v / factor;
1048 result.push_back(storm::utility::convertNumber<TargetValueType, ValueType>(vScaled));
1050 return std::make_pair(std::move(result), std::move(factor));
1053template<
typename ValueType,
typename TargetValueType>
1054typename std::enable_if<!std::is_same<ValueType, storm::RationalNumber>::value, std::pair<std::vector<TargetValueType>, ValueType>>::type
toIntegralVector(
1055 std::vector<ValueType>
const& vec) {
1057 auto rationalNumberVec = convertNumericVector<storm::RationalNumber>(vec);
1058 auto rationalNumberResult = toIntegralVector<storm::RationalNumber, TargetValueType>(rationalNumberVec);
1060 return std::make_pair(std::move(rationalNumberResult.first), storm::utility::convertNumber<ValueType>(rationalNumberResult.second));
1063template<
typename Type>
1065 std::vector<Type> result;
1067 for (
auto index :
filter) {
1068 result.push_back(in[index]);
1074template<
typename Type>
1077 uint_fast64_t size = v.size();
1080 if (firstUnsetIndex < size) {
1081 auto vIt = v.begin() + firstUnsetIndex;
1083 *vIt = std::move(v[index]);
1086 v.resize(vIt - v.begin());
1094 return std::any_of(v.begin(), v.end(), [](T value) { return value < storm::utility::zero<T>(); });
1099 return std::any_of(v.begin(), v.end(), [](T value) { return value > storm::utility::zero<T>(); });
1104 return std::any_of(v.begin(), v.end(), [](T value) { return !storm::utility::isZero(value); });
1109 return std::any_of(v.begin(), v.end(), [](T value) { return storm::utility::isZero(value); });
1114 return std::any_of(v.begin(), v.end(), [](T value) { return storm::utility::isInfinity(value); });
1119 std::vector<T> result;
1120 result.reserve(source.size());
1121 for (uint64_t sourceIndex : inversePermutation) {
1122 result.push_back(source[sourceIndex]);
1129 std::vector<uint64_t>
const& rowGroupIndices) {
1130 STORM_LOG_ASSERT(inversePermutation.size() == rowGroupIndices.size() - 1,
"Inverse permutation and row group indices do not match.");
1131 std::vector<T> result;
1132 result.reserve(source.size());
1133 for (
auto sourceGroupIndex : inversePermutation) {
1134 for (uint64_t sourceIndex = rowGroupIndices[sourceGroupIndex]; sourceIndex < rowGroupIndices[sourceGroupIndex + 1]; ++sourceIndex) {
1135 result.push_back(source[sourceIndex]);
1138 STORM_LOG_ASSERT(result.size() == source.size(),
"result has unexpected length.");
1148template<
typename ValueType>
1149std::string
toString(std::vector<ValueType>
const& vector) {
1150 std::stringstream stream;
1151 stream <<
"vector (" << vector.size() <<
") [ ";
1152 if (!vector.empty()) {
1153 for (uint_fast64_t i = 0; i < vector.size() - 1; ++i) {
1154 stream << vector[i] <<
", ";
1156 stream << vector.back();
1159 return stream.str();
1162template<
typename PT1,
typename PT2>
1163std::string
toString(std::vector<std::pair<PT1, PT2>>
const& vector) {
1164 std::stringstream stream;
1165 stream <<
"vector (" << vector.size() <<
") [ ";
1166 if (!vector.empty()) {
1167 for (uint_fast64_t i = 0; i < vector.size() - 1; ++i) {
1168 stream <<
"{" << vector[i].first <<
"," << vector[i].second <<
"}, ";
1170 stream <<
"{" << vector.back().first <<
"," << vector.back().second <<
"}";
1173 return stream.str();
A bit vector that is internally represented as a vector of 64-bit values.
const_iterator end() const
Returns an iterator pointing at the element past the back of the bit vector.
uint_fast64_t getNextSetIndex(uint_fast64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to true in the bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
const_iterator begin() const
Returns an iterator to the indices of the set bits in the bit vector.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
uint_fast64_t getNextUnsetIndex(uint_fast64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to false in the bit vector.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
#define STORM_LOG_ASSERT(cond, message)
std::size_t findOrInsert(std::vector< T > &vector, T &&element)
Finds the given element in the given vector.
std::vector< TargetType > convertNumericVector(std::vector< SourceType > const &oldVector)
Converts the given vector to the given ValueType Assumes that both, TargetType and SourceType are num...
storm::storage::BitVector filter(std::vector< T > const &values, std::function< bool(T const &value)> const &function)
Retrieves a bit vector containing all the indices for which the value at this position makes the give...
void applyPointwiseTernary(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target, Operation f=Operation())
Applies the given operation pointwise on the two given vectors and writes the result to the third vec...
VT min_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Computes the minimum of the entries from the values that are selected by the (non-empty) filter.
void addVectors(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Adds the two given vectors and writes the result to the target vector.
void divideVectorsPointwise(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Divides the two given vectors (pointwise) and writes the result to the target vector.
T dotProduct(std::vector< T > const &firstOperand, std::vector< T > const &secondOperand)
Computes the dot product (aka scalar product) and returns the result.
std::vector< NewValueType > toValueType(std::vector< ValueType > const &oldVector)
Converts the given vector to the given ValueType.
bool hasInfinityEntry(std::vector< T > const &v)
void addVectorToGroupedVector(std::vector< T > &target, std::vector< T > const &source, std::vector< uint_fast64_t > const &rowGroupIndices)
Adds the source vector to the target vector in a way such that the i-th entry is added to all element...
void setNonzeroIndices(std::vector< T > const &vec, storm::storage::BitVector &bv)
VT max_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Computes the maximum of the entries from the values that are selected by the (non-empty) filter.
void setVectorValues(std::vector< T > &vector, storm::storage::BitVector const &positions, std::vector< T > const &values)
Sets the provided values at the provided positions in the given vector.
bool compareElementWise(std::vector< T > const &left, std::vector< T > const &right, Comparator comp=std::less< T >())
std::vector< T > buildVectorForRange(T min, T max)
Constructs a vector [min, min+1, ...., max-1].
void setAllValues(std::vector< T > &vec, storm::storage::BitVector const &positions, T const &positiveValue=storm::utility::one< T >(), T const &negativeValue=storm::utility::zero< T >())
void addFilteredVectorGroupsToGroupedVector(std::vector< T > &target, std::vector< T > const &source, storm::storage::BitVector const &filter, std::vector< uint_fast64_t > const &rowGroupIndices)
bool equalModuloPrecision(T const &val1, T const &val2, T const &precision, bool relativeError=true)
Compares the given elements and determines whether they are equal modulo the given precision.
void selectVectorValues(std::vector< T > &vector, storm::storage::BitVector const &positions, std::vector< T > const &values)
Selects the elements from a vector at the specified positions and writes them consecutively into anot...
T computeSquaredNorm2Difference(std::vector< T > const &b1, std::vector< T > const &b2)
bool isUnique(std::vector< T > const &v)
Returns true iff every element in the given vector is unique, i.e., there are no i,...
T maximumElementDiff(std::vector< T > const &vectorLeft, std::vector< T > const &vectorRight)
void reduceVectorMinOrMax(storm::solver::OptimizationDirection dir, std::vector< T > const &source, std::vector< T > &target, std::vector< uint_fast64_t > const &rowGrouping, std::vector< uint_fast64_t > *choices=nullptr)
Reduces the given source vector by selecting either the smallest or the largest out of each row group...
storm::storage::BitVector filterGreaterZero(std::vector< T > const &values)
Retrieves a bit vector containing all the indices for which the value at this position is greater tha...
void reduceVector(std::vector< T > const &source, std::vector< T > &target, std::vector< uint_fast64_t > const &rowGrouping, std::vector< uint_fast64_t > *choices)
Reduces the given source vector by selecting an element according to the given filter out of each row...
void addScaledVector(std::vector< InValueType1 > &firstOperand, std::vector< InValueType2 > const &secondOperand, InValueType3 const &factor)
Computes x:= x + a*y, i.e., adds each element of the first vector and (the corresponding element of t...
std::string toString(std::vector< ValueType > const &vector)
Output vector as string.
void multiplyVectorsPointwise(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Multiplies the two given vectors (pointwise) and writes the result to the target vector.
bool hasPositiveEntry(std::vector< T > const &v)
storm::storage::BitVector filterOne(std::vector< T > const &values)
Retrieves a bit vector containing all the indices for which the value at this position is equal to on...
bool hasNegativeEntry(std::vector< T > const &v)
T maximumElementAbs(std::vector< T > const &vector)
void clip(std::vector< ValueType > &x, boost::optional< ValueType > const &lowerBound, boost::optional< ValueType > const &upperBound)
Takes the input vector and ensures that all entries conform to the bounds.
void addFilteredVectorToGroupedVector(std::vector< T > &target, std::vector< T > const &source, storm::storage::BitVector const &filter, std::vector< uint_fast64_t > const &rowGroupIndices)
Adds the source vector to the target vector in a way such that the i-th selected entry is added to al...
void selectVectorValuesRepeatedly(std::vector< T > &vector, storm::storage::BitVector const &positions, std::vector< uint_fast64_t > const &rowGrouping, std::vector< T > const &values)
Selects values from a vector at the specified positions and writes them into another vector as often ...
void applyPointwise(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target, Operation f=Operation())
Applies the given operation pointwise on the two given vectors and writes the result to the third vec...
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)
Reduces the given source vector by selecting the smallest element out of each row group.
VT sum_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Sum the entries from values that are set to one in the filter vector.
storm::storage::BitVector filterInfinity(std::vector< T > const &values)
Retrieves a bit vector containing all the indices for which the value at this position is equal to on...
std::vector< T > applyInversePermutation(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source)
void filterVectorInPlace(std::vector< Type > &v, storm::storage::BitVector const &filter)
void iota_n(OutputIterator first, Size n, Assignable value)
Iota function as a helper for efficient creating a range in a vector.
void subtractVectors(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Subtracts the two given vectors and writes the result to the target vector.
std::vector< uint_fast64_t > getSortedIndices(std::vector< T > const &v)
Returns a list of indices such that the first index refers to the highest entry of the given vector,...
bool hasZeroEntry(std::vector< T > const &v)
storm::storage::BitVector filterZero(std::vector< T > const &values)
Retrieves a bit vector containing all the indices for which the value at this position is equal to ze...
void scaleVectorInPlace(std::vector< ValueType1 > &target, ValueType2 const &factor)
Multiplies each element of the given vector with the given factor and writes the result into the vect...
std::vector< T > applyInversePermutationToGroupedVector(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source, std::vector< uint64_t > const &rowGroupIndices)
std::vector< T > getConstrainedOffsetVector(std::vector< T > const &offsetVector, storm::storage::BitVector const &constraint)
Takes the given offset vector and applies the given contraint.
bool hasNonZeroEntry(std::vector< T > const &v)
void subtractFromConstantOneVector(std::vector< T > &vector)
Subtracts the given vector from the constant one-vector and writes the result to the input vector.
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)
Reduces the given source vector by selecting the largest element out of each row group.
std::enable_if< std::is_same< ValueType, storm::RationalNumber >::value, std::pair< std::vector< TargetValueType >, ValueType > >::type toIntegralVector(std::vector< ValueType > const &vec)
std::vector< Type > filterVector(std::vector< Type > const &in, storm::storage::BitVector const &filter)
ValueType max(ValueType const &first, ValueType const &second)
ValueType min(ValueType const &first, ValueType const &second)
bool isAlmostZero(ValueType const &a)
std::pair< ValueType, ValueType > asFraction(ValueType const &number)
bool isZero(ValueType const &a)
bool isInteger(ValueType const &number)
ValueType abs(ValueType const &number)
size_t operator()(std::vector< ValueType > const &vec) const