Search in sources :

Example 6 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class ExclusiveGatewayEventPlugin method scheduleNextEvent.

private void scheduleNextEvent(GatewayEvent desmojEvent, ProcessInstance processInstance, ProcessModel processModel, Integer nextFlowId) {
    Set<Integer> nodeIds = null;
    try {
        nodeIds = processModel.getTargetObjectIds(nextFlowId);
    } catch (NodeNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (nodeIds.size() != 1) {
        try {
            throw new ScyllaValidationException("Flow " + nextFlowId + " does not connect to 1 node, but" + nodeIds.size() + " .");
        } catch (ScyllaValidationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    int nextNodeId = nodeIds.iterator().next();
    Map<Integer, ScyllaEvent> nextEventMap = desmojEvent.getNextEventMap();
    List<Integer> indicesOfEventsToKeep = new ArrayList<Integer>();
    for (int index : nextEventMap.keySet()) {
        ScyllaEvent eventCandidate = nextEventMap.get(index);
        int nodeIdOfCandidate = eventCandidate.getNodeId();
        if (nodeIdOfCandidate == nextNodeId) {
            indicesOfEventsToKeep.add(index);
            break;
        }
    }
    Map<Integer, TimeSpan> timeSpanToNextEventMap = desmojEvent.getTimeSpanToNextEventMap();
    nextEventMap.keySet().retainAll(indicesOfEventsToKeep);
    timeSpanToNextEventMap.keySet().retainAll(indicesOfEventsToKeep);
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ArrayList(java.util.ArrayList) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent)

Example 7 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class ProcessInstance method cancel.

// public double getTimeRelativeToSubProcessStart() {
// return timeRelativeToSubProcessStart;
// }
// 
// public void setTimeRelativeToSubProcessStart(double timeRelativeToSubProcessStart) {
// this.timeRelativeToSubProcessStart = timeRelativeToSubProcessStart;
// }
// 
// public Double getEndTimeRelativeToSubProcessStart() {
// return endTimeRelativeToSubProcessStart;
// }
// 
// public void setEndTimeRelativeToSubProcessStart(Double endTimeRelativeToSubProcessStart) {
// this.endTimeRelativeToSubProcessStart = endTimeRelativeToSubProcessStart;
// }
@Override
public void cancel() {
    try {
        Iterator<String> iterator = children.keySet().iterator();
        while (iterator.hasNext()) {
            String name = iterator.next();
            ProcessInstance child = children.get(name);
            child.cancel();
        }
        if (isScheduled()) {
            List<EventAbstract> scheduledEvents = getScheduledEvents();
            List<ScyllaEvent> rescheduledEvents = new ArrayList<ScyllaEvent>();
            for (EventAbstract e : scheduledEvents) {
                if (e instanceof TaskEvent) {
                    TaskEvent event = (TaskEvent) e;
                    TaskCancelEvent cancelEvent = new TaskCancelEvent(event.getModel(), event.getSource(), event.getSimulationTimeOfSource(), event.getDesmojObjects(), this, event.getNodeId());
                    rescheduledEvents.add(cancelEvent);
                }
            }
            super.cancel();
            for (ScyllaEvent event : rescheduledEvents) {
                TimeSpan timeSpan = new TimeSpan(0);
                SimulationUtils.scheduleEvent(event, timeSpan);
            }
        }
        if (parent != null) {
            parent.removeChild(this);
        }
    } catch (ScyllaRuntimeException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ArrayList(java.util.ArrayList) TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) TaskEvent(de.hpi.bpt.scylla.simulation.event.TaskEvent) EventAbstract(desmoj.core.simulator.EventAbstract)

Example 8 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class SimulationModel method doInitialSchedules.

@Override
public void doInitialSchedules() {
    TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
    for (String processId : pSimMap.keySet()) {
        ProcessSimulationComponents desmojObj = pSimMap.get(processId);
        // schedule for end of simulation (if defined), aligned to global start time
        ZonedDateTime endDateOfSimulationConf = desmojObj.getSimulationConfiguration().getEndDateTime();
        Long endTimeRelativeToGlobalStart = Long.MAX_VALUE;
        if (endDateOfSimulationConf != null) {
            endTimeRelativeToGlobalStart = DateTimeUtils.getDuration(startDateTime, endDateOfSimulationConf);
            ProcessSimulationStopEvent endEvent = new ProcessSimulationStopEvent(this, processId, traceIsOn());
            // java.util.Date getTime() returns milliseconds
            endEvent.schedule(new TimeSpan(endTimeRelativeToGlobalStart, timeUnit));
        }
        // schedule for start of simulation, aligned to global start time
        ZonedDateTime startDateOfSimulationConf = desmojObj.getSimulationConfiguration().getStartDateTime();
        long startTimeRelativeToGlobalStart = DateTimeUtils.getDuration(startDateTime, startDateOfSimulationConf);
        ProcessModel processModel = desmojObj.getProcessModel();
        int processInstanceId = desmojObj.incrementProcessInstancesStarted();
        ProcessInstance firstProcessInstance = new ProcessInstance(this, processModel, processInstanceId, traceIsOn());
        ProcessInstanceGenerationEvent startEvent = new ProcessInstanceGenerationEvent(this, processId, endTimeRelativeToGlobalStart, traceIsOn());
        startEvent.schedule(firstProcessInstance, new TimeSpan(startTimeRelativeToGlobalStart, timeUnit));
    }
    if (endDateTime != null) {
        // / java.util.Date getTime() returns milliseconds
        long simulationDuration = DateTimeUtils.getDuration(startDateTime, endDateTime);
        TimeInstant timeInstant = new TimeInstant(simulationDuration, DateTimeUtils.getReferenceTimeUnit());
        for (String processId : pSimMap.keySet()) {
            ProcessSimulationStopEvent abortEvent = new ProcessSimulationStopEvent(this, processId, traceIsOn());
            abortEvent.schedule(timeInstant);
        }
    }
}
Also used : ProcessInstanceGenerationEvent(de.hpi.bpt.scylla.simulation.event.ProcessInstanceGenerationEvent) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessSimulationStopEvent(de.hpi.bpt.scylla.simulation.event.ProcessSimulationStopEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ZonedDateTime(java.time.ZonedDateTime) TimeUnit(java.util.concurrent.TimeUnit) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 9 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class GatewayEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    try {
        Set<Integer> idsOfPreviousNodes = processModel.getIdsOfPreviousNodes(nodeId);
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        String message = null;
        GatewayType type = processModel.getGateways().get(nodeId);
        String convergeDivergeName = "Join and Split";
        if (idsOfPreviousNodes.size() == 1) {
            convergeDivergeName = "Split";
        } else if (idsOfNextNodes.size() == 1) {
            convergeDivergeName = "Join";
        }
        if (type == GatewayType.DEFAULT) {
            message = "Default " + convergeDivergeName + " Gateway: " + displayName;
        }
        if (type == GatewayType.EXCLUSIVE) {
            message = "Exclusive " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.EVENT_BASED) {
            message = "Eventbased " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.INCLUSIVE) {
            message = "Inclusive " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.PARALLEL) {
            message = "Parallel " + convergeDivergeName + " Gateway: " + displayName;
        } else if (type == GatewayType.COMPLEX) {
            message = "Complex " + convergeDivergeName + " Gateway: " + displayName;
        } else {
            // TODO write to log because element not supported
            SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
            return;
        }
        sendTraceNote(message);
        // i.e. for splits: default behavior is the one of a parallel gateway
        for (Integer nextNodeId : idsOfNextNodes) {
            List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
            // next DesmoJ event occurs immediately after start event
            TimeSpan timeSpan = new TimeSpan(0);
            for (ScyllaEvent event : events) {
                int index = getNewEventIndex();
                nextEventMap.put(index, event);
                timeSpanToNextEventMap.put(index, timeSpan);
            }
        }
        GatewayEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
    } catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
        return;
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 10 with TimeSpan

use of desmoj.core.simulator.TimeSpan in project scylla by bptlab.

the class ResourceAvailabilityEvent method eventRoutine.

@Override
public void eventRoutine() throws SuspendExecution {
    SimulationModel model = (SimulationModel) getModel();
    TimeInstant currentSimulationTime = model.presentTime();
    Set<String> resourceQueuesUpdated = new HashSet<String>();
    String resourceType = resourceObject.getResourceType();
    resourceQueuesUpdated.add(resourceType);
    try {
        ScyllaEvent eventFromQueue = QueueManager.getEventFromQueueReadyForSchedule(model, resourceQueuesUpdated);
        while (eventFromQueue != null) {
            SimulationUtils.scheduleEvent(eventFromQueue, new TimeSpan(0));
            eventFromQueue = QueueManager.getEventFromQueueReadyForSchedule(model, resourceQueuesUpdated);
        }
        ResourceAvailabilityEventPluggable.runPlugins(this);
        // schedule next ResourceAvailableEvent
        ZonedDateTime currentDateTime = DateTimeUtils.getDateTime(currentSimulationTime);
        boolean currentlyInTimetableItem = true;
        SimulationUtils.scheduleNextResourceAvailableEvent(model, resourceObject, currentDateTime, currentlyInTimetableItem);
    } catch (ScyllaRuntimeException e) {
        throw new RuntimeException(e);
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ZonedDateTime(java.time.ZonedDateTime) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant) HashSet(java.util.HashSet)

Aggregations

TimeSpan (desmoj.core.simulator.TimeSpan)34 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)25 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)17 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)15 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)12 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)11 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)11 TimeUnit (java.util.concurrent.TimeUnit)11 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)10 TimeInstant (desmoj.core.simulator.TimeInstant)9 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)8 Map (java.util.Map)7 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)6 TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)5 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)3 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)3 TaskType (de.hpi.bpt.scylla.model.process.node.TaskType)3 Duration (java.time.Duration)3