dehnert
10 years ago
16 changed files with 217 additions and 210 deletions
-
2CMakeLists.txt
-
2resources/3rdparty/cudd-2.5.0/CMakeLists.txt
-
6resources/3rdparty/log4cplus-1.1.3-rc1/src/CMakeLists.txt
-
4src/modelchecker/reachability/SparseDtmcEliminationModelChecker.cpp
-
1src/storage/BitVector.cpp
-
4src/storage/DeterministicModelBisimulationDecomposition.cpp
-
6src/storage/SparseMatrix.cpp
-
64src/utility/prism.cpp
-
58src/utility/prism.h
-
6test/functional/parser/DeterministicSparseTransitionParserTest.cpp
-
14test/functional/parser/NondeterministicModelParserTest.cpp
-
136test/functional/parser/NondeterministicSparseTransitionParserTest.cpp
-
2test/functional/parser/PrismParserTest.cpp
-
10test/functional/storage/BitVectorTest.cpp
-
110test/functional/storage/CuddDdTest.cpp
-
2test/functional/storage/StronglyConnectedComponentDecompositionTest.cpp
@ -0,0 +1,64 @@ |
|||
#include "src/utility/prism.h"
|
|||
|
|||
namespace storm { |
|||
namespace utility { |
|||
namespace prism { |
|||
std::map<storm::expressions::Variable, storm::expressions::Expression> parseConstantDefinitionString(storm::prism::Program const& program, std::string const& constantDefinitionString) { |
|||
std::map<storm::expressions::Variable, storm::expressions::Expression> constantDefinitions; |
|||
std::set<storm::expressions::Variable> definedConstants; |
|||
|
|||
if (!constantDefinitionString.empty()) { |
|||
// Parse the string that defines the undefined constants of the model and make sure that it contains exactly
|
|||
// one value for each undefined constant of the model.
|
|||
std::vector<std::string> definitions; |
|||
boost::split(definitions, constantDefinitionString, boost::is_any_of(",")); |
|||
for (auto& definition : definitions) { |
|||
boost::trim(definition); |
|||
|
|||
// Check whether the token could be a legal constant definition.
|
|||
uint_fast64_t positionOfAssignmentOperator = definition.find('='); |
|||
if (positionOfAssignmentOperator == std::string::npos) { |
|||
throw storm::exceptions::InvalidArgumentException() << "Illegal constant definition string: syntax error."; |
|||
} |
|||
|
|||
// Now extract the variable name and the value from the string.
|
|||
std::string constantName = definition.substr(0, positionOfAssignmentOperator); |
|||
boost::trim(constantName); |
|||
std::string value = definition.substr(positionOfAssignmentOperator + 1); |
|||
boost::trim(value); |
|||
|
|||
// Check whether the constant is a legal undefined constant of the program and if so, of what type it is.
|
|||
if (program.hasConstant(constantName)) { |
|||
// Get the actual constant and check whether it's in fact undefined.
|
|||
auto const& constant = program.getConstant(constantName); |
|||
storm::expressions::Variable variable = constant.getExpressionVariable(); |
|||
STORM_LOG_THROW(!constant.isDefined(), storm::exceptions::InvalidArgumentException, "Illegally trying to define already defined constant '" << constantName <<"'."); |
|||
STORM_LOG_THROW(definedConstants.find(variable) == definedConstants.end(), storm::exceptions::InvalidArgumentException, "Illegally trying to define constant '" << constantName <<"' twice."); |
|||
definedConstants.insert(variable); |
|||
|
|||
if (constant.getType().isBooleanType()) { |
|||
if (value == "true") { |
|||
constantDefinitions[variable] = program.getManager().boolean(true); |
|||
} else if (value == "false") { |
|||
constantDefinitions[variable] = program.getManager().boolean(false); |
|||
} else { |
|||
throw storm::exceptions::InvalidArgumentException() << "Illegal value for boolean constant: " << value << "."; |
|||
} |
|||
} else if (constant.getType().isIntegerType()) { |
|||
int_fast64_t integerValue = std::stoi(value); |
|||
constantDefinitions[variable] = program.getManager().integer(integerValue); |
|||
} else if (constant.getType().isRationalType()) { |
|||
double doubleValue = std::stod(value); |
|||
constantDefinitions[variable] = program.getManager().rational(doubleValue); |
|||
} |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Illegal constant definition string: unknown undefined constant " << constantName << "."); |
|||
} |
|||
} |
|||
} |
|||
|
|||
return constantDefinitions; |
|||
} |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue