de.uni.freiburg.iig.telematik.sepia.traversal.StochasticPNTraverser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SEPIA Show documentation
Show all versions of SEPIA Show documentation
SEPIA provides implementations for various types of Petri nets. Along Place/Transition-nets, it supports Petri nets with distinguishable token colors and defines coloured workflow nets, where coloured tokens are interpreted as data elements used during process execution. To support information flow analysis of processes, SEPIA defines so-called IF-Nets, tailored for security-oriented workflow modeling which enable users to assign security-levels (HIGH, LOW) to transitions, data elements and persons/agents participating in the process execution.
The newest version!
package de.uni.freiburg.iig.telematik.sepia.traversal;
import java.util.HashMap;
import java.util.List;
import de.invation.code.toval.misc.valuegeneration.StochasticValueGenerator;
import de.invation.code.toval.misc.valuegeneration.ValueGenerationException;
import de.invation.code.toval.validate.InconsistencyException;
import de.invation.code.toval.validate.Validate;
import de.uni.freiburg.iig.telematik.sepia.petrinet.abstr.AbstractPetriNet;
import de.uni.freiburg.iig.telematik.sepia.petrinet.abstr.AbstractTransition;
/**
* This flow control chooses the next transition to fire
* on the basis of predefined probabilities of occurrences of subsequent transition pairs.
*
* @author Thomas Stocker
*
*/
public class StochasticPNTraverser> extends RandomPNTraverser {
public static final int DEFAULT_TOLERANCE_DENOMINATOR = 1000;
private HashMap> flowProbabilities = new HashMap>();
private int toleranceDenominator;
public StochasticPNTraverser(AbstractPetriNet,T,?,?,?> net) {
this(net, DEFAULT_TOLERANCE_DENOMINATOR);
}
public StochasticPNTraverser(AbstractPetriNet,T,?,?,?> net, int toleranceDenominator) {
super(net);
Validate.biggerEqual(toleranceDenominator, 1, "Denominator must be >=1.");
this.toleranceDenominator = toleranceDenominator;
}
public void addFlowProbability(String fromTransitionID, String toTransitionID, double probability) {
addFlowProbability(net.getTransition(fromTransitionID), net.getTransition(toTransitionID), probability);
}
public void addFlowProbability(T fromTransition, T toTransition, double probability) {
Validate.notNull(fromTransition);
Validate.notNull(toTransition);
Validate.inclusiveBetween(0.0, 1.0, probability);
StochasticValueGenerator chooser = flowProbabilities.get(fromTransition);
if(chooser == null){
chooser = new StochasticValueGenerator(toleranceDenominator);
flowProbabilities.put(fromTransition, chooser);
}
chooser.addProbability(toTransition, probability);
}
@Override
public T chooseNextTransition(List enabledTransitions) throws InconsistencyException {
if(!flowProbabilities.containsKey(net.getLastFiredTransition()))
return super.chooseNextTransition(enabledTransitions);
if(!isValid())
throw new InconsistencyException("At least one StochasticChooser is not valid.");
Validate.notNull(enabledTransitions);
Validate.noNullElements(enabledTransitions);
if(enabledTransitions.isEmpty())
return null;
T nextTransition = null;
try {
nextTransition = flowProbabilities.get(net.getLastFiredTransition()).getNextValue();
} catch (ValueGenerationException e) {
// Cannot happen, since all choosers are valid.
e.printStackTrace();
}
if(!net.getEnabledTransitions().contains(nextTransition))
throw new InconsistencyException("Cannot fire transition \""+nextTransition+"\" since it is not enabled.");
return nextTransition;
}
/**
* Checks, if all maintained stochastic choosers are valid.
* @return true
if all choosers are valid,
* false
otherwise.
* @see StochasticValueGenerator#isValid()
*/
@Override
public boolean isValid(){
for(StochasticValueGenerator chooser: flowProbabilities.values())
if(!chooser.isValid())
return false;
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy