Search in sources :

Example 1 with NumericalDist

use of desmoj.core.dist.NumericalDist in project scylla by bptlab.

the class EventArrivalRateDistributionConversionPlugin method convertToDesmoJDistributions.

/**
 * Converts scylla distributions from extension to desmoJ distributions to be stored als distribution extension.
 * @see {@link de.hpi.bpt.scylla.simulation.utils.SimulationUtils#getDistribution(Distribution, SimulationModel, String, Integer, boolean, boolean)}
 */
@Override
public Map<Integer, Object> convertToDesmoJDistributions(ProcessSimulationComponents pSimComponents) {
    Map<Integer, Object> arrivalRateDistributions = new HashMap<Integer, Object>();
    SimulationConfiguration simulationConfiguration = pSimComponents.getSimulationConfiguration();
    Long randomSeed = simulationConfiguration.getRandomSeed();
    /**
     *Get saved extension from sc parser
     */
    @SuppressWarnings("unchecked") HashMap<Integer, TimeDistributionWrapper> arrivalRates = (HashMap<Integer, TimeDistributionWrapper>) simulationConfiguration.getExtensionValue(getName(), EventArrivalRatePluginUtils.ARRIVALRATES_KEY);
    ProcessModel processModel = pSimComponents.getProcessModel();
    SimulationModel model = pSimComponents.getModel();
    boolean showInReport = model.reportIsOn();
    boolean showInTrace = model.traceIsOn();
    for (Entry<Integer, TimeDistributionWrapper> entry : arrivalRates.entrySet()) {
        Integer nodeId = entry.getKey();
        TimeDistributionWrapper arrivalRate = entry.getValue();
        TimeUnit timeUnit = arrivalRate.getTimeUnit();
        Distribution distribution = arrivalRate.getDistribution();
        String name = processModel.getModelScopeId() + "_" + nodeId.toString();
        try {
            NumericalDist<?> desmojDist = SimulationUtils.getDistribution(distribution, model, name, nodeId, showInReport, showInTrace);
            desmojDist.setSeed(randomSeed);
            arrivalRateDistributions.put(nodeId, new SimpleEntry<NumericalDist<?>, TimeUnit>(desmojDist, timeUnit));
        } catch (InstantiationException e) {
            e.printStackTrace();
            continue;
        }
    }
    return arrivalRateDistributions;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) NumericalDist(desmoj.core.dist.NumericalDist) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Distribution(de.hpi.bpt.scylla.model.configuration.distribution.Distribution) TimeUnit(java.util.concurrent.TimeUnit) TimeDistributionWrapper(de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 2 with NumericalDist

use of desmoj.core.dist.NumericalDist in project scylla by bptlab.

the class EventArrivalRateSchedulingPlugin method scheduleEvent.

/**
 * Gets a sample of the arrival rate distribution for this event, if existing,
 * and schedules the event displaced by this value.
 */
@Override
public boolean scheduleEvent(ScyllaEvent event, TimeSpan timeSpan) throws ScyllaRuntimeException {
    ProcessSimulationComponents pSimComponents = event.getDesmojObjects();
    Map<Integer, Object> arrivalRates = pSimComponents.getExtensionDistributions().get(getName());
    @SuppressWarnings("unchecked") SimpleEntry<NumericalDist<?>, TimeUnit> arrivalRate = (SimpleEntry<NumericalDist<?>, TimeUnit>) arrivalRates.get(event.getNodeId());
    if (arrivalRate != null) {
        NumericalDist<?> distribution = arrivalRate.getKey();
        TimeUnit timeUnit = arrivalRate.getValue();
        ProcessInstance processInstance = event.getProcessInstance();
        TimeSpan offset = new TimeSpan(distribution.sample().doubleValue(), timeUnit);
        TimeSpan newTime = new TimeSpan(timeSpan.getTimeAsDouble() + offset.getTimeAsDouble());
        event.schedule(processInstance, newTime);
        return false;
    }
    return true;
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) NumericalDist(desmoj.core.dist.NumericalDist) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) SimpleEntry(java.util.AbstractMap.SimpleEntry) TimeUnit(java.util.concurrent.TimeUnit) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance)

Aggregations

NumericalDist (desmoj.core.dist.NumericalDist)2 TimeUnit (java.util.concurrent.TimeUnit)2 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)1 Distribution (de.hpi.bpt.scylla.model.configuration.distribution.Distribution)1 TimeDistributionWrapper (de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)1 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)1 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)1 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)1 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)1 TimeSpan (desmoj.core.simulator.TimeSpan)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 HashMap (java.util.HashMap)1