Browse Source

Some fixes.

Former-commit-id: 7b2b46d347
tempestpy_adaptions
dehnert 10 years ago
parent
commit
ff5902a17c
  1. 6
      src/adapters/ExplicitModelAdapter.h
  2. 36
      src/storage/expressions/ExpressionEvaluation.h

6
src/adapters/ExplicitModelAdapter.h

@ -351,6 +351,7 @@ namespace storm {
// behaviour for this is undefined anyway, a warning should be issued in that case. // behaviour for this is undefined anyway, a warning should be issued in that case.
for (uint_fast64_t i = 0; i < iteratorList.size(); ++i) { for (uint_fast64_t i = 0; i < iteratorList.size(); ++i) {
storm::prism::Command const& command = *iteratorList[i]; storm::prism::Command const& command = *iteratorList[i];
std::cout << command << std::endl;
for (uint_fast64_t j = 0; j < command.getNumberOfUpdates(); ++j) { for (uint_fast64_t j = 0; j < command.getNumberOfUpdates(); ++j) {
storm::prism::Update const& update = command.getUpdate(j); storm::prism::Update const& update = command.getUpdate(j);
@ -366,6 +367,7 @@ namespace storm {
boost::container::flat_set<uint_fast64_t> newLabelSet = valueLabelSetPair.second; boost::container::flat_set<uint_fast64_t> newLabelSet = valueLabelSetPair.second;
newLabelSet.insert(update.getGlobalIndex()); newLabelSet.insert(update.getGlobalIndex());
std::cout << "got new value " << valueLabelSetPair.first << " * " << updateProbability << " = " << valueLabelSetPair.first * updateProbability << std::endl;
newProbability.addValue(valueLabelSetPair.first * updateProbability, newLabelSet); newProbability.addValue(valueLabelSetPair.first * updateProbability, newLabelSet);
} }
@ -407,6 +409,7 @@ namespace storm {
} }
ValueType probabilitySum = utility::constantZero<ValueType>(); ValueType probabilitySum = utility::constantZero<ValueType>();
std::cout << "resetting prob sum" << std::endl;
for (auto const& stateProbabilityPair : *newTargetStates) { for (auto const& stateProbabilityPair : *newTargetStates) {
std::pair<bool, uint_fast64_t> flagTargetStateIndexPair = getOrAddStateIndex(stateProbabilityPair.first, stateInformation); std::pair<bool, uint_fast64_t> flagTargetStateIndexPair = getOrAddStateIndex(stateProbabilityPair.first, stateInformation);
@ -418,12 +421,13 @@ namespace storm {
for (auto const& probabilityLabelPair : stateProbabilityPair.second) { for (auto const& probabilityLabelPair : stateProbabilityPair.second) {
addProbabilityToChoice(choice, flagTargetStateIndexPair.second, probabilityLabelPair.first, probabilityLabelPair.second); addProbabilityToChoice(choice, flagTargetStateIndexPair.second, probabilityLabelPair.first, probabilityLabelPair.second);
probabilitySum += probabilityLabelPair.first; probabilitySum += probabilityLabelPair.first;
std::cout << "increasing prob sum by " << probabilityLabelPair.first << std::endl;
} }
} }
// Check that the resulting distribution is in fact a distribution. // Check that the resulting distribution is in fact a distribution.
if (!storm::utility::isOne(probabilitySum)) { if (!storm::utility::isOne(probabilitySum)) {
LOG4CPLUS_ERROR(logger, "Sum of update probabilities do not some to one for some command.");
LOG4CPLUS_ERROR(logger, "Sum of update probabilities (" << probabilitySum << ") is not one for some command.");
throw storm::exceptions::WrongFormatException() << "Sum of update probabilities do sum to " << probabilitySum << " to one for some command."; throw storm::exceptions::WrongFormatException() << "Sum of update probabilities do sum to " << probabilitySum << " to one for some command.";
} }

36
src/storage/expressions/ExpressionEvaluation.h

@ -20,7 +20,7 @@
#include "src/storage/parameters.h" #include "src/storage/parameters.h"
namespace storm { namespace storm {
namespace expressions {
namespace expressions {
template<typename T> template<typename T>
struct StateType struct StateType
@ -40,17 +40,9 @@ namespace expressions {
{ {
typedef std::map<std::string, carl::Variable> type; typedef std::map<std::string, carl::Variable> type;
}; };
struct ExpressionEvaluationSettings {
static const bool useFactorizedPolynomials = false;
};
struct FactorizedPolynomialsEvaluationSettings : ExpressionEvaluationSettings {
static const bool useFactorizedPolynomials = true;
};
#endif #endif
template<typename T, typename S, typename X = FactorizedPolynomialsEvaluationSettings>
template<typename T, typename S>
class ExpressionEvaluationVisitor : public ExpressionVisitor class ExpressionEvaluationVisitor : public ExpressionVisitor
{ {
public: public:
@ -60,6 +52,13 @@ namespace expressions {
} }
ExpressionEvaluationVisitor(S* sharedState, std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache)
: mSharedState(sharedState), cache(cache)
{
}
virtual ~ExpressionEvaluationVisitor() { virtual ~ExpressionEvaluationVisitor() {
} }
@ -76,7 +75,7 @@ namespace expressions {
} }
virtual void visit(BinaryNumericalFunctionExpression const* expression) virtual void visit(BinaryNumericalFunctionExpression const* expression)
{ {
ExpressionEvaluationVisitor* visitor = new ExpressionEvaluationVisitor(mSharedState);
ExpressionEvaluationVisitor* visitor = new ExpressionEvaluationVisitor(mSharedState, this->cache);
expression->getFirstOperand()->accept(visitor); expression->getFirstOperand()->accept(visitor);
mValue = visitor->value(); mValue = visitor->value();
expression->getSecondOperand()->accept(visitor); expression->getSecondOperand()->accept(visitor);
@ -86,7 +85,9 @@ namespace expressions {
mValue += visitor->value(); mValue += visitor->value();
break; break;
case BinaryNumericalFunctionExpression::OperatorType::Minus: case BinaryNumericalFunctionExpression::OperatorType::Minus:
std::cout << "mValue: " << mValue << " - " << visitor->value() << std::endl;
mValue -= visitor->value(); mValue -= visitor->value();
std::cout << mValue << std::endl;
break; break;
case BinaryNumericalFunctionExpression::OperatorType::Times: case BinaryNumericalFunctionExpression::OperatorType::Times:
mValue *= visitor->value(); mValue *= visitor->value();
@ -161,32 +162,33 @@ namespace expressions {
private: private:
S* mSharedState; S* mSharedState;
T mValue; T mValue;
carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>* cache;
std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache;
}; };
template<typename T> template<typename T>
class ExpressionEvaluation class ExpressionEvaluation
{ {
public: public:
ExpressionEvaluation() : mState()
ExpressionEvaluation() : mState(), cache(new carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>())
{ {
// Intentionally left empty.
} }
T evaluate(Expression const& expr, storm::expressions::SimpleValuation const* val) T evaluate(Expression const& expr, storm::expressions::SimpleValuation const* val)
{ {
ExpressionEvaluationVisitor<T, typename StateType<T>::type>* visitor = new ExpressionEvaluationVisitor<T, typename StateType<T>::type>(&mState);
ExpressionEvaluationVisitor<T, typename StateType<T>::type>* visitor = new ExpressionEvaluationVisitor<T, typename StateType<T>::type>(&mState, cache);
Expression expressionToTranslate = expr.substitute(*val); Expression expressionToTranslate = expr.substitute(*val);
expressionToTranslate.getBaseExpression().accept(visitor); expressionToTranslate.getBaseExpression().accept(visitor);
T result = visitor->value(); T result = visitor->value();
// result.simplify();
// result.simplify();
delete visitor; delete visitor;
return result; return result;
} }
protected: protected:
typename StateType<T>::type mState; typename StateType<T>::type mState;
std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache;
}; };
/** /**
@ -202,7 +204,7 @@ namespace expressions {
} }
}; };
}
}
} }
#endif #endif
Loading…
Cancel
Save