Browse Source

fixed a bug in symbolic model generator

Former-commit-id: de49f7b812
tempestpy_adaptions
dehnert 9 years ago
parent
commit
6313e4c31b
  1. 34
      src/builder/DdJaniModelBuilder.cpp
  2. 8
      src/builder/DdPrismModelBuilder.cpp
  3. 73
      test/functional/builder/DdJaniModelBuilderTest.cpp
  4. 9
      test/functional/builder/DdPrismModelBuilderTest.cpp

34
src/builder/DdJaniModelBuilder.cpp

@ -173,6 +173,9 @@ namespace storm {
// DDs representing the valid ranges of the variables of each automaton.
std::map<std::string, storm::dd::Add<Type, ValueType>> automatonToRangeMap;
// A DD representing the valid ranges of the global variables.
storm::dd::Add<Type, ValueType> globalVariableRanges;
};
// A class responsible for creating the necessary variables for a subsequent composition of automata.
@ -239,12 +242,16 @@ namespace storm {
}
// Create global variables.
storm::dd::Bdd<Type> globalVariableRanges = result.manager->getBddOne();
for (auto const& variable : this->model.getGlobalVariables().getBoundedIntegerVariables()) {
createVariable(variable, result);
globalVariableRanges &= result.manager->getRange(result.variableToRowMetaVariableMap->at(variable.getExpressionVariable()));
}
for (auto const& variable : this->model.getGlobalVariables().getBooleanVariables()) {
createVariable(variable, result);
globalVariableRanges &= result.manager->getRange(result.variableToRowMetaVariableMap->at(variable.getExpressionVariable()));
}
result.globalVariableRanges = globalVariableRanges.template toAdd<ValueType>();
// Create the variables for the individual automata.
for (auto const& automaton : this->model.getAutomata()) {
@ -271,14 +278,13 @@ namespace storm {
}
result.automatonToIdentityMap[automaton.getName()] = identity.template toAdd<ValueType>();
result.automatonToRangeMap[automaton.getName()] = range.template toAdd<ValueType>();
result.automatonToRangeMap[automaton.getName()] = (range && globalVariableRanges).template toAdd<ValueType>();
}
return result;
}
void createVariable(storm::jani::BoundedIntegerVariable const& variable, CompositionVariables<Type, ValueType>& result) {
std::cout << "creating int variable " << variable.getName() << std::endl;
int_fast64_t low = variable.getLowerBound().evaluateAsInt();
int_fast64_t high = variable.getUpperBound().evaluateAsInt();
std::pair<storm::expressions::Variable, storm::expressions::Variable> variablePair = result.manager->addMetaVariable(variable.getName(), low, high);
@ -299,7 +305,6 @@ namespace storm {
}
void createVariable(storm::jani::BooleanVariable const& variable, CompositionVariables<Type, ValueType>& result) {
std::cout << "creating bool variable " << variable.getName() << std::endl;
std::pair<storm::expressions::Variable, storm::expressions::Variable> variablePair = result.manager->addMetaVariable(variable.getName());
STORM_LOG_TRACE("Created meta variables for global boolean variable: " << variablePair.first.getName() << " and " << variablePair.second.getName() << ".");
@ -612,10 +617,15 @@ namespace storm {
transitionsDd += destinationDd.transitionsDd;
}
transitionsDd.exportToDot("trans_edge" + std::to_string(c) + ".dot");
++c;
// Add the source location and the guard.
transitionsDd *= variables.manager->getEncoding(variables.automatonToLocationVariableMap.at(automaton.getName()).first, edge.getSourceLocationId()).template toAdd<ValueType>() * guard;
// If we Multiply the ranges of global variables if we wrote at least one to make sure everything stays within its bounds.
if (!globalVariablesInSomeUpdate.empty()) {
transitionsDd *= variables.globalVariableRanges;
}
return EdgeDd<Type, ValueType>(guard, variables.manager->getEncoding(variables.automatonToLocationVariableMap.at(automaton.getName()).first, edge.getSourceLocationId()).template toAdd<ValueType>() * guard * transitionsDd, globalVariablesInSomeUpdate);
return EdgeDd<Type, ValueType>(guard, transitionsDd, globalVariablesInSomeUpdate);
} else {
return EdgeDd<Type, ValueType>(variables.manager->template getAddZero<ValueType>(), variables.manager->template getAddZero<ValueType>());
}
@ -729,21 +739,10 @@ namespace storm {
// Simply add all actions, but make sure to include the missing global variable identities.
storm::dd::Add<Type, ValueType> result = variables.manager->template getAddZero<ValueType>();
for (auto const& action : automatonDd.actionIndexToEdges) {
uint64_t edgeIndex = 0;
for (auto const& edge : action.second) {
result += edge.transitionsDd * computeMissingGlobalVariableIdentities(edge, variables);
edge.transitionsDd.exportToDot("edge_" + std::to_string(edgeIndex) + ".dot");
++edgeIndex;
}
}
result.exportToDot("result.dot");
std::cout << "nnz: " << result.getNonZeroCount() << std::endl;
std::cout << "nodecnt: " << result.getNodeCount() << std::endl;
std::cout << "meta var: " << std::endl;
for (auto const& var : result.getContainedMetaVariables()) {
std::cout << var.getName() << std::endl;
}
std::cout << std::endl;
return result;
} else {
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Illegal model type.");
@ -760,7 +759,6 @@ namespace storm {
AutomatonDd<Type, ValueType> system = composer.compose();
storm::dd::Add<Type, ValueType> transitions = createGlobalTransitionRelation(*this->model, system, variables);
transitions.exportToDot("trans.dot");
// FIXME
return nullptr;

8
src/builder/DdPrismModelBuilder.cpp

@ -1104,14 +1104,6 @@ namespace storm {
ModuleDecisionDiagram system = composer.compose(generationInfo.program.specifiesSystemComposition() ? generationInfo.program.getSystemCompositionConstruct().getSystemComposition() : *generationInfo.program.getDefaultSystemComposition());
storm::dd::Add<Type, ValueType> result = createSystemFromModule(generationInfo, system);
result.exportToDot("result_prism.dot");
std::cout << "nnz: " << result.getNonZeroCount() << std::endl;
std::cout << "nodecnt: " << result.getNodeCount() << std::endl;
std::cout << "meta var: " << std::endl;
for (auto const& var : result.getContainedMetaVariables()) {
std::cout << var.getName() << std::endl;
}
std::cout << std::endl;
// Create an auxiliary DD that is used later during the construction of reward models.
storm::dd::Add<Type, ValueType> stateActionDd = result.sumAbstract(generationInfo.columnMetaVariables);

73
test/functional/builder/DdJaniModelBuilderTest.cpp

@ -78,15 +78,6 @@ TEST(DdJaniModelBuilderTest_Cudd, Dtmc) {
// EXPECT_EQ(13ul, model->getNumberOfStates());
// EXPECT_EQ(20ul, model->getNumberOfTransitions());
// program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-2-2.pm");
// janiModel = program.toJani();
//
// builder = storm::builder::DdJaniModelBuilder<storm::dd::DdType::CUDD, double>(janiModel);
// t1 = std::chrono::high_resolution_clock::now();
// builder.translate();
// t2 = std::chrono::high_resolution_clock::now();
// std::cout << "brp2: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
janiModel = program.toJani();
@ -95,38 +86,38 @@ TEST(DdJaniModelBuilderTest_Cudd, Dtmc) {
model = builder.translate();
t2 = std::chrono::high_resolution_clock::now();
std::cout << "brp: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
// // EXPECT_EQ(677ul, model->getNumberOfStates());
// // EXPECT_EQ(867ul, model->getNumberOfTransitions());
//
// program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
// janiModel = program.toJani();
// builder = storm::builder::DdJaniModelBuilder<storm::dd::DdType::CUDD, double>(janiModel);
// t1 = std::chrono::high_resolution_clock::now();
// model = builder.translate();
// t2 = std::chrono::high_resolution_clock::now();
// std::cout << "crowds: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
// // EXPECT_EQ(8607ul, model->getNumberOfStates());
// // EXPECT_EQ(15113ul, model->getNumberOfTransitions());
//
// program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
// janiModel = program.toJani();
// builder = storm::builder::DdJaniModelBuilder<storm::dd::DdType::CUDD, double>(janiModel);
// t1 = std::chrono::high_resolution_clock::now();
// model = builder.translate();
// t2 = std::chrono::high_resolution_clock::now();
// std::cout << "lead: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
// // EXPECT_EQ(273ul, model->getNumberOfStates());
// // EXPECT_EQ(397ul, model->getNumberOfTransitions());
//
// program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
// janiModel = program.toJani();
// builder = storm::builder::DdJaniModelBuilder<storm::dd::DdType::CUDD, double>(janiModel);
// t1 = std::chrono::high_resolution_clock::now();
// model = builder.translate();
// t2 = std::chrono::high_resolution_clock::now();
// std::cout << "nand: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
// // EXPECT_EQ(1728ul, model->getNumberOfStates());
// // EXPECT_EQ(2505ul, model->getNumberOfTransitions());
// EXPECT_EQ(677ul, model->getNumberOfStates());
// EXPECT_EQ(867ul, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
janiModel = program.toJani();
builder = storm::builder::DdJaniModelBuilder<storm::dd::DdType::CUDD, double>(janiModel);
t1 = std::chrono::high_resolution_clock::now();
model = builder.translate();
t2 = std::chrono::high_resolution_clock::now();
std::cout << "crowds: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
// EXPECT_EQ(8607ul, model->getNumberOfStates());
// EXPECT_EQ(15113ul, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
janiModel = program.toJani();
builder = storm::builder::DdJaniModelBuilder<storm::dd::DdType::CUDD, double>(janiModel);
t1 = std::chrono::high_resolution_clock::now();
model = builder.translate();
t2 = std::chrono::high_resolution_clock::now();
std::cout << "lead: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
// EXPECT_EQ(273ul, model->getNumberOfStates());
// EXPECT_EQ(397ul, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
janiModel = program.toJani();
builder = storm::builder::DdJaniModelBuilder<storm::dd::DdType::CUDD, double>(janiModel);
t1 = std::chrono::high_resolution_clock::now();
model = builder.translate();
t2 = std::chrono::high_resolution_clock::now();
std::cout << "nand: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
// EXPECT_EQ(1728ul, model->getNumberOfStates());
// EXPECT_EQ(2505ul, model->getNumberOfTransitions());
}
//TEST(DdPrismModelBuilderTest_Cudd, Dtmc) {

9
test/functional/builder/DdPrismModelBuilderTest.cpp

@ -43,7 +43,7 @@ TEST(DdPrismModelBuilderTest_Sylvan, Dtmc) {
std::cout << "lead: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << std::endl;
EXPECT_EQ(273ul, model->getNumberOfStates());
EXPECT_EQ(397ul, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
t1 = std::chrono::high_resolution_clock::now();
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().translateProgram(program);
@ -59,11 +59,6 @@ TEST(DdPrismModelBuilderTest_Cudd, Dtmc) {
std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
EXPECT_EQ(13ul, model->getNumberOfStates());
EXPECT_EQ(20ul, model->getNumberOfTransitions());
// program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-2-2.pm");
// model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
//
// exit(-1);
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
@ -79,7 +74,7 @@ TEST(DdPrismModelBuilderTest_Cudd, Dtmc) {
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
EXPECT_EQ(273ul, model->getNumberOfStates());
EXPECT_EQ(397ul, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
EXPECT_EQ(1728ul, model->getNumberOfStates());

Loading…
Cancel
Save