Browse Source

add support for transient var

Former-commit-id: 7898f2b084 [formerly af4af4d291]
Former-commit-id: 9ae9361e76
main
sjunges 9 years ago
parent
commit
1dcec6471f
  1. 23
      src/parser/JaniParser.cpp
  2. 4
      src/parser/JaniParser.h
  3. 2
      src/storage/jani/BooleanVariable.cpp
  4. 2
      src/storage/jani/BooleanVariable.h
  5. 5
      src/storage/jani/BoundedIntegerVariable.cpp
  6. 4
      src/storage/jani/BoundedIntegerVariable.h
  7. 2
      src/storage/jani/Property.cpp
  8. 2
      src/storage/jani/UnboundedIntegerVariable.cpp
  9. 2
      src/storage/jani/UnboundedIntegerVariable.h
  10. 6
      src/storage/jani/Variable.cpp
  11. 7
      src/storage/jani/Variable.h

23
src/parser/JaniParser.cpp

@ -16,12 +16,22 @@
namespace storm { namespace storm {
namespace parser { namespace parser {
////////////
// Defaults
////////////
const bool JaniParser::defaultVariableTransient = false;
std::string getString(json const& structure, std::string const& errorInfo) { std::string getString(json const& structure, std::string const& errorInfo) {
STORM_LOG_THROW(structure.is_string(), storm::exceptions::InvalidJaniException, "Expected a string in " << errorInfo << ", got '" << structure.dump() << "'"); STORM_LOG_THROW(structure.is_string(), storm::exceptions::InvalidJaniException, "Expected a string in " << errorInfo << ", got '" << structure.dump() << "'");
return structure.front(); return structure.front();
} }
bool getBoolean(json const& structure, std::string const& errorInfo) {
STORM_LOG_THROW(structure.is_boolean(), storm::exceptions::InvalidJaniException, "Expected a Boolean in " << errorInfo << ", got " << structure.dump() << "'");
return structure.front();
}
uint64_t getUnsignedInt(json const& structure, std::string const& errorInfo) { uint64_t getUnsignedInt(json const& structure, std::string const& errorInfo) {
STORM_LOG_THROW(structure.is_number(), storm::exceptions::InvalidJaniException, "Expected a number in " << errorInfo << ", got '" << structure.dump() << "'"); STORM_LOG_THROW(structure.is_number(), storm::exceptions::InvalidJaniException, "Expected a number in " << errorInfo << ", got '" << structure.dump() << "'");
int num = structure.front(); int num = structure.front();
@ -189,6 +199,13 @@ namespace storm {
// TODO check existance of name. // TODO check existance of name.
// TODO store prefix in variable. // TODO store prefix in variable.
std::string exprManagerName = pref + name; std::string exprManagerName = pref + name;
bool transientVar = defaultVariableTransient; // Default value for variables.
size_t tvarcount = variableStructure.count("transient");
STORM_LOG_THROW(tvarcount <= 1, storm::exceptions::InvalidJaniException, "Multiple definitions of transient not allowed in variable '" + name + "' (scope: " + scopeDescription + ") ");
if(tvarcount == 1) {
transientVar = getBoolean(variableStructure.at("transient"), "transient-attribute in variable '" + name + "' (scope: " + scopeDescription + ") ");
}
STORM_LOG_THROW(variableStructure.count("type") == 1, storm::exceptions::InvalidJaniException, "Variable '" + name + "' (scope: " + scopeDescription + ") must have a (single) type-declaration."); STORM_LOG_THROW(variableStructure.count("type") == 1, storm::exceptions::InvalidJaniException, "Variable '" + name + "' (scope: " + scopeDescription + ") must have a (single) type-declaration.");
if(variableStructure.at("type").is_object()) { if(variableStructure.at("type").is_object()) {
@ -207,7 +224,7 @@ namespace storm {
if(basictype == "int") { if(basictype == "int") {
STORM_LOG_THROW(lowerboundExpr.hasIntegerType(), storm::exceptions::InvalidJaniException, "Lower bound for bounded integer variable " << name << "(scope: " << scopeDescription << ") must be integer-typed"); STORM_LOG_THROW(lowerboundExpr.hasIntegerType(), storm::exceptions::InvalidJaniException, "Lower bound for bounded integer variable " << name << "(scope: " << scopeDescription << ") must be integer-typed");
STORM_LOG_THROW(upperboundExpr.hasIntegerType(), storm::exceptions::InvalidJaniException, "Upper bound for bounded integer variable " << name << "(scope: " << scopeDescription << ") must be integer-typed"); STORM_LOG_THROW(upperboundExpr.hasIntegerType(), storm::exceptions::InvalidJaniException, "Upper bound for bounded integer variable " << name << "(scope: " << scopeDescription << ") must be integer-typed");
return std::make_shared<storm::jani::BoundedIntegerVariable>(name, expressionManager->declareIntegerVariable(exprManagerName), lowerboundExpr, upperboundExpr);
return std::make_shared<storm::jani::BoundedIntegerVariable>(name, expressionManager->declareIntegerVariable(exprManagerName), transientVar, lowerboundExpr, upperboundExpr);
} else { } else {
STORM_LOG_THROW(false, storm::exceptions::InvalidJaniException, "Unsupported base " << basictype << " for bounded variable " << name << "(scope: " << scopeDescription << ") "); STORM_LOG_THROW(false, storm::exceptions::InvalidJaniException, "Unsupported base " << basictype << " for bounded variable " << name << "(scope: " << scopeDescription << ") ");
} }
@ -220,9 +237,9 @@ namespace storm {
// expressionManager->declareRationalVariable(name); // expressionManager->declareRationalVariable(name);
// TODO something. // TODO something.
} else if(variableStructure.at("type") == "bool") { } else if(variableStructure.at("type") == "bool") {
return std::make_shared<storm::jani::BooleanVariable>(name, expressionManager->declareBooleanVariable(exprManagerName));
return std::make_shared<storm::jani::BooleanVariable>(name, expressionManager->declareBooleanVariable(exprManagerName), transientVar);
} else if(variableStructure.at("type") == "int") { } else if(variableStructure.at("type") == "int") {
return std::make_shared<storm::jani::UnboundedIntegerVariable>(name, expressionManager->declareIntegerVariable(exprManagerName));
return std::make_shared<storm::jani::UnboundedIntegerVariable>(name, expressionManager->declareIntegerVariable(exprManagerName), transientVar);
} else { } else {
// TODO clocks. // TODO clocks.
STORM_LOG_THROW(false, storm::exceptions::InvalidJaniException, "Unknown type description " << variableStructure.at("type").dump() << " for Variable '" << name << "' (scope: " << scopeDescription << ")"); STORM_LOG_THROW(false, storm::exceptions::InvalidJaniException, "Unknown type description " << variableStructure.at("type").dump() << " for Variable '" << name << "' (scope: " << scopeDescription << ")");

4
src/parser/JaniParser.h

@ -67,6 +67,10 @@ namespace storm {
std::shared_ptr<storm::expressions::ExpressionManager> expressionManager; std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
//////////
// Default values -- assumptions from JANI.
//////////
static const bool defaultVariableTransient;
}; };
} }

2
src/storage/jani/BooleanVariable.cpp

@ -3,7 +3,7 @@
namespace storm { namespace storm {
namespace jani { namespace jani {
BooleanVariable::BooleanVariable(std::string const& name, storm::expressions::Variable const& variable) : Variable(name, variable) {
BooleanVariable::BooleanVariable(std::string const& name, storm::expressions::Variable const& variable, bool transient) : Variable(name, variable, transient) {
// Intentionally left empty. // Intentionally left empty.
} }

2
src/storage/jani/BooleanVariable.h

@ -10,7 +10,7 @@ namespace storm {
/*! /*!
* Creates a boolean variable. * Creates a boolean variable.
*/ */
BooleanVariable(std::string const& name, storm::expressions::Variable const& variable);
BooleanVariable(std::string const& name, storm::expressions::Variable const& variable, bool transient=false);
virtual bool isBooleanVariable() const override; virtual bool isBooleanVariable() const override;
}; };

5
src/storage/jani/BoundedIntegerVariable.cpp

@ -3,10 +3,15 @@
namespace storm { namespace storm {
namespace jani { namespace jani {
BoundedIntegerVariable::BoundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, bool transient, storm::expressions::Expression const& lowerBound, storm::expressions::Expression const& upperBound) : Variable(name, variable, transient), lowerBound(lowerBound), upperBound(upperBound) {
// Intentionally left empty.
}
BoundedIntegerVariable::BoundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, storm::expressions::Expression const& lowerBound, storm::expressions::Expression const& upperBound) : Variable(name, variable), lowerBound(lowerBound), upperBound(upperBound) { BoundedIntegerVariable::BoundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, storm::expressions::Expression const& lowerBound, storm::expressions::Expression const& upperBound) : Variable(name, variable), lowerBound(lowerBound), upperBound(upperBound) {
// Intentionally left empty. // Intentionally left empty.
} }
storm::expressions::Expression const& BoundedIntegerVariable::getLowerBound() const { storm::expressions::Expression const& BoundedIntegerVariable::getLowerBound() const {
return lowerBound; return lowerBound;
} }

4
src/storage/jani/BoundedIntegerVariable.h

@ -11,6 +11,10 @@ namespace storm {
/*! /*!
* Creates a bounded integer variable. * Creates a bounded integer variable.
*/ */
BoundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, bool transient, storm::expressions::Expression const& lowerBound, storm::expressions::Expression const& upperBound);
/*!
* Creates a bounded integer variable with transient set to false.
*/
BoundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, storm::expressions::Expression const& lowerBound, storm::expressions::Expression const& upperBound); BoundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, storm::expressions::Expression const& lowerBound, storm::expressions::Expression const& upperBound);
/*! /*!

2
src/storage/jani/Property.cpp

@ -15,7 +15,7 @@ namespace storm {
return this->comment; return this->comment;
} }
std::shared_ptr<storm::logic::Formula const> Property::getFormula() const {
std::shared_ptr<storm::logic::Formula const> const& Property::getFormula() const {
return this->formula; return this->formula;
} }

2
src/storage/jani/UnboundedIntegerVariable.cpp

@ -3,7 +3,7 @@
namespace storm { namespace storm {
namespace jani { namespace jani {
UnboundedIntegerVariable::UnboundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable) : Variable(name, variable) {
UnboundedIntegerVariable::UnboundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, bool transient) : Variable(name, variable, transient) {
// Intentionally left empty. // Intentionally left empty.
} }

2
src/storage/jani/UnboundedIntegerVariable.h

@ -10,7 +10,7 @@ namespace storm {
/*! /*!
* Creates an unbounded integer variable. * Creates an unbounded integer variable.
*/ */
UnboundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable);
UnboundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable, bool transient=false);
virtual bool isUnboundedIntegerVariable() const override; virtual bool isUnboundedIntegerVariable() const override;
}; };

6
src/storage/jani/Variable.cpp

@ -7,7 +7,7 @@
namespace storm { namespace storm {
namespace jani { namespace jani {
Variable::Variable(std::string const& name, storm::expressions::Variable const& variable) : name(name), variable(variable) {
Variable::Variable(std::string const& name, storm::expressions::Variable const& variable, bool transient) : name(name), variable(variable), transient(transient) {
// Intentionally left empty. // Intentionally left empty.
} }
@ -31,6 +31,10 @@ namespace storm {
return false; return false;
} }
bool Variable::isTransientVariable() const {
return transient;
}
BooleanVariable& Variable::asBooleanVariable() { BooleanVariable& Variable::asBooleanVariable() {
return dynamic_cast<BooleanVariable&>(*this); return dynamic_cast<BooleanVariable&>(*this);
} }

7
src/storage/jani/Variable.h

@ -18,7 +18,7 @@ namespace storm {
/*! /*!
* Creates a new variable. * Creates a new variable.
*/ */
Variable(std::string const& name, storm::expressions::Variable const& variable);
Variable(std::string const& name, storm::expressions::Variable const& variable, bool transient = false);
/*! /*!
* Retrieves the associated expression variable * Retrieves the associated expression variable
@ -35,6 +35,8 @@ namespace storm {
virtual bool isBoundedIntegerVariable() const; virtual bool isBoundedIntegerVariable() const;
virtual bool isUnboundedIntegerVariable() const; virtual bool isUnboundedIntegerVariable() const;
virtual bool isTransientVariable() const;
// Methods to get the variable as a different type. // Methods to get the variable as a different type.
BooleanVariable& asBooleanVariable(); BooleanVariable& asBooleanVariable();
BooleanVariable const& asBooleanVariable() const; BooleanVariable const& asBooleanVariable() const;
@ -49,6 +51,9 @@ namespace storm {
// The expression variable associated with this variable. // The expression variable associated with this variable.
storm::expressions::Variable variable; storm::expressions::Variable variable;
/// Whether this is a transient variable.
bool transient;
}; };
} }
Loading…
Cancel
Save