Skip to content

Commit

Permalink
Check for transition reward consistency when importing from .trew files.
Browse files Browse the repository at this point in the history
It is assumed that rewards are the same for all successor states from
the same state-choice pair, since we don't support state-choice-state
rewards yet. So the explicit engine now checks that this is the case
when importing a .trew file.

In fact, the symbolic engines _can_ import these (and a check is actually
a bit tricky), so we don't check for the symbolic engines.
  • Loading branch information
davexparker committed Sep 20, 2024
1 parent e164ac1 commit 6b871ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
32 changes: 31 additions & 1 deletion prism/src/explicit/ExplicitFiles2Rewards.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import explicit.rewards.Rewards;
import explicit.rewards.RewardsSimple;
import io.ExplicitModelImporter;
import io.IOUtils;
import parser.State;
import prism.Evaluator;
import prism.PrismComponent;
Expand Down Expand Up @@ -201,7 +202,36 @@ public Rewards<Value> getRewardObject(int r) throws PrismException
if (!model.getModelType().nondeterministic()) {
importer.extractMCTransitionRewards(r, (s, s2, v) -> storeMCTransitionReward(r, s, s2, v), eval);
} else {
importer.extractMDPTransitionRewards(r, (s, i, s2, v) -> storeMDPTransitionReward(r, s, i, s2, v), eval);
importer.extractMDPTransitionRewards(r,
new IOUtils.TransitionStateRewardConsumer<Value>() {
int sLast = -1;
int iLast = -1;
Value vLast = null;
int count = 0;
public void accept(int s, int i, int s2, Value v) throws PrismException
{
count++;
// Check that transition rewards for the same state/choice are the same
// (currently no support for state-choice-state rewards)
if (s == sLast && i == iLast) {
if (!eval.equals(vLast, v)) {
throw new PrismException("mismatching transition rewards " + vLast + " and " + v + " in choice " + i + " of state " + s);
}
}
// And check that were rewards on all successors for each choice
// (for speed, we just check that the right number were present)
else {
if (sLast != -1 && count != ((NondetModel<?>) model).getNumTransitions(sLast, iLast)) {
throw new PrismException("wrong number of transition rewards in choice " + iLast + " of state " + sLast);
}
sLast = s;
iLast = i;
vLast = v;
count = 0;
}
storeMDPTransitionReward(r, s, i, s2, v);
}
}, eval);
}
}
return rewards[r];
Expand Down
6 changes: 3 additions & 3 deletions prism/src/io/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public interface MDPTransitionConsumer<V> {
*/
@FunctionalInterface
public interface LTSTransitionConsumer {
void accept(int s, int i, int s2, Object a) throws PrismException;;
void accept(int s, int i, int s2, Object a) throws PrismException;
}

/**
Expand All @@ -75,7 +75,7 @@ public interface LTSTransitionConsumer {
*/
@FunctionalInterface
public interface TransitionRewardConsumer<V> {
void accept(int s, int i, V v);
void accept(int s, int i, V v) throws PrismException;
}

/**
Expand All @@ -84,6 +84,6 @@ public interface TransitionRewardConsumer<V> {
*/
@FunctionalInterface
public interface TransitionStateRewardConsumer<V> {
void accept(int s, int i, int s2, V v);
void accept(int s, int i, int s2, V v) throws PrismException;
}
}

0 comments on commit 6b871ec

Please sign in to comment.