Search in sources :

Example 6 with ProcessNodeInfo

use of de.hpi.bpt.scylla.logger.ProcessNodeInfo in project scylla by bptlab.

the class DataObjectBPMNIntermediateEvent method eventRoutine.

@Override
public void eventRoutine(BPMNIntermediateEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    // int processInstanceId = processInstance.getId();
    try {
        if (processModel.getDataObjectsGraph().getNodes().containsKey(desmojEvent.getNodeId())) {
            Set<Integer> refferingObjects = processModel.getDataObjectsGraph().getTargetObjects(desmojEvent.getNodeId());
            Collection<Object> allFields = desmojEvent.getDesmojObjects().getExtensionDistributions().get("dataobject").values();
            for (Object fields : allFields) {
                Integer i = 0;
                while (((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray().length - i != 0) {
                    DataObjectField field = (DataObjectField) ((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray()[i];
                    if (refferingObjects.contains(field.getNodeId())) {
                        // System.out.println(processInstance.getId() + " " + desmojEvent.getDisplayName() + " " + processModel.getDisplayNames().get(field.getNodeId()) + " " + field.getDataDistributionWrapper().getSample());
                        SimulationModel model = (SimulationModel) desmojEvent.getModel();
                        Collection<Map<Integer, java.util.List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
                        for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
                            List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
                            for (ProcessNodeInfo task : currentProcess) {
                                // System.out.println(processModel.getDisplayNames().get(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[0]) + " " + task.getTaskName());
                                for (Integer j = 0; j < processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray().length; j++) {
                                    if (task.getId().equals(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[j]) && task.getTransition() == ProcessNodeTransitionType.EVENT_TERMINATE) {
                                        // check all tasks and find the ones that may be looged; already logged ones will get ignored next line
                                        if (!task.getDataObjectField().containsKey(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName())) {
                                            // don't log if task already has this field logged
                                            Map<String, Object> fieldSample = new HashMap<String, Object>();
                                            Object currentSample = field.getDataDistributionWrapper().getSample();
                                            // log Value at TaskTerminate
                                            fieldSample.put(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName(), currentSample);
                                            task.SetDataObjectField(fieldSample);
                                            // set current DataObjectFieldValue
                                            DataObjectField.addDataObjectValue(processInstance.getId(), fieldSample.keySet().toArray()[0].toString(), currentSample);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    i++;
                }
            }
        } else {
        // do nothing and continue with the next task because Node has no dataobejcts
        }
    } catch (ScyllaRuntimeException | ScyllaValidationException | NodeNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) java.util(java.util) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 7 with ProcessNodeInfo

use of de.hpi.bpt.scylla.logger.ProcessNodeInfo in project scylla by bptlab.

the class DataObjectBPMNStartEvent method eventRoutine.

@Override
public void eventRoutine(BPMNStartEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    // int processInstanceId = processInstance.getId();
    try {
        if (processModel.getDataObjectsGraph().getNodes().containsKey(desmojEvent.getNodeId())) {
            Set<Integer> refferingObjects = processModel.getDataObjectsGraph().getTargetObjects(desmojEvent.getNodeId());
            Collection<Object> allFields = desmojEvent.getDesmojObjects().getExtensionDistributions().get("dataobject").values();
            for (Object fields : allFields) {
                Integer i = 0;
                while (((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray().length - i != 0) {
                    DataObjectField field = (DataObjectField) ((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray()[i];
                    if (refferingObjects.contains(field.getNodeId())) {
                        // System.out.println(processInstance.getId() + " " + desmojEvent.getDisplayName() + " " + processModel.getDisplayNames().get(field.getNodeId()) + " " + field.getDataDistributionWrapper().getSample());
                        SimulationModel model = (SimulationModel) desmojEvent.getModel();
                        Collection<Map<Integer, java.util.List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
                        for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
                            List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
                            for (ProcessNodeInfo task : currentProcess) {
                                // System.out.println(processModel.getDisplayNames().get(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[0]) + " " + task.getTaskName());
                                for (Integer j = 0; j < processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray().length; j++) {
                                    if (task.getId().equals(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[j]) && task.getTransition() == ProcessNodeTransitionType.EVENT_TERMINATE) {
                                        // check all tasks and find the ones that may be looged; already logged ones will get ignored next line
                                        if (!task.getDataObjectField().containsKey(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName())) {
                                            // don't log if task already has this field logged
                                            Map<String, Object> fieldSample = new HashMap<String, Object>();
                                            Object currentSample = field.getDataDistributionWrapper().getSample();
                                            // log Value at TaskTerminate
                                            fieldSample.put(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName(), currentSample);
                                            task.SetDataObjectField(fieldSample);
                                            // set current DataObjectFieldValue
                                            DataObjectField.addDataObjectValue(processInstance.getId(), fieldSample.keySet().toArray()[0].toString(), currentSample);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    i++;
                }
            }
        } else {
        // do nothing and continue with the next task because Node has no dataobejcts
        }
    } catch (ScyllaRuntimeException | ScyllaValidationException | NodeNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) java.util(java.util) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 8 with ProcessNodeInfo

use of de.hpi.bpt.scylla.logger.ProcessNodeInfo in project scylla by bptlab.

the class StatisticsLogger method writeToLog.

public void writeToLog(SimulationModel model, String outputPathWithoutExtension) throws IOException {
    TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
    double totalEndTime = model.presentTime().getTimeAsDouble(timeUnit);
    Map<String, Map<Integer, List<ProcessNodeInfo>>> processNodeInfos = model.getProcessNodeInfos();
    Map<String, Map<String, List<ResourceInfo>>> resourceInfos = model.getResourceInfos();
    Set<ResourceObject> resourceObjectsSet = QueueManager.getAllResourceObjects(model);
    Map<String, Double> costPerResourceInstance = new HashMap<String, Double>();
    Map<String, Map<String, ResourceObject>> resourceObjects = new HashMap<String, Map<String, ResourceObject>>();
    for (ResourceObject res : resourceObjectsSet) {
        String resourceName = res.getResourceType() + "_" + res.getId();
        TimeUnit timeUnitOfResource = res.getTimeUnit();
        TimeUnit referenceUnit = DateTimeUtils.getReferenceTimeUnit();
        double cost = res.getCost();
        double costInReferenceUnit = DateTimeUtils.convertCost(timeUnitOfResource, referenceUnit, cost);
        costPerResourceInstance.put(resourceName, costInReferenceUnit);
        String resourceType = res.getResourceType();
        if (!resourceObjects.containsKey(resourceType)) {
            resourceObjects.put(resourceType, new HashMap<String, ResourceObject>());
        }
        String resourceId = res.getId();
        resourceObjects.get(resourceType).put(resourceId, res);
    }
    // resource utilization
    Map<String, Map<String, StatisticsResourceObject>> statsPerResource = new HashMap<String, Map<String, StatisticsResourceObject>>();
    // double totalEndTime = 0;
    for (String resourceType : resourceInfos.keySet()) {
        Map<String, StatisticsResourceObject> statsPerResourceInstance = new HashMap<String, StatisticsResourceObject>();
        Map<String, List<ResourceInfo>> resourceInfosOfType = resourceInfos.get(resourceType);
        for (String resourceId : resourceInfosOfType.keySet()) {
            long durationInUse = 0;
            long durationInUseIdle = 0;
            long currentTime = 0;
            List<ResourceInfo> infosOfResource = resourceInfosOfType.get(resourceId);
            ResourceStatus previousStatus = null;
            for (ResourceInfo info : infosOfResource) {
                ResourceStatus status = info.getTransition();
                long timestamp = info.getTimestamp();
                // FREE <-> IN_USE <-> IN_USE_IDLE
                if (status == ResourceStatus.IN_USE) {
                    if (previousStatus == ResourceStatus.IN_USE_IDLE) {
                        durationInUseIdle += timestamp - currentTime;
                    }
                } else if (status == ResourceStatus.FREE || status == ResourceStatus.IN_USE_IDLE) {
                    durationInUse += timestamp - currentTime;
                } else {
                    DebugLogger.log("Resource transition type not supported: " + status);
                }
                currentTime = timestamp;
            // if (currentTime > totalEndTime) {
            // totalEndTime = currentTime;
            // }
            }
            long durationAvailable = DateTimeUtils.getAvailabilityTime(resourceObjects.get(resourceType).get(resourceId).getTimetable(), new TimeInstant(totalEndTime));
            String resourceName = resourceType + "_" + resourceId;
            Double costPerUnit = costPerResourceInstance.get(resourceName);
            double costs = durationAvailable * costPerUnit;
            StatisticsResourceObject sro = new StatisticsResourceObject();
            sro.setDurationAvailable(durationAvailable);
            sro.setDurationInUse(durationInUse);
            // for total available time
            sro.setCosts(costs);
            sro.setDurationInUseIdle(durationInUseIdle);
            statsPerResourceInstance.put(resourceId, sro);
        }
        statsPerResource.put(resourceType, statsPerResourceInstance);
    }
    // process time with and without off-timetable hours (= idle time)
    // process waiting time
    // process costs
    // task duration
    // task waiting time
    Map<String, Map<Integer, StatisticsProcessInstanceObject>> statsPerProcess = new HashMap<String, Map<Integer, StatisticsProcessInstanceObject>>();
    Map<String, Map<String, Map<String, StatisticsTaskInstanceObject>>> statsPerTask = new HashMap<String, Map<String, Map<String, StatisticsTaskInstanceObject>>>();
    for (String processId : processNodeInfos.keySet()) {
        Map<Integer, StatisticsProcessInstanceObject> statsPerProcessInstance = new HashMap<Integer, StatisticsProcessInstanceObject>();
        Map<String, Map<String, StatisticsTaskInstanceObject>> statsPerTaskOfProcess = new HashMap<String, Map<String, StatisticsTaskInstanceObject>>();
        Map<Integer, List<ProcessNodeInfo>> nodeInfoOfProcessInstances = processNodeInfos.get(processId);
        for (int processInstanceId : nodeInfoOfProcessInstances.keySet()) {
            List<ProcessNodeInfo> nodeInfoList = nodeInfoOfProcessInstances.get(processInstanceId);
            long durationTotal = 0;
            long durationInactive = 0;
            long durationResourcesIdle = 0;
            long durationWaiting = 0;
            double costs = 0;
            Long previousTimestamp = null;
            long timeProcessStart = 0;
            Map<TaskInstanceIdentifier, Long> taskDurations = new HashMap<TaskInstanceIdentifier, Long>();
            Map<TaskInstanceIdentifier, Long> begunOrResumedTasks = new HashMap<TaskInstanceIdentifier, Long>();
            Map<TaskInstanceIdentifier, Long> enabledTasks = new HashMap<TaskInstanceIdentifier, Long>();
            Map<TaskInstanceIdentifier, Long> pausedTasks = new HashMap<TaskInstanceIdentifier, Long>();
            for (int i = 0; i < nodeInfoList.size(); i++) {
                String taskInstanceId = String.valueOf(i);
                long taskDurationEffective = 0;
                long taskDurationResourcesIdle = 0;
                long taskDurationWaiting = 0;
                double taskCosts = 0;
                ProcessNodeInfo ni = nodeInfoList.get(i);
                long timestamp = ni.getTimestamp();
                String processScopeNodeId = ni.getProcessScopeNodeId();
                String source = ni.getSource();
                TaskInstanceIdentifier taskInstanceIdentifier = new TaskInstanceIdentifier(processScopeNodeId, source);
                Set<String> resources = ni.getResources();
                String taskName = ni.getTaskName();
                StatisticsTaskInstanceObject stio = new StatisticsTaskInstanceObject(taskName);
                if (i == 0) {
                    previousTimestamp = timestamp;
                    timeProcessStart = timestamp;
                } else if (i == nodeInfoList.size() - 1) {
                    durationTotal = timestamp - timeProcessStart;
                }
                ProcessNodeTransitionType transition = ni.getTransition();
                if (begunOrResumedTasks.isEmpty()) {
                    durationInactive += timestamp - previousTimestamp;
                }
                if (transition == ProcessNodeTransitionType.ENABLE) {
                    enabledTasks.put(taskInstanceIdentifier, timestamp);
                } else if (transition == ProcessNodeTransitionType.BEGIN) {
                    Long enableTimestamp = enabledTasks.get(taskInstanceIdentifier);
                    if (enableTimestamp != null) {
                        long duration = timestamp - enableTimestamp;
                        durationWaiting += duration;
                        taskDurationWaiting += duration;
                        enabledTasks.remove(taskInstanceIdentifier);
                    }
                    taskDurations.put(taskInstanceIdentifier, 0L);
                    begunOrResumedTasks.put(taskInstanceIdentifier, timestamp);
                } else if (transition == ProcessNodeTransitionType.PAUSE) {
                    pausedTasks.put(taskInstanceIdentifier, timestamp);
                    Long beginOrResumeTimestamp = begunOrResumedTasks.get(taskInstanceIdentifier);
                    long duration = timestamp - beginOrResumeTimestamp;
                    for (String resourceName : resources) {
                        Double costPerUnit = costPerResourceInstance.get(resourceName);
                        costs += duration * costPerUnit;
                        taskCosts += duration * costPerUnit;
                    }
                    taskDurations.put(taskInstanceIdentifier, taskDurations.get(taskInstanceIdentifier) + duration);
                    begunOrResumedTasks.remove(taskInstanceIdentifier);
                } else if (transition == ProcessNodeTransitionType.RESUME) {
                    Long pauseTimestamp = pausedTasks.get(taskInstanceIdentifier);
                    long duration = timestamp - pauseTimestamp;
                    durationResourcesIdle += duration;
                    taskDurationResourcesIdle += duration;
                    pausedTasks.remove(taskInstanceIdentifier);
                    begunOrResumedTasks.put(taskInstanceIdentifier, timestamp);
                } else if (transition == ProcessNodeTransitionType.TERMINATE || transition == ProcessNodeTransitionType.CANCEL) {
                    Long beginOrResumeTimestamp = begunOrResumedTasks.get(taskInstanceIdentifier);
                    long duration = timestamp - beginOrResumeTimestamp;
                    for (String resourceName : resources) {
                        Double costPerUnit = costPerResourceInstance.get(resourceName);
                        costs += duration * costPerUnit;
                        taskCosts += duration * costPerUnit;
                    }
                    taskDurationEffective = taskDurations.get(taskInstanceIdentifier) + duration;
                    taskDurations.remove(taskInstanceIdentifier);
                    begunOrResumedTasks.remove(taskInstanceIdentifier);
                } else if (transition == ProcessNodeTransitionType.EVENT_BEGIN || transition == ProcessNodeTransitionType.EVENT_TERMINATE) {
                // not supported
                }
                stio.setDurationEffective(taskDurationEffective);
                stio.setDurationResourcesIdle(taskDurationResourcesIdle);
                stio.setDurationWaiting(taskDurationWaiting);
                stio.setCost(taskCosts);
                if (!statsPerTaskOfProcess.containsKey(processScopeNodeId)) {
                    statsPerTaskOfProcess.put(processScopeNodeId, new HashMap<String, StatisticsTaskInstanceObject>());
                }
                statsPerTaskOfProcess.get(processScopeNodeId).put(taskInstanceId, stio);
                previousTimestamp = ni.getTimestamp();
            }
            StatisticsProcessInstanceObject spio = new StatisticsProcessInstanceObject();
            spio.setDurationTotal(durationTotal);
            spio.setDurationInactive(durationInactive);
            spio.setDurationResourcesIdle(durationResourcesIdle);
            spio.setDurationWaiting(durationWaiting);
            spio.setCosts(costs);
            statsPerProcessInstance.put(processInstanceId, spio);
        }
        statsPerProcess.put(processId, statsPerProcessInstance);
        statsPerTask.put(processId, statsPerTaskOfProcess);
    }
    // build xml document
    Element resourceUtilization = new Element("resourceUtilization");
    Document doc = new Document(resourceUtilization);
    Element configuration = new Element("configuration");
    Element processes = new Element("processes");
    Element resources = new Element("resources");
    doc.getRootElement().addContent(configuration);
    doc.getRootElement().addContent(processes);
    doc.getRootElement().addContent(resources);
    configuration.addContent(new Element("time_unit").setText(String.valueOf(DateTimeUtils.getReferenceTimeUnit())));
    // add processes
    for (String processId : statsPerProcess.keySet()) {
        Map<Integer, StatisticsProcessInstanceObject> statsPerProcessInstance = statsPerProcess.get(processId);
        Element process = new Element("process");
        processes.addContent(process);
        process.addContent(new Element("id").setText(processId));
        Element processCost = new Element("cost");
        Element processTime = new Element("time");
        Element processInstances = new Element("instances");
        Element processActivities = new Element("activities");
        process.addContent(processCost);
        process.addContent(processTime);
        process.addContent(processInstances);
        process.addContent(processActivities);
        Element processFlowTime = new Element("flow_time");
        Element processEffectiveTime = new Element("effective");
        Element processWaitingTime = new Element("waiting");
        Element processOffTime = new Element("off_timetable");
        processTime.addContent(processFlowTime);
        processTime.addContent(processEffectiveTime);
        processTime.addContent(processWaitingTime);
        processTime.addContent(processOffTime);
        StatisticsCalculationObject costStats = new StatisticsCalculationObject();
        StatisticsCalculationObject flowTimeStats = new StatisticsCalculationObject();
        StatisticsCalculationObject effectiveStats = new StatisticsCalculationObject();
        StatisticsCalculationObject offTimeStats = new StatisticsCalculationObject();
        StatisticsCalculationObject waitingStats = new StatisticsCalculationObject();
        // add process instances
        for (Integer processInstanceId : statsPerProcessInstance.keySet()) {
            StatisticsProcessInstanceObject stats = statsPerProcessInstance.get(processInstanceId);
            long durationTotal = stats.getDurationTotal();
            long durationEffective = durationTotal - stats.getDurationInactive();
            long durationResourcesIdle = stats.getDurationResourcesIdle();
            long durationWaiting = stats.getDurationWaiting();
            double cost = stats.getCosts();
            Element instance = new Element("instance");
            processInstances.addContent(instance);
            instance.addContent(new Element("costs").setText(String.valueOf(cost)));
            Element instanceTime = new Element("time");
            instanceTime.addContent(new Element("duration").setText(String.valueOf(durationTotal)));
            instanceTime.addContent(new Element("effective").setText(String.valueOf(durationEffective)));
            instanceTime.addContent(new Element("waiting").setText(String.valueOf(durationWaiting)));
            instanceTime.addContent(new Element("offTime").setText(String.valueOf(durationResourcesIdle)));
            instance.addContent(instanceTime);
            costStats.addValue(cost);
            flowTimeStats.addValue(durationTotal);
            effectiveStats.addValue(durationEffective);
            offTimeStats.addValue(durationResourcesIdle);
            waitingStats.addValue(durationWaiting);
        }
        costStats.calculateStatistics();
        flowTimeStats.calculateStatistics();
        effectiveStats.calculateStatistics();
        waitingStats.calculateStatistics();
        offTimeStats.calculateStatistics();
        processCost.addContent(costStats.getStatsAsElements());
        processFlowTime.addContent(flowTimeStats.getStatsAsElements());
        processEffectiveTime.addContent(effectiveStats.getStatsAsElements());
        processWaitingTime.addContent(waitingStats.getStatsAsElements());
        processOffTime.addContent(offTimeStats.getStatsAsElements());
        Map<String, Map<String, StatisticsTaskInstanceObject>> statsPerTaskOfProcess = statsPerTask.get(processId);
        // add activities
        for (String processScopeNodeId : statsPerTaskOfProcess.keySet()) {
            long taskDuration = 0;
            for (StatisticsTaskInstanceObject instance : statsPerTaskOfProcess.get(processScopeNodeId).values()) {
                taskDuration += instance.getDurationEffective();
            }
            // skip tasks with zero duration (which are most likely events)
            if (taskDuration == 0)
                continue;
            StatisticsCalculationObject taskCostStats = new StatisticsCalculationObject();
            StatisticsCalculationObject taskDurationStats = new StatisticsCalculationObject();
            StatisticsCalculationObject taskWaitingStats = new StatisticsCalculationObject();
            StatisticsCalculationObject taskResourcesIdleStats = new StatisticsCalculationObject();
            Map<String, StatisticsTaskInstanceObject> statsPerTaskInstance = statsPerTaskOfProcess.get(processScopeNodeId);
            String taskName = "";
            Element activity = new Element("activity");
            processActivities.addContent(activity);
            activity.addContent(new Element("id").setText(processScopeNodeId));
            Element activityName = new Element("name");
            Element activityCost = new Element("cost");
            Element activityTime = new Element("time");
            Element activityInstances = new Element("instances");
            activity.addContent(activityName);
            activity.addContent(activityCost);
            activity.addContent(activityTime);
            activity.addContent(activityInstances);
            Element activityDurationTime = new Element("duration");
            Element activityWaitingTime = new Element("waiting");
            Element activityResourcesIdleTime = new Element("resources_idle");
            activityTime.addContent(activityDurationTime);
            activityTime.addContent(activityWaitingTime);
            activityTime.addContent(activityResourcesIdleTime);
            // add activity instances
            for (String taskInstanceId : statsPerTaskInstance.keySet()) {
                StatisticsTaskInstanceObject stats = statsPerTaskInstance.get(taskInstanceId);
                if (taskName.isEmpty()) {
                    taskName = stats.getTaskName();
                }
                long durationEffective = stats.getDurationEffective();
                long durationResourcesIdle = stats.getDurationResourcesIdle();
                long durationWaiting = stats.getDurationWaiting();
                double cost = stats.getCost();
                Element activityInstance = new Element("instance");
                activityInstances.addContent(activityInstance);
                activityInstance.addContent(new Element("cost").setText(String.valueOf(cost)));
                Element activityInstanceTime = new Element("time");
                activityInstanceTime.addContent(new Element("effective").setText(String.valueOf(durationEffective)));
                activityInstanceTime.addContent(new Element("waiting").setText(String.valueOf(durationWaiting)));
                activityInstanceTime.addContent(new Element("resources_idle").setText(String.valueOf(durationResourcesIdle)));
                activityInstance.addContent(activityInstanceTime);
                taskCostStats.addValue(cost);
                taskDurationStats.addValue(durationEffective);
                taskWaitingStats.addValue(durationWaiting);
                taskResourcesIdleStats.addValue(durationResourcesIdle);
            }
            activityName.setText(taskName);
            taskCostStats.calculateStatistics();
            taskDurationStats.calculateStatistics();
            taskWaitingStats.calculateStatistics();
            taskResourcesIdleStats.calculateStatistics();
            activityCost.addContent(taskCostStats.getStatsAsElements());
            activityDurationTime.addContent(taskDurationStats.getStatsAsElements());
            activityWaitingTime.addContent(taskWaitingStats.getStatsAsElements());
            activityResourcesIdleTime.addContent(taskResourcesIdleStats.getStatsAsElements());
        }
        // add resources
        for (String resourceType : statsPerResource.keySet()) {
            Map<String, StatisticsResourceObject> statsPerResourceInstance = statsPerResource.get(resourceType);
            Element resource = new Element("resource");
            resources.addContent(resource);
            resource.addContent(new Element("type").setText(resourceType));
            Element resourceCost = new Element("cost");
            Element resourceTime = new Element("time");
            Element resourceInstances = new Element("instances");
            resource.addContent(resourceCost);
            resource.addContent(resourceTime);
            resource.addContent(resourceInstances);
            Element resourceInUse = new Element("in_use");
            Element resourceAvailable = new Element("available");
            Element resourceWorkload = new Element("workload");
            resourceTime.addContent(resourceInUse);
            resourceTime.addContent(resourceAvailable);
            resourceTime.addContent(resourceWorkload);
            StatisticsCalculationObject resourceCostStats = new StatisticsCalculationObject();
            StatisticsCalculationObject resourceInUseStats = new StatisticsCalculationObject();
            StatisticsCalculationObject resourceAvailableStats = new StatisticsCalculationObject();
            StatisticsCalculationObject resourceWorkloadStats = new StatisticsCalculationObject();
            // add resource instances
            for (String resourceId : statsPerResourceInstance.keySet()) {
                StatisticsResourceObject stats = statsPerResourceInstance.get(resourceId);
                long durationInUse = stats.getDurationInUse();
                long durationAvailable = stats.getDurationAvailable();
                double percentageInUse = durationInUse / (double) durationAvailable;
                double cost = stats.getCosts();
                Element resourceInstance = new Element("instance");
                resourceInstances.addContent(resourceInstance);
                resourceInstance.addContent(new Element("id").setText(resourceId));
                resourceInstance.addContent(new Element("cost").setText(String.valueOf(cost)));
                Element resourceInstanceTime = new Element("time");
                resourceInstanceTime.addContent(new Element("in_use").setText(String.valueOf(durationInUse)));
                resourceInstanceTime.addContent(new Element("available").setText(String.valueOf(durationAvailable)));
                resourceInstanceTime.addContent(new Element("workload").setText(String.valueOf(percentageInUse)));
                resourceInstance.addContent(resourceInstanceTime);
                resourceCostStats.addValue(cost);
                resourceInUseStats.addValue(durationInUse);
                resourceAvailableStats.addValue(durationAvailable);
                resourceWorkloadStats.addValue(percentageInUse);
            }
            resourceCostStats.calculateStatistics();
            resourceInUseStats.calculateStatistics();
            resourceAvailableStats.calculateStatistics();
            resourceWorkloadStats.calculateStatistics();
            resourceCost.addContent(resourceCostStats.getStatsAsElements());
            resourceInUse.addContent(resourceInUseStats.getStatsAsElements());
            resourceAvailable.addContent(resourceAvailableStats.getStatsAsElements());
            resourceWorkload.addContent(resourceWorkloadStats.getStatsAsElements());
        }
    }
    // print
    String resourceUtilizationFileName = outputPathWithoutExtension + model.getGlobalConfiguration().getFileNameWithoutExtension() + "_resourceutilization.xml";
    FileOutputStream fos = new FileOutputStream(resourceUtilizationFileName);
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.output(doc, fos);
}
Also used : ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) XMLOutputter(org.jdom2.output.XMLOutputter) HashMap(java.util.HashMap) Element(org.jdom2.Element) Document(org.jdom2.Document) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) TimeUnit(java.util.concurrent.TimeUnit) ResourceStatus(de.hpi.bpt.scylla.logger.ResourceStatus) List(java.util.List) ResourceInfo(de.hpi.bpt.scylla.logger.ResourceInfo) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 9 with ProcessNodeInfo

use of de.hpi.bpt.scylla.logger.ProcessNodeInfo in project scylla by bptlab.

the class StatisticsLogger method writeToLog.

public void writeToLog(SimulationModel model, String outputPathWithoutExtension) throws IOException {
    TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
    double totalEndTime = model.presentTime().getTimeAsDouble(timeUnit);
    Map<String, Map<Integer, List<ProcessNodeInfo>>> processNodeInfos = model.getProcessNodeInfos();
    Map<String, Map<String, List<ResourceInfo>>> resourceInfos = model.getResourceInfos();
    Set<ResourceObject> resourceObjectsSet = QueueManager.getAllResourceObjects(model);
    Map<String, Double> costPerResourceInstance = new HashMap<String, Double>();
    Map<String, Map<String, ResourceObject>> resourceObjects = new HashMap<String, Map<String, ResourceObject>>();
    for (ResourceObject res : resourceObjectsSet) {
        String resourceName = res.getResourceType() + "_" + res.getId();
        TimeUnit timeUnitOfResource = res.getTimeUnit();
        TimeUnit referenceUnit = DateTimeUtils.getReferenceTimeUnit();
        double cost = res.getCost();
        double costInReferenceUnit = DateTimeUtils.convertCost(timeUnitOfResource, referenceUnit, cost);
        costPerResourceInstance.put(resourceName, costInReferenceUnit);
        String resourceType = res.getResourceType();
        if (!resourceObjects.containsKey(resourceType)) {
            resourceObjects.put(resourceType, new HashMap<String, ResourceObject>());
        }
        String resourceId = res.getId();
        resourceObjects.get(resourceType).put(resourceId, res);
    }
    // resource utilization
    Map<String, Map<String, StatisticsResourceObject>> statsPerResource = new HashMap<String, Map<String, StatisticsResourceObject>>();
    // double totalEndTime = 0;
    for (String resourceType : resourceInfos.keySet()) {
        Map<String, StatisticsResourceObject> statsPerResourceInstance = new HashMap<String, StatisticsResourceObject>();
        Map<String, List<ResourceInfo>> resourceInfosOfType = resourceInfos.get(resourceType);
        for (String resourceId : resourceInfosOfType.keySet()) {
            long durationInUse = 0;
            long durationInUseIdle = 0;
            long currentTime = 0;
            List<ResourceInfo> infosOfResource = resourceInfosOfType.get(resourceId);
            ResourceStatus previousStatus = null;
            for (ResourceInfo info : infosOfResource) {
                ResourceStatus status = info.getTransition();
                long timestamp = info.getTimestamp();
                // FREE <-> IN_USE <-> IN_USE_IDLE
                if (status == ResourceStatus.IN_USE) {
                    if (previousStatus == ResourceStatus.IN_USE_IDLE) {
                        durationInUseIdle += timestamp - currentTime;
                    }
                } else if (status == ResourceStatus.FREE || status == ResourceStatus.IN_USE_IDLE) {
                    durationInUse += timestamp - currentTime;
                } else {
                    DebugLogger.log("Resource transition type not supported: " + status);
                }
                currentTime = timestamp;
            // if (currentTime > totalEndTime) {
            // totalEndTime = currentTime;
            // }
            }
            long durationAvailable = DateTimeUtils.getAvailabilityTime(resourceObjects.get(resourceType).get(resourceId).getTimetable(), new TimeInstant(totalEndTime));
            String resourceName = resourceType + "_" + resourceId;
            Double costPerUnit = costPerResourceInstance.get(resourceName);
            double costs = durationAvailable * costPerUnit;
            StatisticsResourceObject sro = new StatisticsResourceObject();
            sro.setDurationAvailable(durationAvailable);
            sro.setDurationInUse(durationInUse);
            // for total available time
            sro.setCosts(costs);
            sro.setDurationInUseIdle(durationInUseIdle);
            statsPerResourceInstance.put(resourceId, sro);
        }
        statsPerResource.put(resourceType, statsPerResourceInstance);
    }
    // process time with and without off-timetable hours (= idle time)
    // process waiting time
    // process costs
    // task duration
    // task waiting time
    Map<String, Map<Integer, StatisticsProcessInstanceObject>> statsPerProcess = new HashMap<String, Map<Integer, StatisticsProcessInstanceObject>>();
    Map<String, Map<String, Map<String, StatisticsTaskInstanceObject>>> statsPerTask = new HashMap<String, Map<String, Map<String, StatisticsTaskInstanceObject>>>();
    for (String processId : processNodeInfos.keySet()) {
        Map<Integer, StatisticsProcessInstanceObject> statsPerProcessInstance = new HashMap<Integer, StatisticsProcessInstanceObject>();
        Map<String, Map<String, StatisticsTaskInstanceObject>> statsPerTaskOfProcess = new HashMap<String, Map<String, StatisticsTaskInstanceObject>>();
        Map<Integer, List<ProcessNodeInfo>> nodeInfoOfProcessInstances = processNodeInfos.get(processId);
        for (int processInstanceId : nodeInfoOfProcessInstances.keySet()) {
            List<ProcessNodeInfo> nodeInfoList = nodeInfoOfProcessInstances.get(processInstanceId);
            long durationTotal = 0;
            long durationInactive = 0;
            long durationResourcesIdle = 0;
            long durationWaiting = 0;
            double costs = 0;
            Long previousTimestamp = null;
            long timeProcessStart = 0;
            Map<TaskInstanceIdentifier, Long> taskDurations = new HashMap<TaskInstanceIdentifier, Long>();
            Map<TaskInstanceIdentifier, Long> begunOrResumedTasks = new HashMap<TaskInstanceIdentifier, Long>();
            Map<TaskInstanceIdentifier, Long> enabledTasks = new HashMap<TaskInstanceIdentifier, Long>();
            Map<TaskInstanceIdentifier, Long> pausedTasks = new HashMap<TaskInstanceIdentifier, Long>();
            for (int i = 0; i < nodeInfoList.size(); i++) {
                String taskInstanceId = String.valueOf(i);
                long taskDurationEffective = 0;
                long taskDurationResourcesIdle = 0;
                long taskDurationWaiting = 0;
                double taskCosts = 0;
                ProcessNodeInfo ni = nodeInfoList.get(i);
                long timestamp = ni.getTimestamp();
                String processScopeNodeId = ni.getProcessScopeNodeId();
                String source = ni.getSource();
                TaskInstanceIdentifier taskInstanceIdentifier = new TaskInstanceIdentifier(processScopeNodeId, source);
                Set<String> resources = ni.getResources();
                String taskName = ni.getTaskName();
                StatisticsTaskInstanceObject stio = new StatisticsTaskInstanceObject(taskName);
                if (i == 0) {
                    previousTimestamp = timestamp;
                    timeProcessStart = timestamp;
                } else if (i == nodeInfoList.size() - 1) {
                    durationTotal = timestamp - timeProcessStart;
                }
                ProcessNodeTransitionType transition = ni.getTransition();
                if (begunOrResumedTasks.isEmpty()) {
                    durationInactive += timestamp - previousTimestamp;
                }
                if (transition == ProcessNodeTransitionType.ENABLE) {
                    enabledTasks.put(taskInstanceIdentifier, timestamp);
                } else if (transition == ProcessNodeTransitionType.BEGIN) {
                    Long enableTimestamp = enabledTasks.get(taskInstanceIdentifier);
                    if (enableTimestamp != null) {
                        long duration = timestamp - enableTimestamp;
                        durationWaiting += duration;
                        taskDurationWaiting += duration;
                        enabledTasks.remove(taskInstanceIdentifier);
                    }
                    taskDurations.put(taskInstanceIdentifier, 0L);
                    begunOrResumedTasks.put(taskInstanceIdentifier, timestamp);
                } else if (transition == ProcessNodeTransitionType.PAUSE) {
                    pausedTasks.put(taskInstanceIdentifier, timestamp);
                    Long beginOrResumeTimestamp = begunOrResumedTasks.get(taskInstanceIdentifier);
                    long duration = timestamp - beginOrResumeTimestamp;
                    for (String resourceName : resources) {
                        Double costPerUnit = costPerResourceInstance.get(resourceName);
                        costs += duration * costPerUnit;
                        taskCosts += duration * costPerUnit;
                    }
                    taskDurations.put(taskInstanceIdentifier, taskDurations.get(taskInstanceIdentifier) + duration);
                    begunOrResumedTasks.remove(taskInstanceIdentifier);
                } else if (transition == ProcessNodeTransitionType.RESUME) {
                    Long pauseTimestamp = pausedTasks.get(taskInstanceIdentifier);
                    long duration = timestamp - pauseTimestamp;
                    durationResourcesIdle += duration;
                    taskDurationResourcesIdle += duration;
                    pausedTasks.remove(taskInstanceIdentifier);
                    begunOrResumedTasks.put(taskInstanceIdentifier, timestamp);
                } else if (transition == ProcessNodeTransitionType.TERMINATE || transition == ProcessNodeTransitionType.CANCEL) {
                    Long beginOrResumeTimestamp = begunOrResumedTasks.get(taskInstanceIdentifier);
                    long duration = timestamp - beginOrResumeTimestamp;
                    for (String resourceName : resources) {
                        Double costPerUnit = costPerResourceInstance.get(resourceName);
                        costs += duration * costPerUnit;
                        taskCosts += duration * costPerUnit;
                    }
                    taskDurationEffective = taskDurations.get(taskInstanceIdentifier) + duration;
                    taskDurations.remove(taskInstanceIdentifier);
                    begunOrResumedTasks.remove(taskInstanceIdentifier);
                } else if (transition == ProcessNodeTransitionType.EVENT_BEGIN || transition == ProcessNodeTransitionType.EVENT_TERMINATE) {
                // not supported
                }
                stio.setDurationEffective(taskDurationEffective);
                stio.setDurationResourcesIdle(taskDurationResourcesIdle);
                stio.setDurationWaiting(taskDurationWaiting);
                stio.setCost(taskCosts);
                if (!statsPerTaskOfProcess.containsKey(processScopeNodeId)) {
                    statsPerTaskOfProcess.put(processScopeNodeId, new HashMap<String, StatisticsTaskInstanceObject>());
                }
                statsPerTaskOfProcess.get(processScopeNodeId).put(taskInstanceId, stio);
                previousTimestamp = ni.getTimestamp();
            }
            StatisticsProcessInstanceObject spio = new StatisticsProcessInstanceObject();
            spio.setDurationTotal(durationTotal);
            spio.setDurationInactive(durationInactive);
            spio.setDurationResourcesIdle(durationResourcesIdle);
            spio.setDurationWaiting(durationWaiting);
            spio.setCosts(costs);
            statsPerProcessInstance.put(processInstanceId, spio);
        }
        statsPerProcess.put(processId, statsPerProcessInstance);
        statsPerTask.put(processId, statsPerTaskOfProcess);
    }
    // build xml document
    Element resourceUtilization = new Element("resourceUtilization");
    Document doc = new Document(resourceUtilization);
    Element configuration = new Element("configuration");
    Element processes = new Element("processes");
    Element resources = new Element("resources");
    doc.getRootElement().addContent(configuration);
    doc.getRootElement().addContent(processes);
    doc.getRootElement().addContent(resources);
    configuration.addContent(new Element("time_unit").setText(String.valueOf(DateTimeUtils.getReferenceTimeUnit())));
    // add processes
    for (String processId : statsPerProcess.keySet()) {
        Map<Integer, StatisticsProcessInstanceObject> statsPerProcessInstance = statsPerProcess.get(processId);
        Element process = new Element("process");
        processes.addContent(process);
        process.addContent(new Element("id").setText(processId));
        Element processCost = new Element("cost");
        Element processTime = new Element("time");
        Element processInstances = new Element("instances");
        Element processActivities = new Element("activities");
        process.addContent(processCost);
        process.addContent(processTime);
        process.addContent(processInstances);
        process.addContent(processActivities);
        Element processFlowTime = new Element("flow_time");
        Element processEffectiveTime = new Element("effective");
        Element processWaitingTime = new Element("waiting");
        Element processOffTime = new Element("off_timetable");
        processTime.addContent(processFlowTime);
        processTime.addContent(processEffectiveTime);
        processTime.addContent(processWaitingTime);
        processTime.addContent(processOffTime);
        StatisticsCalculationObject costStats = new StatisticsCalculationObject();
        StatisticsCalculationObject flowTimeStats = new StatisticsCalculationObject();
        StatisticsCalculationObject effectiveStats = new StatisticsCalculationObject();
        StatisticsCalculationObject offTimeStats = new StatisticsCalculationObject();
        StatisticsCalculationObject waitingStats = new StatisticsCalculationObject();
        // add process instances
        for (Integer processInstanceId : statsPerProcessInstance.keySet()) {
            StatisticsProcessInstanceObject stats = statsPerProcessInstance.get(processInstanceId);
            long durationTotal = stats.getDurationTotal();
            long durationEffective = durationTotal - stats.getDurationInactive();
            long durationResourcesIdle = stats.getDurationResourcesIdle();
            long durationWaiting = stats.getDurationWaiting();
            double cost = stats.getCosts();
            Element instance = new Element("instance");
            processInstances.addContent(instance);
            instance.addContent(new Element("costs").setText(String.valueOf(cost)));
            Element instanceTime = new Element("time");
            instanceTime.addContent(new Element("duration").setText(String.valueOf(durationTotal)));
            instanceTime.addContent(new Element("effective").setText(String.valueOf(durationEffective)));
            instanceTime.addContent(new Element("waiting").setText(String.valueOf(durationWaiting)));
            instanceTime.addContent(new Element("offTime").setText(String.valueOf(durationResourcesIdle)));
            instance.addContent(instanceTime);
            costStats.addValue(cost);
            flowTimeStats.addValue(durationTotal);
            effectiveStats.addValue(durationEffective);
            offTimeStats.addValue(durationResourcesIdle);
            waitingStats.addValue(durationWaiting);
        }
        costStats.calculateStatistics();
        flowTimeStats.calculateStatistics();
        effectiveStats.calculateStatistics();
        waitingStats.calculateStatistics();
        offTimeStats.calculateStatistics();
        processCost.addContent(costStats.getStatsAsElements());
        processFlowTime.addContent(flowTimeStats.getStatsAsElements());
        processEffectiveTime.addContent(effectiveStats.getStatsAsElements());
        processWaitingTime.addContent(waitingStats.getStatsAsElements());
        processOffTime.addContent(offTimeStats.getStatsAsElements());
        Map<String, Map<String, StatisticsTaskInstanceObject>> statsPerTaskOfProcess = statsPerTask.get(processId);
        // add activities
        for (String processScopeNodeId : statsPerTaskOfProcess.keySet()) {
            long taskDuration = 0;
            for (StatisticsTaskInstanceObject instance : statsPerTaskOfProcess.get(processScopeNodeId).values()) {
                taskDuration += instance.getDurationEffective();
            }
            // skip tasks with zero duration (which are most likely events)
            if (taskDuration == 0)
                continue;
            StatisticsCalculationObject taskCostStats = new StatisticsCalculationObject();
            StatisticsCalculationObject taskDurationStats = new StatisticsCalculationObject();
            StatisticsCalculationObject taskWaitingStats = new StatisticsCalculationObject();
            StatisticsCalculationObject taskResourcesIdleStats = new StatisticsCalculationObject();
            Map<String, StatisticsTaskInstanceObject> statsPerTaskInstance = statsPerTaskOfProcess.get(processScopeNodeId);
            String taskName = "";
            Element activity = new Element("activity");
            processActivities.addContent(activity);
            activity.addContent(new Element("id").setText(processScopeNodeId));
            Element activityName = new Element("name");
            Element activityCost = new Element("cost");
            Element activityTime = new Element("time");
            Element activityInstances = new Element("instances");
            activity.addContent(activityName);
            activity.addContent(activityCost);
            activity.addContent(activityTime);
            activity.addContent(activityInstances);
            Element activityDurationTime = new Element("duration");
            Element activityWaitingTime = new Element("waiting");
            Element activityResourcesIdleTime = new Element("resources_idle");
            activityTime.addContent(activityDurationTime);
            activityTime.addContent(activityWaitingTime);
            activityTime.addContent(activityResourcesIdleTime);
            // add activity instances
            for (String taskInstanceId : statsPerTaskInstance.keySet()) {
                StatisticsTaskInstanceObject stats = statsPerTaskInstance.get(taskInstanceId);
                if (taskName.isEmpty()) {
                    taskName = stats.getTaskName();
                }
                long durationEffective = stats.getDurationEffective();
                long durationResourcesIdle = stats.getDurationResourcesIdle();
                long durationWaiting = stats.getDurationWaiting();
                double cost = stats.getCost();
                Element activityInstance = new Element("instance");
                activityInstances.addContent(activityInstance);
                activityInstance.addContent(new Element("cost").setText(String.valueOf(cost)));
                Element activityInstanceTime = new Element("time");
                activityInstanceTime.addContent(new Element("effective").setText(String.valueOf(durationEffective)));
                activityInstanceTime.addContent(new Element("waiting").setText(String.valueOf(durationWaiting)));
                activityInstanceTime.addContent(new Element("resources_idle").setText(String.valueOf(durationResourcesIdle)));
                activityInstance.addContent(activityInstanceTime);
                taskCostStats.addValue(cost);
                taskDurationStats.addValue(durationEffective);
                taskWaitingStats.addValue(durationWaiting);
                taskResourcesIdleStats.addValue(durationResourcesIdle);
            }
            activityName.setText(taskName);
            taskCostStats.calculateStatistics();
            taskDurationStats.calculateStatistics();
            taskWaitingStats.calculateStatistics();
            taskResourcesIdleStats.calculateStatistics();
            activityCost.addContent(taskCostStats.getStatsAsElements());
            activityDurationTime.addContent(taskDurationStats.getStatsAsElements());
            activityWaitingTime.addContent(taskWaitingStats.getStatsAsElements());
            activityResourcesIdleTime.addContent(taskResourcesIdleStats.getStatsAsElements());
        }
        // add resources
        for (String resourceType : statsPerResource.keySet()) {
            Map<String, StatisticsResourceObject> statsPerResourceInstance = statsPerResource.get(resourceType);
            Element resource = new Element("resource");
            resources.addContent(resource);
            resource.addContent(new Element("type").setText(resourceType));
            Element resourceCost = new Element("cost");
            Element resourceTime = new Element("time");
            Element resourceInstances = new Element("instances");
            resource.addContent(resourceCost);
            resource.addContent(resourceTime);
            resource.addContent(resourceInstances);
            Element resourceInUse = new Element("in_use");
            Element resourceAvailable = new Element("available");
            Element resourceWorkload = new Element("workload");
            resourceTime.addContent(resourceInUse);
            resourceTime.addContent(resourceAvailable);
            resourceTime.addContent(resourceWorkload);
            StatisticsCalculationObject resourceCostStats = new StatisticsCalculationObject();
            StatisticsCalculationObject resourceInUseStats = new StatisticsCalculationObject();
            StatisticsCalculationObject resourceAvailableStats = new StatisticsCalculationObject();
            StatisticsCalculationObject resourceWorkloadStats = new StatisticsCalculationObject();
            // add resource instances
            for (String resourceId : statsPerResourceInstance.keySet()) {
                StatisticsResourceObject stats = statsPerResourceInstance.get(resourceId);
                long durationInUse = stats.getDurationInUse();
                long durationAvailable = stats.getDurationAvailable();
                double percentageInUse = durationInUse / (double) durationAvailable;
                double cost = stats.getCosts();
                Element resourceInstance = new Element("instance");
                resourceInstances.addContent(resourceInstance);
                resourceInstance.addContent(new Element("id").setText(resourceId));
                resourceInstance.addContent(new Element("cost").setText(String.valueOf(cost)));
                Element resourceInstanceTime = new Element("time");
                resourceInstanceTime.addContent(new Element("in_use").setText(String.valueOf(durationInUse)));
                resourceInstanceTime.addContent(new Element("available").setText(String.valueOf(durationAvailable)));
                resourceInstanceTime.addContent(new Element("workload").setText(String.valueOf(percentageInUse)));
                resourceInstance.addContent(resourceInstanceTime);
                resourceCostStats.addValue(cost);
                resourceInUseStats.addValue(durationInUse);
                resourceAvailableStats.addValue(durationAvailable);
                resourceWorkloadStats.addValue(percentageInUse);
            }
            resourceCostStats.calculateStatistics();
            resourceInUseStats.calculateStatistics();
            resourceAvailableStats.calculateStatistics();
            resourceWorkloadStats.calculateStatistics();
            resourceCost.addContent(resourceCostStats.getStatsAsElements());
            resourceInUse.addContent(resourceInUseStats.getStatsAsElements());
            resourceAvailable.addContent(resourceAvailableStats.getStatsAsElements());
            resourceWorkload.addContent(resourceWorkloadStats.getStatsAsElements());
        }
    }
    // print
    String resourceUtilizationFileName = outputPathWithoutExtension + model.getGlobalConfiguration().getFileNameWithoutExtension() + "_resourceutilization.xml";
    FileOutputStream fos = new FileOutputStream(resourceUtilizationFileName);
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.output(doc, fos);
}
Also used : ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) XMLOutputter(org.jdom2.output.XMLOutputter) HashMap(java.util.HashMap) Element(org.jdom2.Element) Document(org.jdom2.Document) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) TimeUnit(java.util.concurrent.TimeUnit) ResourceStatus(de.hpi.bpt.scylla.logger.ResourceStatus) List(java.util.List) ResourceInfo(de.hpi.bpt.scylla.logger.ResourceInfo) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 10 with ProcessNodeInfo

use of de.hpi.bpt.scylla.logger.ProcessNodeInfo in project scylla by bptlab.

the class SimulationModel method addNodeInfo.

public boolean addNodeInfo(ProcessModel processModel, ProcessInstance processInstance, ProcessNodeInfo nodeInfo) {
    String processId = processModel.getId();
    ProcessModel parent = processModel.getParent();
    while (parent != null) {
        processId = parent.getId();
        parent = parent.getParent();
    }
    int processInstanceId = processInstance.getId();
    if (!processNodeInfos.containsKey(processId)) {
        processNodeInfos.put(processId, new TreeMap<Integer, List<ProcessNodeInfo>>());
    }
    Map<Integer, List<ProcessNodeInfo>> nodeInfosOfProcess = processNodeInfos.get(processId);
    if (!nodeInfosOfProcess.containsKey(processInstanceId)) {
        nodeInfosOfProcess.put(processInstanceId, new ArrayList<ProcessNodeInfo>());
    }
    return nodeInfosOfProcess.get(processInstanceId).add(nodeInfo);
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ArrayList(java.util.ArrayList) List(java.util.List) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo)

Aggregations

ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)17 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)13 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)13 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)9 ResourceObject (de.hpi.bpt.scylla.simulation.ResourceObject)7 HashSet (java.util.HashSet)6 List (java.util.List)6 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)3 ResourceInfo (de.hpi.bpt.scylla.logger.ResourceInfo)3 ResourceStatus (de.hpi.bpt.scylla.logger.ResourceStatus)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)3 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)3 TimeInstant (desmoj.core.simulator.TimeInstant)3 FileOutputStream (java.io.FileOutputStream)3 ZonedDateTime (java.time.ZonedDateTime)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2