|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.BitSet; |
|
|
|
import java.util.Vector; |
|
|
|
|
|
|
|
import common.StopWatch; |
|
|
|
import explicit.rewards.ConstructRewards; |
|
|
|
import explicit.rewards.Rewards; |
|
|
|
import parser.ast.Expression; |
|
|
|
@ -16,7 +17,7 @@ import parser.visitor.ReplaceAccumulationBox; |
|
|
|
import prism.PrismException; |
|
|
|
import prism.PrismSettings; |
|
|
|
|
|
|
|
public class AccumulationTransformation<M extends Model> implements ModelExpressionTransformation<M, M> { |
|
|
|
public class AccumulationTransformation<M extends ModelExplicit> implements ModelExpressionTransformation<M, M> { |
|
|
|
final protected Expression originalExpression; |
|
|
|
final protected M originalModel; |
|
|
|
final protected BitSet statesOfInterest; |
|
|
|
@ -66,10 +67,16 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
} |
|
|
|
|
|
|
|
protected void doTransformation() throws PrismException { |
|
|
|
mc.getLog().println("Handling maximal state formulas..."); |
|
|
|
transformedExpression = mc.handleMaximalStateFormulas(originalModel, originalExpression); |
|
|
|
|
|
|
|
mc.getLog().println("Performing accumulation transformation..."); |
|
|
|
// We work on a copy |
|
|
|
transformedExpression = originalExpression.deepCopy(); |
|
|
|
|
|
|
|
// Is this whole thing an ExpressionAccumulation? |
|
|
|
//if(transformedExpression.isAccumulationExpression()) { System.out.println("HEYOOOO!!! " + transformedExpression); } |
|
|
|
|
|
|
|
// TODO: WHILE getFirstAccumulationExpression |
|
|
|
|
|
|
|
// Get the first ExpressionAccumulation |
|
|
|
ExpressionAccumulation accexp = transformedExpression.getFirstAccumulationExpression(); |
|
|
|
mc.getLog().println(" [AT] for " + accexp); |
|
|
|
@ -116,7 +123,11 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
protected void doTransformationComplex(ExpressionAccumulation accexp, Vector<Rewards> rewards) throws PrismException { |
|
|
|
StopWatch clock = new StopWatch(mc.getLog()); |
|
|
|
|
|
|
|
// Build the product |
|
|
|
clock.start("accumulation product construction"); |
|
|
|
|
|
|
|
if(accexp.hasRegularExpression()) { |
|
|
|
product = (AccumulationProductComplexRegular<M>) AccumulationProductComplexRegular.generate(originalModel, accexp, rewards, mc, statesOfInterest); |
|
|
|
} else if (accexp.hasBoundExpression()) { |
|
|
|
@ -125,6 +136,8 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
throw new PrismException("Accumulation Expression has no valid monitor!"); |
|
|
|
} |
|
|
|
|
|
|
|
clock.stop(product.getTransformedModel().getNumStates() + " states"); |
|
|
|
|
|
|
|
mc.getLog().println(" [AT] finished product construction: " + product.getTransformedModel().getNumStates()); |
|
|
|
|
|
|
|
// Transform the model |
|
|
|
@ -147,11 +160,16 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
goalLabels.add(goalLabel); |
|
|
|
} |
|
|
|
// Transform the expression |
|
|
|
clock.start("transforming expresssion"); |
|
|
|
|
|
|
|
mc.getLog().println(" [AT] replacing the formula..."); |
|
|
|
ReplaceAccumulationExpressionComplex replace = new ReplaceAccumulationExpressionComplex(accexp, initLabels, runLabels, goalLabels, product.getNumberOfTracks()-1); |
|
|
|
transformedExpression = (Expression)transformedExpression.accept(replace); |
|
|
|
mc.getLog().println(" [AT] " + originalExpression.toString() + "\n" + |
|
|
|
" -> " + transformedExpression.toString()); |
|
|
|
|
|
|
|
clock.stop(); |
|
|
|
|
|
|
|
if(mc.getSettings().getBoolean(PrismSettings.ACC_GENERATE_DOTS)) { |
|
|
|
product.exportToDotFile("DEBUG-product.dot"); |
|
|
|
} |
|
|
|
@ -159,7 +177,11 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
protected void doTransformationSimple(ExpressionAccumulation accexp, Vector<Rewards> rewards) throws PrismException { |
|
|
|
StopWatch clock = new StopWatch(mc.getLog()); |
|
|
|
|
|
|
|
// Build the product |
|
|
|
clock.start("accumulation product construction"); |
|
|
|
|
|
|
|
if(accexp.hasRegularExpression()) { |
|
|
|
//throw new PrismException("I don't know how to do regular things..."); |
|
|
|
product = (AccumulationProductSimpleRegular<M>) AccumulationProductSimpleRegular.generate(originalModel, accexp, rewards, mc, statesOfInterest); |
|
|
|
@ -169,6 +191,8 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
throw new PrismException("Accumulation Expression has no valid monitor!"); |
|
|
|
} |
|
|
|
|
|
|
|
clock.stop(product.getTransformedModel().getNumStates() + " states"); |
|
|
|
|
|
|
|
mc.getLog().println(" [AT] finished product construction: " + product.getTransformedModel().getNumStates()); |
|
|
|
|
|
|
|
// Transform the model |
|
|
|
@ -176,12 +200,18 @@ public class AccumulationTransformation<M extends Model> implements ModelExpress |
|
|
|
|
|
|
|
BitSet goodStates = ((AccumulationProductSimple<M,?>)product).getGoodStates(); |
|
|
|
String goodLabel = ((ModelExplicit)product.getTransformedModel()).addUniqueLabel("goal", goodStates, product.getTransformedModel().getLabels()); |
|
|
|
|
|
|
|
// Transform the expression |
|
|
|
clock.start("transforming expresssion"); |
|
|
|
|
|
|
|
mc.getLog().println(" [AT] replacing the formula..."); |
|
|
|
ReplaceAccumulationExpressionSimple replace = new ReplaceAccumulationExpressionSimple(accexp, goodLabel, product.getNumberOfTracks()-2); |
|
|
|
transformedExpression = (Expression)transformedExpression.accept(replace); |
|
|
|
mc.getLog().println(" [AT] " + originalExpression.toString() + "\n" + |
|
|
|
" -> " + transformedExpression.toString()); |
|
|
|
|
|
|
|
clock.stop(); |
|
|
|
|
|
|
|
if(mc.getSettings().getBoolean(PrismSettings.ACC_GENERATE_DOTS)) { |
|
|
|
product.exportToDotFile("DEBUG-product.dot"); |
|
|
|
} |
|
|
|
|