dehnert
12 years ago
22 changed files with 735 additions and 160 deletions
-
231src/adapters/SymbolicExpressionAdapter.h
-
182src/adapters/SymbolicModelAdapter.h
-
22src/ir/Module.cpp
-
14src/ir/Module.h
-
5src/ir/expressions/BaseExpression.h
-
30src/ir/expressions/BinaryBooleanFunctionExpression.h
-
44src/ir/expressions/BinaryExpression.h
-
36src/ir/expressions/BinaryNumericalFunctionExpression.h
-
34src/ir/expressions/BinaryRelationExpression.h
-
10src/ir/expressions/BooleanConstantExpression.h
-
5src/ir/expressions/BooleanLiteral.h
-
10src/ir/expressions/DoubleConstantExpression.h
-
5src/ir/expressions/DoubleLiteral.h
-
43src/ir/expressions/ExpressionVisitor.h
-
10src/ir/expressions/IntegerConstantExpression.h
-
5src/ir/expressions/IntegerLiteral.h
-
20src/ir/expressions/UnaryBooleanFunctionExpression.h
-
39src/ir/expressions/UnaryExpression.h
-
24src/ir/expressions/UnaryNumericalFunctionExpression.h
-
24src/ir/expressions/VariableExpression.h
-
90src/utility/CuddUtility.cpp
-
12src/utility/CuddUtility.h
@ -0,0 +1,231 @@ |
|||||
|
/* |
||||
|
* SymbolicExpressionAdapter.h |
||||
|
* |
||||
|
* Created on: 27.01.2013 |
||||
|
* Author: Christian Dehnert |
||||
|
*/ |
||||
|
|
||||
|
#ifndef STORM_ADAPTERS_SYMBOLICEXPRESSIONADAPTER_H_ |
||||
|
#define STORM_ADAPTERS_SYMBOLICEXPRESSIONADAPTER_H_ |
||||
|
|
||||
|
#include "src/ir/expressions/ExpressionVisitor.h" |
||||
|
#include "src/exceptions/ExpressionEvaluationException.h" |
||||
|
|
||||
|
#include "cuddObj.hh" |
||||
|
|
||||
|
#include <stack> |
||||
|
#include <iostream> |
||||
|
|
||||
|
namespace storm { |
||||
|
|
||||
|
namespace adapters { |
||||
|
|
||||
|
class SymbolicExpressionAdapter : public storm::ir::expressions::ExpressionVisitor { |
||||
|
public: |
||||
|
SymbolicExpressionAdapter(std::unordered_map<std::string, std::vector<ADD*>>& variableToDecisionDiagramVariableMap) : stack(), variableToDecisionDiagramVariableMap(variableToDecisionDiagramVariableMap) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
ADD* translateExpression(std::shared_ptr<storm::ir::expressions::BaseExpression> expression) { |
||||
|
expression->accept(this); |
||||
|
return stack.top(); |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::BaseExpression* expression) { |
||||
|
std::cout << expression->toString() << std::endl; |
||||
|
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression " |
||||
|
<< " of abstract superclass type."; |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::BinaryBooleanFunctionExpression* expression) { |
||||
|
expression->getLeft()->accept(this); |
||||
|
expression->getRight()->accept(this); |
||||
|
|
||||
|
ADD* rightResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
ADD* leftResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
|
||||
|
switch(expression->getFunctionType()) { |
||||
|
case storm::ir::expressions::BinaryBooleanFunctionExpression::AND: |
||||
|
stack.push(new ADD(leftResult->Times(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryBooleanFunctionExpression::OR: |
||||
|
stack.push(new ADD(leftResult->Plus(*rightResult))); |
||||
|
break; |
||||
|
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Unknown boolean binary operator: '" << expression->getFunctionType() << "'."; |
||||
|
} |
||||
|
|
||||
|
// delete leftResult; |
||||
|
// delete rightResult; |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::BinaryNumericalFunctionExpression* expression) { |
||||
|
expression->getLeft()->accept(this); |
||||
|
expression->getRight()->accept(this); |
||||
|
|
||||
|
ADD* rightResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
ADD* leftResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
|
||||
|
switch(expression->getFunctionType()) { |
||||
|
case storm::ir::expressions::BinaryNumericalFunctionExpression::PLUS: |
||||
|
stack.push(new ADD(leftResult->Plus(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryNumericalFunctionExpression::MINUS: |
||||
|
stack.push(new ADD(leftResult->Minus(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryNumericalFunctionExpression::TIMES: |
||||
|
stack.push(new ADD(leftResult->Times(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryNumericalFunctionExpression::DIVIDE: |
||||
|
stack.push(new ADD(leftResult->Divide(*rightResult))); |
||||
|
break; |
||||
|
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Unknown boolean binary operator: '" << expression->getFunctionType() << "'."; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::BinaryRelationExpression* expression) { |
||||
|
expression->getLeft()->accept(this); |
||||
|
expression->getRight()->accept(this); |
||||
|
|
||||
|
ADD* rightResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
ADD* leftResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
|
||||
|
switch(expression->getRelationType()) { |
||||
|
case storm::ir::expressions::BinaryRelationExpression::EQUAL: |
||||
|
stack.push(new ADD(leftResult->Equals(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryRelationExpression::NOT_EQUAL: |
||||
|
stack.push(new ADD(leftResult->NotEquals(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryRelationExpression::LESS: |
||||
|
stack.push(new ADD(leftResult->LessThan(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryRelationExpression::LESS_OR_EQUAL: |
||||
|
stack.push(new ADD(leftResult->LessThanOrEqual(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryRelationExpression::GREATER: |
||||
|
stack.push(new ADD(leftResult->GreaterThan(*rightResult))); |
||||
|
break; |
||||
|
case storm::ir::expressions::BinaryRelationExpression::GREATER_OR_EQUAL: |
||||
|
stack.push(new ADD(leftResult->GreaterThanOrEqual(*rightResult))); |
||||
|
break; |
||||
|
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Unknown boolean binary operator: '" << expression->getRelationType() << "'."; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::BooleanConstantExpression* expression) { |
||||
|
if (!expression->isDefined()) { |
||||
|
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Boolean constant '" << expression->getConstantName() << "' is undefined."; |
||||
|
} |
||||
|
|
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
stack.push(new ADD(*cuddUtility->getConstant(expression->getValue() ? 1 : 0))); |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::BooleanLiteral* expression) { |
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
stack.push(new ADD(*cuddUtility->getConstant(expression->getValueAsBool(nullptr) ? 1 : 0))); |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::DoubleConstantExpression* expression) { |
||||
|
if (expression->isDefined()) { |
||||
|
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Double constant '" << expression->getConstantName() << "' is undefined."; |
||||
|
} |
||||
|
|
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
stack.push(new ADD(*cuddUtility->getConstant(expression->getValue()))); |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::DoubleLiteral* expression) { |
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
stack.push(new ADD(*cuddUtility->getConstant(expression->getValueAsDouble(nullptr)))); |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::IntegerConstantExpression* expression) { |
||||
|
if (!expression->isDefined()) { |
||||
|
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Integer constant '" << expression->getConstantName() << "' is undefined."; |
||||
|
} |
||||
|
|
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
stack.push(new ADD(*cuddUtility->getConstant(expression->getValue()))); |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::IntegerLiteral* expression) { |
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
stack.push(new ADD(*cuddUtility->getConstant(expression->getValueAsInt(nullptr)))); |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::UnaryBooleanFunctionExpression* expression) { |
||||
|
expression->getChild()->accept(this); |
||||
|
|
||||
|
ADD* childResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
|
||||
|
switch (expression->getFunctionType()) { |
||||
|
case storm::ir::expressions::UnaryBooleanFunctionExpression::NOT: |
||||
|
stack.push(new ADD(~(*childResult))); |
||||
|
break; |
||||
|
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Unknown boolean unary operator: '" << expression->getFunctionType() << "'."; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::UnaryNumericalFunctionExpression* expression) { |
||||
|
expression->getChild()->accept(this); |
||||
|
|
||||
|
ADD* childResult = stack.top(); |
||||
|
stack.pop(); |
||||
|
|
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
ADD* result = cuddUtility->getConstant(0); |
||||
|
switch(expression->getFunctionType()) { |
||||
|
case storm::ir::expressions::UnaryNumericalFunctionExpression::MINUS: |
||||
|
stack.push(new ADD(result->Minus(*childResult))); |
||||
|
break; |
||||
|
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
||||
|
<< "Unknown numerical unary operator: '" << expression->getFunctionType() << "'."; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
virtual void visit(storm::ir::expressions::VariableExpression* expression) { |
||||
|
storm::utility::CuddUtility* cuddUtility = storm::utility::cuddUtilityInstance(); |
||||
|
|
||||
|
std::vector<ADD*> const& variables = variableToDecisionDiagramVariableMap[expression->getVariableName()]; |
||||
|
|
||||
|
ADD* result = cuddUtility->getConstant(0); |
||||
|
if (expression->getType() == storm::ir::expressions::BaseExpression::bool_) { |
||||
|
cuddUtility->setValueAtIndex(result, 1, variables, 1); |
||||
|
} else { |
||||
|
int64_t low = expression->getLowerBound()->getValueAsInt(nullptr); |
||||
|
int64_t high = expression->getUpperBound()->getValueAsInt(nullptr); |
||||
|
|
||||
|
for (uint_fast64_t i = low; i <= high; ++i) { |
||||
|
cuddUtility->setValueAtIndex(result, i - low, variables, i); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
stack.push(result); |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
std::stack<ADD*> stack; |
||||
|
std::unordered_map<std::string, std::vector<ADD*>>& variableToDecisionDiagramVariableMap; |
||||
|
}; |
||||
|
|
||||
|
} // namespace adapters |
||||
|
|
||||
|
} // namespace storm |
||||
|
|
||||
|
#endif /* STORM_ADAPTERS_SYMBOLICEXPRESSIONADAPTER_H_ */ |
@ -0,0 +1,44 @@ |
|||||
|
/* |
||||
|
* BinaryExpression.h |
||||
|
* |
||||
|
* Created on: 27.01.2013 |
||||
|
* Author: Christian Dehnert |
||||
|
*/ |
||||
|
|
||||
|
#ifndef STORM_IR_EXPRESSIONS_BINARYEXPRESSION_H_ |
||||
|
#define STORM_IR_EXPRESSIONS_BINARYEXPRESSION_H_ |
||||
|
|
||||
|
#include "BaseExpression.h" |
||||
|
|
||||
|
namespace storm { |
||||
|
|
||||
|
namespace ir { |
||||
|
|
||||
|
namespace expressions { |
||||
|
|
||||
|
class BinaryExpression : public BaseExpression { |
||||
|
public: |
||||
|
BinaryExpression(ReturnType type, std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right) : BaseExpression(type), left(left), right(right) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<BaseExpression> const& getLeft() const { |
||||
|
return left; |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<BaseExpression> const& getRight() const { |
||||
|
return right; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
std::shared_ptr<BaseExpression> left; |
||||
|
std::shared_ptr<BaseExpression> right; |
||||
|
}; |
||||
|
|
||||
|
} // namespace expressions |
||||
|
|
||||
|
} // namespace ir |
||||
|
|
||||
|
} // namespace storm |
||||
|
|
||||
|
#endif /* STORM_IR_EXPRESSIONS_BINARYEXPRESSION_H_ */ |
@ -0,0 +1,39 @@ |
|||||
|
/* |
||||
|
* UnaryExpression.h |
||||
|
* |
||||
|
* Created on: 27.01.2013 |
||||
|
* Author: Christian Dehnert |
||||
|
*/ |
||||
|
|
||||
|
#ifndef STORM_IR_EXPRESSIONS_UNARYEXPRESSION_H_ |
||||
|
#define STORM_IR_EXPRESSIONS_UNARYEXPRESSION_H_ |
||||
|
|
||||
|
#include "BaseExpression.h" |
||||
|
|
||||
|
namespace storm { |
||||
|
|
||||
|
namespace ir { |
||||
|
|
||||
|
namespace expressions { |
||||
|
|
||||
|
class UnaryExpression : public BaseExpression { |
||||
|
public: |
||||
|
UnaryExpression(ReturnType type, std::shared_ptr<BaseExpression> child) : BaseExpression(type), child(child) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<BaseExpression> const& getChild() const { |
||||
|
return child; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
std::shared_ptr<BaseExpression> child; |
||||
|
}; |
||||
|
|
||||
|
} // namespace expressions |
||||
|
|
||||
|
} // namespace ir |
||||
|
|
||||
|
} // namespace storm |
||||
|
|
||||
|
#endif /* STORM_IR_EXPRESSIONS_UNARYEXPRESSION_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue