10template<
typename ParametricType,
typename ConstantType>
14 bool useMonotonicityInFuture) {
16 oldToNewColumnIndexMapping = std::vector<uint_fast64_t>(selectedColumns.
size(), selectedColumns.
size());
17 uint_fast64_t newIndex = 0;
18 for (
auto const& oldColumn : selectedColumns) {
19 oldToNewColumnIndexMapping[oldColumn] = newIndex++;
23 occurringVariablesAtState = std::vector<std::set<VariableType>>(pMatrix.
getColumnCount());
29 uint_fast64_t pMatrixEntryCount = 0;
30 uint_fast64_t pVectorEntryCount = 0;
34 rowGroupToStateNumber = std::vector<uint_fast64_t>();
35 uint_fast64_t newRowIndex = 0;
36 for (
auto const& rowIndex : selectedRows) {
38 rowGroupToStateNumber.push_back(rowIndex);
41 std::set<VariableType> occurringVariables;
42 for (
auto const& entry : pMatrix.
getRow(rowIndex)) {
43 if (selectedColumns.
get(entry.getColumn())) {
46 nonConstMatrixEntries.set(pMatrixEntryCount,
true);
56 ParametricType
const& pVectorEntry = pVector[rowIndex];
57 std::set<VariableType> vectorEntryVariables;
60 if (generateRowLabels) {
63 occurringVariables.insert(vectorEntryVariables.begin(), vectorEntryVariables.end());
65 nonConstVectorEntries.set(pVectorEntryCount,
true);
69 auto rowValuations = getVerticesOfAbstractRegion(occurringVariables);
70 for (
auto const& val : rowValuations) {
71 if (generateRowLabels) {
72 rowLabels.push_back(val);
78 for (
auto const& entry : pMatrix.
getRow(rowIndex)) {
79 if (selectedColumns.
get(entry.getColumn())) {
81 builder.
addNextValue(newRowIndex, oldToNewColumnIndexMapping[entry.getColumn()],
82 storm::utility::convertNumber<ConstantType>(entry.getValue()));
84 builder.
addNextValue(newRowIndex, oldToNewColumnIndexMapping[entry.getColumn()], storm::utility::one<ConstantType>());
85 ConstantType& placeholder = functionValuationCollector.add(entry.getValue(), val);
94 vector.push_back(storm::utility::convertNumber<ConstantType>(pVectorEntry));
96 vector.push_back(storm::utility::one<ConstantType>());
98 for (
auto const& vectorVar : vectorEntryVariables) {
99 if (occurringVariables.find(vectorVar) == occurringVariables.end()) {
100 assert(!generateRowLabels);
104 ConstantType& placeholder = functionValuationCollector.add(pVectorEntry, vectorVal);
105 vectorAssignment.push_back(
106 std::pair<
typename std::vector<ConstantType>::iterator, ConstantType&>(
typename std::vector<ConstantType>::iterator(), placeholder));
111 if (useMonotonicityInFuture) {
113 for (
auto& var : occurringVariables) {
114 occuringStatesAtVariable[var].insert(rowIndex);
116 occurringVariablesAtState[rowIndex] = std::move(occurringVariables);
121 matrix = builder.
build(newRowIndex);
122 vector.shrink_to_fit();
123 matrixAssignment.shrink_to_fit();
124 vectorAssignment.shrink_to_fit();
125 nonConstMatrixEntries.resize(pMatrixEntryCount);
128 auto matrixAssignmentIt = matrixAssignment.begin();
129 uint_fast64_t startEntryOfRow = 0;
130 for (uint_fast64_t group = 0; group < matrix.getRowGroupCount(); ++group) {
131 uint_fast64_t startEntryOfNextRow = startEntryOfRow + matrix.getRow(group, 0).getNumberOfEntries();
132 for (uint_fast64_t matrixRow = matrix.getRowGroupIndices()[group]; matrixRow < matrix.getRowGroupIndices()[group + 1]; ++matrixRow) {
133 auto matrixEntryIt = matrix.getRow(matrixRow).begin();
134 for (uint_fast64_t nonConstEntryIndex = nonConstMatrixEntries.getNextSetIndex(startEntryOfRow); nonConstEntryIndex < startEntryOfNextRow;
135 nonConstEntryIndex = nonConstMatrixEntries.getNextSetIndex(nonConstEntryIndex + 1)) {
136 matrixAssignmentIt->first = matrixEntryIt + (nonConstEntryIndex - startEntryOfRow);
137 ++matrixAssignmentIt;
140 startEntryOfRow = startEntryOfNextRow;
142 STORM_LOG_ASSERT(matrixAssignmentIt == matrixAssignment.end(),
"Unexpected number of entries in the matrix assignment.");
144 auto vectorAssignmentIt = vectorAssignment.begin();
145 for (
auto const& nonConstVectorEntry : nonConstVectorEntries) {
146 for (uint_fast64_t vectorIndex = matrix.getRowGroupIndices()[nonConstVectorEntry]; vectorIndex != matrix.getRowGroupIndices()[nonConstVectorEntry + 1];
148 vectorAssignmentIt->first = vector.begin() + vectorIndex;
149 ++vectorAssignmentIt;
152 STORM_LOG_ASSERT(vectorAssignmentIt == vectorAssignment.end(),
"Unexpected number of entries in the vector assignment.");
155template<
typename ParametricType,
typename ConstantType>
159 functionValuationCollector.evaluateCollectedFunctions(region, dirForParameters);
162 for (
auto& assignment : matrixAssignment) {
165 "Parameter lifting on region "
167 <<
" affects the underlying graph structure (the region is not strictly well defined). The result for this region might be incorrect.");
168 assignment.first->setValue(assignment.second);
171 for (
auto& assignment : vectorAssignment) {
172 *assignment.first = assignment.second;
176template<
typename ParametricType,
typename ConstantType>
178 return matrix.getRowGroupIndices()[oldToNewColumnIndexMapping[originalState]];
181template<
typename ParametricType,
typename ConstantType>
183 return rowGroupToStateNumber[newState];
186template<
typename ParametricType,
typename ConstantType>
188 return matrix.getRowGroupSize(oldToNewColumnIndexMapping[originalState]);
190template<
typename ParametricType,
typename ConstantType>
192 return matrix.getRowGroupCount();
195template<
typename ParametricType,
typename ConstantType>
200template<
typename ParametricType,
typename ConstantType>
205template<
typename ParametricType,
typename ConstantType>
211template<
typename ParametricType,
typename ConstantType>
212std::vector<typename ParameterLifter<ParametricType, ConstantType>::AbstractValuation>
214 std::size_t
const numOfVertices = std::pow(2, variables.size());
215 std::vector<AbstractValuation> result(numOfVertices);
217 for (uint_fast64_t vertexId = 0; vertexId < numOfVertices; ++vertexId) {
221 uint_fast64_t variableIndex = 0;
222 for (
auto const& variable : variables) {
223 if ((vertexId >> variableIndex) % 2 == 0) {
224 result[vertexId].addParameterLower(variable);
226 result[vertexId].addParameterUpper(variable);
234template<
typename ParametricType,
typename ConstantType>
235const std::vector<std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>>&
237 return occurringVariablesAtState;
240template<
typename ParametricType,
typename ConstantType>
241std::map<typename ParameterLifter<ParametricType, ConstantType>::VariableType, std::set<uint_fast64_t>>
const&
243 return occuringStatesAtVariable;
246template<
typename ParametricType,
typename ConstantType>
248 return this->lowerPars == other.lowerPars && this->upperPars == other.upperPars && this->unspecifiedPars == other.unspecifiedPars;
251template<
typename ParametricType,
typename ConstantType>
253 lowerPars.insert(var);
256template<
typename ParametricType,
typename ConstantType>
258 upperPars.insert(var);
261template<
typename ParametricType,
typename ConstantType>
263 unspecifiedPars.insert(var);
266template<
typename ParametricType,
typename ConstantType>
268 std::size_t seed = 0;
269 for (
auto const& p : lowerPars) {
270 carl::hash_add(seed, p);
272 for (
auto const& p : upperPars) {
273 carl::hash_add(seed, p);
275 for (
auto const& p : unspecifiedPars) {
276 carl::hash_add(seed, p);
281template<
typename ParametricType,
typename ConstantType>
283 std::set<VariableType>
const& pars)
const {
285 for (
auto const& p : pars) {
286 if (std::find(lowerPars.begin(), lowerPars.end(), p) != lowerPars.end()) {
288 }
else if (std::find(upperPars.begin(), upperPars.end(), p) != upperPars.end()) {
290 }
else if (std::find(unspecifiedPars.begin(), unspecifiedPars.end(), p) != unspecifiedPars.end()) {
294 "Tried to obtain a subvaluation for parameters that are not specified by this valuation");
300template<
typename ParametricType,
typename ConstantType>
301std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>
const&
306template<
typename ParametricType,
typename ConstantType>
307std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>
const&
312template<
typename ParametricType,
typename ConstantType>
313std::set<typename ParameterLifter<ParametricType, ConstantType>::VariableType>
const&
315 return unspecifiedPars;
318template<
typename ParametricType,
typename ConstantType>
322 for (
auto& valuation : result) {
323 for (
auto const& lowerPar : lowerPars) {
324 valuation.insert(std::pair<VariableType, CoefficientType>(lowerPar, region.
getLowerBoundary(lowerPar)));
326 for (
auto const& upperPar : upperPars) {
327 valuation.insert(std::pair<VariableType, CoefficientType>(upperPar, region.
getUpperBoundary(upperPar)));
333template<
typename ParametricType,
typename ConstantType>
336 ParametricType simplifiedFunction = function;
338 std::set<VariableType> variablesInFunction;
343 auto insertionRes = collectedFunctions.insert(std::pair<FunctionValuation, ConstantType>(
344 FunctionValuation(std::move(simplifiedFunction), std::move(simplifiedValuation)), storm::utility::one<ConstantType>()));
345 return insertionRes.first->second;
348template<
typename ParametricType,
typename ConstantType>
351 for (
auto& collectedFunctionValuationPlaceholder : collectedFunctions) {
352 ParametricType
const& function = collectedFunctionValuationPlaceholder.first.first;
353 AbstractValuation
const& abstrValuation = collectedFunctionValuationPlaceholder.first.second;
354 ConstantType& placeholder = collectedFunctionValuationPlaceholder.second;
355 auto concreteValuations = abstrValuation.getConcreteValuations(region);
356 auto concreteValuationIt = concreteValuations.begin();
357 placeholder = storm::utility::parametric::evaluate<ConstantType>(function, *concreteValuationIt);
358 for (++concreteValuationIt; concreteValuationIt != concreteValuations.end(); ++concreteValuationIt) {
359 ConstantType currentResult = storm::utility::parametric::evaluate<ConstantType>(function, *concreteValuationIt);
361 placeholder = std::min(placeholder, currentResult);
363 placeholder = std::max(placeholder, currentResult);
369template class ParameterLifter<storm::RationalFunction, double>;
370template class ParameterLifter<storm::RationalFunction, storm::RationalNumber>;
A bit vector that is internally represented as a vector of 64-bit values.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint64_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.
bool isConstant(ValueType const &)
ValueType simplify(ValueType value)
bool isZero(ValueType const &a)