Browse Source
Replaced VectorSet bei boost::container::flat_set, which does essentially the same. Fixed a bug in sparse matrix creation.
Replaced VectorSet bei boost::container::flat_set, which does essentially the same. Fixed a bug in sparse matrix creation.
Former-commit-id: cb632bcfd4
tempestpy_adaptions
dehnert
11 years ago
35 changed files with 242 additions and 751 deletions
-
20src/adapters/ExplicitModelAdapter.h
-
22src/counterexamples/MILPMinimalLabelSetGenerator.h
-
152src/counterexamples/SMTMinimalCommandSetGenerator.h
-
4src/ir/Module.cpp
-
4src/ir/Module.h
-
2src/ir/Program.cpp
-
4src/ir/Program.h
-
4src/modelchecker/csl/SparseMarkovAutomatonCslModelChecker.h
-
6src/models/AbstractDeterministicModel.h
-
13src/models/AbstractModel.h
-
8src/models/AbstractNondeterministicModel.h
-
6src/models/Ctmc.h
-
6src/models/Ctmdp.h
-
14src/models/Dtmc.h
-
6src/models/MarkovAutomaton.h
-
18src/models/Mdp.h
-
4src/parser/DeterministicModelParser.cpp
-
2src/parser/MarkovAutomatonParser.cpp
-
4src/parser/NondeterministicModelParser.cpp
-
7src/storage/BitVector.cpp
-
15src/storage/Decomposition.cpp
-
7src/storage/Decomposition.h
-
18src/storage/LabeledValues.h
-
14src/storage/MaximalEndComponent.cpp
-
13src/storage/MaximalEndComponent.h
-
12src/storage/MaximalEndComponentDecomposition.cpp
-
52src/storage/SparseMatrix.cpp
-
49src/storage/SparseMatrix.h
-
3src/storage/StronglyConnectedComponentDecomposition.h
-
299src/storage/VectorSet.cpp
-
116src/storage/VectorSet.h
-
10src/utility/IRUtility.h
-
20src/utility/counterexamples.h
-
53src/utility/set.h
-
6test/functional/storage/SparseMatrixTest.cpp
@ -1,299 +0,0 @@ |
|||
#include "src/storage/VectorSet.h"
|
|||
#include "src/storage/BitVector.h"
|
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet() : data(), dirty(false) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet(uint_fast64_t size) : data(), dirty(false) { |
|||
data.reserve(size); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
template<typename InputIterator> |
|||
VectorSet<ValueType>::VectorSet(InputIterator first, InputIterator last) : dirty(true) { |
|||
this->data.insert(this->data.end(), first, last); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet(std::vector<ValueType> const& data) : data(data), dirty(true) { |
|||
ensureSet(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet(std::set<ValueType> const& data) : dirty(false) { |
|||
this->data.reserve(data.size()); |
|||
for (auto const& element : data) { |
|||
this->data.push_back(element); |
|||
} |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet(storm::storage::BitVector const& data) : dirty(false) { |
|||
this->data.reserve(data.getNumberOfSetBits()); |
|||
for (auto element : data) { |
|||
this->data.push_back(element); |
|||
} |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet(uint_fast64_t from, uint_fast64_t to) : dirty(false) { |
|||
data.reserve(to - from); |
|||
|
|||
for (uint_fast64_t element = from; element < to; ++element) { |
|||
data.push_back(element); |
|||
} |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet(VectorSet const& other) : dirty(false) { |
|||
other.ensureSet(); |
|||
data = other.data; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>& VectorSet<ValueType>::operator=(VectorSet<ValueType> const& other) { |
|||
data = other.data; |
|||
dirty = other.dirty; |
|||
return *this; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>::VectorSet(VectorSet<ValueType>&& other) : data(std::move(other.data)), dirty(std::move(other.dirty)) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType>& VectorSet<ValueType>::operator=(VectorSet&& other) { |
|||
data = std::move(other.data); |
|||
dirty = std::move(other.dirty); |
|||
return *this; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::operator==(VectorSet<ValueType> const& other) const { |
|||
ensureSet(); |
|||
if (this->size() != other.size()) return false; |
|||
return std::equal(data.begin(), data.end(), other.begin()); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::operator<(VectorSet<ValueType> const& other) const { |
|||
ensureSet(); |
|||
if (this->size() < other.size()) return true; |
|||
if (this->size() > other.size()) return false; |
|||
for (auto it1 = this->begin(), it2 = other.begin(); it1 != this->end(); ++it1, ++it2) { |
|||
if (*it1 < *it2) return true; |
|||
if (*it1 > *it2) return false; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::operator>(VectorSet<ValueType> const& other) const { |
|||
ensureSet(); |
|||
if (this->size() > other.size()) return true; |
|||
if (this->size() < other.size()) return false; |
|||
for (auto it1 = this->begin(), it2 = other.begin(); it1 != this->end(); ++it1, ++it2) { |
|||
if (*it1 > *it2) return true; |
|||
if (*it1 < *it2) return false; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void VectorSet<ValueType>::ensureSet() const { |
|||
if (dirty) { |
|||
std::sort(data.begin(), data.end()); |
|||
data.erase(std::unique(data.begin(), data.end()), data.end()); |
|||
dirty = false; |
|||
} |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::contains(ValueType const& element) const { |
|||
ensureSet(); |
|||
return std::binary_search(data.begin(), data.end(), element); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::subsetOf(VectorSet<ValueType> const& other) const { |
|||
ensureSet(); |
|||
other.ensureSet(); |
|||
return std::includes(other.begin(), other.end(), data.begin(), data.end()); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::supersetOf(VectorSet<ValueType> const& other) const { |
|||
ensureSet(); |
|||
return other.subsetOf(*this); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType> VectorSet<ValueType>::intersect(VectorSet<ValueType> const& other) { |
|||
ensureSet(); |
|||
other.ensureSet(); |
|||
VectorSet result; |
|||
std::set_intersection(data.begin(), data.end(), other.begin(), other.end(), std::inserter(result.data, result.data.end())); |
|||
return result; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
VectorSet<ValueType> VectorSet<ValueType>::join(VectorSet<ValueType> const& other) { |
|||
ensureSet(); |
|||
other.ensureSet(); |
|||
VectorSet result; |
|||
std::set_union(data.begin(), data.end(), other.begin(), other.end(), std::inserter(result.data, result.data.end())); |
|||
return result; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
typename VectorSet<ValueType>::iterator VectorSet<ValueType>::begin() { |
|||
ensureSet(); |
|||
return data.begin(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
typename VectorSet<ValueType>::iterator VectorSet<ValueType>::end() { |
|||
ensureSet(); |
|||
return data.end(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
typename VectorSet<ValueType>::const_iterator VectorSet<ValueType>::begin() const { |
|||
ensureSet(); |
|||
return data.begin(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
typename VectorSet<ValueType>::const_iterator VectorSet<ValueType>::end() const { |
|||
ensureSet(); |
|||
return data.end(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
ValueType const& VectorSet<ValueType>::min() const { |
|||
if (this->size() == 0) { |
|||
throw storm::exceptions::InvalidStateException() << "Cannot retrieve minimum of empty set."; |
|||
} |
|||
|
|||
ensureSet(); |
|||
return data.front(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
ValueType const& VectorSet<ValueType>::max() const { |
|||
if (this->size() == 0) { |
|||
throw storm::exceptions::InvalidStateException() << "Cannot retrieve minimum of empty set."; |
|||
} |
|||
|
|||
ensureSet(); |
|||
return data.back(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void VectorSet<ValueType>::insert(ValueType const& element) { |
|||
data.push_back(element); |
|||
dirty = true; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
typename VectorSet<ValueType>::iterator VectorSet<ValueType>::insert(typename VectorSet<ValueType>::iterator pos, ValueType const& element) { |
|||
dirty = true; |
|||
return data.insert(pos, element); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void VectorSet<ValueType>::insert(VectorSet<ValueType> const& other) { |
|||
data.insert(data.end(), other.data.begin(), other.data.end()); |
|||
dirty = true; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::empty() const { |
|||
ensureSet(); |
|||
return data.empty(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
size_t VectorSet<ValueType>::size() const { |
|||
ensureSet(); |
|||
return data.size(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void VectorSet<ValueType>::clear() { |
|||
data.clear(); |
|||
dirty = false; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
bool VectorSet<ValueType>::erase(ValueType const& element) { |
|||
ensureSet(); |
|||
uint_fast64_t lowerBound = 0; |
|||
uint_fast64_t upperBound = data.size(); |
|||
while (lowerBound != upperBound) { |
|||
uint_fast64_t currentPosition = lowerBound + (upperBound - lowerBound) / 2; |
|||
bool searchInLowerHalf = element < data[currentPosition]; |
|||
if (searchInLowerHalf) { |
|||
upperBound = currentPosition; |
|||
} else { |
|||
bool searchInRightHalf = element > data[currentPosition]; |
|||
if (searchInRightHalf) { |
|||
lowerBound = currentPosition + 1; |
|||
} else { |
|||
// At this point we have found the element.
|
|||
data.erase(data.begin() + currentPosition); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void VectorSet<ValueType>::erase(VectorSet<ValueType> const& eraseSet) { |
|||
if (eraseSet.size() > 0 && this->size() > 0) { |
|||
ensureSet(); |
|||
eraseSet.ensureSet(); |
|||
|
|||
for (typename std::vector<ValueType>::reverse_iterator delIt = eraseSet.data.rbegin(), setIt = data.rbegin(); delIt != eraseSet.data.rend() && setIt != eraseSet.data.rend(); ++delIt) { |
|||
while (setIt != eraseSet.data.rend() && *setIt > *delIt) { |
|||
++setIt; |
|||
} |
|||
if (setIt == data.rend()) break; |
|||
|
|||
if (*setIt == *delIt) { |
|||
data.erase((setIt + 1).base()); |
|||
++setIt; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
std::ostream& operator<<(std::ostream& stream, VectorSet<ValueType> const& set) { |
|||
set.ensureSet(); |
|||
stream << "VectorSet(" << set.size() << ") { "; |
|||
if (set.size() > 0) { |
|||
for (uint_fast64_t index = 0; index < set.size() - 1; ++index) { |
|||
stream << set.data[index] << ", "; |
|||
} |
|||
stream << set.data[set.size() - 1] << " }"; |
|||
} else { |
|||
stream << "}"; |
|||
} |
|||
return stream; |
|||
} |
|||
|
|||
template class VectorSet<uint_fast64_t>; |
|||
template class VectorSet<VectorSet<uint_fast64_t>>; |
|||
template VectorSet<uint_fast64_t>::VectorSet(storm::storage::BitVector::const_iterator, storm::storage::BitVector::const_iterator); |
|||
template std::ostream& operator<<(std::ostream& stream, VectorSet<uint_fast64_t> const& set); |
|||
template std::ostream& operator<<(std::ostream& stream, VectorSet<VectorSet<uint_fast64_t>> const& set); |
|||
} |
|||
} |
@ -1,116 +0,0 @@ |
|||
/* |
|||
* VectorSet.h |
|||
* |
|||
* Created on: 23.10.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#ifndef STORM_STORAGE_VECTORSET_H |
|||
#define STORM_STORAGE_VECTORSET_H |
|||
|
|||
#include <cstdint> |
|||
#include <set> |
|||
#include <algorithm> |
|||
#include <iostream> |
|||
#include <vector> |
|||
#include <set> |
|||
|
|||
#include "src/exceptions/InvalidStateException.h" |
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
|
|||
// Forward declare bit vector class. |
|||
class BitVector; |
|||
|
|||
template<typename ValueType> |
|||
class VectorSet { |
|||
public: |
|||
typedef ValueType* difference_type; |
|||
typedef ValueType value_type; |
|||
typedef ValueType* pointer; |
|||
typedef ValueType& reference; |
|||
typedef typename std::vector<ValueType>::iterator iterator; |
|||
typedef typename std::vector<ValueType>::const_iterator const_iterator; |
|||
|
|||
VectorSet(); |
|||
|
|||
VectorSet(uint_fast64_t size); |
|||
|
|||
template<typename InputIterator> |
|||
VectorSet(InputIterator first, InputIterator last); |
|||
|
|||
VectorSet(std::vector<ValueType> const& data); |
|||
|
|||
VectorSet(std::set<ValueType> const& data); |
|||
|
|||
VectorSet(BitVector const& data); |
|||
|
|||
VectorSet(uint_fast64_t from, uint_fast64_t to); |
|||
|
|||
VectorSet(VectorSet const& other); |
|||
|
|||
VectorSet& operator=(VectorSet const& other); |
|||
|
|||
VectorSet(VectorSet&& other); |
|||
|
|||
VectorSet& operator=(VectorSet&& other); |
|||
|
|||
bool operator==(VectorSet const& other) const; |
|||
|
|||
bool operator<(VectorSet const& other) const; |
|||
|
|||
bool operator>(VectorSet const& other) const; |
|||
|
|||
void ensureSet() const; |
|||
|
|||
bool contains(ValueType const& element) const; |
|||
|
|||
bool subsetOf(VectorSet const& other) const; |
|||
|
|||
bool supersetOf(VectorSet const& other) const; |
|||
|
|||
VectorSet intersect(VectorSet const& other); |
|||
|
|||
VectorSet join(VectorSet const& other); |
|||
|
|||
iterator begin(); |
|||
|
|||
iterator end(); |
|||
|
|||
const_iterator begin() const; |
|||
|
|||
const_iterator end() const; |
|||
|
|||
ValueType const& min() const; |
|||
|
|||
ValueType const& max() const; |
|||
|
|||
void insert(ValueType const& element); |
|||
|
|||
// FIXME: As soon as gcc provides an erase(const_iterator) method, change this iterator back to a const_iterator. |
|||
iterator insert(iterator pos, ValueType const& element); |
|||
|
|||
void insert(VectorSet<ValueType> const& other); |
|||
|
|||
bool empty() const; |
|||
|
|||
size_t size() const; |
|||
|
|||
void clear(); |
|||
|
|||
bool erase(ValueType const& element); |
|||
|
|||
void erase(VectorSet const& eraseSet); |
|||
|
|||
template<typename ValueTypePrime> |
|||
friend std::ostream& operator<< (std::ostream& stream, VectorSet<ValueTypePrime> const& set); |
|||
|
|||
private: |
|||
mutable std::vector<ValueType> data; |
|||
mutable bool dirty; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_VECTORSET_H */ |
@ -1,53 +0,0 @@ |
|||
/* |
|||
* set.h |
|||
* |
|||
* Created on: 06.12.2012 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#ifndef STORM_UTILITY_SET_H_ |
|||
#define STORM_UTILITY_SET_H_ |
|||
|
|||
#include <set> |
|||
|
|||
#include "log4cplus/logger.h" |
|||
#include "log4cplus/loggingmacros.h" |
|||
|
|||
extern log4cplus::Logger logger; |
|||
|
|||
namespace storm { |
|||
namespace utility { |
|||
namespace set { |
|||
|
|||
template<typename T, typename Compare> |
|||
bool isSubsetOf(std::set<T, Compare> const& set1, std::set<T, Compare> const& set2) { |
|||
// First, get a comparator object. |
|||
typename std::set<T, Compare>::key_compare comparator = set1.key_comp(); |
|||
|
|||
for (typename std::set<T, Compare>::const_iterator it1 = set1.begin(), it2 = set2.begin(); it1 != set1.end() && it2 != set2.end(); ++it1) { |
|||
// If the value in set1 is smaller than the value in set2, set1 is not a subset of set2. |
|||
if (comparator(*it1, *it2)) { |
|||
return false; |
|||
} |
|||
|
|||
// If the value in the second set is smaller, we need to move the iterator until the comparison is false. |
|||
while(comparator(*it2, *it1) && it2 != set2.end()) { |
|||
++it2; |
|||
} |
|||
|
|||
// If we have reached the end of set2 or the element we found is actually larger than the one in set1 |
|||
// we know that the subset property is violated. |
|||
if (it2 == set2.end() || comparator(*it1, *it2)) { |
|||
return false; |
|||
} |
|||
|
|||
// Otherwise, we have found an equivalent element and can continue with the next one. |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
} // namespace set |
|||
} // namespace utility |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_UTILITY_SET_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue