Browse Source

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-cb519fbb1720
master
Dave Parker 15 years ago
parent
commit
d207970473
  1. 2
      prism/src/explicit/rewards/MCRewards.java
  2. 10
      prism/src/explicit/rewards/MCRewardsStateArray.java
  3. 10
      prism/src/explicit/rewards/MCRewardsStateConstant.java
  4. 2
      prism/src/explicit/rewards/MDPRewards.java
  5. 4
      prism/src/explicit/rewards/MDPRewardsSimple.java
  6. 44
      prism/src/explicit/rewards/StateRewards.java
  7. 51
      prism/src/explicit/rewards/StateRewardsConstant.java
  8. 80
      prism/src/explicit/rewards/StateRewardsSimple.java

2
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}.

10
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;
}
}

10
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;
}
}

2
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}.

4
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)

44
prism/src/explicit/rewards/StateRewards.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;
}
}

51
prism/src/explicit/rewards/StateRewardsConstant.java

@ -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;
}
}

80
prism/src/explicit/rewards/StateRewardsSimple.java

@ -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;
}
}
}
Loading…
Cancel
Save