Search in sources :

Example 26 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class SimulationConfigurationParserPluggable method runPlugins.

public static void runPlugins(SimulationManager simEnvironment, SimulationConfiguration simulationConfiguration, Document document) throws ScyllaValidationException {
    Namespace simNamespace = document.getRootElement().getNamespace();
    List<Element> simElements = document.getRootElement().getChildren("simulationConfiguration", simNamespace);
    Element sim = simElements.get(0);
    String processRef = sim.getAttributeValue("processRef");
    ProcessModel processModel = simEnvironment.getProcessModels().get(processRef);
    runPluginsPerSC(simEnvironment, simulationConfiguration, processModel, sim);
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 27 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class GlobalConfigurationParser method parse.

@Override
public GlobalConfiguration parse(Element rootElement) throws ScyllaValidationException {
    System.out.println(rootElement.getNamespace());
    Iterator<EventOrderType> eventOrderTypesIterator = PluginLoader.dGetPlugins(EventOrderType.class);
    // ServiceLoader.load(EventOrderType.class).iterator();
    // Get all event order type plugins and store them in eventOrderTypes
    Map<String, EventOrderType> eventOrderTypes = new HashMap<String, EventOrderType>();
    while (eventOrderTypesIterator.hasNext()) {
        EventOrderType eot = eventOrderTypesIterator.next();
        eventOrderTypes.put(eot.getName(), eot);
    }
    Namespace bsimNamespace = rootElement.getNamespace();
    List<Element> globalConfigurationElements = rootElement.getChildren(null, bsimNamespace);
    String globalConfId = rootElement.getAttributeValue("id");
    Long randomSeed = null;
    ZoneId zoneId = ZoneId.of("UTC");
    Map<String, Resource> resources = new HashMap<String, Resource>();
    List<EventOrderType> resourceAssignmentOrder = new ArrayList<EventOrderType>();
    // resourceId:[instanceName:timetableId]
    Map<String, Map<String, String>> resourcesToTimetableIds = new HashMap<String, Map<String, String>>();
    Map<String, List<TimetableItem>> timetables = new HashMap<String, List<TimetableItem>>();
    for (Element el : globalConfigurationElements) {
        String elementName = el.getName();
        if (isKnownElement(elementName)) {
            if (el.getText().isEmpty()) {
                continue;
            }
            if (elementName.equals("resourceAssignmentOrder")) {
                String resourceAssignmentOrderString = el.getText();
                String[] orderTypeArray = resourceAssignmentOrderString.split(",");
                for (String orderTypeName : orderTypeArray) {
                    if (orderTypeName.isEmpty()) {
                        continue;
                    }
                    EventOrderType eventOrderType = eventOrderTypes.get(orderTypeName);
                    if (eventOrderType == null) {
                        throw new ScyllaValidationException("Event order type " + orderTypeName + " for resource assignment is unknown.");
                    }
                    resourceAssignmentOrder.add(eventOrderType);
                }
            } else if (elementName.equals("randomSeed")) {
                randomSeed = Long.parseLong(el.getText());
            } else if (elementName.equals("zoneOffset")) {
                zoneId = ZoneId.of("GMT" + el.getText());
            } else if (elementName.equals("resourceData")) {
                List<Element> rDataElements = el.getChildren();
                for (Element elem : rDataElements) {
                    String resourceId = elem.getAttributeValue("id");
                    String rDataElementName = elem.getName();
                    if (rDataElementName.equals("dynamicResource")) {
                        String resourceName = elem.getAttributeValue("name");
                        Integer defaultQuantity = Integer.valueOf(elem.getAttributeValue("defaultQuantity"));
                        Double defaultCost = Double.valueOf(elem.getAttributeValue("defaultCost"));
                        TimeUnit defaultTimeUnit = TimeUnit.valueOf(elem.getAttributeValue("defaultTimeUnit"));
                        DynamicResource dynamicResource = new DynamicResource(resourceId, resourceName, defaultQuantity, defaultCost, defaultTimeUnit);
                        String defaultTimetableId = elem.getAttributeValue("defaultTimetableId");
                        if (resourcesToTimetableIds.containsKey(resourceId)) {
                            throw new ScyllaValidationException("Multiple resource definitions: " + resourceId);
                        }
                        resourcesToTimetableIds.put(resourceId, new HashMap<String, String>());
                        Map<String, DynamicResourceInstance> resourceInstances = dynamicResource.getResourceInstances();
                        List<Element> instanceElements = elem.getChildren("instance", bsimNamespace);
                        // fill up list of resource instances if not explicitly defined
                        if (instanceElements.size() > defaultQuantity) {
                            throw new ScyllaValidationException("Too many instances defined for resource " + resourceId);
                        }
                        int numberOfDefaultInstances = defaultQuantity - instanceElements.size();
                        for (int i = 0; i < numberOfDefaultInstances; i++) {
                            String name = "#" + i;
                            DynamicResourceInstance instance = new DynamicResourceInstance(defaultCost, defaultTimeUnit);
                            resourceInstances.put(name, instance);
                            if (defaultTimetableId != null) {
                                resourcesToTimetableIds.get(resourceId).put(name, defaultTimetableId);
                            }
                        }
                        // parse defined resource instances
                        for (Element element : instanceElements) {
                            String name = element.getAttributeValue("name");
                            if (name == null) {
                                throw new ScyllaValidationException("Resource instance of type " + resourceId + " does not have name.");
                            }
                            Double cost;
                            if (element.getAttributeValue("cost") == null) {
                                cost = defaultCost;
                            } else {
                                cost = Double.valueOf(element.getAttributeValue("cost"));
                            }
                            TimeUnit timeUnit;
                            if (element.getAttributeValue("timeUnit") == null) {
                                timeUnit = defaultTimeUnit;
                            } else {
                                timeUnit = TimeUnit.valueOf(element.getAttributeValue("timeUnit"));
                            }
                            DynamicResourceInstance instance = new DynamicResourceInstance(cost, timeUnit);
                            if (resourceInstances.containsKey(name)) {
                                throw new ScyllaValidationException("Duplicate resource instance: " + name);
                            }
                            resourceInstances.put(name, instance);
                            String timetableId = element.getAttributeValue("timetableId");
                            if (timetableId != null) {
                                resourcesToTimetableIds.get(resourceId).put(name, timetableId);
                            }
                        }
                        resources.put(resourceId, dynamicResource);
                    } else {
                        DebugLogger.log("Element " + elem.getName() + " of resource data is expected to be known, but not supported.");
                    }
                }
            } else if (elementName.equals("timetables")) {
                List<Element> tElements = el.getChildren("timetable", bsimNamespace);
                for (Element tElement : tElements) {
                    String timetableId = tElement.getAttributeValue("id");
                    List<TimetableItem> items = new ArrayList<TimetableItem>();
                    List<Element> tItemElements = tElement.getChildren("timetableItem", bsimNamespace);
                    for (Element tItemElement : tItemElements) {
                        DayOfWeek weekdayFrom = DayOfWeek.valueOf(tItemElement.getAttributeValue("from"));
                        DayOfWeek weekdayTo = DayOfWeek.valueOf(tItemElement.getAttributeValue("to"));
                        LocalTime beginTime = LocalTime.parse(tItemElement.getAttributeValue("beginTime"));
                        LocalTime endTime = LocalTime.parse(tItemElement.getAttributeValue("endTime"));
                        // TODO check for overlapping timetable items and handle them
                        if (DateTimeUtils.compareWeekdayTime(weekdayFrom, beginTime, weekdayTo, endTime) != 0) {
                            if (weekdayFrom.compareTo(weekdayTo) > 0) {
                                // e.g. FRIDAY to MONDAY
                                TimetableItem item = new TimetableItem(weekdayFrom, DayOfWeek.SUNDAY, beginTime, LocalTime.MAX);
                                items.add(item);
                                item = new TimetableItem(DayOfWeek.MONDAY, weekdayTo, LocalTime.MIN, endTime);
                                items.add(item);
                            } else {
                                TimetableItem item = new TimetableItem(weekdayFrom, weekdayTo, beginTime, endTime);
                                items.add(item);
                            }
                        }
                    }
                    timetables.put(timetableId, items);
                }
            }
        } else {
            DebugLogger.log("Element " + el.getName() + " of global configuration is not supported.");
        }
    }
    // match timetables (if any available) and resource data (if any available)s
    for (String resourceId : resourcesToTimetableIds.keySet()) {
        Map<String, String> resourceInstanceIdToTimetableIds = resourcesToTimetableIds.get(resourceId);
        for (String resourceInstanceName : resourceInstanceIdToTimetableIds.keySet()) {
            String timetableId = resourceInstanceIdToTimetableIds.get(resourceInstanceName);
            if (!timetables.containsKey(timetableId)) {
                DebugLogger.log("Timetable " + timetableId + " not found.");
            }
            List<TimetableItem> timetable = timetables.get(timetableId);
            Resource resource = resources.get(resourceId);
            if (resource instanceof DynamicResource) {
                DynamicResource dResource = (DynamicResource) resource;
                dResource.getResourceInstances().get(resourceInstanceName).setTimetable(timetable);
            }
        }
    }
    if (resources.isEmpty()) {
        throw new ScyllaValidationException("No resource data definitions in file.");
    }
    if (randomSeed == null) {
        Random random = new Random();
        randomSeed = random.nextLong();
    }
    DebugLogger.log("Random seed for whole simulation (if not overriden by simulation configuration): " + randomSeed);
    GlobalConfiguration globalConfiguration = new GlobalConfiguration(globalConfId, zoneId, randomSeed, resources, resourceAssignmentOrder);
    return globalConfiguration;
}
Also used : HashMap(java.util.HashMap) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) Random(java.util.Random) DynamicResourceInstance(de.hpi.bpt.scylla.model.global.resource.DynamicResourceInstance) TimeUnit(java.util.concurrent.TimeUnit) ArrayList(java.util.ArrayList) List(java.util.List) TimetableItem(de.hpi.bpt.scylla.model.global.resource.TimetableItem) DayOfWeek(java.time.DayOfWeek) GlobalConfiguration(de.hpi.bpt.scylla.model.global.GlobalConfiguration) ZoneId(java.time.ZoneId) LocalTime(java.time.LocalTime) EventOrderType(de.hpi.bpt.scylla.plugin_type.parser.EventOrderType) DynamicResource(de.hpi.bpt.scylla.model.global.resource.DynamicResource) Resource(de.hpi.bpt.scylla.model.global.resource.Resource) Namespace(org.jdom2.Namespace) DynamicResource(de.hpi.bpt.scylla.model.global.resource.DynamicResource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class SimulationConfigurationParser method parseSimulationConfiguration.

private SimulationConfiguration parseSimulationConfiguration(Element sim, Namespace simNamespace, String processIdFromSimElement, ProcessModel processModel, Long randomSeed) throws ScyllaValidationException {
    Map<String, Resource> resources = simulationEnvironment.getGlobalConfiguration().getResources();
    if (processModel == null) {
        throw new ScyllaValidationException("Simulation configuration is for (sub)process '" + processIdFromSimElement + "', which is not found in the simulation environment.");
    }
    String processRef = processIdFromSimElement;
    String simId = null;
    Integer numberOfProcessInstances = null;
    ZonedDateTime startDateTime = null;
    ZonedDateTime endDateTime = null;
    if (processModel.getParent() == null) {
        List<Element> startEvents = sim.getChildren("startEvent", simNamespace);
        if (startEvents.size() == 0)
            throw new ScyllaValidationException("No definition of start event in simulation scenario.");
        else {
            for (Element el : startEvents) {
                // it is sufficient if at least one of the start events has an arrival rate defined
                if (el.getChild("arrivalRate", simNamespace) != null) {
                    break;
                }
                throw new ScyllaValidationException("No arrival rate defined in any of the start events in simulation scenario.");
            }
        }
        // store identifier of simulation configuration only if it is for top level process
        simId = sim.getAttributeValue("id");
        numberOfProcessInstances = Integer.valueOf(sim.getAttributeValue("processInstances"));
        startDateTime = DateTimeUtils.parse(sim.getAttributeValue("startDateTime"));
        String endDateTimeString = sim.getAttributeValue("endDateTime");
        if (endDateTimeString != null) {
            endDateTime = DateTimeUtils.parse(endDateTimeString);
        }
        String randomSeedString = sim.getAttributeValue("randomSeed");
        if (randomSeedString != null) {
            randomSeed = Long.valueOf(sim.getAttributeValue("randomSeed"));
            DebugLogger.log("Random seed for simulation configuration " + processRef + ": " + randomSeed);
        }
    }
    Map<Integer, TimeDistributionWrapper> arrivalRates = new HashMap<Integer, TimeDistributionWrapper>();
    Map<Integer, TimeDistributionWrapper> durations = new HashMap<Integer, TimeDistributionWrapper>();
    Map<Integer, TimeDistributionWrapper> setUpDurations = new HashMap<Integer, TimeDistributionWrapper>();
    Map<Integer, Set<ResourceReference>> resourceReferences = new HashMap<Integer, Set<ResourceReference>>();
    // gateways and events
    // Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
    Map<Integer, SimulationConfiguration> configurationsOfSubProcesses = new HashMap<Integer, SimulationConfiguration>();
    // take resource definitions from process model
    Map<Integer, Set<String>> resourceReferencesFromProcessModel = processModel.getResourceReferences();
    for (Integer nodeId : resourceReferencesFromProcessModel.keySet()) {
        Set<String> resourceRefFromModel = resourceReferencesFromProcessModel.get(nodeId);
        Set<ResourceReference> resourceRefs = new HashSet<ResourceReference>();
        for (String resourceId : resourceRefFromModel) {
            int amount = 1;
            Map<String, String> assignmentDefinition = new HashMap<String, String>();
            ResourceReference resourceReference = new ResourceReference(resourceId, amount, assignmentDefinition);
            resourceRefs.add(resourceReference);
        }
        resourceReferences.put(nodeId, resourceRefs);
    }
    for (Element el : sim.getChildren()) {
        String elementName = el.getName();
        if (isKnownElement(elementName)) {
            if (elementName.equals("resources")) {
                // in parent process
                continue;
            }
            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;
            }
            if (elementName.equals("startEvent")) {
                Element elem = el.getChild("arrivalRate", simNamespace);
                if (elem != null) {
                    TimeDistributionWrapper distribution = getTimeDistributionWrapper(elem, simNamespace);
                    arrivalRates.put(nodeId, distribution);
                }
            } else if (elementName.equals("task") || elementName.endsWith("Task") || elementName.equals("subProcess")) {
                Element durationElem = el.getChild("duration", simNamespace);
                if (durationElem != null) {
                    TimeDistributionWrapper distribution = getTimeDistributionWrapper(durationElem, simNamespace);
                    durations.put(nodeId, distribution);
                }
                Element setUpDurationElem = el.getChild("setUpDuration", simNamespace);
                if (setUpDurationElem != null) {
                    TimeDistributionWrapper distribution = getTimeDistributionWrapper(setUpDurationElem, simNamespace);
                    setUpDurations.put(nodeId, distribution);
                }
                Element resourcesElem = el.getChild("resources", simNamespace);
                if (resourcesElem != null) {
                    List<Element> resourceElements = resourcesElem.getChildren("resource", simNamespace);
                    // process model)
                    if (resourceElements.size() > 0) {
                        Set<ResourceReference> resourceRefs = new HashSet<ResourceReference>();
                        Set<String> resourceIdentifiers = new HashSet<String>();
                        for (Element elem : resourceElements) {
                            String resourceId = elem.getAttributeValue("id");
                            if (resources.get(resourceId) == null) {
                                throw new ScyllaValidationException("Simulation configuration " + simId + " refers to unknown resource " + resourceId + ".");
                            }
                            if (resourceIdentifiers.contains(resourceId)) {
                                throw new ScyllaValidationException("Simulation configuration " + simId + " defines multiple resources for task / subprocess " + identifier);
                            }
                            resourceIdentifiers.add(resourceId);
                            // XXX implementation currently supports more than one instance per resource. however
                            // BPMN standard does not support that.
                            // int amount = 1;
                            int amount = Integer.parseInt(elem.getAttributeValue("amount"));
                            Map<String, String> assignmentDefinition = new HashMap<String, String>();
                            Element assignmentDefinitionElement = elem.getChild("assignmentDefinition", simNamespace);
                            if (assignmentDefinitionElement != null) {
                                List<Element> adElements = assignmentDefinitionElement.getChildren(null, simNamespace);
                                for (Element adElem : adElements) {
                                    assignmentDefinition.put(adElem.getName(), adElem.getText());
                                }
                            }
                            ResourceReference resourceReference = new ResourceReference(resourceId, amount, assignmentDefinition);
                            resourceRefs.add(resourceReference);
                        }
                        resourceReferences.put(nodeId, resourceRefs);
                    }
                }
                if (elementName.equals("subProcess")) {
                    ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
                    String subProcessIdFromSimElement = el.getAttributeValue("id");
                    SimulationConfiguration simulationConfiguration = parseSimulationConfiguration(el, simNamespace, subProcessIdFromSimElement, subProcess, randomSeed);
                    configurationsOfSubProcesses.put(nodeId, simulationConfiguration);
                }
            } else {
                DebugLogger.log("Element " + el.getName() + " of simulation scenario is expected to be known, but not supported.");
            }
        } else {
            DebugLogger.log("Element " + el.getName() + " of simulation scenario not supported.");
        }
    }
    SimulationConfiguration simulationConfiguration = new SimulationConfiguration(simId, processModel, numberOfProcessInstances, startDateTime, endDateTime, randomSeed, arrivalRates, durations, setUpDurations, resourceReferences, configurationsOfSubProcesses);
    return simulationConfiguration;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Element(org.jdom2.Element) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) ZonedDateTime(java.time.ZonedDateTime) List(java.util.List) ResourceReference(de.hpi.bpt.scylla.model.configuration.ResourceReference) TimeDistributionWrapper(de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper) HashSet(java.util.HashSet) Resource(de.hpi.bpt.scylla.model.global.resource.Resource) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class SimulationConfigurationParser method getDistribution.

public static Distribution getDistribution(Element element, Namespace simNamespace, String fieldType) throws ScyllaValidationException {
    Distribution distribution;
    if (element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace) != null && fieldType.equals("string")) {
        Element el = element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace);
        // changed name here but now in the whole project
        EmpiricalStringDistribution dist = new EmpiricalStringDistribution();
        List<Element> entries = el.getChildren("entry", simNamespace);
        if (entries.isEmpty()) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        double sum = 0;
        try {
            for (Element entry : entries) {
                // normalize frequency to 1.0
                sum += Double.valueOf(entry.getAttributeValue("frequency"));
            }
            for (Element entry : entries) {
                dist.addEntry(entry.getAttributeValue("value"), Double.valueOf(entry.getAttributeValue("frequency")) / sum);
            }
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        distribution = dist;
    } else if (element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace) != null) {
        Element el = element.getChild("arbitraryFiniteProbabilityDistribution", simNamespace);
        // changed name here but now in the whole project
        EmpiricalDistribution dist = new EmpiricalDistribution();
        List<Element> entries = el.getChildren("entry", simNamespace);
        if (entries.isEmpty()) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        double sum = 0;
        try {
            for (Element entry : entries) {
                // normalize frequency to 1.0
                sum += Double.valueOf(entry.getAttributeValue("frequency"));
            }
            for (Element entry : entries) {
                dist.addEntry(Double.valueOf(entry.getAttributeValue("value")), Double.valueOf(entry.getAttributeValue("frequency")) / sum);
            }
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify pairs of a vaule and a frequency for arbitraryFiniteProbabilityDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
        distribution = dist;
    } else if (element.getChild("binomialDistribution", simNamespace) != null) {
        Element el = element.getChild("binomialDistribution", simNamespace);
        try {
            double probability = Double.valueOf(el.getChildText("probability", simNamespace));
            int amount = Integer.valueOf(el.getChildText("amount", simNamespace));
            distribution = new BinomialDistribution(probability, amount);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a probability and an amount for binomialDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("constantDistribution", simNamespace) != null) {
        Element el = element.getChild("constantDistribution", simNamespace);
        try {
            double constantValue = Double.valueOf(el.getChildText("constantValue", simNamespace));
            distribution = new ConstantDistribution(constantValue);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a constantValue for constantDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("erlangDistribution", simNamespace) != null) {
        Element el = element.getChild("erlangDistribution", simNamespace);
        try {
            long order = Long.valueOf(el.getChildText("order", simNamespace));
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            distribution = new ErlangDistribution(order, mean);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a order and a mean for erlangDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("exponentialDistribution", simNamespace) != null) {
        Element el = element.getChild("exponentialDistribution", simNamespace);
        try {
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            distribution = new ExponentialDistribution(mean);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a mean for exponentialDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("triangularDistribution", simNamespace) != null) {
        Element el = element.getChild("triangularDistribution", simNamespace);
        try {
            double lower = Double.valueOf(el.getChildText("lower", simNamespace));
            double upper = Double.valueOf(el.getChildText("upper", simNamespace));
            double peak = Double.valueOf(el.getChildText("peak", simNamespace));
            distribution = new TriangularDistribution(lower, upper, peak);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a lower, a upper and a peak for triangularDistribution at" + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("normalDistribution", simNamespace) != null) {
        Element el = element.getChild("normalDistribution", simNamespace);
        try {
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            double standardDeviation = Double.valueOf(el.getChildText("standardDeviation", simNamespace));
            distribution = new NormalDistribution(mean, standardDeviation);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a mean and a standardDeviation for normalDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("poissonDistribution", simNamespace) != null) {
        Element el = element.getChild("poissonDistribution", simNamespace);
        try {
            double mean = Double.valueOf(el.getChildText("mean", simNamespace));
            distribution = new PoissonDistribution(mean);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a mean for poissonDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else if (element.getChild("uniformDistribution", simNamespace) != null) {
        Element el = element.getChild("uniformDistribution", simNamespace);
        try {
            double lower = Double.valueOf(el.getChildText("lower", simNamespace));
            double upper = Double.valueOf(el.getChildText("upper", simNamespace));
            distribution = new UniformDistribution(lower, upper);
        } catch (NullPointerException e) {
            throw new ScyllaValidationException("You have to specify a lower and an upper for uniformDistribution at " + getTaskOfDistribution(element) + ". Check spelling!");
        }
    } else {
        throw new ScyllaValidationException("Distribution definition at " + getTaskOfDistribution(element) + " not found or not supported. Check spelling!");
    }
    return distribution;
}
Also used : PoissonDistribution(de.hpi.bpt.scylla.model.configuration.distribution.PoissonDistribution) EmpiricalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalDistribution) ErlangDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ErlangDistribution) Element(org.jdom2.Element) ExponentialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ExponentialDistribution) UniformDistribution(de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution) EmpiricalStringDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalStringDistribution) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NormalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.NormalDistribution) EmpiricalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalDistribution) NormalDistribution(de.hpi.bpt.scylla.model.configuration.distribution.NormalDistribution) ExponentialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ExponentialDistribution) TriangularDistribution(de.hpi.bpt.scylla.model.configuration.distribution.TriangularDistribution) UniformDistribution(de.hpi.bpt.scylla.model.configuration.distribution.UniformDistribution) ErlangDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ErlangDistribution) ConstantDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ConstantDistribution) Distribution(de.hpi.bpt.scylla.model.configuration.distribution.Distribution) BinomialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.BinomialDistribution) EmpiricalStringDistribution(de.hpi.bpt.scylla.model.configuration.distribution.EmpiricalStringDistribution) PoissonDistribution(de.hpi.bpt.scylla.model.configuration.distribution.PoissonDistribution) List(java.util.List) BinomialDistribution(de.hpi.bpt.scylla.model.configuration.distribution.BinomialDistribution) ConstantDistribution(de.hpi.bpt.scylla.model.configuration.distribution.ConstantDistribution) TriangularDistribution(de.hpi.bpt.scylla.model.configuration.distribution.TriangularDistribution)

