Search in sources :

Example 1 with Parameter

use of bpsim.Parameter in project kie-wb-common by kiegroup.

the class SimulationSets method toParameter.

private static Parameter toParameter(Double value) {
    Parameter parameter = bpsim.createParameter();
    FloatingParameterType parameterValue = bpsim.createFloatingParameterType();
    parameterValue.setValue(value);
    parameter.getParameterValue().add(parameterValue);
    return parameter;
}
Also used : Parameter(bpsim.Parameter) FloatingParameterType(bpsim.FloatingParameterType)

Example 2 with Parameter

use of bpsim.Parameter in project kie-wb-common by kiegroup.

the class SimulationSets method of.

public static SimulationSet of(ElementParameters eleType) {
    TimeParameters timeParams = eleType.getTimeParameters();
    if (timeParams == null) {
        return new SimulationSet();
    }
    Parameter processingTime = timeParams.getProcessingTime();
    ParameterValue paramValue = processingTime.getParameterValue().get(0);
    SimulationSet simulationSet = Match.of(ParameterValue.class, SimulationSet.class).when(NormalDistributionType.class, ndt -> {
        SimulationSet sset = new SimulationSet();
        sset.getMean().setValue(ndt.getMean());
        sset.getStandardDeviation().setValue(ndt.getStandardDeviation());
        sset.getDistributionType().setValue("normal");
        return sset;
    }).when(UniformDistributionType.class, udt -> {
        SimulationSet sset = new SimulationSet();
        sset.getMin().setValue(udt.getMin());
        sset.getMax().setValue(udt.getMax());
        sset.getDistributionType().setValue("uniform");
        return sset;
    }).when(PoissonDistributionType.class, pdt -> {
        SimulationSet sset = new SimulationSet();
        sset.getMean().setValue(pdt.getMean());
        sset.getDistributionType().setValue("poisson");
        return sset;
    }).apply(paramValue).asSuccess().value();
    CostParameters costParams = eleType.getCostParameters();
    if (costParams != null) {
        simulationSet.getUnitCost().setValue(extractDouble(costParams.getUnitCost()));
    }
    ResourceParameters resourceParams = eleType.getResourceParameters();
    if (resourceParams != null) {
        Double quantity = extractDouble(resourceParams.getQuantity());
        simulationSet.getQuantity().setValue(quantity);
        Double availability = extractDouble(resourceParams.getAvailability());
        simulationSet.getWorkingHours().setValue(availability);
    }
    return simulationSet;
}
Also used : ParameterValue(bpsim.ParameterValue) Parameter(bpsim.Parameter) PoissonDistributionType(bpsim.PoissonDistributionType) SimulationSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationSet) ResourceParameters(bpsim.ResourceParameters) Factories.bpsim(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpsim) UniformDistributionType(bpsim.UniformDistributionType) EList(org.eclipse.emf.common.util.EList) CostParameters(bpsim.CostParameters) FloatingParameterType(bpsim.FloatingParameterType) NormalDistributionType(bpsim.NormalDistributionType) Match(org.kie.workbench.common.stunner.bpmn.backend.converters.Match) ElementParameters(bpsim.ElementParameters) TimeParameters(bpsim.TimeParameters) PoissonDistributionType(bpsim.PoissonDistributionType) SimulationSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationSet) ParameterValue(bpsim.ParameterValue) CostParameters(bpsim.CostParameters) NormalDistributionType(bpsim.NormalDistributionType) Parameter(bpsim.Parameter) TimeParameters(bpsim.TimeParameters) ResourceParameters(bpsim.ResourceParameters)

Example 3 with Parameter

use of bpsim.Parameter in project kie-wb-common by kiegroup.

the class Simulations method simulationSet.

