Browse Source

Use name + id for getting unique json element

tempestpy_adaptions
Matthias Volk 8 years ago
parent
commit
f9114bb54d
  1. 27
      src/storm-dft/parser/DFTJsonParser.cpp
  2. 2
      src/storm-dft/storage/dft/DFTBuilder.cpp
  3. 2
      src/storm-dft/storage/dft/DFTBuilder.h

27
src/storm-dft/parser/DFTJsonParser.cpp

@ -74,27 +74,33 @@ namespace storm {
if (element.at("classes") != "") { if (element.at("classes") != "") {
json data = element.at("data"); json data = element.at("data");
std::string id = data.at("id"); std::string id = data.at("id");
std::string name = data.at("name");
// Append to id to distinguish elements with the same name
std::stringstream stream;
stream << data.at("name").get<std::string>() << "-" << id;
std::string name = stream.str();
nameMapping[id] = name; nameMapping[id] = name;
if (data.count("toplevel") > 0) {
STORM_LOG_ASSERT(toplevelName.empty(), "Toplevel element already defined.");
toplevelName = name;
}
} }
} }
std::cout << toplevelName << std::endl; std::cout << toplevelName << std::endl;
for (auto& element : parsedJson) { for (auto& element : parsedJson) {
STORM_LOG_TRACE("Parsing: " << element);
bool success = true; bool success = true;
if (element.at("classes") == "") { if (element.at("classes") == "") {
continue; continue;
} }
json data = element.at("data"); json data = element.at("data");
std::string name = data.at("name");
std::stringstream stream;
stream << data.at("name").get<std::string>() << "-" << data.at("id").get<std::string>();
std::string name = stream.str();
if (data.count("toplevel") > 0) {
STORM_LOG_ASSERT(toplevelName.empty(), "Toplevel element already defined.");
toplevelName = name;
}
std::vector<std::string> childNames; std::vector<std::string> childNames;
if (data.count("children") > 0) { if (data.count("children") > 0) {
for (auto& child : data.at("children")) {
childNames.push_back(nameMapping[child]);
for (json& child : data.at("children")) {
childNames.push_back(nameMapping[child.get<std::string>()]);
} }
} }
@ -126,11 +132,16 @@ namespace storm {
success = false; success = false;
} }
// Do not set layout for dependencies
// This does not work because dependencies might be splitted
// TODO: do splitting later in rewriting step
if (type != "fdep" && type != "pdep") {
// Set layout positions // Set layout positions
json position = element.at("position"); json position = element.at("position");
double x = position.at("x"); double x = position.at("x");
double y = position.at("y"); double y = position.at("y");
builder.addLayoutInfo(name, x / 7, y / 7); builder.addLayoutInfo(name, x / 7, y / 7);
}
STORM_LOG_THROW(success, storm::exceptions::FileIoException, "Error while adding element '" << element << "'."); STORM_LOG_THROW(success, storm::exceptions::FileIoException, "Error while adding element '" << element << "'.");
} }

2
src/storm-dft/storage/dft/DFTBuilder.cpp

@ -159,7 +159,7 @@ namespace storm {
template<typename ValueType> template<typename ValueType>
bool DFTBuilder<ValueType>::addStandardGate(std::string const& name, std::vector<std::string> const& children, DFTElementType tp) { bool DFTBuilder<ValueType>::addStandardGate(std::string const& name, std::vector<std::string> const& children, DFTElementType tp) {
STORM_LOG_ASSERT(children.size() > 0, "No child.");
STORM_LOG_ASSERT(children.size() > 0, "No child for " << name);
if(mElements.count(name) != 0) { if(mElements.count(name) != 0) {
// Element with that name already exists. // Element with that name already exists.
return false; return false;

2
src/storm-dft/storage/dft/DFTBuilder.h

@ -103,7 +103,7 @@ namespace storm {
//TODO Matthias: collect constraints for SMT solving //TODO Matthias: collect constraints for SMT solving
//0 <= probability <= 1 //0 <= probability <= 1
if (binaryDependencies && !storm::utility::isOne(probability) && children.size() > 2) { if (binaryDependencies && !storm::utility::isOne(probability) && children.size() > 2) {
// Introduce additional element for first capturing the proabilistic dependency
// Introduce additional element for first capturing the probabilistic dependency
std::string nameAdditional = name + "_additional"; std::string nameAdditional = name + "_additional";
addBasicElement(nameAdditional, storm::utility::zero<ValueType>(), storm::utility::zero<ValueType>()); addBasicElement(nameAdditional, storm::utility::zero<ValueType>(), storm::utility::zero<ValueType>());
// First consider probabilistic dependency // First consider probabilistic dependency

Loading…
Cancel
Save