Example 30 with Namespace

use of org.jdom2.Namespace in project scylla by bptlab.

the class SimulationConfigurationParser method parse.

@Override
public SimulationConfiguration parse(Element rootElement) throws ScyllaValidationException {
    Namespace simNamespace = rootElement.getNamespace();
    List<Element> simElements = rootElement.getChildren("simulationConfiguration", simNamespace);
    if (simElements.isEmpty()) {
        throw new ScyllaValidationException("No simulation configuration in file.");
    } else if (simElements.size() > 1) {
        throw new ScyllaValidationException("Multiple simulation configurations in file. If you want to simulate mulitple scenarios, then store them in separate simulation configuration files.");
    }
    Element sim = simElements.get(0);
    String processRef = sim.getAttributeValue("processRef");
    ProcessModel processModel = simulationEnvironment.getProcessModels().get(processRef);
    Long randomSeed = simulationEnvironment.getGlobalConfiguration().getRandomSeed();
    SimulationConfiguration simulationConfiguration = parseSimulationConfiguration(sim, simNamespace, processRef, processModel, randomSeed);
    // }
    return simulationConfiguration;
}
Also used : ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Aggregations

Element (org.jdom2.Element)31 Namespace (org.jdom2.Namespace)17 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)11 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)10 HashMap (java.util.HashMap)9 JDOMException (org.jdom2.JDOMException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 BranchingBehavior (de.hpi.bpt.scylla.model.configuration.BranchingBehavior)3 TimeDistributionWrapper (de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)3 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)2 Distribution (de.hpi.bpt.scylla.model.configuration.distribution.Distribution)2 Resource (de.hpi.bpt.scylla.model.global.resource.Resource)2 CommonProcessElements (de.hpi.bpt.scylla.model.process.CommonProcessElements)2 Graph (de.hpi.bpt.scylla.model.process.graph.Graph)2 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 DataObjectType (de.hpi.bpt.scylla.model.process.node.DataObjectType)2