public static SimulationSet simulationSet(ElementParameters eleType) {
    SimulationSet simulationSet = new SimulationSet();
    TimeParameters timeParams = eleType.getTimeParameters();
    if (timeParams == null) {
        return simulationSet;
    }
    Parameter processingTime = timeParams.getProcessingTime();
    ParameterValue paramValue = processingTime.getParameterValue().get(0);
    VoidMatch.of(ParameterValue.class).when(NormalDistributionType.class, ndt -> {
        simulationSet.getMean().setValue(ndt.getMean());
        simulationSet.getStandardDeviation().setValue(ndt.getStandardDeviation());
        simulationSet.getDistributionType().setValue("normal");
    }).when(UniformDistributionType.class, udt -> {
        simulationSet.getMin().setValue(udt.getMin());
        simulationSet.getMax().setValue(udt.getMax());
        simulationSet.getDistributionType().setValue("uniform");
    }).when(PoissonDistributionType.class, pdt -> {
        simulationSet.getMean().setValue(pdt.getMean());
        simulationSet.getDistributionType().setValue("poisson");
    }).apply(paramValue).asSuccess().value();
    CostParameters costParams = eleType.getCostParameters();
    if (costParams != null) {
        simulationSet.getUnitCost().setValue(extractDouble(costParams.getUnitCost()));
    }
    // controlParams(eleType, simulationSet);
    ResourceParameters resourceParams = eleType.getResourceParameters();
    if (resourceParams != null) {
        Double quantity = extractDouble(resourceParams.getQuantity());
        simulationSet.getQuantity().setValue(quantity);
        Double availability = extractDouble(resourceParams.getAvailability());
        simulationSet.getWorkingHours().setValue(availability);
    }
    return simulationSet;
}
Also used : VoidMatch(org.kie.workbench.common.stunner.bpmn.backend.converters.VoidMatch) ParameterValue(bpsim.ParameterValue) Parameter(bpsim.Parameter) PoissonDistributionType(bpsim.PoissonDistributionType) SimulationSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationSet) ResourceParameters(bpsim.ResourceParameters) UniformDistributionType(bpsim.UniformDistributionType) EList(org.eclipse.emf.common.util.EList) CostParameters(bpsim.CostParameters) FloatingParameterType(bpsim.FloatingParameterType) NormalDistributionType(bpsim.NormalDistributionType) Match(org.kie.workbench.common.stunner.bpmn.backend.converters.Match) ElementParameters(bpsim.ElementParameters) TimeParameters(bpsim.TimeParameters) SimulationAttributeSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationAttributeSet) PoissonDistributionType(bpsim.PoissonDistributionType) SimulationSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationSet) ParameterValue(bpsim.ParameterValue) CostParameters(bpsim.CostParameters) NormalDistributionType(bpsim.NormalDistributionType) Parameter(bpsim.Parameter) TimeParameters(bpsim.TimeParameters) ResourceParameters(bpsim.ResourceParameters)

Example 4 with Parameter

use of bpsim.Parameter in project kie-wb-common by kiegroup.

the class Simulations method simulationAttributeSet.

public static SimulationAttributeSet simulationAttributeSet(ElementParameters eleType) {
    SimulationAttributeSet simulationSet = new SimulationAttributeSet();
    TimeParameters timeParams = eleType.getTimeParameters();
    if (timeParams == null) {
        return simulationSet;
    }
    Parameter processingTime = timeParams.getProcessingTime();
    ParameterValue paramValue = processingTime.getParameterValue().get(0);
    return Match.of(ParameterValue.class, SimulationAttributeSet.class).when(NormalDistributionType.class, ndt -> {
        simulationSet.getMean().setValue(ndt.getMean());
        simulationSet.getStandardDeviation().setValue(ndt.getStandardDeviation());
        simulationSet.getDistributionType().setValue("normal");
        return simulationSet;
    }).when(UniformDistributionType.class, udt -> {
        simulationSet.getMin().setValue(udt.getMin());
        simulationSet.getMax().setValue(udt.getMax());
        simulationSet.getDistributionType().setValue("uniform");
        return simulationSet;
    }).when(PoissonDistributionType.class, pdt -> {
        simulationSet.getMean().setValue(pdt.getMean());
        simulationSet.getDistributionType().setValue("poisson");
        return simulationSet;
    }).apply(paramValue).asSuccess().value();
}
Also used : VoidMatch(org.kie.workbench.common.stunner.bpmn.backend.converters.VoidMatch) ParameterValue(bpsim.ParameterValue) Parameter(bpsim.Parameter) PoissonDistributionType(bpsim.PoissonDistributionType) SimulationSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationSet) ResourceParameters(bpsim.ResourceParameters) UniformDistributionType(bpsim.UniformDistributionType) EList(org.eclipse.emf.common.util.EList) CostParameters(bpsim.CostParameters) FloatingParameterType(bpsim.FloatingParameterType) NormalDistributionType(bpsim.NormalDistributionType) Match(org.kie.workbench.common.stunner.bpmn.backend.converters.Match) ElementParameters(bpsim.ElementParameters) TimeParameters(bpsim.TimeParameters) SimulationAttributeSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationAttributeSet) PoissonDistributionType(bpsim.PoissonDistributionType) SimulationAttributeSet(org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationAttributeSet) ParameterValue(bpsim.ParameterValue) NormalDistributionType(bpsim.NormalDistributionType) Parameter(bpsim.Parameter) TimeParameters(bpsim.TimeParameters)

Example 5 with Parameter

use of bpsim.Parameter in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyCallActivityProperties.

