39 const uint64_t resolution) {
46 helper[0] = resolutionConverted;
49 std::vector<storm::expressions::Expression> decisionVariables;
54 std::vector<storm::expressions::Expression> deltas;
62 std::vector<BeliefType> gridCandidates;
68 uint64_t
const jMax = belief.size() - 1;
72 candidateBuilder.
addValue(state, (helper[j] - helper[j + 1]) / resolutionConverted);
76 candidateBuilder.
addValue(state, helper[jMax] / resolutionConverted);
81 auto candidate = candidateBuilder.
build();
82 if (candidate == belief) {
87 gridCandidates.push_back(candidate);
90 auto decisionVar = lpSolver->addBinaryVariable(
"a_" + std::to_string(gridCandidates.size() - 1));
98 lpSolver->addConstraint(
"state_eq_" + std::to_string(i) +
"_" + std::to_string(gridCandidates.size() - 1),
99 deltas.at(i) >= lpSolver->getConstant(beliefValue) - lpSolver->getConstant(candidateValue) +
112 auto helperIt = helper.end() - 1;
113 while (*helperIt == *(helperIt - 1)) {
116 STORM_LOG_ASSERT(helperIt != helper.begin(),
"Error in grid clipping - index wrong");
121 while (helperIt != helper.end()) {
137 lpSolver->optimize();
143 if (lpSolver->isOptimal()) {
144 uint64_t targetBeliefIndex = std::numeric_limits<uint64_t>::max();
145 optDelta = lpSolver->getObjectiveValue();
146 for (uint64_t dist = 0; dist < gridCandidates.size(); ++dist) {
147 if (lpSolver->getBinaryValue(lpSolver->getManager().getVariable(
"a_" + std::to_string(dist)))) {
148 targetBeliefIndex = dist;
152 STORM_LOG_ASSERT(targetBeliefIndex < gridCandidates.size(),
"LP optimal but no belief selected");
153 auto targetBelief = gridCandidates.at(targetBeliefIndex);
155 belief.forEachStateInSupport([
this, &i, &deltaValues, &deltaSum](
BeliefStateType const& state) {
156 auto val = lpSolver->getContinuousValue(lpSolver->getManager().getVariable(
"d_" + std::to_string(i)));
158 deltaValues.emplace(state, val);
167 "Grid clipping LP returned a clipping value of zero for distinct beliefs. This may be due to numeric instability. Origin: "
168 << belief.toString(
false,
true) <<
", target: " << targetBelief.toString(
false,
true)
173 "Grid clipping LP returned a clipping value of one, leaving no retained probability. Origin: "
174 << belief.toString(
false,
true) <<
", target: " << targetBelief.toString(
false,
true)
180 STORM_LOG_TRACE(
"Clip " << belief.toString() <<
" to " << targetBelief.toString() <<
" with value " << optDelta);
181 return BeliefClipping{
true, std::move(targetBelief), optDelta, deltaValues,
false};
183 STORM_LOG_TRACE(
"Clipping " << belief.toString() <<
" not possible. LP not optimal.");
184 return BeliefClipping{
false, belief, optDelta, deltaValues,
false};