Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1#ifndef STORM_UTILITY_VECTOR_H_
2#define STORM_UTILITY_VECTOR_H_
3
4#include <algorithm>
5#include <functional>
6#include <iosfwd>
7#include <numeric>
10
11#include <boost/optional.hpp>
12
17
19
20namespace storm {
21namespace utility {
22namespace vector {
23
24template<typename ValueType>
25struct VectorHash {
26 size_t operator()(std::vector<ValueType> const& vec) const {
27 std::hash<ValueType> hasher;
28 std::size_t seed = 0;
29 for (ValueType const& element : vec) {
30 seed ^= hasher(element) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
31 }
32 return seed;
33 }
34};
35
48template<class T>
49std::size_t findOrInsert(std::vector<T>& vector, T&& element) {
50 std::size_t position = std::find(vector.begin(), vector.end(), element) - vector.begin();
51 if (position == vector.size()) {
52 vector.emplace_back(std::move(element));
53 }
54 return position;
55}
56
57template<typename T>
58void setAllValues(std::vector<T>& vec, storm::storage::BitVector const& positions, T const& positiveValue = storm::utility::one<T>(),
59 T const& negativeValue = storm::utility::zero<T>()) {
60 if (positions.getNumberOfSetBits() * 2 > positions.size()) {
61 vec.resize(positions.size(), positiveValue);
62 uint64_t index = positions.getNextUnsetIndex(0);
63 while (index < positions.size()) {
64 vec[index] = negativeValue;
65 index = positions.getNextUnsetIndex(index + 1);
66 }
67 } else {
68 vec.resize(positions.size(), negativeValue);
69 for (uint64_t index : positions) {
70 vec[index] = positiveValue;
71 }
72 }
73}
74
82template<class T>
83void setVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<T> const& values) {
84 STORM_LOG_ASSERT(positions.size() <= vector.size(), "We cannot set positions that have not been initialized");
85 STORM_LOG_ASSERT(positions.getNumberOfSetBits() <= values.size(), "The number of selected positions (" << positions.getNumberOfSetBits()
86 << ") exceeds the size of the input vector ("
87 << values.size() << ").");
88 uint_fast64_t oldPosition = 0;
89 for (auto position : positions) {
90 vector[position] = values[oldPosition++];
91 }
92}
93
102template<class T>
103void setVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, T value) {
104 STORM_LOG_ASSERT(positions.size() <= vector.size(), "We cannot set positions that have not been initialized");
105 for (auto position : positions) {
106 vector[position] = value;
107 }
108}
109
110template<typename T>
111void setNonzeroIndices(std::vector<T> const& vec, storm::storage::BitVector& bv) {
112 STORM_LOG_ASSERT(bv.size() == vec.size(), "Bitvector size should match vector size");
113 for (uint64_t i = 0; i < vec.size(); ++i) {
114 if (!storm::utility::isZero(vec[i])) {
115 bv.set(i, true);
116 }
117 }
118}
119
125template<class OutputIterator, class Size, class Assignable>
126void iota_n(OutputIterator first, Size n, Assignable value) {
127 std::generate_n(first, n, [&value]() { return value++; });
128}
129
133template<typename T>
134inline std::vector<T> buildVectorForRange(T min, T max) {
135 STORM_LOG_ASSERT(min <= max, "Invalid range.");
136 T diff = max - min;
137 std::vector<T> v;
138 v.reserve(diff);
139 iota_n(std::back_inserter(v), diff, min);
140 return v;
141}
142
148template<typename T>
149std::vector<uint_fast64_t> getSortedIndices(std::vector<T> const& v) {
150 std::vector<uint_fast64_t> res = buildVectorForRange<uint_fast64_t>(0, v.size());
151 std::sort(res.begin(), res.end(), [&v](uint_fast64_t index1, uint_fast64_t index2) { return v[index1] > v[index2]; });
152 return res;
153}
154
158template<typename T>
159bool isUnique(std::vector<T> const& v) {
160 if (v.size() < 2) {
161 return true;
162 }
163 auto sortedIndices = getSortedIndices(v);
164 auto indexIt = sortedIndices.begin();
165 T const* previous = &v[*indexIt];
166 for (++indexIt; indexIt != sortedIndices.end(); ++indexIt) {
167 T const& current = v[*indexIt];
168 if (current == *previous) {
169 return false;
170 }
171 previous = &current;
172 }
173 return true;
174}
175
176template<typename T, typename Comparator>
177bool compareElementWise(std::vector<T> const& left, std::vector<T> const& right, Comparator comp = std::less<T>()) {
178 STORM_LOG_ASSERT(left.size() == right.size(), "Expected that vectors for comparison have equal size");
179 return std::equal(left.begin(), left.end(), right.begin(), comp);
180}
181
188template<class T>
189void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<T> const& values) {
190 STORM_LOG_ASSERT(positions.getNumberOfSetBits() <= vector.size(), "The number of selected positions (" << positions.getNumberOfSetBits()
191 << ") exceeds the size of the target vector ("
192 << vector.size() << ").");
193 STORM_LOG_ASSERT(positions.size() == values.size(),
194 "Size mismatch of the positions vector (" << positions.size() << ") and the values vector (" << values.size() << ").");
195 auto targetIt = vector.begin();
196 for (auto position : positions) {
197 *targetIt = values[position];
198 ++targetIt;
199 }
200}
201
210template<class T>
211void selectVectorValues(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<uint_fast64_t> const& rowGrouping,
212 std::vector<T> const& values) {
213 auto targetIt = vector.begin();
214 for (auto position : positions) {
215 for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i, ++targetIt) {
216 *targetIt = values[i];
217 }
218 }
219}
220
230template<class T>
231void selectVectorValues(std::vector<T>& vector, std::vector<uint_fast64_t> const& rowGroupToRowIndexMapping, std::vector<uint_fast64_t> const& rowGrouping,
232 std::vector<T> const& values) {
233 auto targetIt = vector.begin();
234 for (uint_fast64_t i = 0; i < vector.size(); ++i, ++targetIt) {
235 *targetIt = values[rowGrouping[i] + rowGroupToRowIndexMapping[i]];
236 }
237}
238
246template<class T>
247void selectVectorValues(std::vector<T>& vector, std::vector<uint_fast64_t> const& indexSequence, std::vector<T> const& values) {
248 STORM_LOG_ASSERT(indexSequence.size() <= vector.size(),
249 "The number of selected positions (" << indexSequence.size() << ") exceeds the size of the target vector (" << vector.size() << ").");
250
251 for (uint_fast64_t vectorIndex = 0; vectorIndex < vector.size(); ++vectorIndex) {
252 vector[vectorIndex] = values[indexSequence[vectorIndex]];
253 }
254}
255
265template<class T>
266void selectVectorValuesRepeatedly(std::vector<T>& vector, storm::storage::BitVector const& positions, std::vector<uint_fast64_t> const& rowGrouping,
267 std::vector<T> const& values) {
268 auto targetIt = vector.begin();
269 for (auto position : positions) {
270 for (uint_fast64_t i = rowGrouping[position]; i < rowGrouping[position + 1]; ++i, ++targetIt) {
271 *targetIt = values[position];
272 }
273 }
274}
275
281template<class T>
282void subtractFromConstantOneVector(std::vector<T>& vector) {
283 for (auto& element : vector) {
284 element = storm::utility::one<T>() - element;
285 }
286}
287
288template<class T>
289void addFilteredVectorGroupsToGroupedVector(std::vector<T>& target, std::vector<T> const& source, storm::storage::BitVector const& filter,
290 std::vector<uint_fast64_t> const& rowGroupIndices) {
291 auto targetIt = target.begin();
292 for (auto group : filter) {
293 auto it = source.cbegin() + rowGroupIndices[group];
294 auto ite = source.cbegin() + rowGroupIndices[group + 1];
295 for (; it != ite; ++targetIt, ++it) {
296 *targetIt += *it;
297 }
298 }
299}
300
309template<class T>
310void addVectorToGroupedVector(std::vector<T>& target, std::vector<T> const& source, std::vector<uint_fast64_t> const& rowGroupIndices) {
311 auto targetIt = target.begin();
312 auto sourceIt = source.cbegin();
313 auto sourceIte = source.cend();
314 auto rowGroupIt = rowGroupIndices.cbegin();
315
316 for (; sourceIt != sourceIte; ++sourceIt) {
317 uint_fast64_t current = *rowGroupIt;
318 ++rowGroupIt;
319 uint_fast64_t next = *rowGroupIt;
320 for (; current < next; ++targetIt, ++current) {
321 *targetIt += *sourceIt;
322 }
323 }
324}
325
334template<class T>
335void addFilteredVectorToGroupedVector(std::vector<T>& target, std::vector<T> const& source, storm::storage::BitVector const& filter,
336 std::vector<uint_fast64_t> const& rowGroupIndices) {
337 auto targetIt = target.begin();
338 for (auto group : filter) {
339 uint_fast64_t current = rowGroupIndices[group];
340 uint_fast64_t next = rowGroupIndices[group + 1];
341 for (; current < next; ++current, ++targetIt) {
342 *targetIt += source[group];
343 }
344 }
345}
346
355template<class InValueType1, class InValueType2, class OutValueType, class Operation>
356void applyPointwiseTernary(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand, std::vector<OutValueType>& target,
357 Operation f = Operation()) {
358 auto firstIt = firstOperand.begin();
359 auto firstIte = firstOperand.end();
360 auto secondIt = secondOperand.begin();
361 auto targetIt = target.begin();
362 while (firstIt != firstIte) {
363 *targetIt = f(*firstIt, *secondIt, *targetIt);
364 ++targetIt;
365 ++firstIt;
366 ++secondIt;
367 }
368}
369
370#ifdef STORM_HAVE_INTELTBB
371template<class InValueType1, class InValueType2, class OutValueType, class Operation>
372void applyPointwiseTernaryParallel(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand,
373 std::vector<OutValueType>& target, Operation f = Operation()) {
374 tbb::parallel_for(tbb::blocked_range<uint_fast64_t>(0, target.size()), [&](tbb::blocked_range<uint_fast64_t> const& range) {
375 auto firstIt = firstOperand.begin() + range.begin();
376 auto firstIte = firstOperand.begin() + range.end();
377 auto secondIt = secondOperand.begin() + range.begin();
378 auto targetIt = target.begin() + range.begin();
379 while (firstIt != firstIte) {
380 *targetIt = f(*firstIt, *secondIt, *targetIt);
381 ++targetIt;
382 ++firstIt;
383 ++secondIt;
384 }
385 });
386}
387#endif
388
397template<class InValueType1, class InValueType2, class OutValueType, class Operation>
398void applyPointwise(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand, std::vector<OutValueType>& target,
399 Operation f = Operation()) {
400 std::transform(firstOperand.begin(), firstOperand.end(), secondOperand.begin(), target.begin(), f);
401}
402
403#ifdef STORM_HAVE_INTELTBB
404template<class InValueType1, class InValueType2, class OutValueType, class Operation>
405void applyPointwiseParallel(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand, std::vector<OutValueType>& target,
406 Operation f = Operation()) {
407 tbb::parallel_for(tbb::blocked_range<uint_fast64_t>(0, target.size()), [&](tbb::blocked_range<uint_fast64_t> const& range) {
408 std::transform(firstOperand.begin() + range.begin(), firstOperand.begin() + range.end(), secondOperand.begin() + range.begin(),
409 target.begin() + range.begin(), f);
410 });
411}
412#endif
413
421template<class InValueType, class OutValueType, class Operation>
422void applyPointwise(std::vector<InValueType> const& operand, std::vector<OutValueType>& target, Operation f = Operation()) {
423 std::transform(operand.begin(), operand.end(), target.begin(), f);
424}
425
426#ifdef STORM_HAVE_INTELTBB
427template<class InValueType, class OutValueType, class Operation>
428void applyPointwiseParallel(std::vector<InValueType> const& operand, std::vector<OutValueType>& target, Operation f = Operation()) {
429 tbb::parallel_for(tbb::blocked_range<uint_fast64_t>(0, target.size()), [&](tbb::blocked_range<uint_fast64_t> const& range) {
430 std::transform(operand.begin() + range.begin(), operand.begin() + range.end(), target.begin() + range.begin(), f);
431 });
432}
433#endif
434
442template<class InValueType1, class InValueType2, class OutValueType>
443void addVectors(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand, std::vector<OutValueType>& target) {
444 applyPointwise<InValueType1, InValueType2, OutValueType, std::plus<>>(firstOperand, secondOperand, target);
445}
446
454template<class InValueType1, class InValueType2, class OutValueType>
455void subtractVectors(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand, std::vector<OutValueType>& target) {
456 applyPointwise<InValueType1, InValueType2, OutValueType, std::minus<>>(firstOperand, secondOperand, target);
457}
458
466template<class InValueType1, class InValueType2, class OutValueType>
467void multiplyVectorsPointwise(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand,
468 std::vector<OutValueType>& target) {
469 applyPointwise<InValueType1, InValueType2, OutValueType, std::multiplies<>>(firstOperand, secondOperand, target);
470}
471
479template<class InValueType1, class InValueType2, class OutValueType>
480void divideVectorsPointwise(std::vector<InValueType1> const& firstOperand, std::vector<InValueType2> const& secondOperand, std::vector<OutValueType>& target) {
481 applyPointwise<InValueType1, InValueType2, OutValueType, std::divides<>>(firstOperand, secondOperand, target);
482}
483
490template<class ValueType1, class ValueType2>
491void scaleVectorInPlace(std::vector<ValueType1>& target, ValueType2 const& factor) {
492 applyPointwise<ValueType1, ValueType1>(target, target, [&](ValueType1 const& argument) -> ValueType1 { return argument * factor; });
493}
494
503template<class InValueType1, class InValueType2, class InValueType3>
504void addScaledVector(std::vector<InValueType1>& firstOperand, std::vector<InValueType2> const& secondOperand, InValueType3 const& factor) {
505 applyPointwise<InValueType1, InValueType2, InValueType1>(
506 firstOperand, secondOperand, firstOperand, [&](InValueType1 const& val1, InValueType2 const& val2) -> InValueType1 { return val1 + (factor * val2); });
507}
508
516template<class T>
517T dotProduct(std::vector<T> const& firstOperand, std::vector<T> const& secondOperand) {
518 return std::inner_product(firstOperand.begin(), firstOperand.end(), secondOperand.begin(), storm::utility::zero<T>());
519}
520
529template<class T>
530storm::storage::BitVector filter(std::vector<T> const& values, std::function<bool(T const& value)> const& function) {
531 storm::storage::BitVector result(values.size(), false);
532
533 uint_fast64_t currentIndex = 0;
534 for (auto const& value : values) {
535 if (function(value)) {
536 result.set(currentIndex, true);
537 }
538 ++currentIndex;
539 }
540
541 return result;
542}
543
551template<class T>
552storm::storage::BitVector filterGreaterZero(std::vector<T> const& values) {
553 return filter<T>(values, [](T const& value) -> bool { return value > storm::utility::zero<T>(); });
554}
555
562template<class T>
563storm::storage::BitVector filterZero(std::vector<T> const& values) {
564 return filter<T>(values, storm::utility::isZero<T>);
565}
566
573template<class T>
574storm::storage::BitVector filterOne(std::vector<T> const& values) {
575 return filter<T>(values, storm::utility::isOne<T>);
576}
577
584template<class T>
585storm::storage::BitVector filterInfinity(std::vector<T> const& values) {
586 return filter<T>(values, storm::utility::isInfinity<T>);
587}
588
595template<typename VT>
596VT sum_if(std::vector<VT> const& values, storm::storage::BitVector const& filter) {
597 STORM_LOG_ASSERT(values.size() == filter.size(), "Vector sizes mismatch.");
598 VT sum = storm::utility::zero<VT>();
599 for (auto pos : filter) {
600 sum += values[pos];
601 }
602 return sum;
603}
604
611template<typename VT>
612VT max_if(std::vector<VT> const& values, storm::storage::BitVector const& filter) {
613 STORM_LOG_ASSERT(values.size() == filter.size(), "Vector sizes mismatch.");
614 STORM_LOG_ASSERT(!filter.empty(), "Empty selection.");
615
616 auto it = filter.begin();
617 auto ite = filter.end();
618
619 VT current = values[*it];
620 ++it;
621
622 for (; it != ite; ++it) {
623 current = std::max(values[*it], current);
624 }
625 return current;
626}
627
634template<typename VT>
635VT min_if(std::vector<VT> const& values, storm::storage::BitVector const& filter) {
636 STORM_LOG_ASSERT(values.size() == filter.size(), "Vector sizes mismatch.");
637 STORM_LOG_ASSERT(!filter.empty(), "Empty selection.");
638
639 auto it = filter.begin();
640 auto ite = filter.end();
641
642 VT current = values[*it];
643 ++it;
644
645 for (; it != ite; ++it) {
646 current = std::min(values[*it], current);
647 }
648 return current;
649}
650
651#ifdef STORM_HAVE_INTELTBB
652template<class T, class Filter>
653class TbbReduceVectorFunctor {
654 public:
655 TbbReduceVectorFunctor(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping,
656 std::vector<uint_fast64_t>* choices, Filter const& f)
657 : source(source), target(target), rowGrouping(rowGrouping), choices(choices), f(f) {
658 // Intentionally left empty.
659 }
660
661 void operator()(tbb::blocked_range<uint64_t> const& range) const {
662 uint_fast64_t startRow = range.begin();
663 uint_fast64_t endRow = range.end();
664
665 typename std::vector<T>::iterator targetIt = target.begin() + startRow;
666 typename std::vector<T>::iterator targetIte = target.begin() + endRow;
667 typename std::vector<uint_fast64_t>::const_iterator rowGroupingIt = rowGrouping.begin() + startRow;
668 typename std::vector<T>::const_iterator sourceIt = source.begin() + *rowGroupingIt;
669 typename std::vector<T>::const_iterator sourceIte;
670 typename std::vector<uint_fast64_t>::iterator choiceIt;
671 if (choices) {
672 choiceIt = choices->begin() + startRow;
673 }
674
675 // Variables for correctly tracking choices (only update if new choice is strictly better).
676 T oldSelectedChoiceValue;
677 uint64_t selectedChoice;
678
679 uint64_t currentRow = 0;
680 for (; targetIt != targetIte; ++targetIt, ++rowGroupingIt, ++choiceIt) {
681 // Only traverse elements if the row group is non-empty.
682 if (*rowGroupingIt != *(rowGroupingIt + 1)) {
683 *targetIt = *sourceIt;
684
685 if (choices) {
686 selectedChoice = 0;
687 if (*choiceIt == 0) {
688 oldSelectedChoiceValue = *targetIt;
689 }
690 }
691
692 ++sourceIt;
693 ++currentRow;
694
695 for (sourceIte = source.begin() + *(rowGroupingIt + 1); sourceIt != sourceIte; ++sourceIt, ++currentRow) {
696 if (choices && *choiceIt + *rowGroupingIt == currentRow) {
697 oldSelectedChoiceValue = *sourceIt;
698 }
699
700 if (f(*sourceIt, *targetIt)) {
701 *targetIt = *sourceIt;
702 if (choices) {
703 selectedChoice = std::distance(source.begin(), sourceIt) - *rowGroupingIt;
704 }
705 }
706 }
707
708 if (choices && f(*targetIt, oldSelectedChoiceValue)) {
709 *choiceIt = selectedChoice;
710 }
711 }
712 }
713 }
714
715 private:
716 std::vector<T> const& source;
717 std::vector<T>& target;
718 std::vector<uint_fast64_t> const& rowGrouping;
719 std::vector<uint_fast64_t>* choices;
720 Filter const& f;
721};
722#endif
723
734template<class T, class Filter>
735void reduceVector(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping, std::vector<uint_fast64_t>* choices) {
736 Filter f;
737 typename std::vector<T>::iterator targetIt = target.begin();
738 typename std::vector<T>::iterator targetIte = target.end();
739 typename std::vector<uint_fast64_t>::const_iterator rowGroupingIt = rowGrouping.begin();
740 typename std::vector<T>::const_iterator sourceIt = source.begin();
741 typename std::vector<T>::const_iterator sourceIte;
742 typename std::vector<uint_fast64_t>::iterator choiceIt;
743 if (choices) {
744 choiceIt = choices->begin();
745 }
746
747 // Variables for correctly tracking choices (only update if new choice is strictly better).
748 T oldSelectedChoiceValue;
749 uint64_t selectedChoice;
750
751 uint64_t currentRow = 0;
752 for (; targetIt != targetIte; ++targetIt, ++rowGroupingIt, ++choiceIt) {
753 // Only traverse elements if the row group is non-empty.
754 if (*rowGroupingIt != *(rowGroupingIt + 1)) {
755 *targetIt = *sourceIt;
756
757 if (choices) {
758 selectedChoice = 0;
759 if (*choiceIt == 0) {
760 oldSelectedChoiceValue = *targetIt;
761 }
762 }
763
764 ++sourceIt;
765 ++currentRow;
766
767 for (sourceIte = source.begin() + *(rowGroupingIt + 1); sourceIt != sourceIte; ++sourceIt, ++currentRow) {
768 if (choices && *rowGroupingIt + *choiceIt == currentRow) {
769 oldSelectedChoiceValue = *sourceIt;
770 }
771
772 if (f(*sourceIt, *targetIt)) {
773 *targetIt = *sourceIt;
774 if (choices) {
775 selectedChoice = std::distance(source.begin(), sourceIt) - *rowGroupingIt;
776 }
777 }
778 }
779
780 if (choices && f(*targetIt, oldSelectedChoiceValue)) {
781 *choiceIt = selectedChoice;
782 }
783 } else {
784 *choiceIt = 0;
785 *targetIt = storm::utility::zero<T>();
786 }
787 }
788}
789
790#ifdef STORM_HAVE_INTELTBB
791template<class T, class Filter>
792void reduceVectorParallel(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping,
793 std::vector<uint_fast64_t>* choices) {
794 tbb::parallel_for(tbb::blocked_range<uint64_t>(0, target.size()), TbbReduceVectorFunctor<T, Filter>(source, target, rowGrouping, choices, Filter()));
795}
796#endif
797
806template<class T>
807void reduceVectorMin(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping,
808 std::vector<uint_fast64_t>* choices = nullptr) {
809 reduceVector<T, storm::utility::ElementLess<T>>(source, target, rowGrouping, choices);
810}
811
812#ifdef STORM_HAVE_INTELTBB
813template<class T>
814void reduceVectorMinParallel(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping,
815 std::vector<uint_fast64_t>* choices = nullptr) {
816 reduceVector<T, storm::utility::ElementLess<T>>(source, target, rowGrouping, choices);
817}
818#endif
819
828template<class T>
829void reduceVectorMax(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping,
830 std::vector<uint_fast64_t>* choices = nullptr) {
831 reduceVector<T, storm::utility::ElementGreater<T>>(source, target, rowGrouping, choices);
832}
833
834#ifdef STORM_HAVE_INTELTBB
835template<class T>
836void reduceVectorMaxParallel(std::vector<T> const& source, std::vector<T>& target, std::vector<uint_fast64_t> const& rowGrouping,
837 std::vector<uint_fast64_t>* choices = nullptr) {
838 reduceVector<T, storm::utility::ElementGreater<T>>(source, target, rowGrouping, choices);
839}
840#endif
841
851template<class T>
852void reduceVectorMinOrMax(storm::solver::OptimizationDirection dir, std::vector<T> const& source, std::vector<T>& target,
853 std::vector<uint_fast64_t> const& rowGrouping, std::vector<uint_fast64_t>* choices = nullptr) {
854 if (dir == storm::solver::OptimizationDirection::Minimize) {
855 reduceVectorMin(source, target, rowGrouping, choices);
856 } else {
857 reduceVectorMax(source, target, rowGrouping, choices);
858 }
859}
860
861#ifdef STORM_HAVE_INTELTBB
862template<class T>
863void reduceVectorMinOrMaxParallel(storm::solver::OptimizationDirection dir, std::vector<T> const& source, std::vector<T>& target,
864 std::vector<uint_fast64_t> const& rowGrouping, std::vector<uint_fast64_t>* choices = nullptr) {
865 if (dir == storm::solver::OptimizationDirection::Minimize) {
866 reduceVectorMinParallel(source, target, rowGrouping, choices);
867 } else {
868 reduceVectorMaxParallel(source, target, rowGrouping, choices);
869 }
870}
871#endif
872
883template<class T>
884bool equalModuloPrecision(T const& val1, T const& val2, T const& precision, bool relativeError = true) {
885 if (relativeError) {
886 if (storm::utility::isZero<T>(val1)) {
887 return storm::utility::isZero(val2);
888 }
889 T relDiff = (val1 - val2) / val1;
890 if (storm::utility::abs(relDiff) > precision) {
891 return false;
892 }
893 } else {
894 T diff = val1 - val2;
895 if (storm::utility::abs(diff) > precision) {
896 return false;
897 }
898 }
899 return true;
900}
901
902// Specializiation for double as the relative check for doubles very close to zero is not meaningful.
903template<>
904inline bool equalModuloPrecision(double const& val1, double const& val2, double const& precision, bool relativeError) {
905 if (relativeError) {
907 return storm::utility::isAlmostZero(val1);
908 }
909 double relDiff = (val1 - val2) / val1;
910 if (storm::utility::abs(relDiff) > precision) {
911 return false;
912 }
913 } else {
914 double diff = val1 - val2;
915 if (storm::utility::abs(diff) > precision) {
916 return false;
917 }
918 }
919 return true;
920}
921
931template<class T>
932bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight, T const& precision, bool relativeError) {
933 STORM_LOG_ASSERT(vectorLeft.size() == vectorRight.size(), "Lengths of vectors does not match.");
934
935 auto leftIt = vectorLeft.begin();
936 auto leftIte = vectorLeft.end();
937 auto rightIt = vectorRight.begin();
938 for (; leftIt != leftIte; ++leftIt, ++rightIt) {
939 if (!equalModuloPrecision(*leftIt, *rightIt, precision, relativeError)) {
940 return false;
941 }
942 }
943
944 return true;
945}
946
958template<class T>
959bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight, storm::storage::BitVector const& positions, T const& precision,
960 bool relativeError) {
961 STORM_LOG_ASSERT(vectorLeft.size() == vectorRight.size(), "Lengths of vectors does not match.");
962
963 for (auto position : positions) {
964 if (!equalModuloPrecision(vectorLeft[position], vectorRight[position], precision, relativeError)) {
965 return false;
966 }
967 }
968
969 return true;
970}
971
983template<class T>
984bool equalModuloPrecision(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight, std::vector<uint_fast64_t> const& positions, T const& precision,
985 bool relativeError) {
986 STORM_LOG_ASSERT(vectorLeft.size() == vectorRight.size(), "Lengths of vectors does not match.");
987
988 for (uint_fast64_t position : positions) {
989 if (!equalModuloPrecision(vectorLeft[position], vectorRight[position], precision, relativeError)) {
990 return false;
991 }
992 }
993
994 return true;
995}
996
997template<class T>
998T maximumElementAbs(std::vector<T> const& vector) {
999 T res = storm::utility::zero<T>();
1000 for (auto const& element : vector) {
1001 res = std::max(res, storm::utility::abs(element));
1002 }
1003 return res;
1004}
1005
1006template<class T>
1007T maximumElementDiff(std::vector<T> const& vectorLeft, std::vector<T> const& vectorRight) {
1008 T maxDiff = storm::utility::zero<T>();
1009 auto leftIt = vectorLeft.begin();
1010 auto leftIte = vectorLeft.end();
1011 auto rightIt = vectorRight.begin();
1012 for (; leftIt != leftIte; ++leftIt, ++rightIt) {
1013 T diff = *leftIt - *rightIt;
1014 T possDiff = storm::utility::abs(diff);
1015 maxDiff = maxDiff < possDiff ? possDiff : maxDiff;
1016 }
1017 return maxDiff;
1018}
1019
1020template<class T>
1021T computeSquaredNorm2Difference(std::vector<T> const& b1, std::vector<T> const& b2) {
1022 STORM_LOG_ASSERT(b1.size() == b2.size(), "Vector sizes mismatch.");
1023
1024 T result = storm::utility::zero<T>();
1025
1026 auto b1It = b1.begin();
1027 auto b1Ite = b1.end();
1028 auto b2It = b2.begin();
1029
1030 for (; b1It != b1Ite; ++b1It, ++b2It) {
1031 result += storm::utility::pow<T>(*b1It - *b2It, 2);
1032 }
1033
1034 return result;
1035}
1036
1040template<typename ValueType>
1041void clip(std::vector<ValueType>& x, boost::optional<ValueType> const& lowerBound, boost::optional<ValueType> const& upperBound) {
1042 for (auto& entry : x) {
1043 if (lowerBound && entry < lowerBound.get()) {
1044 entry = lowerBound.get();
1045 } else if (upperBound && entry > upperBound.get()) {
1046 entry = upperBound.get();
1047 }
1048 }
1049}
1050
1054template<typename ValueType>
1055void clip(std::vector<ValueType>& x, ValueType const& bound, bool boundFromBelow) {
1056 for (auto& entry : x) {
1057 if (boundFromBelow && entry < bound) {
1058 entry = bound;
1059 } else if (!boundFromBelow && entry > bound) {
1060 entry = bound;
1061 }
1062 }
1063}
1064
1068template<typename ValueType>
1069void clip(std::vector<ValueType>& x, std::vector<ValueType> const& bounds, bool boundFromBelow) {
1070 auto boundsIt = bounds.begin();
1071 for (auto& entry : x) {
1072 if (boundFromBelow && entry < *boundsIt) {
1073 entry = *boundsIt;
1074 } else if (!boundFromBelow && entry > *boundsIt) {
1075 entry = *boundsIt;
1076 }
1077 ++boundsIt;
1078 }
1079}
1080
1089template<class T>
1090std::vector<T> getConstrainedOffsetVector(std::vector<T> const& offsetVector, storm::storage::BitVector const& constraint) {
1091 // Reserve the known amount of slots for the resulting vector.
1092 std::vector<uint_fast64_t> subVector(constraint.getNumberOfSetBits() + 1);
1093 uint_fast64_t currentRowCount = 0;
1094 uint_fast64_t currentIndexCount = 1;
1095
1096 // Set the first element as this will clearly begin at offset 0.
1097 subVector[0] = 0;
1098
1099 // Loop over all states that need to be kept and copy the relative indices of the nondeterministic choices over
1100 // to the resulting vector.
1101 for (auto index : constraint) {
1102 subVector[currentIndexCount] = currentRowCount + offsetVector[index + 1] - offsetVector[index];
1103 currentRowCount += offsetVector[index + 1] - offsetVector[index];
1104 ++currentIndexCount;
1105 }
1106
1107 // Put a sentinel element at the end.
1108 subVector[constraint.getNumberOfSetBits()] = currentRowCount;
1109
1110 return subVector;
1111}
1112
1118template<typename TargetType, typename SourceType>
1119std::vector<TargetType> convertNumericVector(std::vector<SourceType> const& oldVector) {
1120 std::vector<TargetType> resultVector;
1121 resultVector.reserve(oldVector.size());
1122 for (auto const& oldValue : oldVector) {
1123 resultVector.push_back(storm::utility::convertNumber<TargetType>(oldValue));
1124 }
1125 return resultVector;
1126}
1127
1137template<typename TargetType, typename SourceType>
1138void convertNumericVector(std::vector<SourceType> const& inputVector, std::vector<TargetType>& targetVector) {
1139 assert(inputVector.size() == targetVector.size());
1140 applyPointwise(inputVector, targetVector, [](SourceType const& v) { return storm::utility::convertNumber<TargetType>(v); });
1141}
1142
1146template<typename NewValueType, typename ValueType>
1147std::vector<NewValueType> toValueType(std::vector<ValueType> const& oldVector) {
1148 std::vector<NewValueType> resultVector;
1149 resultVector.reserve(oldVector.size());
1150 for (auto const& oldValue : oldVector) {
1151 resultVector.push_back(static_cast<NewValueType>(oldValue));
1152 }
1153 return resultVector;
1154}
1155
1156template<typename ValueType, typename TargetValueType>
1157typename std::enable_if<std::is_same<ValueType, storm::RationalNumber>::value, std::pair<std::vector<TargetValueType>, ValueType>>::type toIntegralVector(
1158 std::vector<ValueType> const& vec) {
1159 // Collect the numbers occurring in the input vector
1160 std::set<ValueType> occurringNonZeroNumbers;
1161 for (auto const& v : vec) {
1162 if (!storm::utility::isZero(v)) {
1163 occurringNonZeroNumbers.insert(v);
1164 }
1165 }
1166
1167 // Compute the scaling factor
1168 ValueType factor;
1169 if (occurringNonZeroNumbers.empty()) {
1170 factor = storm::utility::one<ValueType>();
1171 } else if (occurringNonZeroNumbers.size() == 1) {
1172 factor = *occurringNonZeroNumbers.begin();
1173 } else {
1174 // Obtain the least common multiple of the denominators of the occurring numbers.
1175 // We can then multiply the numbers with the lcm to obtain integers.
1176 auto numberIt = occurringNonZeroNumbers.begin();
1177 ValueType lcm = storm::utility::asFraction(*numberIt).second;
1178 for (++numberIt; numberIt != occurringNonZeroNumbers.end(); ++numberIt) {
1179 lcm = carl::lcm(lcm, storm::utility::asFraction(*numberIt).second);
1180 }
1181 // Multiply all values with the lcm. To reduce the range of considered integers, we also obtain the gcd of the results.
1182 numberIt = occurringNonZeroNumbers.begin();
1183 ValueType gcd = *numberIt * lcm;
1184 for (++numberIt; numberIt != occurringNonZeroNumbers.end(); ++numberIt) {
1185 gcd = carl::gcd(gcd, static_cast<ValueType>(*numberIt * lcm));
1186 }
1187
1188 factor = gcd / lcm;
1189 }
1190
1191 // Build the result
1192 std::vector<TargetValueType> result;
1193 result.reserve(vec.size());
1194 for (auto const& v : vec) {
1195 ValueType vScaled = v / factor;
1196 STORM_LOG_ASSERT(storm::utility::isInteger(vScaled), "Resulting number '(" << v << ")/(" << factor << ") = " << vScaled << "' is not integral.");
1197 result.push_back(storm::utility::convertNumber<TargetValueType, ValueType>(vScaled));
1198 }
1199 return std::make_pair(std::move(result), std::move(factor));
1200}
1201
1202template<typename ValueType, typename TargetValueType>
1203typename std::enable_if<!std::is_same<ValueType, storm::RationalNumber>::value, std::pair<std::vector<TargetValueType>, ValueType>>::type toIntegralVector(
1204 std::vector<ValueType> const& vec) {
1205 // TODO: avoid converting back and forth
1206 auto rationalNumberVec = convertNumericVector<storm::RationalNumber>(vec);
1207 auto rationalNumberResult = toIntegralVector<storm::RationalNumber, TargetValueType>(rationalNumberVec);
1208
1209 return std::make_pair(std::move(rationalNumberResult.first), storm::utility::convertNumber<ValueType>(rationalNumberResult.second));
1210}
1211
1212template<typename Type>
1213std::vector<Type> filterVector(std::vector<Type> const& in, storm::storage::BitVector const& filter) {
1214 std::vector<Type> result;
1215 result.reserve(filter.getNumberOfSetBits());
1216 for (auto index : filter) {
1217 result.push_back(in[index]);
1218 }
1219 STORM_LOG_ASSERT(result.size() == filter.getNumberOfSetBits(), "Result does not match.");
1220 return result;
1221}
1222
1223template<typename Type>
1224void filterVectorInPlace(std::vector<Type>& v, storm::storage::BitVector const& filter) {
1225 STORM_LOG_ASSERT(v.size() == filter.size(), "The filter size does not match the size of the input vector");
1226 uint_fast64_t size = v.size();
1227 // we can start our work at the first index where the filter has value zero
1228 uint_fast64_t firstUnsetIndex = filter.getNextUnsetIndex(0);
1229 if (firstUnsetIndex < size) {
1230 auto vIt = v.begin() + firstUnsetIndex;
1231 for (uint_fast64_t index = filter.getNextSetIndex(firstUnsetIndex + 1); index != size; index = filter.getNextSetIndex(index + 1)) {
1232 *vIt = std::move(v[index]);
1233 ++vIt;
1234 }
1235 v.resize(vIt - v.begin());
1236 v.shrink_to_fit();
1237 }
1238 STORM_LOG_ASSERT(v.size() == filter.getNumberOfSetBits(), "Result does not match.");
1239}
1240
1241template<typename T>
1242bool hasNegativeEntry(std::vector<T> const& v) {
1243 return std::any_of(v.begin(), v.end(), [](T value) { return value < storm::utility::zero<T>(); });
1244}
1245
1246template<typename T>
1247bool hasPositiveEntry(std::vector<T> const& v) {
1248 return std::any_of(v.begin(), v.end(), [](T value) { return value > storm::utility::zero<T>(); });
1249}
1250
1251template<typename T>
1252bool hasNonZeroEntry(std::vector<T> const& v) {
1253 return std::any_of(v.begin(), v.end(), [](T value) { return !storm::utility::isZero(value); });
1254}
1255
1256template<typename T>
1257bool hasZeroEntry(std::vector<T> const& v) {
1258 return std::any_of(v.begin(), v.end(), [](T value) { return storm::utility::isZero(value); });
1259}
1260
1261template<typename T>
1262bool hasInfinityEntry(std::vector<T> const& v) {
1263 return std::any_of(v.begin(), v.end(), [](T value) { return storm::utility::isInfinity(value); });
1264}
1265
1266template<typename T>
1267std::vector<T> applyInversePermutation(std::vector<uint64_t> const& inversePermutation, std::vector<T> const& source) {
1268 std::vector<T> result;
1269 result.reserve(source.size());
1270 for (uint64_t sourceIndex : inversePermutation) {
1271 result.push_back(source[sourceIndex]);
1272 }
1273 return result;
1274}
1275
1276template<typename T>
1277std::vector<T> applyInversePermutationToGroupedVector(std::vector<uint64_t> const& inversePermutation, std::vector<T> const& source,
1278 std::vector<uint64_t> const& rowGroupIndices) {
1279 STORM_LOG_ASSERT(inversePermutation.size() == rowGroupIndices.size() - 1, "Inverse permutation and row group indices do not match.");
1280 std::vector<T> result;
1281 result.reserve(source.size());
1282 for (auto sourceGroupIndex : inversePermutation) {
1283 for (uint64_t sourceIndex = rowGroupIndices[sourceGroupIndex]; sourceIndex < rowGroupIndices[sourceGroupIndex + 1]; ++sourceIndex) {
1284 result.push_back(source[sourceIndex]);
1285 }
1286 }
1287 STORM_LOG_ASSERT(result.size() == source.size(), "result has unexpected length.");
1288 return result;
1289}
1290
1297template<typename ValueType>
1298std::string toString(std::vector<ValueType> const& vector) {
1299 std::stringstream stream;
1300 stream << "vector (" << vector.size() << ") [ ";
1301 if (!vector.empty()) {
1302 for (uint_fast64_t i = 0; i < vector.size() - 1; ++i) {
1303 stream << vector[i] << ", ";
1304 }
1305 stream << vector.back();
1306 }
1307 stream << " ]";
1308 return stream.str();
1309}
1310
1311template<typename PT1, typename PT2>
1312std::string toString(std::vector<std::pair<PT1, PT2>> const& vector) {
1313 std::stringstream stream;
1314 stream << "vector (" << vector.size() << ") [ ";
1315 if (!vector.empty()) {
1316 for (uint_fast64_t i = 0; i < vector.size() - 1; ++i) {
1317 stream << "{" << vector[i].first << "," << vector[i].second << "}, ";
1318 }
1319 stream << "{" << vector.back().first << "," << vector.back().second << "}";
1320 }
1321 stream << " ]";
1322 return stream.str();
1323}
1324
1325} // namespace vector
1326} // namespace utility
1327} // namespace storm
1328
1329#endif /* STORM_UTILITY_VECTOR_H_ */
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
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)
Definition macros.h:11
std::size_t findOrInsert(std::vector< T > &vector, T &&element)
Finds the given element in the given vector.
Definition vector.h:49
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...
Definition vector.h:1119
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...
Definition vector.h:530
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...
Definition vector.h:356
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.
Definition vector.h:635
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.
Definition vector.h:443
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.
Definition vector.h:480
T dotProduct(std::vector< T > const &firstOperand, std::vector< T > const &secondOperand)
Computes the dot product (aka scalar product) and returns the result.
Definition vector.h:517
std::vector< NewValueType > toValueType(std::vector< ValueType > const &oldVector)
Converts the given vector to the given ValueType.
Definition vector.h:1147
bool hasInfinityEntry(std::vector< T > const &v)
Definition vector.h:1262
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...
Definition vector.h:310
void setNonzeroIndices(std::vector< T > const &vec, storm::storage::BitVector &bv)
Definition vector.h:111
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.
Definition vector.h:612
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.
Definition vector.h:83
bool compareElementWise(std::vector< T > const &left, std::vector< T > const &right, Comparator comp=std::less< T >())
Definition vector.h:177
std::vector< T > buildVectorForRange(T min, T max)
Constructs a vector [min, min+1, ...., max-1].
Definition vector.h:134
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 >())
Definition vector.h:58
void addFilteredVectorGroupsToGroupedVector(std::vector< T > &target, std::vector< T > const &source, storm::storage::BitVector const &filter, std::vector< uint_fast64_t > const &rowGroupIndices)
Definition vector.h:289
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.
Definition vector.h:884
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...
Definition vector.h:189
T computeSquaredNorm2Difference(std::vector< T > const &b1, std::vector< T > const &b2)
Definition vector.h:1021
bool isUnique(std::vector< T > const &v)
Returns true iff every element in the given vector is unique, i.e., there are no i,...
Definition vector.h:159
T maximumElementDiff(std::vector< T > const &vectorLeft, std::vector< T > const &vectorRight)
Definition vector.h:1007
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...
Definition vector.h:852
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...
Definition vector.h:552
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...
Definition vector.h:735
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...
Definition vector.h:504
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.
Definition vector.h:467
bool hasPositiveEntry(std::vector< T > const &v)
Definition vector.h:1247
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...
Definition vector.h:574
bool hasNegativeEntry(std::vector< T > const &v)
Definition vector.h:1242
T maximumElementAbs(std::vector< T > const &vector)
Definition vector.h:998
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.
Definition vector.h:1041
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...
Definition vector.h:335
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 ...
Definition vector.h:266
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...
Definition vector.h:398
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.
Definition vector.h:807
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.
Definition vector.h:596
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...
Definition vector.h:585
std::vector< T > applyInversePermutation(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source)
Definition vector.h:1267
void filterVectorInPlace(std::vector< Type > &v, storm::storage::BitVector const &filter)
Definition vector.h:1224
void iota_n(OutputIterator first, Size n, Assignable value)
Iota function as a helper for efficient creating a range in a vector.
Definition vector.h:126
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.
Definition vector.h:455
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,...
Definition vector.h:149
bool hasZeroEntry(std::vector< T > const &v)
Definition vector.h:1257
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...
Definition vector.h:563
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...
Definition vector.h:491
std::vector< T > applyInversePermutationToGroupedVector(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source, std::vector< uint64_t > const &rowGroupIndices)
Definition vector.h:1277
std::vector< T > getConstrainedOffsetVector(std::vector< T > const &offsetVector, storm::storage::BitVector const &constraint)
Takes the given offset vector and applies the given contraint.
Definition vector.h:1090
bool hasNonZeroEntry(std::vector< T > const &v)
Definition vector.h:1252
void subtractFromConstantOneVector(std::vector< T > &vector)
Subtracts the given vector from the constant one-vector and writes the result to the input vector.
Definition vector.h:282
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.
Definition vector.h:829
std::enable_if< std::is_same< ValueType, storm::RationalNumber >::value, std::pair< std::vector< TargetValueType >, ValueType > >::type toIntegralVector(std::vector< ValueType > const &vec)
Definition vector.h:1157
std::vector< Type > filterVector(std::vector< Type > const &in, storm::storage::BitVector const &filter)
Definition vector.h:1213
ValueType max(ValueType const &first, ValueType const &second)
ValueType min(ValueType const &first, ValueType const &second)
bool isAlmostZero(ValueType const &a)
Definition constants.cpp:56
std::pair< ValueType, ValueType > asFraction(ValueType const &number)
bool isZero(ValueType const &a)
Definition constants.cpp:41
bool isInteger(ValueType const &number)
Definition constants.cpp:76
ValueType abs(ValueType const &number)
std::string toString(Engine const &engine)
Returns a string representation of the given engine.
Definition Engine.cpp:41
LabParser.cpp.
Definition cli.cpp:18
size_t operator()(std::vector< ValueType > const &vec) const
Definition vector.h:26