Browse Source

explicit: Fix transition rewards from deadlock states

Previously, a transition reward with [] would match the self loop
transition added for fixing deadlocks in the explicit engine.

Fixes #29 and adds test case.
master
Joachim Klein 8 years ago
committed by Dave Parker
parent
commit
eeb8016184
  1. 15
      prism-tests/bugfixes/deadlock-rewards-issue-29.prism
  2. 3
      prism-tests/bugfixes/deadlock-rewards-issue-29.prism.mc.props
  3. 11
      prism-tests/bugfixes/deadlock-rewards-issue-29.prism.mc.props.args
  4. 6
      prism-tests/bugfixes/deadlock-rewards-issue-29.prism.props
  5. 4
      prism-tests/bugfixes/deadlock-rewards-issue-29.prism.props.args
  6. 13
      prism/src/explicit/rewards/ConstructRewards.java

15
prism-tests/bugfixes/deadlock-rewards-issue-29.prism

@ -0,0 +1,15 @@
// test case for github issue #29
// transitions added for deadlock removal should not get rewards
mdp
module M1
s: [0..1] init 0;
// deadlock for state 1
[] s=0 -> 1:(s'=1);
endmodule
rewards "r"
[] true: 2;
endrewards

3
prism-tests/bugfixes/deadlock-rewards-issue-29.prism.mc.props

@ -0,0 +1,3 @@
// total reward
// RESULT: 2.0
R=?[ C ]

11
prism-tests/bugfixes/deadlock-rewards-issue-29.prism.mc.props.args

@ -0,0 +1,11 @@
# As a CTMC
-ctmc -ex
-ctmc -mtbdd
-ctmc -hybrid
-ctmc -sparse
# As a DTMC
-dtmc -ex
-dtmc -mtbdd
-dtmc -hybrid
-dtmc -sparse

6
prism-tests/bugfixes/deadlock-rewards-issue-29.prism.props

@ -0,0 +1,6 @@
// total reward
// RESULT: 2.0
Rmax=?[ C ]
// RESULT: 2.0
Rmin=?[ C ]

4
prism-tests/bugfixes/deadlock-rewards-issue-29.prism.props.args

@ -0,0 +1,4 @@
-ex
-mtbdd
-hybrid
-sparse

13
prism/src/explicit/rewards/ConstructRewards.java

@ -174,6 +174,12 @@ public class ConstructRewards
if (guard.evaluateBoolean(constantValues, statesList.get(j))) { if (guard.evaluateBoolean(constantValues, statesList.get(j))) {
// Transition reward // Transition reward
if (rewStr.getRewardStructItem(i).isTransitionReward()) { if (rewStr.getRewardStructItem(i).isTransitionReward()) {
if (mdp.isDeadlockState(j)) {
// As state j is a deadlock state, any outgoing transition
// was added to "fix" the deadlock and thus does not get a reward.
// Skip to next state
continue;
}
numChoices = mdp.getNumChoices(j); numChoices = mdp.getNumChoices(j);
for (k = 0; k < numChoices; k++) { for (k = 0; k < numChoices; k++) {
mdpAction = mdp.getAction(j, k); mdpAction = mdp.getAction(j, k);
@ -275,7 +281,14 @@ public class ConstructRewards
if (!allowNegative && rew < 0) if (!allowNegative && rew < 0)
throw new PrismException("Reward structure evaluates to " + rew + " at state " + state +", negative rewards not allowed"); throw new PrismException("Reward structure evaluates to " + rew + " at state " + state +", negative rewards not allowed");
rewSimple.addToStateReward(j, rew); rewSimple.addToStateReward(j, rew);
// State-action rewards // State-action rewards
if (mdp.isDeadlockState(j)) {
// As state j is a deadlock state, any outgoing transition
// was added to "fix" the deadlock and thus does not get a reward.
// Skip to next state
continue;
}
int numChoices = mdp.getNumChoices(j); int numChoices = mdp.getNumChoices(j);
for (int k = 0; k < numChoices; k++) { for (int k = 0; k < numChoices; k++) {
rew = modelGen.getStateActionReward(r, state, mdp.getAction(j, k)); rew = modelGen.getStateActionReward(r, state, mdp.getAction(j, k));

Loading…
Cancel
Save