Browse Source
Explicit engine improvements, mainly MDP rewards:
Explicit engine improvements, mainly MDP rewards:
* Explicit engine gets MDP rewards (transition rewards only) from the model * Rewards detached from MDPs (but attached ones still available, e.g. for A-R) * Various bug fixes in MDPSparse, especially wrt rewards * Few code tidies git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@3215 bbc10eb1-c90d-0410-af57-cb519fbb1720master
8 changed files with 316 additions and 195 deletions
-
11prism/src/explicit/MDP.java
-
140prism/src/explicit/MDPModelChecker.java
-
18prism/src/explicit/MDPSimple.java
-
120prism/src/explicit/MDPSparse.java
-
60prism/src/explicit/ProbModelChecker.java
-
12prism/src/explicit/QuantAbstractRefine.java
-
43prism/src/explicit/rewards/MDPRewards.java
-
107prism/src/explicit/rewards/MDPRewardsSimple.java
@ -0,0 +1,43 @@ |
|||
//============================================================================== |
|||
// |
|||
// Copyright (c) 2002- |
|||
// Authors: |
|||
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford) |
|||
// |
|||
//------------------------------------------------------------------------------ |
|||
// |
|||
// This file is part of PRISM. |
|||
// |
|||
// PRISM is free software; you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation; either version 2 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// PRISM is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with PRISM; if not, write to the Free Software Foundation, |
|||
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
// |
|||
//============================================================================== |
|||
|
|||
package explicit.rewards; |
|||
|
|||
/** |
|||
* Classes that provide (read) access to explicit-state rewards for an MDP. |
|||
*/ |
|||
public abstract class MDPRewards |
|||
{ |
|||
/** |
|||
* Get the state reward for state {@code s}. |
|||
*/ |
|||
public abstract double getStateReward(int s); |
|||
|
|||
/** |
|||
* Get the transition reward for the {@code i}th choice from state {@code s}. |
|||
*/ |
|||
public abstract double getTransitionReward(int s, int i); |
|||
} |
|||
@ -0,0 +1,107 @@ |
|||
//============================================================================== |
|||
// |
|||
// Copyright (c) 2002- |
|||
// Authors: |
|||
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford) |
|||
// |
|||
//------------------------------------------------------------------------------ |
|||
// |
|||
// This file is part of PRISM. |
|||
// |
|||
// PRISM is free software; you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation; either version 2 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// PRISM is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with PRISM; if not, write to the Free Software Foundation, |
|||
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
// |
|||
//============================================================================== |
|||
|
|||
package explicit.rewards; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* Simple explicit-state storage of rewards for an MDP. |
|||
* Like the related class MDPSimple, this is not especially efficient, but mutable (in terms of size). |
|||
*/ |
|||
public class MDPRewardsSimple extends MDPRewards |
|||
{ |
|||
/** Number of state */ |
|||
protected int numStates; |
|||
/** State rewards **/ |
|||
protected List<Double> stateRewards; |
|||
/** Transition rewards **/ |
|||
protected List<List<Double>> transRewards; |
|||
|
|||
/** |
|||
* Constructor: all zero rewards. |
|||
* @param numStates Number of states |
|||
*/ |
|||
public MDPRewardsSimple(int numStates) |
|||
{ |
|||
this.numStates = numStates; |
|||
// Initially lists are just null (denoting all 0) |
|||
stateRewards = null; |
|||
transRewards = null; |
|||
} |
|||
|
|||
// Mutators |
|||
|
|||
/** |
|||
* Set the reward for choice {@code i} of state {@code s} to {@code r}. |
|||
*/ |
|||
public void setTransitionReward(int s, int i, double r) |
|||
{ |
|||
List<Double> list; |
|||
// If no rewards array created yet, create it |
|||
if (transRewards == null) { |
|||
transRewards = new ArrayList<List<Double>>(numStates); |
|||
for (int j = 0; j < numStates; j++) |
|||
transRewards.add(null); |
|||
} |
|||
// If no rewards for state i yet, create list |
|||
if (transRewards.get(s) == null) { |
|||
list = new ArrayList<Double>(); |
|||
transRewards.set(s, list); |
|||
} else { |
|||
list = transRewards.get(s); |
|||
} |
|||
// If list not big enough, extend |
|||
int n = i - list.size() + 1; |
|||
if (n > 0) { |
|||
for (int j = 0; j < n; j++) { |
|||
list.add(0.0); |
|||
} |
|||
} |
|||
// Set reward |
|||
list.set(i, r); |
|||
} |
|||
|
|||
// Accessors (for MDPRewards) |
|||
|
|||
@Override |
|||
public double getStateReward(int s) |
|||
{ |
|||
return stateRewards.get(s); |
|||
} |
|||
|
|||
@Override |
|||
public double getTransitionReward(int s, int i) |
|||
{ |
|||
List<Double> list; |
|||
if (transRewards == null || (list = transRewards.get(s)) == null) |
|||
return 0.0; |
|||
if (list.size() <= i) |
|||
return 0.0; |
|||
return list.get(i); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue