Browse Source

Aligning with prism-games a bit (explicit reward stuff).

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@6873 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 13 years ago
parent
commit
1539fc766c
  1. 35
      prism/src/explicit/rewards/MDPRewardsSimple.java
  2. 5
      prism/src/explicit/rewards/STPGRewards.java
  3. 8
      prism/src/explicit/rewards/STPGRewardsSimple.java
  4. 19
      prism/src/explicit/rewards/StateRewards.java
  5. 8
      prism/src/explicit/rewards/StateRewardsConstant.java
  6. 38
      prism/src/explicit/rewards/StateRewardsSimple.java

35
prism/src/explicit/rewards/MDPRewardsSimple.java

@ -54,6 +54,41 @@ public class MDPRewardsSimple implements MDPRewards
transRewards = null; transRewards = null;
} }
/**
* Copy constructor
* @param rews Rewards to copy
*/
public MDPRewardsSimple(MDPRewardsSimple rews)
{
numStates = rews.numStates;
if (rews.stateRewards == null) {
stateRewards = null;
} else {
stateRewards = new ArrayList<Double>(numStates);
for (int i = 0; i < numStates; i++) {
stateRewards.add(rews.stateRewards.get(i));
}
}
if (rews.transRewards == null) {
transRewards = null;
} else {
transRewards = new ArrayList<List<Double>>(numStates);
for (int i = 0; i < numStates; i++) {
List<Double> list = rews.transRewards.get(i);
if (list == null) {
transRewards.add(null);
} else {
int n = list.size();
List<Double> list2 = new ArrayList<Double>(n);
transRewards.add(list2);
for (int j = 0; j < n; j++) {
list2.add(list.get(j));
}
}
}
}
}
// Mutators // Mutators
/** /**

5
prism/src/explicit/rewards/STPGRewards.java

@ -48,4 +48,9 @@ public interface STPGRewards extends Rewards
* Get the transition reward for the {@code i,j}th nested choice from state {@code s}. * Get the transition reward for the {@code i,j}th nested choice from state {@code s}.
*/ */
public abstract double getNestedTransitionReward(int s, int i, int j); public abstract double getNestedTransitionReward(int s, int i, int j);
/**
* Build an MDPRewards object containing all the same rewards except for the nested ones.
*/
public abstract MDPRewards buildMDPRewards();
} }

8
prism/src/explicit/rewards/STPGRewardsSimple.java

@ -123,6 +123,14 @@ public class STPGRewardsSimple extends MDPRewardsSimple implements STPGRewards
return list2.get(j); return list2.get(j);
} }
// Other
@Override
public MDPRewards buildMDPRewards()
{
return new MDPRewardsSimple(this);
}
@Override @Override
public String toString() public String toString()
{ {

19
prism/src/explicit/rewards/StateRewards.java

@ -29,7 +29,7 @@ package explicit.rewards;
/** /**
* Explicit-state storage of just state rewards. * Explicit-state storage of just state rewards.
*/ */
public abstract class StateRewards implements MCRewards, MDPRewards
public abstract class StateRewards implements MCRewards, MDPRewards, STPGRewards
{ {
/** /**
* Get the state reward for state {@code s}. * Get the state reward for state {@code s}.
@ -41,4 +41,21 @@ public abstract class StateRewards implements MCRewards, MDPRewards
{ {
return 0.0; return 0.0;
} }
@Override
public double getNestedTransitionReward(int s, int i, int j)
{
return 0.0;
}
@Override
public MDPRewards buildMDPRewards()
{
return deepCopy();
}
/**
* Perform a deep copy.
*/
public abstract StateRewards deepCopy();
} }

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

@ -48,4 +48,12 @@ public class StateRewardsConstant extends StateRewards
{ {
return stateReward; return stateReward;
} }
// Other
@Override
public StateRewardsConstant deepCopy()
{
return new StateRewardsConstant(stateReward);
}
} }

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

@ -38,13 +38,27 @@ public class StateRewardsSimple extends StateRewards
/** /**
* Constructor: all zero rewards. * Constructor: all zero rewards.
* @param numStates Number of states
*/ */
public StateRewardsSimple(int numStates)
public StateRewardsSimple()
{ {
stateRewards = new ArrayList<Double>(numStates);
for (int i = 0; i < numStates; i++)
stateRewards.add(0.0);
stateRewards = new ArrayList<Double>();
}
/**
* Copy constructor
* @param rews Rewards to copy
*/
public StateRewardsSimple(StateRewardsSimple rews)
{
if (rews.stateRewards == null) {
stateRewards = null;
} else {
int n = rews.stateRewards.size();
stateRewards = new ArrayList<Double>(n);
for (int i = 0; i < n; i++) {
stateRewards.add(rews.stateRewards.get(i));
}
}
} }
// Mutators // Mutators
@ -54,8 +68,7 @@ public class StateRewardsSimple extends StateRewards
*/ */
public void setStateReward(int s, double r) public void setStateReward(int s, double r)
{ {
// Nothing to do for zero reward
if (r == 0.0)
if (r == 0.0 && s >= stateRewards.size())
return; return;
// If list not big enough, extend // If list not big enough, extend
int n = s - stateRewards.size() + 1; int n = s - stateRewards.size() + 1;
@ -75,9 +88,16 @@ public class StateRewardsSimple extends StateRewards
{ {
try { try {
return stateRewards.get(s); return stateRewards.get(s);
}
catch (ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException e) {
return 0.0; return 0.0;
} }
} }
// Other
@Override
public StateRewardsSimple deepCopy()
{
return new StateRewardsSimple(this);
}
} }
Loading…
Cancel
Save