protected void applyCallActivityProperties(CallActivity callActivity, Map<String, String> properties) {
    if (properties.get("name") != null) {
        callActivity.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
        // add unescaped and untouched name value as extension element as well
        Utils.setMetaDataExtensionValue(callActivity, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
    } else {
        callActivity.setName("");
    }
    if (properties.get("independent") != null && properties.get("independent").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "independent", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("independent"));
        callActivity.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("waitforcompletion") != null && properties.get("waitforcompletion").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "waitForCompletion", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("waitforcompletion"));
        callActivity.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("calledelement") != null && properties.get("calledelement").length() > 0) {
        callActivity.setCalledElement(properties.get("calledelement"));
    }
    // isAsync metadata
    if (properties.get("isasync") != null && properties.get("isasync").length() > 0 && properties.get("isasync").equals("true")) {
        Utils.setMetaDataExtensionValue(callActivity, "customAsync", wrapInCDATABlock(properties.get("isasync")));
    }
    parseAssignmentsInfo(properties);
    // callActivity data input set
    applyDataInputProperties(callActivity, properties, new HashMap<String, DataInput>());
    // callActivity data output set
    applyDataOutputProperties(callActivity, properties);
    // callActivity assignments
    if (properties.get("assignments") != null && properties.get("assignments").length() > 0) {
        String[] allAssignments = properties.get("assignments").split(",\\s*");
        for (String assignment : allAssignments) {
            if (assignment.contains("=")) {
                String[] assignmentParts = assignment.split("=\\s*");
                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                String fromPart = assignmentParts[0];
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                }
                boolean foundTaskName = false;
                if (callActivity.getIoSpecification() != null && callActivity.getIoSpecification().getDataOutputs() != null) {
                    List<DataInput> dataInputs = callActivity.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(callActivity.getId() + "_" + fromPart + "InputX")) {
                            dia.setTargetRef(di);
                            if (di.getName().equals("TaskName")) {
                                foundTaskName = true;
                                break;
                            }
                        }
                    }
                }
                Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
                FormalExpression fromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                if (assignmentParts.length > 1) {
                    String replacer = decodeAssociationValue(assignmentParts[1]);
                    fromExpression.setBody(wrapInCDATABlock(replacer));
                } else {
                    fromExpression.setBody("");
                }
                FormalExpression toExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                toExpression.setBody(dia.getTargetRef().getId());
                a.setFrom(fromExpression);
                a.setTo(toExpression);
                dia.getAssignment().add(a);
                callActivity.getDataInputAssociations().add(dia);
            // } else if(assignment.contains("<->")) {
            // String[] assignmentParts = assignment.split( "<->\\s*" );
            // DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            // DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
            // 
            // ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            // ie.setId(assignmentParts[0]);
            // dia.getSourceRef().add(ie);
            // doa.setTargetRef(ie);
            // 
            // List<DataInput> dataInputs = callActivity.getIoSpecification().getDataInputs();
            // for(DataInput di : dataInputs) {
            // if(di.getId().equals(callActivity.getId() + "_" + assignmentParts[1] + "InputX")) {
            // dia.setTargetRef(di);
            // break;
            // }
            // }
            // List<DataOutput> dataOutputs = callActivity.getIoSpecification().getDataOutputs();
            // for(DataOutput dout : dataOutputs) {
            // if(dout.getId().equals(callActivity.getId() + "_" + assignmentParts[1] + "OutputX")) {
            // doa.getSourceRef().add(dout);
            // break;
            // }
            // }
            // 
            // callActivity.getDataInputAssociations().add(dia);
            // callActivity.getDataOutputAssociations().add(doa);
            } else if (assignment.contains("->")) {
                String[] assignmentParts = assignment.split("->\\s*");
                String fromPart = assignmentParts[0];
                boolean isDataInput = false;
                boolean isDataOutput = false;
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                    isDataInput = true;
                }
                if (fromPart.startsWith("[dout]")) {
                    fromPart = fromPart.substring(6, fromPart.length());
                    isDataOutput = true;
                }
                List<DataOutput> dataOutputs = callActivity.getIoSpecification().getDataOutputs();
                if (isDataOutput) {
                    // doing data output
                    DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                    for (DataOutput dout : dataOutputs) {
                        if (dout.getId().equals(callActivity.getId() + "_" + fromPart + "OutputX")) {
                            doa.getSourceRef().add(dout);
                            break;
                        }
                    }
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(assignmentParts[1]);
                    doa.setTargetRef(ie);
                    callActivity.getDataOutputAssociations().add(doa);
                } else if (isDataInput) {
                    // doing data input
                    DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                    // association from process var to dataInput var
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(fromPart);
                    dia.getSourceRef().add(ie);
                    List<DataInput> dataInputs = callActivity.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(callActivity.getId() + "_" + assignmentParts[1] + "InputX")) {
                            dia.setTargetRef(di);
                            break;
                        }
                    }
                    callActivity.getDataInputAssociations().add(dia);
                }
            } else {
            // TODO throw exception here?
            }
        }
    }
    // process on-entry and on-exit actions as custom elements
    applyOnEntryActions(callActivity, properties);
    applyOnExitActions(callActivity, properties);
    // simulation
    if (properties.get("distributiontype") != null && properties.get("distributiontype").length() > 0) {
        TimeParameters timeParams = BpsimFactory.eINSTANCE.createTimeParameters();
        Parameter processingTimeParam = BpsimFactory.eINSTANCE.createParameter();
        if (properties.get("distributiontype").equals("normal")) {
            NormalDistributionType normalDistributionType = BpsimFactory.eINSTANCE.createNormalDistributionType();
            normalDistributionType.setStandardDeviation(Double.valueOf(properties.get("standarddeviation")));
            normalDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(normalDistributionType);
        } else if (properties.get("distributiontype").equals("uniform")) {
            UniformDistributionType uniformDistributionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
            uniformDistributionType.setMax(Double.valueOf(properties.get("max")));
            uniformDistributionType.setMin(Double.valueOf(properties.get("min")));
            processingTimeParam.getParameterValue().add(uniformDistributionType);
        // random distribution not supported in bpsim 1.0
        // } else if(properties.get("distributiontype").equals("random")) {
        // RandomDistributionType randomDistributionType = BpsimFactory.eINSTANCE.createRandomDistributionType();
        // randomDistributionType.setMax(Double.valueOf(properties.get("max")));
        // randomDistributionType.setMin(Double.valueOf(properties.get("min")));
        // processingTimeParam.getParameterValue().add(randomDistributionType);
        } else if (properties.get("distributiontype").equals("poisson")) {
            PoissonDistributionType poissonDistributionType = BpsimFactory.eINSTANCE.createPoissonDistributionType();
            poissonDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(poissonDistributionType);
        }
        // }
        if (properties.get("waittime") != null) {
            Parameter waittimeParam = BpsimFactory.eINSTANCE.createParameter();
            FloatingParameterType waittimeParamValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
            DecimalFormat twoDForm = new DecimalFormat("#.##");
            waittimeParamValue.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("waittime")))));
            waittimeParam.getParameterValue().add(waittimeParamValue);
            timeParams.setWaitTime(waittimeParam);
        }
        timeParams.setProcessingTime(processingTimeParam);
        if (_simulationElementParameters.containsKey(callActivity.getId())) {
            _simulationElementParameters.get(callActivity.getId()).add(timeParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(timeParams);
            _simulationElementParameters.put(callActivity.getId(), values);
        }
    }
    CostParameters costParameters = BpsimFactory.eINSTANCE.createCostParameters();
    if (properties.get("unitcost") != null && properties.get("unitcost").length() > 0) {
        Parameter unitcostParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType unitCostParameterValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
        unitCostParameterValue.setValue(new Double(properties.get("unitcost")));
        unitcostParam.getParameterValue().add(unitCostParameterValue);
        costParameters.setUnitCost(unitcostParam);
    }
    // }
    if (_simulationElementParameters.containsKey(callActivity.getId())) {
        _simulationElementParameters.get(callActivity.getId()).add(costParameters);
    } else {
        List<EObject> values = new ArrayList<EObject>();
        values.add(costParameters);
        _simulationElementParameters.put(callActivity.getId(), values);
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) CostParameters(bpsim.CostParameters) NormalDistributionType(bpsim.NormalDistributionType) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Assignment(org.eclipse.bpmn2.Assignment) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) EObject(org.eclipse.emf.ecore.EObject) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ArrayList(java.util.ArrayList) List(java.util.List) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) UniformDistributionType(bpsim.UniformDistributionType) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) FloatingParameterType(bpsim.FloatingParameterType) DataInput(org.eclipse.bpmn2.DataInput) PoissonDistributionType(bpsim.PoissonDistributionType) Parameter(bpsim.Parameter) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) TimeParameters(bpsim.TimeParameters) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Aggregations

Parameter (bpsim.Parameter)36 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)20 TimeParameters (bpsim.TimeParameters)13 UniformDistributionType (bpsim.UniformDistributionType)13 NormalDistributionType (bpsim.NormalDistributionType)12 PoissonDistributionType (bpsim.PoissonDistributionType)12 FloatingParameterType (bpsim.FloatingParameterType)10 CostParameters (bpsim.CostParameters)7 ElementParameters (bpsim.ElementParameters)7 ArrayList (java.util.ArrayList)7 EObject (org.eclipse.emf.ecore.EObject)7 DecimalFormat (java.text.DecimalFormat)6 EAttributeImpl (org.eclipse.emf.ecore.impl.EAttributeImpl)6 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)6 ExtendedMetaData (org.eclipse.emf.ecore.util.ExtendedMetaData)6 ParameterValue (bpsim.ParameterValue)5 ResourceParameters (bpsim.ResourceParameters)5 Assignment (org.eclipse.bpmn2.Assignment)5 DataInput (org.eclipse.bpmn2.DataInput)5 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)5