Browse Source
Some proposed changes to explicit.rewards classes (from prism-qar).
Some proposed changes to explicit.rewards classes (from prism-qar).
git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@3250 bbc10eb1-c90d-0410-af57-cb519fbb1720master
8 changed files with 195 additions and 8 deletions
-
2prism/src/explicit/rewards/MCRewards.java
-
10prism/src/explicit/rewards/MCRewardsStateArray.java
-
10prism/src/explicit/rewards/MCRewardsStateConstant.java
-
2prism/src/explicit/rewards/MDPRewards.java
-
4prism/src/explicit/rewards/MDPRewardsSimple.java
-
44prism/src/explicit/rewards/StateRewards.java
-
51prism/src/explicit/rewards/StateRewardsConstant.java
-
80prism/src/explicit/rewards/StateRewardsSimple.java
@ -0,0 +1,44 @@ |
|||||
|
//============================================================================== |
||||
|
// |
||||
|
// 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; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
//============================================================================== |
||||
|
// |
||||
|
// 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; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
//============================================================================== |
||||
|
// |
||||
|
// 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; |
||||
|
|
||||
|
/** |
||||
|
* Explicit-state storage of just state rewards (mutable). |
||||
|
*/ |
||||
|
public class StateRewardsSimple extends StateRewards |
||||
|
{ |
||||
|
/** Arraylist of state rewards **/ |
||||
|
protected ArrayList<Double> stateRewards; |
||||
|
|
||||
|
/** |
||||
|
* Constructor: all zero rewards. |
||||
|
* @param numStates Number of states |
||||
|
*/ |
||||
|
public StateRewardsSimple(int numStates) |
||||
|
{ |
||||
|
stateRewards = new ArrayList<Double>(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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue