You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
29 lines
1.1 KiB
#include "storm/utility/ExpressionHelper.h"
|
|
#include "storm/utility/constants.h"
|
|
|
|
namespace storm {
|
|
namespace utility {
|
|
|
|
ExpressionHelper::ExpressionHelper(std::shared_ptr<storm::expressions::ExpressionManager> const& expressionManager) : manager(expressionManager) {
|
|
// Intentionally left empty
|
|
}
|
|
|
|
storm::expressions::Expression ExpressionHelper::sum(std::vector<storm::expressions::Expression>&& summands) const {
|
|
if (summands.empty()) {
|
|
return manager->rational(storm::utility::zero<storm::RationalNumber>());
|
|
}
|
|
// As the sum can potentially have many summands, we want to make sure that the formula tree is (roughly balanced)
|
|
auto it = summands.begin();
|
|
while (summands.size() > 1) {
|
|
if (it == summands.end() || it == summands.end() - 1) {
|
|
it = summands.begin();
|
|
}
|
|
*it = *it + summands.back();
|
|
summands.pop_back();
|
|
++it;
|
|
}
|
|
return summands.front();
|
|
}
|
|
|
|
}
|
|
}
|