3#include <boost/algorithm/string.hpp>
4#include <boost/lexical_cast.hpp>
17template<
typename ValueType>
18ValueParser<ValueType>::ParametricData::ParametricData()
20 parser(
std::make_unique<ExpressionParser>(*
manager)),
23 parser->setIdentifierMapping(identifierMapping);
26template<
typename ValueType>
27ValueParser<ValueType>::ParametricData::~ParametricData() =
default;
29template<
typename ValueType>
31 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Parameters are not supported in this build (Have you checked storm-pars?).");
37 data.identifierMapping.emplace(var.
getName(), var);
38 data.parser->setIdentifierMapping(data.identifierMapping);
46 return rationalFunction;
49template<
typename ValueType>
51 return parseNumber<ValueType>(value);
54template<
typename NumberType>
58 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Could not parse value '" << value <<
"' into " <<
typeid(NumberType).name() <<
".");
64 if (boost::conversion::try_lexical_convert(value, result)) {
68 storm::RationalNumber rationalResult;
70 result = storm::utility::convertNumber<double>(rationalResult);
79 if (
double pointResult;
parseNumber(value, pointResult)) {
84 std::string intermediate = value;
85 boost::trim(intermediate);
86 carl::BoundType leftBound;
87 carl::BoundType rightBound;
88 if (intermediate.front() ==
'(') {
89 leftBound = carl::BoundType::STRICT;
90 }
else if (intermediate.front() ==
'[') {
91 leftBound = carl::BoundType::WEAK;
95 if (intermediate.back() ==
')') {
96 rightBound = carl::BoundType::STRICT;
97 }
else if (intermediate.back() ==
']') {
98 rightBound = carl::BoundType::WEAK;
102 intermediate = intermediate.substr(1, intermediate.size() - 2);
104 std::vector<std::string> words;
105 boost::split(words, intermediate, boost::is_any_of(
","));
106 if (words.size() != 2) {
109 double leftVal, rightVal;
110 boost::trim(words[0]);
114 boost::trim(words[1]);
122template<
typename NumberType>
124 if constexpr (std::is_same_v<NumberType, double>) {
126 }
else if constexpr (std::is_same_v<NumberType, storm::RationalNumber>) {
127 return carl::try_parse(value, result);
128 }
else if constexpr (std::is_same_v<NumberType, storm::Interval>) {
131 return boost::conversion::try_lexical_convert(value, result);
136template class ValueParser<double>;
137template class ValueParser<storm::RationalNumber>;
138template class ValueParser<storm::RationalFunction>;
139template class ValueParser<storm::Interval>;
141template std::size_t parseNumber<std::size_t>(std::string
const&);
Variable declareRationalVariable(std::string const &name, bool auxiliary=false)
Declares a new rational variable with a name that must not yet exist and its corresponding type.
std::string const & getName() const
Retrieves the name of the variable.
Parser for values according to their ValueType.
#define STORM_LOG_TRACE(message)
#define STORM_LOG_THROW(cond, exception, message)
NumberType parseNumber(std::string const &value)
Parse number from string.
bool parseDouble(std::string const &value, double &result)
bool parseInterval(std::string const &value, storm::Interval &result)
SettingsManager const & manager()
Retrieves the settings manager.
carl::Interval< double > Interval
Interval type.
carl::RationalFunction< Polynomial, true > RationalFunction