Search in sources :

Example 1 with BranchingBehavior

use of de.hpi.bpt.scylla.model.configuration.BranchingBehavior in project scylla by bptlab.

the class InclusiveGatewayDistributionConversionPlugin method convertToDesmoJDistributions.

@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> branchingDistributionsInclusive = new HashMap<Integer, Object>();
    SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
    Map<Integer, BranchingBehavior> branchingBehaviors = (Map<Integer, BranchingBehavior>) simulationConfiguration.getExtensionValue(getName(), "branchingBehaviors");
    Long randomSeed = simulationConfiguration.getRandomSeed();
    ProcessModel processModel = pSimComponents.getProcessModel();
    SimulationModel model = pSimComponents.getModel();
    boolean showInReport = model.reportIsOn();
    boolean showInTrace = model.traceIsOn();
    for (Integer nodeId : branchingBehaviors.keySet()) {
        BranchingBehavior branchingBehavior = branchingBehaviors.get(nodeId);
        Map<Integer, Double> branchingProbabilities = branchingBehavior.getBranchingProbabilities();
        String name = processModel.getModelScopeId() + "_" + nodeId.toString();
        Map<Integer, BoolDistBernoulli> inclusiveDistributions = new HashMap<Integer, BoolDistBernoulli>();
        for (Integer nextNodeId : branchingProbabilities.keySet()) {
            Double probability = branchingProbabilities.get(nextNodeId);
            BoolDistBernoulli desmojDist = new BoolDistBernoulli(model, name, probability, showInReport, showInTrace);
            desmojDist.setSeed(randomSeed);
            inclusiveDistributions.put(nextNodeId, desmojDist);
        }
        branchingDistributionsInclusive.put(nodeId, inclusiveDistributions);
    }
    return branchingDistributionsInclusive;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) BoolDistBernoulli(desmoj.core.dist.BoolDistBernoulli) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 2 with BranchingBehavior

use of de.hpi.bpt.scylla.model.configuration.BranchingBehavior in project scylla by bptlab.

the class ExclusiveGatewayDistributionConversionPlugin method convertToDesmoJDistributions.

@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> branchingDistributionsExclusive = new HashMap<Integer, Object>();
    SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
    Map<Integer, BranchingBehavior> branchingBehaviors = (Map<Integer, BranchingBehavior>) simulationConfiguration.getExtensionValue(getName(), "branchingBehaviors");
    Long randomSeed = simulationConfiguration.getRandomSeed();
    ProcessModel processModel = pSimComponents.getProcessModel();
    SimulationModel model = pSimComponents.getModel();
    boolean showInReport = model.reportIsOn();
    boolean showInTrace = model.traceIsOn();
    for (Integer nodeId : branchingBehaviors.keySet()) {
        BranchingBehavior branchingBehavior = branchingBehaviors.get(nodeId);
        Map<Integer, Double> branchingProbabilities = branchingBehavior.getBranchingProbabilities();
        String name = processModel.getModelScopeId() + "_" + nodeId.toString();
        DiscreteDistEmpirical<Integer> desmojDist = new DiscreteDistEmpirical<Integer>(model, name, showInReport, showInTrace);
        for (Integer nextNodeId : branchingProbabilities.keySet()) {
            Double probability = branchingProbabilities.get(nextNodeId);
            desmojDist.addEntry(nextNodeId, probability);
        }
        desmojDist.setSeed(randomSeed);
        branchingDistributionsExclusive.put(nodeId, desmojDist);
    }
    return branchingDistributionsExclusive;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) DiscreteDistEmpirical(desmoj.core.dist.DiscreteDistEmpirical) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 3 with BranchingBehavior

use of de.hpi.bpt.scylla.model.configuration.BranchingBehavior in project scylla by bptlab.

the class ExclusiveGatewaySCParserPlugin method parse.

@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
    Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
    Namespace simNamespace = sim.getNamespace();
    ProcessModel processModel = simulationInput.getProcessModel();
    for (Element el : sim.getChildren()) {
        String elementName = el.getName();
        if (elementName.equals("exclusiveGateway")) {
            String identifier = el.getAttributeValue("id");
            if (identifier == null) {
                DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
                // no matching element in process, so skip definition
                continue;
            }
            Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
            if (nodeId == null) {
                DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
                // no matching element in process, so skip definition
                continue;
            }
            List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
            if (outgoingSequenceFlows.size() > 0) {
                Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
                Double probabilitySum = 0d;
                for (Element elem : outgoingSequenceFlows) {
                    Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
                    if (nodeIdOfSequenceFlow != null) {
                        Double branchingProbability = Double.parseDouble(elem.getChildText("branchingProbability", simNamespace));
                        if (branchingProbability < 0 || branchingProbability > 1) {
                            throw new ScyllaValidationException("Exclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
                        }
                        probabilitySum += branchingProbability;
                        branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
                    }
                }
                if (probabilitySum <= 0) {
                    throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", where the sum of probabilities is negative or zero.");
                }
                if (probabilitySum > 1) {
                    // XXX imprecision by IEEE 754 floating point representation
                    throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", exceeding 1 in total.");
                }
                // complete probabilities with the default flow probability
                if (probabilitySum > 0 && probabilitySum <= 1) {
                    Map<String, String> gatewayAttributes = processModel.getNodeAttributes().get(nodeId);
                    String defaultFlowIdentifier = gatewayAttributes.get("default");
                    if (defaultFlowIdentifier != null) {
                        double probabilityOfDefaultFlow = 1 - probabilitySum;
                        int defaultFlowNodeId = processModel.getIdentifiersToNodeIds().get(defaultFlowIdentifier);
                        if (!branchingProbabilities.containsKey(defaultFlowNodeId)) {
                            branchingProbabilities.put(defaultFlowNodeId, probabilityOfDefaultFlow);
                        } else {
                            branchingProbabilities.put(defaultFlowNodeId, branchingProbabilities.get(defaultFlowNodeId) + probabilityOfDefaultFlow);
                        }
                        ;
                    }
                }
                try {
                    if (branchingProbabilities.keySet().size() != processModel.getIdsOfNextNodes(nodeId).size()) {
                        throw new ScyllaValidationException("Number of branching probabilities defined in simulation configuration " + "does not match to number of outgoing flows of exclusive gateway " + identifier + ".");
                    }
                } catch (NodeNotFoundException e) {
                    throw new ScyllaValidationException("Node not found: " + e.getMessage());
                }
                BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
                branchingBehaviors.put(nodeId, branchingBehavior);
            }
        }
    }
    HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
    extensionAttributes.put("branchingBehaviors", branchingBehaviors);
    return extensionAttributes;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)

Example 4 with BranchingBehavior

use of de.hpi.bpt.scylla.model.configuration.BranchingBehavior in project scylla by bptlab.

the class InclusiveGatewaySCParserPlugin method parse.

@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
    Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
    Namespace simNamespace = sim.getNamespace();
    ProcessModel processModel = simulationInput.getProcessModel();
    for (Element el : sim.getChildren()) {
        String elementName = el.getName();
        if (elementName.equals("inclusiveGateway")) {
            String identifier = el.getAttributeValue("id");
            if (identifier == null) {
                DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
                // no matching element in process, so skip definition
                continue;
            }
            Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
            if (nodeId == null) {
                DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
                // no matching element in process, so skip definition
                continue;
            }
            List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
            if (outgoingSequenceFlows.size() > 0) {
                Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
                for (Element elem : outgoingSequenceFlows) {
                    Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
                    if (nodeIdOfSequenceFlow != null) {
                        Double branchingProbability = Double.valueOf(elem.getChildText("branchingProbability", simNamespace));
                        if (branchingProbability < 0 || branchingProbability > 1) {
                            throw new ScyllaValidationException("Inclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
                        }
                        branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
                    }
                }
                BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
                branchingBehaviors.put(nodeId, branchingBehavior);
            }
        }
    }
    HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
    extensionAttributes.put("branchingBehaviors", branchingBehaviors);
    return extensionAttributes;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException)

Example 5 with BranchingBehavior

use of de.hpi.bpt.scylla.model.configuration.BranchingBehavior in project scylla by bptlab.

the class BoundaryDistributionConversionPlugin method convertToDesmoJDistributions.

// Took the branching behaviour also used in exclusive gateways. I did not touch it for now, have a look on it later. Should just be needed for event probability...
// TODO: Resolve redundancy.
@SuppressWarnings("unchecked")
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> boundaryEventDistributions = new HashMap<Integer, Object>();
    SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
    Long randomSeed = simulationConfiguration.getRandomSeed();
    Map<Integer, BranchingBehavior> branchingBehaviors = (Map<Integer, BranchingBehavior>) simulationConfiguration.getExtensionValue(getName(), "branchingBehaviors");
    ProcessModel processModel = pSimComponents.getProcessModel();
    SimulationModel model = pSimComponents.getModel();
    boolean showInReport = model.reportIsOn();
    boolean showInTrace = model.traceIsOn();
    for (Integer nodeId : branchingBehaviors.keySet()) {
        BranchingBehavior branchingBehavior = branchingBehaviors.get(nodeId);
        Map<Integer, Double> branchingProbabilities = branchingBehavior.getBranchingProbabilities();
        String name = processModel.getModelScopeId() + "_" + nodeId.toString();
        DiscreteDistEmpirical<Integer> desmojDist = new DiscreteDistEmpirical<Integer>(model, name, showInReport, showInTrace);
        for (Integer nextNodeId : branchingProbabilities.keySet()) {
            Double probability = branchingProbabilities.get(nextNodeId);
            desmojDist.addEntry(nextNodeId, probability);
        }
        desmojDist.setSeed(randomSeed);
        boundaryEventDistributions.put(nodeId, desmojDist);
    }
    return boundaryEventDistributions;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) DiscreteDistEmpirical(desmoj.core.dist.DiscreteDistEmpirical) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

BranchingBehavior (de.hpi.bpt.scylla.model.configuration.BranchingBehavior)6 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)6 HashMap (java.util.HashMap)6 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)3 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)3 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)3 Map (java.util.Map)3 Element (org.jdom2.Element)3 Namespace (org.jdom2.Namespace)3 DiscreteDistEmpirical (desmoj.core.dist.DiscreteDistEmpirical)2 TimeDistributionWrapper (de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)1 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)1 BoolDistBernoulli (desmoj.core.dist.BoolDistBernoulli)1