From 629c30545633504ec3a3b34b2bd6b4a928fc7432 Mon Sep 17 00:00:00 2001 From: TimQu Date: Thu, 16 Aug 2018 10:16:09 +0200 Subject: [PATCH] Added option to specify one global capacity for all places of a gspn --- src/storm-gspn-cli/storm-gspn.cpp | 7 +++++++ src/storm-gspn/settings/modules/GSPNSettings.cpp | 15 +++++++++++++++ src/storm-gspn/settings/modules/GSPNSettings.h | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/storm-gspn-cli/storm-gspn.cpp b/src/storm-gspn-cli/storm-gspn.cpp index cb12de228..70272e5b2 100644 --- a/src/storm-gspn-cli/storm-gspn.cpp +++ b/src/storm-gspn-cli/storm-gspn.cpp @@ -110,6 +110,13 @@ int main(const int argc, const char **argv) { if(storm::settings::getModule().isCapacitiesFileSet()) { auto capacities = parseCapacitiesList(storm::settings::getModule().getCapacitiesFilename()); gspn->setCapacities(capacities); + } else if (storm::settings::getModule().isCapacitySet()) { + uint64_t capacity = storm::settings::getModule().getCapacity(); + std::unordered_map capacities; + for (auto const& place : gspn->getPlaces()) { + capacities.emplace(place.getName(), capacity); + } + gspn->setCapacities(capacities); } storm::api::handleGSPNExportSettings(*gspn, [&](storm::builder::JaniGSPNBuilder const&) { return properties; }); diff --git a/src/storm-gspn/settings/modules/GSPNSettings.cpp b/src/storm-gspn/settings/modules/GSPNSettings.cpp index 2cca4b2f9..0efed0525 100644 --- a/src/storm-gspn/settings/modules/GSPNSettings.cpp +++ b/src/storm-gspn/settings/modules/GSPNSettings.cpp @@ -18,11 +18,13 @@ namespace storm { const std::string GSPNSettings::gspnFileOptionShortName = "gspn"; const std::string GSPNSettings::capacitiesFileOptionName = "capacitiesfile"; const std::string GSPNSettings::capacitiesFileOptionShortName = "capacities"; + const std::string GSPNSettings::capacityOptionName = "capacity"; GSPNSettings::GSPNSettings() : ModuleSettings(moduleName) { this->addOption(storm::settings::OptionBuilder(moduleName, gspnFileOptionName, false, "Parses the GSPN.").setShortName(gspnFileOptionShortName).addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "path to file").addValidatorString(ArgumentValidatorFactory::createExistingFileValidator()).build()).build()); this->addOption(storm::settings::OptionBuilder(moduleName, capacitiesFileOptionName, false, "Capacaties as invariants for places.").setShortName(capacitiesFileOptionShortName).addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "path to file").addValidatorString(ArgumentValidatorFactory::createExistingFileValidator()).build()).build()); + this->addOption(storm::settings::OptionBuilder(moduleName, capacityOptionName, false, "Global capacity as invariants for all places.").addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("value", "capacity").build()).build()); } bool GSPNSettings::isGspnFileSet() const { @@ -41,6 +43,14 @@ namespace storm { return this->getOption(capacitiesFileOptionName).getArgumentByName("filename").getValueAsString(); } + bool GSPNSettings::isCapacitySet() const { + return this->getOption(capacityOptionName).getHasOptionBeenSet(); + } + + uint64_t GSPNSettings::getCapacity() const { + return this->getOption(capacityOptionName).getArgumentByName("value").getValueAsUnsignedInteger(); + } + void GSPNSettings::finalize() { } @@ -51,6 +61,11 @@ namespace storm { return false; } } + + if (isCapacitiesFileSet() && isCapacitySet()) { + STORM_LOG_ERROR("Conflicting settings: Capacity file AND capacity was set."); + return false; + } return true; } } diff --git a/src/storm-gspn/settings/modules/GSPNSettings.h b/src/storm-gspn/settings/modules/GSPNSettings.h index e5128c30e..665e588fb 100644 --- a/src/storm-gspn/settings/modules/GSPNSettings.h +++ b/src/storm-gspn/settings/modules/GSPNSettings.h @@ -34,6 +34,16 @@ namespace storm { */ std::string getCapacitiesFilename() const; + /** + * Retrievew whether a global capacity was set + */ + bool isCapacitySet() const; + + /** + * Retrieves the global capacity + */ + uint64_t getCapacity() const; + bool check() const override; void finalize() override; @@ -45,6 +55,7 @@ namespace storm { static const std::string gspnFileOptionShortName; static const std::string capacitiesFileOptionName; static const std::string capacitiesFileOptionShortName; + static const std::string capacityOptionName; }; }