Browse Source

array variables can now have only a lower (or upper) element type bound

tempestpy_adaptions
TimQu 6 years ago
parent
commit
e7c0bd0f7d
  1. 21
      src/storm-parsers/parser/JaniParser.cpp
  2. 6
      src/storm/storage/jani/ArrayEliminator.cpp
  3. 37
      src/storm/storage/jani/ArrayVariable.cpp
  4. 43
      src/storm/storage/jani/ArrayVariable.h
  5. 7
      src/storm/storage/jani/FunctionEliminator.cpp
  6. 10
      src/storm/storage/jani/JSONExporter.cpp
  7. 9
      src/storm/storage/jani/VariableSet.cpp
  8. 16
      src/storm/storage/jani/traverser/JaniTraverser.cpp

21
src/storm-parsers/parser/JaniParser.cpp

@ -847,8 +847,17 @@ namespace storm {
case ParsedType::BasicType::Int:
if (setInitValFromDefault) {
if (type.bounds) {
initVal = storm::expressions::ite(type.bounds->first < 0 && type.bounds->second > 0, expressionManager->integer(defaultIntegerInitialValue), type.bounds->first);
// TODO as soon as we support half-open intervals, we have to change this.
storm::expressions::Expression takeDefaultCondition;
if (type.bounds->first.isInitialized()) {
takeDefaultCondition = type.bounds->first < defaultIntegerInitialValue;
if (type.bounds->second.isInitialized()) {
takeDefaultCondition = takeDefaultCondition && type.bounds->second >= defaultIntegerInitialValue;
}
} else {
STORM_LOG_ASSERT(type.bounds->second.isInitialized(), "Expected to have either a lower or an upper bound");
takeDefaultCondition = type.bounds->second >= defaultIntegerInitialValue;
}
initVal = storm::expressions::ite(takeDefaultCondition, expressionManager->integer(defaultIntegerInitialValue), type.bounds->first);
} else {
initVal = expressionManager->integer(defaultIntegerInitialValue);
}
@ -910,7 +919,13 @@ namespace storm {
result = std::make_shared<storm::jani::ArrayVariable>(name, expressionManager->declareArrayVariable(exprManagerName, exprVariableType.getElementType()), elementType);
}
if (type.arrayBase->bounds) {
result->setElementTypeBounds(type.arrayBase->bounds->first, type.arrayBase->bounds->second);
auto const& bounds = type.arrayBase->bounds.get();
if (bounds.first.isInitialized()) {
result->setLowerElementTypeBound(bounds.first);
}
if (bounds.second.isInitialized()) {
result->setUpperElementTypeBound(bounds.second);
}
}
return result;
}

6
src/storm/storage/jani/ArrayEliminator.cpp

@ -569,11 +569,11 @@ namespace storm {
}
if (arrayVariable.getElementType() == ArrayVariable::ElementType::Int) {
storm::expressions::Variable exprVariable = expressionManager.declareIntegerVariable(name);
if (arrayVariable.hasElementTypeBounds()) {
if (arrayVariable.hasElementTypeBound()) {
if (initValue.isInitialized()) {
return std::make_shared<BoundedIntegerVariable>(name, exprVariable, initValue, arrayVariable.isTransient(), arrayVariable.getElementTypeBounds().first, arrayVariable.getElementTypeBounds().second);
return std::make_shared<BoundedIntegerVariable>(name, exprVariable, initValue, arrayVariable.isTransient(), arrayVariable.getLowerElementTypeBound(), arrayVariable.getUpperElementTypeBound());
} else {
return std::make_shared<BoundedIntegerVariable>(name, exprVariable, arrayVariable.getElementTypeBounds().first, arrayVariable.getElementTypeBounds().second);
return std::make_shared<BoundedIntegerVariable>(name, exprVariable, arrayVariable.getLowerElementTypeBound(), arrayVariable.getUpperElementTypeBound());
}
} else {
if (initValue.isInitialized()) {

37
src/storm/storage/jani/ArrayVariable.cpp

@ -1,5 +1,7 @@
#include "storm/storage/jani/ArrayVariable.h"
#include "storm/storage/jani/expressions/JaniExpressionSubstitutionVisitor.h"
namespace storm {
namespace jani {
@ -11,28 +13,32 @@ namespace storm {
// Intentionally left empty.
}
void ArrayVariable::setElementTypeBounds(storm::expressions::Expression lowerBound, storm::expressions::Expression upperBound) {
elementTypeBounds = std::make_pair(lowerBound, upperBound);
void ArrayVariable::setLowerElementTypeBound(storm::expressions::Expression const& lowerBound) {
lowerElementTypeBound = lowerBound;
}
bool ArrayVariable::hasElementTypeBounds() const {
return elementTypeBounds.is_initialized();
void ArrayVariable::setUpperElementTypeBound(storm::expressions::Expression const& upperBound) {
upperElementTypeBound = upperBound;
}
bool ArrayVariable::hasElementTypeBound() const {
return hasLowerElementTypeBound() || hasUpperElementTypeBound();
}
std::pair<storm::expressions::Expression, storm::expressions::Expression> const& ArrayVariable::getElementTypeBounds() const {
return elementTypeBounds.get();
bool ArrayVariable::hasLowerElementTypeBound() const {
return lowerElementTypeBound.isInitialized();
}
void ArrayVariable::setMaxSize(uint64_t size) {
maxSize = size;
bool ArrayVariable::hasUpperElementTypeBound() const {
return upperElementTypeBound.isInitialized();
}
bool ArrayVariable::hasMaxSize() const {
return maxSize.is_initialized();
storm::expressions::Expression const& ArrayVariable::getLowerElementTypeBound() const {
return lowerElementTypeBound;
}
uint64_t ArrayVariable::getMaxSize() const {
return maxSize.get();
storm::expressions::Expression const& ArrayVariable::getUpperElementTypeBound() const {
return upperElementTypeBound;
}
typename ArrayVariable::ElementType ArrayVariable::getElementType() const {
@ -49,8 +55,11 @@ namespace storm {
void ArrayVariable::substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution) {
Variable::substitute(substitution);
if (hasElementTypeBounds()) {
setElementTypeBounds(elementTypeBounds->first.substitute(substitution), elementTypeBounds->second.substitute(substitution));
if (hasLowerElementTypeBound()) {
setLowerElementTypeBound(substituteJaniExpression(getLowerElementTypeBound(), substitution));
}
if (hasUpperElementTypeBound()) {
setUpperElementTypeBound(substituteJaniExpression(getUpperElementTypeBound(), substitution));
}
}
}

43
src/storm/storage/jani/ArrayVariable.h

@ -21,18 +21,42 @@ namespace storm {
ArrayVariable(std::string const& name, storm::expressions::Variable const& variable, ElementType const& elementType, storm::expressions::Expression const& initValue, bool transient);
/*!
* Sets/Gets bounds to the values stored in this array
* Sets the lower bound to the values stored in this array
*/
void setElementTypeBounds(storm::expressions::Expression lowerBound, storm::expressions::Expression upperBound);
bool hasElementTypeBounds() const;
std::pair<storm::expressions::Expression, storm::expressions::Expression> const& getElementTypeBounds() const;
void setLowerElementTypeBound(storm::expressions::Expression const& lowerBound);
/*!
* Sets the upper bound to the values stored in this array
*/
void setUpperElementTypeBound(storm::expressions::Expression const& upperBound);
/*!
* Returns true if there is either an upper bound or a lower bound
*/
bool hasElementTypeBound() const;
/*!
* Sets/Gets the maximum size of the array
* Returns true if there is an upper element type bound
*/
void setMaxSize(uint64_t size);
bool hasMaxSize() const;
uint64_t getMaxSize() const;
bool hasUpperElementTypeBound() const;
/*!
* Returns true if there is a lower element type bound
*/
bool hasLowerElementTypeBound() const;
/*!
* Returns the upper element type bound. The returned expression might not be initialized if there is no such bound.
*/
storm::expressions::Expression const& getUpperElementTypeBound() const;
/*!
* Returns the lower element type bound. The returned expression might not be initialized if there is no such bound.
*/
storm::expressions::Expression const& getLowerElementTypeBound() const;
std::pair<storm::expressions::Expression, storm::expressions::Expression> const& getElementTypeBounds() const;
ElementType getElementType() const;
@ -43,8 +67,7 @@ namespace storm {
private:
ElementType elementType;
boost::optional<std::pair<storm::expressions::Expression, storm::expressions::Expression>> elementTypeBounds;
boost::optional<uint64_t> maxSize;
storm::expressions::Expression lowerElementTypeBound, upperElementTypeBound;
};

7
src/storm/storage/jani/FunctionEliminator.cpp

@ -344,8 +344,11 @@ namespace storm {
if (variable.hasInitExpression()) {
variable.setInitExpression(functionEliminationVisitor->eliminate(variable.getInitExpression()));
}
if (variable.hasElementTypeBounds()) {
variable.setElementTypeBounds(functionEliminationVisitor->eliminate(variable.getElementTypeBounds().first), functionEliminationVisitor->eliminate(variable.getElementTypeBounds().second));
if (variable.hasLowerElementTypeBound()) {
variable.setLowerElementTypeBound(functionEliminationVisitor->eliminate(variable.getLowerElementTypeBound()));
}
if (variable.hasUpperElementTypeBound()) {
variable.setUpperElementTypeBound(functionEliminationVisitor->eliminate(variable.getUpperElementTypeBound()));
}
}

10
src/storm/storage/jani/JSONExporter.cpp

@ -847,12 +847,16 @@ namespace storm {
typeDesc["base"] = "real";
break;
case storm::jani::ArrayVariable::ElementType::Int:
if (variable.asArrayVariable().hasElementTypeBounds()) {
if (variable.asArrayVariable().hasElementTypeBound()) {
modernjson::json baseTypeDescr;
baseTypeDescr["kind"] = "bounded";
baseTypeDescr["base "] = "int";
baseTypeDescr["lower-bound"] = buildExpression(variable.asArrayVariable().getElementTypeBounds().first, constants, globalVariables, localVariables);
baseTypeDescr["upper-bound"] = buildExpression(variable.asArrayVariable().getElementTypeBounds().second, constants, globalVariables, localVariables);
if (variable.asArrayVariable().hasLowerElementTypeBound()) {
baseTypeDescr["lower-bound"] = buildExpression(variable.asArrayVariable().getLowerElementTypeBound(), constants, globalVariables, localVariables);
}
if (variable.asArrayVariable().hasUpperElementTypeBound()) {
baseTypeDescr["upper-bound"] = buildExpression(variable.asArrayVariable().getUpperElementTypeBound(), constants, globalVariables, localVariables);
}
typeDesc["base"] = baseTypeDescr;
} else {
typeDesc["base"] = "int";

9
src/storm/storage/jani/VariableSet.cpp

@ -311,12 +311,13 @@ namespace storm {
return true;
}
}
if (arrayVariable.hasElementTypeBounds()) {
auto const& bounds = arrayVariable.getElementTypeBounds();
if (bounds.first.containsVariable(variables)) {
if (arrayVariable.hasLowerElementTypeBound()) {
if (arrayVariable.getLowerElementTypeBound().containsVariable(variables)) {
return true;
}
if (bounds.second.containsVariable(variables)) {
}
if (arrayVariable.hasUpperElementTypeBound()) {
if (arrayVariable.getUpperElementTypeBound().containsVariable(variables)) {
return true;
}
}

16
src/storm/storage/jani/traverser/JaniTraverser.cpp

@ -103,9 +103,11 @@ namespace storm {
if (variable.hasInitExpression()) {
traverse(variable.getInitExpression(), data);
}
if (variable.hasElementTypeBounds()) {
traverse(variable.getElementTypeBounds().first, data);
traverse(variable.getElementTypeBounds().second, data);
if (variable.hasLowerElementTypeBound()) {
traverse(variable.getLowerElementTypeBound(), data);
}
if (variable.hasUpperElementTypeBound()) {
traverse(variable.getUpperElementTypeBound(), data);
}
}
@ -264,9 +266,11 @@ namespace storm {
if (variable.hasInitExpression()) {
traverse(variable.getInitExpression(), data);
}
if (variable.hasElementTypeBounds()) {
traverse(variable.getElementTypeBounds().first, data);
traverse(variable.getElementTypeBounds().second, data);
if (variable.hasLowerElementTypeBound()) {
traverse(variable.getLowerElementTypeBound(), data);
}
if (variable.hasUpperElementTypeBound()) {
traverse(variable.getUpperElementTypeBound(), data);
}
}

Loading…
Cancel
Save