11template<
typename ParametricType,
typename ConstantType>
15 bool useMonotonicityInFuture) {
17 oldToNewColumnIndexMapping = std::vector<uint_fast64_t>(selectedColumns.
size(), selectedColumns.
size());
18 uint_fast64_t newIndex = 0;
19 for (
auto const& oldColumn : selectedColumns) {
20 oldToNewColumnIndexMapping[oldColumn] = newIndex++;
24 occurringVariablesAtState = std::vector<std::set<VariableType>>(pMatrix.
getColumnCount());
30 uint_fast64_t pMatrixEntryCount = 0;
31 uint_fast64_t pVectorEntryCount = 0;
35 rowGroupToStateNumber = std::vector<uint_fast64_t>();
36 uint_fast64_t newRowIndex = 0;
37 for (
auto const& rowIndex : selectedRows) {
39 rowGroupToStateNumber.push_back(rowIndex);
42 std::set<VariableType> occurringVariables;
43 for (
auto const& entry : pMatrix.
getRow(rowIndex)) {
44 if (selectedColumns.
get(entry.getColumn())) {
47 nonConstMatrixEntries.set(pMatrixEntryCount,
true);
57 ParametricType
const& pVectorEntry = pVector[rowIndex];
58 std::set<VariableType> vectorEntryVariables;
61 if (generateRowLabels) {
64 occurringVariables.insert(vectorEntryVariables.begin(), vectorEntryVariables.end());
66 nonConstVectorEntries.set(pVectorEntryCount,
true);
70 auto rowValuations = getVerticesOfAbstractRegion(occurringVariables);
71 for (
auto const& val : rowValuations) {
72 if (generateRowLabels) {
73 rowLabels.push_back(val);
79 for (
auto const& entry : pMatrix.
getRow(rowIndex)) {
80 if (selectedColumns.
get(entry.getColumn())) {
82 builder.
addNextValue(newRowIndex, oldToNewColumnIndexMapping[entry.getColumn()],
83 storm::utility::convertNumber<ConstantType>(entry.getValue()));
85 builder.
addNextValue(newRowIndex, oldToNewColumnIndexMapping[entry.getColumn()], storm::utility::one<ConstantType>());
86 ConstantType& placeholder = functionValuationCollector.add(entry.getValue(), val);
95 vector.push_back(storm::utility::convertNumber<ConstantType>(pVectorEntry));
97 vector.push_back(storm::utility::one<ConstantType>());
99 for (
auto const& vectorVar : vectorEntryVariables) {
100 if (occurringVariables.find(vectorVar) == occurringVariables.end()) {
101 assert(!generateRowLabels);
105 ConstantType& placeholder = functionValuationCollector.add(pVectorEntry, vectorVal);
106 vectorAssignment.push_back(
107 std::pair<
typename std::vector<ConstantType>::iterator, ConstantType&>(
typename std::vector<ConstantType>::iterator(), placeholder));
112 if (useMonotonicityInFuture) {
114 for (
auto& var : occurringVariables) {
115 occuringStatesAtVariable[var].insert(rowIndex);
117 occurringVariablesAtState[rowIndex] = std::move(occurringVariables);
122 matrix = builder.
build(newRowIndex);
123 vector.shrink_to_fit();
124 matrixAssignment.shrink_to_fit();
125 vectorAssignment.shrink_to_fit();
126 nonConstMatrixEntries.resize(pMatrixEntryCount);
129 auto matrixAssignmentIt = matrixAssignment.begin();
130 uint_fast64_t startEntryOfRow = 0;
131 for (uint_fast64_t group = 0; group < matrix.getRowGroupCount(); ++group) {
132 uint_fast64_t startEntryOfNextRow = startEntryOfRow + matrix.getRow(group, 0).getNumberOfEntries();
133 for (uint_fast64_t matrixRow = matrix.getRowGroupIndices()[group]; matrixRow < matrix.getRowGroupIndices()[group + 1]; ++matrixRow) {
134 auto matrixEntryIt = matrix.getRow(matrixRow).begin();
135 for (uint_fast64_t nonConstEntryIndex = nonConstMatrixEntries.getNextSetIndex(startEntryOfRow); nonConstEntryIndex < startEntryOfNextRow;
136 nonConstEntryIndex = nonConstMatrixEntries.getNextSetIndex(nonConstEntryIndex + 1)) {
137 matrixAssignmentIt->first = matrixEntryIt + (nonConstEntryIndex - startEntryOfRow);
138 ++matrixAssignmentIt;
141 startEntryOfRow = startEntryOfNextRow;
143 STORM_LOG_ASSERT(matrixAssignmentIt == matrixAssignment.end(),
"Unexpected number of entries in the matrix assignment.");
145 auto vectorAssignmentIt = vectorAssignment.begin();
146 for (
auto const& nonConstVectorEntry : nonConstVectorEntries) {
147 for (uint_fast64_t vectorIndex = matrix.getRowGroupIndices()[nonConstVectorEntry]; vectorIndex != matrix.getRowGroupIndices()[nonConstVectorEntry + 1];
149 vectorAssignmentIt->first = vector.begin() + vectorIndex;
150 ++vectorAssignmentIt;
153 STORM_LOG_ASSERT(vectorAssignmentIt == vectorAssignment.end(),
"Unexpected number of entries in the vector assignment.");
156template<
typename ParametricType,
typename ConstantType>
160 functionValuationCollector.evaluateCollectedFunctions(region, dirForParameters);
163 for (
auto& assignment : matrixAssignment) {
166 "Parameter lifting on region "
168 <<
" affects the underlying graph structure (the region is not strictly well defined). The result for this region might be incorrect.");
169 assignment.first->setValue(assignment.second);
172 for (
auto& assignment : vectorAssignment) {
173 *assignment.first = assignment.second;
177template<
typename ParametricType,
typename ConstantType>
179 return matrix.getRowGroupIndices()[oldToNewColumnIndexMapping[originalState]];
182template<
typename ParametricType,
typename ConstantType>
184 return rowGroupToStateNumber[newState];
187template<
typename ParametricType,
typename ConstantType>
189 return matrix.getRowGroupSize(oldToNewColumnIndexMapping[originalState]);
191template<
typename ParametricType,
typename ConstantType>
193 return matrix.getRowGroupCount();
196template<
typename ParametricType,
typename ConstantType>
201template<
typename ParametricType,
typename ConstantType>
206template<
typename ParametricType,
typename ConstantType>
212template<
typename ParametricType,
typename ConstantType>
213std::vector<typename ParameterLifter<ParametricType, ConstantType>::AbstractValuation>
215 std::size_t
const numOfVertices = std::pow(2, variables.size());
216 std::vector<AbstractValuation> result(numOfVertices);
218 for (uint_fast64_t vertexId = 0; vertexId < numOfVertices; ++vertexId) {
222 uint_fast64_t variableIndex = 0;
223 for (
auto const& variable : variables) {
224 if ((vertexId >> variableIndex) % 2 == 0) {
225 result[vertexId].addParameterLower(variable);
227 result[vertexId].addParameterUpper(variable);
235template<
typename ParametricType,
typename ConstantType>
236const std::vector<std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>>&
238 return occurringVariablesAtState;
241template<
typename ParametricType,
typename ConstantType>
242std::map<typename ParameterLifter<ParametricType, ConstantType>::VariableType, std::set<uint_fast64_t>>
244 return occuringStatesAtVariable;
247template<
typename ParametricType,
typename ConstantType>
249 return this->lowerPars == other.lowerPars && this->upperPars == other.upperPars && this->unspecifiedPars == other.unspecifiedPars;
252template<
typename ParametricType,
typename ConstantType>
254 lowerPars.insert(var);
257template<
typename ParametricType,
typename ConstantType>
259 upperPars.insert(var);
262template<
typename ParametricType,
typename ConstantType>
264 unspecifiedPars.insert(var);
267template<
typename ParametricType,
typename ConstantType>
269 std::size_t seed = 0;
270 for (
auto const& p : lowerPars) {
271 carl::hash_add(seed, p);
273 for (
auto const& p : upperPars) {
274 carl::hash_add(seed, p);
276 for (
auto const& p : unspecifiedPars) {
277 carl::hash_add(seed, p);
282template<
typename ParametricType,
typename ConstantType>
284 std::set<VariableType>
const& pars)
const {
286 for (
auto const& p : pars) {
287 if (std::find(lowerPars.begin(), lowerPars.end(), p) != lowerPars.end()) {
289 }
else if (std::find(upperPars.begin(), upperPars.end(), p) != upperPars.end()) {
291 }
else if (std::find(unspecifiedPars.begin(), unspecifiedPars.end(), p) != unspecifiedPars.end()) {
295 "Tried to obtain a subvaluation for parameters that are not specified by this valuation");
301template<
typename ParametricType,
typename ConstantType>
302std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>
const&
307template<
typename ParametricType,
typename ConstantType>
308std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>
const&
313template<
typename ParametricType,
typename ConstantType>
314std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>
const&
316 return unspecifiedPars;
319template<
typename ParametricType,
typename ConstantType>
323 for (
auto& valuation : result) {
324 for (
auto const& lowerPar : lowerPars) {
325 valuation.insert(std::pair<VariableType, CoefficientType>(lowerPar, region.
getLowerBoundary(lowerPar)));
327 for (
auto const& upperPar : upperPars) {
328 valuation.insert(std::pair<VariableType, CoefficientType>(upperPar, region.
getUpperBoundary(upperPar)));
334template<
typename ParametricType,
typename ConstantType>
337 ParametricType simplifiedFunction = function;
339 std::set<VariableType> variablesInFunction;
344 auto insertionRes = collectedFunctions.insert(std::pair<FunctionValuation, ConstantType>(
345 FunctionValuation(std::move(simplifiedFunction), std::move(simplifiedValuation)), storm::utility::one<ConstantType>()));
346 return insertionRes.first->second;
349template<
typename ParametricType,
typename ConstantType>
352 for (
auto& collectedFunctionValuationPlaceholder : collectedFunctions) {
353 ParametricType
const& function = collectedFunctionValuationPlaceholder.first.first;
354 AbstractValuation
const& abstrValuation = collectedFunctionValuationPlaceholder.first.second;
355 ConstantType& placeholder = collectedFunctionValuationPlaceholder.second;
356 auto concreteValuations = abstrValuation.getConcreteValuations(region);
357 auto concreteValuationIt = concreteValuations.begin();
359 for (++concreteValuationIt; concreteValuationIt != concreteValuations.end(); ++concreteValuationIt) {
362 placeholder = std::min(placeholder, currentResult);
364 placeholder = std::max(placeholder, currentResult);
370template class ParameterLifter<storm::RationalFunction, double>;
371template class ParameterLifter<storm::RationalFunction, storm::RationalNumber>;
A bit vector that is internally represented as a vector of 64-bit values.
size_t size() const
Retrieves the number of bits this bit vector can store.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
std::string toString(bool boundariesAsDouble=false) const
CoefficientType const & getLowerBoundary(VariableType const &variable) const
CoefficientType const & getUpperBoundary(VariableType const &variable) const
std::vector< Valuation > getVerticesOfRegion(std::set< VariableType > const &consideredVariables) const
Returns a vector of all possible combinations of lower and upper bounds of the given variables.
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
void newRowGroup(index_type startingRow)
Starts a new row group in the matrix.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
index_type getEntryCount() const
Returns the number of entries in the matrix.
index_type getColumnCount() const
Returns the number of columns of the matrix.
std::vector< MatrixEntry< index_type, value_type > >::iterator iterator
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_WARN_COND(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
bool constexpr minimize(OptimizationDirection d)
void gatherOccurringVariables(FunctionType const &function, std::set< typename VariableType< FunctionType >::type > &variableSet)
Add all variables that occur in the given function to the the given set.
CoefficientType< FunctionType >::type evaluate(FunctionType const &function, Valuation< FunctionType > const &valuation)
Evaluates the given function wrt.
bool isConstant(ValueType const &)
ValueType simplify(ValueType value)
bool isZero(ValueType const &a)