From 1dd339ede594d17b5a14d8b4e80e5b58b65f616d Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Fri, 21 Jul 2017 13:20:46 +0000 Subject: [PATCH] explicit.DTMC: mvMultRewGS for Gauss-Seidel style reward computations git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@12098 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/explicit/DTMC.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/prism/src/explicit/DTMC.java b/prism/src/explicit/DTMC.java index d4d606ea..5ca11310 100644 --- a/prism/src/explicit/DTMC.java +++ b/prism/src/explicit/DTMC.java @@ -392,6 +392,28 @@ public interface DTMC extends Model } } + /** + * Do a matrix-vector multiplication and sum of action reward (Gauss-Seidel). + * @param vect Vector to multiply by and store result in + * @param mcRewards The rewards + * @param states Do multiplication for these rows, in the specified order + * @param absolute If true, compute absolute, rather than relative, difference + * @return The maximum difference between old/new elements of {@code vect} + */ + public default double mvMultRewGS(double vect[], MCRewards mcRewards, PrimitiveIterator.OfInt states, boolean absolute) + { + double d, diff, maxDiff = 0.0; + while (states.hasNext()) { + int s = states.nextInt(); + d = mvMultRewJacSingle(s, vect, mcRewards); + + diff = absolute ? (Math.abs(d - vect[s])) : (Math.abs(d - vect[s]) / d); + maxDiff = diff > maxDiff ? diff : maxDiff; + vect[s] = d; + } + return maxDiff; + } + /** * Do a single row of matrix-vector multiplication and sum of action reward. * @param s Row index