|
|
@ -9,8 +9,8 @@ import parser.ast.AccumulationFactor; |
|
|
import parser.ast.ExpressionAccumulation; |
|
|
import parser.ast.ExpressionAccumulation; |
|
|
import prism.IntegerBound; |
|
|
import prism.IntegerBound; |
|
|
import prism.PrismException; |
|
|
import prism.PrismException; |
|
|
import prism.PrismFileLog; |
|
|
|
|
|
import prism.PrismLog; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import common.Dottable; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* An AccumulationProduct has ProductStates, where the first component is the |
|
|
* An AccumulationProduct has ProductStates, where the first component is the |
|
|
@ -22,7 +22,7 @@ import prism.PrismLog; |
|
|
* @param <M> |
|
|
* @param <M> |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
public abstract class AccumulationProduct<M extends Model,Component> extends ProductWithProductStates<M> |
|
|
|
|
|
|
|
|
public abstract class AccumulationProduct<M extends Model,Component> extends ProductWithProductStates<M> implements Dottable |
|
|
{ |
|
|
{ |
|
|
final StoragePool<AccumulationTracker<Component>> trackers; |
|
|
final StoragePool<AccumulationTracker<Component>> trackers; |
|
|
final StoragePool<AccumulationState<Component>> accStates; |
|
|
final StoragePool<AccumulationState<Component>> accStates; |
|
|
@ -113,69 +113,56 @@ public abstract class AccumulationProduct<M extends Model,Component> extends Pro |
|
|
ArrayList<AccumulationTrack<Component>> oldTracks = oldTracker.getTracks(); |
|
|
ArrayList<AccumulationTrack<Component>> oldTracks = oldTracker.getTracks(); |
|
|
|
|
|
|
|
|
BitSet oldGoodTracks = accstate.getGoodTracks(); |
|
|
BitSet oldGoodTracks = accstate.getGoodTracks(); |
|
|
BitSet newGoodTracks = (BitSet) oldGoodTracks.clone(); |
|
|
|
|
|
|
|
|
BitSet newGoodTracks = new BitSet(); |
|
|
|
|
|
|
|
|
// This restart will be... |
|
|
// This restart will be... |
|
|
int newLastRestartNr = accstate.getNextRestartNr(); |
|
|
int newLastRestartNr = accstate.getNextRestartNr(); |
|
|
//mc.getLog().print(newLastRestartNr); |
|
|
//mc.getLog().print(newLastRestartNr); |
|
|
|
|
|
|
|
|
// Build the new tracks. |
|
|
|
|
|
|
|
|
// Build the new tracks and determine their goodness; |
|
|
ArrayList<AccumulationTrack<Component>> newTracks = new ArrayList<>(); |
|
|
ArrayList<AccumulationTrack<Component>> newTracks = new ArrayList<>(); |
|
|
|
|
|
|
|
|
int trackNr = 0; |
|
|
int trackNr = 0; |
|
|
for(AccumulationTrack<Component> oldTrack : oldTracks) { |
|
|
for(AccumulationTrack<Component> oldTrack : oldTracks) { |
|
|
|
|
|
|
|
|
AccumulationTrack<Component> newTrack; |
|
|
AccumulationTrack<Component> newTrack; |
|
|
|
|
|
boolean oldTrackGood = oldGoodTracks.get(trackNr); |
|
|
|
|
|
boolean newTrackGood; |
|
|
|
|
|
|
|
|
// restart or advance |
|
|
// restart or advance |
|
|
if(trackNr == newLastRestartNr) { |
|
|
if(trackNr == newLastRestartNr) { |
|
|
//assert oldTrack == null : "Track " + newLastRestartNr + " is not null!"; |
|
|
|
|
|
|
|
|
// If we have a restart, we produce an initial track and reset its goodness. |
|
|
newTrack = new AccumulationTrack<Component>(numberOfWeights, getInitialComponent()); |
|
|
newTrack = new AccumulationTrack<Component>(numberOfWeights, getInitialComponent()); |
|
|
newGoodTracks.clear(trackNr); |
|
|
|
|
|
} else if (oldTrack == null) { |
|
|
|
|
|
newTrack = null; |
|
|
|
|
|
} else if (oldGoodTracks.get(trackNr)) { |
|
|
|
|
|
|
|
|
newTrackGood = false; |
|
|
|
|
|
} else if (oldTrackGood || oldTrack == null) { |
|
|
|
|
|
// If the old track is already good or undefined, the new track is as well. Goodness indicators stay. |
|
|
newTrack = null; |
|
|
newTrack = null; |
|
|
|
|
|
newTrackGood = oldTrackGood; |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
// Otherwise, the track is defined and not good yet. |
|
|
assert oldTrack != null; |
|
|
assert oldTrack != null; |
|
|
newTrack = updateTrack(modelFromStateId, oldTrack, accexp, weights, mc); |
|
|
newTrack = updateTrack(modelFromStateId, oldTrack, accexp, weights, mc); |
|
|
|
|
|
newTrackGood = isGoodTrack(newTrack, accexp, mc); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// check whether the track is good |
|
|
|
|
|
if(oldGoodTracks.get(trackNr) || isGoodTrack(newTrack,accexp,mc)) { |
|
|
|
|
|
newGoodTracks.set(trackNr); |
|
|
|
|
|
|
|
|
// if the new track is good, we can forget about its contents and set the new goodness |
|
|
|
|
|
if(newTrackGood) { |
|
|
newTrack = null; |
|
|
newTrack = null; |
|
|
} |
|
|
|
|
|
|
|
|
newGoodTracks.set(trackNr); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
newTracks.add(newTrack); |
|
|
newTracks.add(newTrack); |
|
|
trackNr++; |
|
|
trackNr++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Create a new tracker with the right tracks and add it to storage. |
|
|
AccumulationTracker<Component> newTracker = new AccumulationTracker<>(newTracks); |
|
|
AccumulationTracker<Component> newTracker = new AccumulationTracker<>(newTracks); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int newTrackerId = trackers.findOrAdd(newTracker); |
|
|
int newTrackerId = trackers.findOrAdd(newTracker); |
|
|
|
|
|
|
|
|
return new AccumulationState<>(newTrackerId, newLastRestartNr, numberOfTracks, newGoodTracks); |
|
|
return new AccumulationState<>(newTrackerId, newLastRestartNr, numberOfTracks, newGoodTracks); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void exportToDotFile(String filename) throws PrismException { |
|
|
|
|
|
try (PrismFileLog log = PrismFileLog.create(filename)) { |
|
|
|
|
|
exportToDotFile(log); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void exportToDotFile(PrismLog out) { |
|
|
|
|
|
out.print(toDot()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String quoteForDot(String original) { |
|
|
|
|
|
String result = original; |
|
|
|
|
|
result = result.replaceAll("&", "&"); |
|
|
|
|
|
result = result.replaceAll("<", "<"); |
|
|
|
|
|
result = result.replaceAll(">", ">"); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
public String toDot() { |
|
|
public String toDot() { |
|
|
StringBuffer result = new StringBuffer(); |
|
|
StringBuffer result = new StringBuffer(); |
|
|
|
|
|
|
|
|
@ -194,7 +181,7 @@ public abstract class AccumulationProduct<M extends Model,Component> extends Pro |
|
|
+ "</TR><TR>" |
|
|
+ "</TR><TR>" |
|
|
+ "<TD>" + accState + "</TD>" |
|
|
+ "<TD>" + accState + "</TD>" |
|
|
+ "</TR><TR>" |
|
|
+ "</TR><TR>" |
|
|
+ "<TD>\"" + quoteForDot(tracker.toString()) + "\"</TD>" |
|
|
|
|
|
|
|
|
+ "<TD>\"" + Dottable.quoteForDot(tracker.toString()) + "\"</TD>" |
|
|
+ "</TR>" |
|
|
+ "</TR>" |
|
|
+ " </TABLE> >]\n"); |
|
|
+ " </TABLE> >]\n"); |
|
|
|
|
|
|
|
|
|