|
|
|
@ -5,8 +5,7 @@ import java.util.BitSet; |
|
|
|
import java.util.Vector; |
|
|
|
|
|
|
|
import explicit.rewards.ConstructRewards; |
|
|
|
import explicit.rewards.MCRewards; |
|
|
|
import explicit.rewards.MDPRewards; |
|
|
|
import explicit.rewards.Rewards; |
|
|
|
import parser.ast.Expression; |
|
|
|
import parser.ast.ExpressionAccumulation; |
|
|
|
import parser.ast.ExpressionReward; |
|
|
|
@ -77,57 +76,28 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
mc.getLog().println(" ... a simple expression."); |
|
|
|
} |
|
|
|
|
|
|
|
// Get the rewards and build the product |
|
|
|
switch(originalModel.getModelType()) { |
|
|
|
case DTMC: |
|
|
|
Vector<MCRewards> dtmc_rewards = new Vector<MCRewards>(); |
|
|
|
|
|
|
|
for (int i=0; i < accexp.getConstraint().getFactors().size(); i++) { |
|
|
|
Object rewardIndex = accexp.getConstraint().getFactors().get(i).getFunction().getRewardIndex(); |
|
|
|
|
|
|
|
RewardStruct rewStruct = ExpressionReward.getRewardStructByIndexObject(rewardIndex, mc.modulesFile, originalModel.getConstantValues()); |
|
|
|
ConstructRewards constructRewards = new ConstructRewards(); |
|
|
|
constructRewards.allowNegativeRewards(); |
|
|
|
|
|
|
|
MCRewards dtmc_reward = constructRewards.buildMCRewardStructure((DTMC)originalModel, rewStruct, mc.getConstantValues()); |
|
|
|
dtmc_rewards.add(i,dtmc_reward); |
|
|
|
} |
|
|
|
mc.getLog().println(" [AT] performing product construction..."); |
|
|
|
if(accexp.hasRegularExpression()) { |
|
|
|
product = (AccumulationProductRegular<M>) AccumulationProductRegular.generate((DTMC)originalModel, accexp, dtmc_rewards, mc, statesOfInterest); |
|
|
|
} else if (accexp.hasBoundExpression()) { |
|
|
|
product = (AccumulationProductCounting<M>) AccumulationProductCounting.generate((DTMC)originalModel, accexp, dtmc_rewards, mc, statesOfInterest); |
|
|
|
} else { |
|
|
|
throw new PrismException("Accumulation Expression has no valid monitor!"); |
|
|
|
} |
|
|
|
break; |
|
|
|
case MDP: |
|
|
|
Vector<MDPRewards> mdp_rewards = new Vector<MDPRewards>(); |
|
|
|
// Get the rewards and build the product |
|
|
|
Vector<Rewards> rewards = new Vector<Rewards>(); |
|
|
|
|
|
|
|
for (int i=0; i < accexp.getConstraint().getFactors().size(); i++) { |
|
|
|
Object rewardIndex = accexp.getConstraint().getFactors().get(i).getFunction().getRewardIndex(); |
|
|
|
|
|
|
|
for (int i=0; i < accexp.getConstraint().getFactors().size(); i++) { |
|
|
|
Object rewardIndex = accexp.getConstraint().getFactors().get(i).getFunction().getRewardIndex(); |
|
|
|
|
|
|
|
RewardStruct rewStruct = ExpressionReward.getRewardStructByIndexObject(rewardIndex, mc.modulesFile, originalModel.getConstantValues()); |
|
|
|
ConstructRewards constructRewards = new ConstructRewards(); |
|
|
|
constructRewards.allowNegativeRewards(); |
|
|
|
|
|
|
|
MDPRewards mdp_reward = constructRewards.buildMDPRewardStructure((MDP)originalModel, rewStruct, mc.getConstantValues()); |
|
|
|
mdp_rewards.add(i,mdp_reward); |
|
|
|
} |
|
|
|
mc.getLog().println(" [AT] performing product construction..."); |
|
|
|
if(accexp.hasRegularExpression()) { |
|
|
|
product = (AccumulationProductRegular<M>) AccumulationProductRegular.generate((MDP)originalModel, accexp, mdp_rewards, mc, statesOfInterest); |
|
|
|
} else if (accexp.hasBoundExpression()) { |
|
|
|
product = (AccumulationProductCounting<M>) AccumulationProductCounting.generate((MDP)originalModel, accexp, mdp_rewards, mc, statesOfInterest); |
|
|
|
} else { |
|
|
|
throw new PrismException("Accumulation Expression has no valid monitor!"); |
|
|
|
} |
|
|
|
mc.getLog().println(" [AT] finished product construction: " + product.getTransformedModel().getNumStates()); |
|
|
|
RewardStruct rewStruct = ExpressionReward.getRewardStructByIndexObject(rewardIndex, mc.modulesFile, originalModel.getConstantValues()); |
|
|
|
ConstructRewards constructRewards = new ConstructRewards(); |
|
|
|
constructRewards.allowNegativeRewards(); |
|
|
|
|
|
|
|
break; |
|
|
|
default: |
|
|
|
throw new PrismException("Can't handle weight functions for " + originalModel.getModelType()); |
|
|
|
Rewards dtmc_reward = constructRewards.buildRewardStructure(originalModel, rewStruct, mc.getConstantValues()); |
|
|
|
rewards.add(i,dtmc_reward); |
|
|
|
} |
|
|
|
if(accexp.hasRegularExpression()) { |
|
|
|
product = (AccumulationProductRegular<M>) AccumulationProductRegular.generate(originalModel, accexp, rewards, mc, statesOfInterest); |
|
|
|
} else if (accexp.hasBoundExpression()) { |
|
|
|
product = (AccumulationProductCounting<M>) AccumulationProductCounting.generate(originalModel, accexp, rewards, mc, statesOfInterest); |
|
|
|
} else { |
|
|
|
throw new PrismException("Accumulation Expression has no valid monitor!"); |
|
|
|
} |
|
|
|
|
|
|
|
mc.getLog().println(" [AT] finished product construction: " + product.getTransformedModel().getNumStates()); |
|
|
|
|
|
|
|
// Transform the model |
|
|
|
mc.getLog().println(" [AT] getting the init/run/goal states: "); |
|
|
|
|