Skip to content

Commit

Permalink
Implement forEachTransition in terms of reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Märcker committed Jun 15, 2020
1 parent f1eeeda commit c1f16b2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 44 deletions.
11 changes: 4 additions & 7 deletions prism/src/explicit/DTMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public interface TransitionConsumer {
}

/**
* Iterate over the outgoing transitions of state {@code s} and call the accept method
* Iterate over the outgoing transitions of state {@code state} and call the accept method
* of the consumer for each of them:
* <br>
* Call {@code accept(s,t,d)} where t is the successor state and,
Expand All @@ -80,15 +80,12 @@ public interface TransitionConsumer {
* computation methods (mvMult, etc). In derived classes, it may thus be worthwhile to
* provide a specialised implementation for this method that avoids using the Iterator mechanism.
*
* @param s the state s
* @param state the state
* @param c the consumer
*/
public default void forEachTransition(int s, TransitionConsumer c)
public default void forEachTransition(int state, TransitionConsumer c)
{
for (Iterator<Entry<Integer, Double>> it = getTransitionsIterator(s); it.hasNext(); ) {
Entry<Integer, Double> e = it.next();
c.accept(s, e.getKey(), e.getValue());
}
reduceTransitions(state, null, (r, s, t, d) -> {c.accept(s,t,d); return r;});
}

/**
Expand Down
14 changes: 0 additions & 14 deletions prism/src/explicit/DTMCEmbeddedSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,6 @@ public Double setValue(Double value)
}
}

@Override
public void forEachTransition(int s, TransitionConsumer c)
{
final double er = exitRates[s];
if (er == 0) {
// exit rate = 0 -> prob 1 self loop
c.accept(s, s, 1.0);
} else {
ctmc.forEachTransition(s, (s_,t,rate) -> {
c.accept(s_, t, rate / er);
});
}
}

@Override
public <T> T reduceTransitions(int state, T init, ObjTransitionFunction<T> fn)
{
Expand Down
9 changes: 0 additions & 9 deletions prism/src/explicit/DTMCFromMDPAndMDStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,6 @@ public Iterator<Entry<Integer, Double>> getTransitionsIterator(int s)
}
}

@Override
public void forEachTransition(int s, TransitionConsumer c)
{
if (!strat.isChoiceDefined(s)) {
return;
}
mdp.forEachTransition(s, strat.getChoiceIndex(s), c);
}

@Override
public <T> T reduceTransitions(int state, T init, ObjTransitionFunction<T> fn)
{
Expand Down
8 changes: 0 additions & 8 deletions prism/src/explicit/DTMCSparse.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,6 @@ public void buildFromPrismExplicit(String filename) throws PrismException

//--- DTMC ---

@Override
public void forEachTransition(int state, TransitionConsumer consumer)
{
for (int col = rows[state], stop = rows[state+1]; col < stop; col++) {
consumer.accept(state, columns[col], probabilities[col]);
}
}

@Override
public <T> T reduceTransitions(int state, T init, ObjTransitionFunction<T> fn)
{
Expand Down
9 changes: 3 additions & 6 deletions prism/src/explicit/MDP.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface MDP extends MDPGeneric<Double>
public Iterator<Entry<Integer, Double>> getTransitionsIterator(int s, int i);

/**
* Iterate over the outgoing transitions of state {@code s} and choice {@code i}
* Iterate over the outgoing transitions of state {@code state} and choice {@code i}
* and call the accept method of the consumer for each of them:
* <br>
* Call {@code accept(s,t,d)} where t is the successor state d = P(s,i,t)
Expand All @@ -75,12 +75,9 @@ public interface MDP extends MDPGeneric<Double>
* @param i the choice i
* @param c the consumer
*/
public default void forEachTransition(int s, int i, TransitionConsumer c)
public default void forEachTransition(int state, int choice, TransitionConsumer c)
{
for (Iterator<Entry<Integer, Double>> it = getTransitionsIterator(s, i); it.hasNext(); ) {
Entry<Integer, Double> e = it.next();
c.accept(s, e.getKey(), e.getValue());
}
reduceTransitions(state, choice, null, (r, s, t, d) -> {c.accept(s,t,d); return r;});
}

/**
Expand Down

0 comments on commit c1f16b2

Please sign in to comment.