Browse Source

added state labeling generator interface

Former-commit-id: eb7668741f
tempestpy_adaptions
dehnert 9 years ago
parent
commit
1f5439e270
  1. 30
      src/builder/ExplicitPrismModelBuilder.cpp
  2. 2
      src/generator/NextStateGenerator.h
  3. 2
      src/generator/PrismNextStateGenerator.h
  4. 50
      src/generator/PrismStateLabelingGenerator.cpp
  5. 31
      src/generator/PrismStateLabelingGenerator.h
  6. 20
      src/generator/StateLabelingGenerator.h

30
src/builder/ExplicitPrismModelBuilder.cpp

@ -12,6 +12,7 @@
#include "src/settings/modules/GeneralSettings.h"
#include "src/generator/PrismNextStateGenerator.h"
#include "src/generator/PrismStateLabelingGenerator.h"
#include "src/utility/prism.h"
#include "src/utility/constants.h"
@ -558,33 +559,8 @@ namespace storm {
template <typename ValueType, typename RewardModelType, typename StateType>
storm::models::sparse::StateLabeling ExplicitPrismModelBuilder<ValueType, RewardModelType, StateType>::buildStateLabeling() {
std::vector<storm::prism::Label> const& labels = program.getLabels();
storm::expressions::ExpressionEvaluator<ValueType> evaluator(program.getManager());
storm::models::sparse::StateLabeling result(internalStateInformation.numberOfStates);
// Initialize labeling.
for (auto const& label : labels) {
result.addLabel(label.getName());
}
for (auto const& stateIndexPair : internalStateInformation.stateStorage) {
unpackStateIntoEvaluator(stateIndexPair.first, variableInformation, evaluator);
for (auto const& label : labels) {
// Add label to state, if the corresponding expression is true.
if (evaluator.asBool(label.getStatePredicateExpression())) {
result.addLabelToState(label.getName(), stateIndexPair.second);
}
}
}
// Also label the initial state with the special label "init".
result.addLabel("init");
for (auto index : internalStateInformation.initialStateIndices) {
result.addLabelToState("init", index);
}
return result;
storm::generator::PrismStateLabelingGenerator<ValueType, StateType> generator(program, variableInformation);
return generator.generate(internalStateInformation.stateStorage, internalStateInformation.initialStateIndices);
}
// Explicitly instantiate the class.

2
src/generator/NextStateGenerator.h

@ -21,4 +21,4 @@ namespace storm {
}
}
#endif
#endif /* STORM_GENERATOR_NEXTSTATEGENERATOR_H_ */

2
src/generator/PrismNextStateGenerator.h

@ -92,7 +92,7 @@ namespace storm {
// An optional expression that governs which states must not be explored.
boost::optional<storm::expressions::Expression> terminalExpression;
// Information about how the variables are packed
// Information about how the variables are packed.
VariableInformation const& variableInformation;
// An evaluator used to evaluate expressions.

50
src/generator/PrismStateLabelingGenerator.cpp

@ -0,0 +1,50 @@
#include "src/generator/PrismStateLabelingGenerator.h"
#include "src/generator/CompressedState.h"
#include "src/storage/expressions/ExpressionEvaluator.h"
namespace storm {
namespace generator {
template<typename ValueType, typename StateType>
PrismStateLabelingGenerator<ValueType, StateType>::PrismStateLabelingGenerator(storm::prism::Program const& program, VariableInformation const& variableInformation) : program(program), variableInformation(variableInformation) {
// Intentionally left empty.
}
template<typename ValueType, typename StateType>
storm::models::sparse::StateLabeling PrismStateLabelingGenerator<ValueType, StateType>::generate(storm::storage::BitVectorHashMap<StateType> const& states, std::vector<StateType> const& initialStateIndices) {
std::vector<storm::prism::Label> const& labels = program.getLabels();
storm::expressions::ExpressionEvaluator<ValueType> evaluator(program.getManager());
storm::models::sparse::StateLabeling result(states.size());
// Initialize labeling.
for (auto const& label : labels) {
result.addLabel(label.getName());
}
for (auto const& stateIndexPair : states) {
unpackStateIntoEvaluator(stateIndexPair.first, variableInformation, evaluator);
for (auto const& label : labels) {
// Add label to state, if the corresponding expression is true.
if (evaluator.asBool(label.getStatePredicateExpression())) {
result.addLabelToState(label.getName(), stateIndexPair.second);
}
}
}
// Also label the initial state with the special label "init".
result.addLabel("init");
for (auto index : initialStateIndices) {
result.addLabelToState("init", index);
}
return result;
}
template class PrismStateLabelingGenerator<double, uint32_t>;
template class PrismStateLabelingGenerator<storm::RationalFunction, uint32_t>;
}
}

31
src/generator/PrismStateLabelingGenerator.h

@ -0,0 +1,31 @@
#ifndef STORM_GENERATOR_PRISMSTATELABELINGGENERATOR_H_
#define STORM_GENERATOR_PRISMSTATELABELINGGENERATOR_H_
#include "src/generator/StateLabelingGenerator.h"
#include "src/generator/VariableInformation.h"
#include "src/storage/prism/Program.h"
namespace storm {
namespace generator {
template<typename ValueType, typename StateType = uint32_t>
class PrismStateLabelingGenerator : public StateLabelingGenerator<StateType> {
public:
PrismStateLabelingGenerator(storm::prism::Program const& program, VariableInformation const& variableInformation);
virtual storm::models::sparse::StateLabeling generate(storm::storage::BitVectorHashMap<StateType> const& states, std::vector<StateType> const& initialStateIndices = {}) override;
private:
// The program for which to generate the labels.
storm::prism::Program const& program;
// Information about how the variables are packed.
VariableInformation const& variableInformation;
};
}
}
#endif /* STORM_GENERATOR_PRISMSTATELABELINGGENERATOR_H_ */

20
src/generator/StateLabelingGenerator.h

@ -0,0 +1,20 @@
#ifndef STORM_GENERATOR_STATELABELINGGENERATOR_H_
#define STORM_GENERATOR_STATELABELINGGENERATOR_H_
#include "src/models/sparse/StateLabeling.h"
#include "src/storage/BitVectorHashMap.h"
namespace storm {
namespace generator {
template<typename StateType = uint32_t>
class StateLabelingGenerator {
public:
virtual storm::models::sparse::StateLabeling generate(storm::storage::BitVectorHashMap<StateType> const& states, std::vector<StateType> const& initialStateIndices = {}) = 0;
};
}
}
#endif /* STORM_GENERATOR_STATELABELINGGENERATOR_H_ */
Loading…
Cancel
Save