|
|
|
@ -5,7 +5,6 @@ import java.util.BitSet; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import parser.ast.Expression; |
|
|
|
import prism.PrismException; |
|
|
|
|
|
|
|
import common.Dottable; |
|
|
|
@ -45,21 +44,6 @@ public abstract class AccumulationProductComplex<M extends Model,Component> exte |
|
|
|
return goalStates.get(track); |
|
|
|
} |
|
|
|
|
|
|
|
protected final int createInitialStateId() { |
|
|
|
Component initialComponent = getInitialComponent(); |
|
|
|
|
|
|
|
// The initial active track is the first one, all tracks are non-good by default |
|
|
|
int initialActiveTrack = 0; |
|
|
|
|
|
|
|
// Generate the initial track and product state |
|
|
|
AccumulationTracker<Component> initialTracker = new AccumulationTracker<Component>(numberOfTracks, numberOfWeights, initialComponent); |
|
|
|
int initialTrackerId = trackers.findOrAdd(initialTracker); |
|
|
|
AccumulationState<Component> initialAccState = new AccumulationState<Component>(initialTrackerId, initialActiveTrack, numberOfTracks, false); |
|
|
|
int initialAccStateId = accStates.findOrAdd(initialAccState); |
|
|
|
|
|
|
|
return initialAccStateId; |
|
|
|
} |
|
|
|
|
|
|
|
protected void generateTrackInfo(ProductState state, Integer index) throws PrismException { |
|
|
|
AccumulationState<Component> accState = accStates.getById(state.getSecondState()); |
|
|
|
AccumulationTracker<Component> tracker = accState.getTracker(trackers); |
|
|
|
@ -69,7 +53,7 @@ public abstract class AccumulationProductComplex<M extends Model,Component> exte |
|
|
|
|
|
|
|
boolean isInitial = trackIdx==accState.lastRestartNr; |
|
|
|
boolean isRunning = track != null; |
|
|
|
boolean isGoal = isGoalTrack(track); |
|
|
|
boolean isGoal = accState.getGoodTracks().get(trackIdx); // isGoalTrack(track) |
|
|
|
|
|
|
|
// Is this an initial |
|
|
|
initStates.get(trackIdx).set(index, isInitial); |
|
|
|
@ -82,106 +66,7 @@ public abstract class AccumulationProductComplex<M extends Model,Component> exte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** Updates a single AccumulationTrack. Used in updateAccumulationState. |
|
|
|
* |
|
|
|
* Uses updateComponent to get the next Component, accumulates the current weights |
|
|
|
* and makes a new track. |
|
|
|
* @param modelFromStateId |
|
|
|
* @param track |
|
|
|
* @param accexp |
|
|
|
* @param weights |
|
|
|
* @param mc |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
protected final AccumulationTrack<Component> updateTrack(Integer modelFromStateId, final AccumulationTrack<Component> track, final double[] weights) { |
|
|
|
Component nextComponent = updateComponent(modelFromStateId, track); |
|
|
|
|
|
|
|
// If we are done, return null-Track |
|
|
|
if (nextComponent == null) { return null; } |
|
|
|
|
|
|
|
// Otherwise, we update the weights and increase the step. |
|
|
|
double[] newweights = new double[weights.length]; |
|
|
|
for (int i = 0; i < weights.length; i++) { |
|
|
|
newweights[i] = weights[i] + track.getWeights()[i]; |
|
|
|
} |
|
|
|
|
|
|
|
return new AccumulationTrack<Component>(newweights, nextComponent); |
|
|
|
} |
|
|
|
|
|
|
|
/** Generates a new accumulation state from an old one. |
|
|
|
* |
|
|
|
* To do so, it reads the necessary information from the model and its rewards |
|
|
|
* and updates all tracks and their goodness accordingly. |
|
|
|
* @param modelFromStateId |
|
|
|
* @param accstate |
|
|
|
* @param accexp |
|
|
|
* @param weights |
|
|
|
* @param mc |
|
|
|
* @return |
|
|
|
* @throws PrismException |
|
|
|
*/ |
|
|
|
protected final AccumulationState<Component> updateAccumulationState(final int modelFromStateId, final AccumulationState<Component> accstate, final double[] weights) throws PrismException { |
|
|
|
// If we are in singleTrack mode and the last restart is the numberOfTracks, we can stop... |
|
|
|
if(ctx.singleTrack && (accstate.lastRestartNr == numberOfTracks-1)) { return accstate; } |
|
|
|
|
|
|
|
|
|
|
|
// Check if we even need to fire here. |
|
|
|
if(ctx.accexp.hasFireOn()) { |
|
|
|
boolean stutter = true; |
|
|
|
for(Expression f : ctx.accexp.getFireOn()) { |
|
|
|
if(ctx.mc.checkExpression(originalModel, f, null).getBitSet().get(modelFromStateId)) { |
|
|
|
//mc.getLog().println("f:" + f); |
|
|
|
stutter = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// If this is a stutter action, we can return the same accstate. Copies are made on modification. |
|
|
|
if(stutter) { return accstate; } |
|
|
|
} |
|
|
|
// ...otherwise proceed. |
|
|
|
|
|
|
|
// Get the old tracker and tracks. |
|
|
|
AccumulationTracker<Component> oldTracker = accstate.getTracker(trackers); |
|
|
|
ArrayList<AccumulationTrack<Component>> oldTracks = oldTracker.getTracks(); |
|
|
|
|
|
|
|
// This restart will be... |
|
|
|
int newLastRestartNr = accstate.getNextRestartNr(); |
|
|
|
//mc.getLog().print(newLastRestartNr); |
|
|
|
|
|
|
|
// Build the new tracks and determine their goodness; |
|
|
|
ArrayList<AccumulationTrack<Component>> newTracks = new ArrayList<>(); |
|
|
|
|
|
|
|
int trackNr = 0; |
|
|
|
for(AccumulationTrack<Component> oldTrack : oldTracks) { |
|
|
|
|
|
|
|
AccumulationTrack<Component> newTrack; |
|
|
|
|
|
|
|
// restart or advance |
|
|
|
if(trackNr == newLastRestartNr && !ctx.singleTrack) { |
|
|
|
// If we have a restart, we produce an initial track and let it advance. |
|
|
|
AccumulationTrack<Component> freshTrack = new AccumulationTrack<Component>(numberOfWeights, getInitialComponent()); |
|
|
|
//newTrack = updateTrack(modelFromStateId, freshTrack, accexp, weights, mc); |
|
|
|
newTrack = freshTrack; |
|
|
|
} else if (oldTrack == null || (ctx.singleTrack && trackNr>0)) { |
|
|
|
// If the old track is undefined, the new track is as well. |
|
|
|
newTrack = null; |
|
|
|
} else { |
|
|
|
// Otherwise, the track is defined and advances. |
|
|
|
assert oldTrack != null; |
|
|
|
newTrack = updateTrack(modelFromStateId, oldTrack, weights); |
|
|
|
} |
|
|
|
|
|
|
|
newTracks.add(newTrack); |
|
|
|
trackNr++; |
|
|
|
} |
|
|
|
|
|
|
|
//Create a new tracker with the right tracks and add it to storage. |
|
|
|
AccumulationTracker<Component> newTracker = new AccumulationTracker<>(newTracks); |
|
|
|
int newTrackerId = trackers.findOrAdd(newTracker); |
|
|
|
|
|
|
|
return new AccumulationState<>(newTrackerId, newLastRestartNr, numberOfTracks); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected String labelString(Integer stateId) { |
|
|
|
StringBuffer result = new StringBuffer(); |
|
|
|
|
|
|
|
|