diff --git a/prism/src/explicit/rewards/MCRewards.java b/prism/src/explicit/rewards/MCRewards.java index 0ae582c0..2cf63212 100644 --- a/prism/src/explicit/rewards/MCRewards.java +++ b/prism/src/explicit/rewards/MCRewards.java @@ -29,7 +29,7 @@ package explicit.rewards; /** * Classes that provide (read) access to explicit-state rewards for a Markov chain (DTMC/CTMC). */ -public abstract class MCRewards +public interface MCRewards { /** * Get the state reward for state {@code s}. diff --git a/prism/src/explicit/rewards/MCRewardsStateArray.java b/prism/src/explicit/rewards/MCRewardsStateArray.java index 7c4cb85d..8a938f29 100644 --- a/prism/src/explicit/rewards/MCRewardsStateArray.java +++ b/prism/src/explicit/rewards/MCRewardsStateArray.java @@ -29,7 +29,7 @@ package explicit.rewards; /** * Explicit-state storage of just state rewards for a DTMC/CTMC (as an array). */ -public class MCRewardsStateArray extends MCRewards +public class MCRewardsStateArray implements MCRewards, MDPRewards { /** Array of state rewards **/ protected double stateRewards[] = null; @@ -55,11 +55,17 @@ public class MCRewardsStateArray extends MCRewards stateRewards[s] = r; } - // Accessors (for MCRewards) + // Accessors @Override public double getStateReward(int s) { return stateRewards[s]; } + + @Override + public double getTransitionReward(int s, int i) + { + return 0.0; + } } diff --git a/prism/src/explicit/rewards/MCRewardsStateConstant.java b/prism/src/explicit/rewards/MCRewardsStateConstant.java index 1e7f2d60..b10ef683 100644 --- a/prism/src/explicit/rewards/MCRewardsStateConstant.java +++ b/prism/src/explicit/rewards/MCRewardsStateConstant.java @@ -29,7 +29,7 @@ package explicit.rewards; /** * Explicit-state storage of constant state rewards for a DTMC/CTMC. */ -public class MCRewardsStateConstant extends MCRewards +public class MCRewardsStateConstant implements MCRewards, MDPRewards { protected double stateReward = 0.0; @@ -41,11 +41,17 @@ public class MCRewardsStateConstant extends MCRewards stateReward = r; } - // Accessors (for MCRewards) + // Accessors @Override public double getStateReward(int s) { return stateReward; } + + @Override + public double getTransitionReward(int s, int i) + { + return 0.0; + } } diff --git a/prism/src/explicit/rewards/MDPRewards.java b/prism/src/explicit/rewards/MDPRewards.java index 9b88973b..a34929f6 100644 --- a/prism/src/explicit/rewards/MDPRewards.java +++ b/prism/src/explicit/rewards/MDPRewards.java @@ -29,7 +29,7 @@ package explicit.rewards; /** * Classes that provide (read) access to explicit-state rewards for an MDP. */ -public abstract class MDPRewards +public interface MDPRewards { /** * Get the state reward for state {@code s}. diff --git a/prism/src/explicit/rewards/MDPRewardsSimple.java b/prism/src/explicit/rewards/MDPRewardsSimple.java index d114b542..79ebf8ad 100644 --- a/prism/src/explicit/rewards/MDPRewardsSimple.java +++ b/prism/src/explicit/rewards/MDPRewardsSimple.java @@ -33,7 +33,7 @@ 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 +public class MDPRewardsSimple implements MDPRewards { /** Number of state */ protected int numStates; @@ -86,7 +86,7 @@ public class MDPRewardsSimple extends MDPRewards list.set(i, r); } - // Accessors (for MDPRewards) + // Accessors @Override public double getStateReward(int s) diff --git a/prism/src/explicit/rewards/StateRewards.java b/prism/src/explicit/rewards/StateRewards.java new file mode 100644 index 00000000..9e404e38 --- /dev/null +++ b/prism/src/explicit/rewards/StateRewards.java @@ -0,0 +1,44 @@ +//============================================================================== +// +// Copyright (c) 2002- +// Authors: +// * Dave Parker (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; + +/** + * Explicit-state storage of just state rewards. + */ +public abstract class StateRewards implements MCRewards, MDPRewards +{ + /** + * Get the state reward for state {@code s}. + */ + public abstract double getStateReward(int s); + + @Override + public double getTransitionReward(int s, int i) + { + return 0.0; + } +} diff --git a/prism/src/explicit/rewards/StateRewardsConstant.java b/prism/src/explicit/rewards/StateRewardsConstant.java new file mode 100644 index 00000000..d254fdcd --- /dev/null +++ b/prism/src/explicit/rewards/StateRewardsConstant.java @@ -0,0 +1,51 @@ +//============================================================================== +// +// Copyright (c) 2002- +// Authors: +// * Dave Parker (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; + +/** + * Explicit-state storage of constant state rewards. + */ +public class StateRewardsConstant extends StateRewards +{ + protected double stateReward = 0.0; + + /** + * Constructor: all rewards equal to {@code r} + */ + public StateRewardsConstant(double r) + { + stateReward = r; + } + + // Accessors + + @Override + public double getStateReward(int s) + { + return stateReward; + } +} diff --git a/prism/src/explicit/rewards/StateRewardsSimple.java b/prism/src/explicit/rewards/StateRewardsSimple.java new file mode 100644 index 00000000..c0a33592 --- /dev/null +++ b/prism/src/explicit/rewards/StateRewardsSimple.java @@ -0,0 +1,80 @@ +//============================================================================== +// +// Copyright (c) 2002- +// Authors: +// * Dave Parker (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; + +/** + * Explicit-state storage of just state rewards (mutable). + */ +public class StateRewardsSimple extends StateRewards +{ + /** Arraylist of state rewards **/ + protected ArrayList stateRewards; + + /** + * Constructor: all zero rewards. + * @param numStates Number of states + */ + public StateRewardsSimple(int numStates) + { + stateRewards = new ArrayList(numStates); + for (int i = 0; i < numStates; i++) + stateRewards.add(0.0); + } + + // Mutators + + /** + * Set the reward for state {@code s} to {@code r}. + */ + public void setStateReward(int s, double r) + { + // If list not big enough, extend + int n = s - stateRewards.size() + 1; + if (n > 0) { + for (int j = 0; j < n; j++) { + stateRewards.add(0.0); + } + } + // Set reward + stateRewards.set(s, r); + } + + // Accessors + + @Override + public double getStateReward(int s) + { + try { + return stateRewards.get(s); + } + catch (ArrayIndexOutOfBoundsException e) { + return 0.0; + } + } +}