1 package org.opentrafficsim.simulationengine;
2
3 import java.io.Serializable;
4
5 import javax.naming.NamingException;
6
7 import org.djunits.unit.TimeUnit;
8 import org.djunits.value.vdouble.scalar.Duration;
9 import org.djunits.value.vdouble.scalar.Time;
10 import org.opentrafficsim.core.dsol.OTSDEVSSimulator;
11 import org.opentrafficsim.core.dsol.OTSModelInterface;
12 import org.opentrafficsim.core.dsol.OTSReplication;
13 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
14
15 import nl.tudelft.simulation.dsol.SimRuntimeException;
16 import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
17 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent;
18
19
20
21
22
23
24
25
26
27
28
29 public class SimpleSimulator extends OTSDEVSSimulator implements SimpleSimulatorInterface, Serializable
30 {
31
32 private static final long serialVersionUID = 20150510L;
33
34
35 private int lastReplication = 0;
36
37
38
39
40
41
42
43
44
45
46
47 public SimpleSimulator(final Time startTime, final Duration warmupPeriod, final Duration runLength,
48 final OTSModelInterface model) throws SimRuntimeException, NamingException
49 {
50 setPauseOnError(true);
51 initialize(new OTSReplication("rep" + ++this.lastReplication, new OTSSimTimeDouble(startTime), warmupPeriod,
52 runLength, model), ReplicationMode.TERMINATING);
53 }
54
55
56
57
58 public final SimEvent<OTSSimTimeDouble> scheduleEvent(final Time executionTime, final short priority,
59 final Object source, final Object target, final String method, final Object[] args) throws SimRuntimeException
60 {
61 SimEvent<OTSSimTimeDouble> result =
62 new SimEvent<OTSSimTimeDouble>(new OTSSimTimeDouble(new Time(executionTime.getSI(), TimeUnit.SECOND)),
63 priority, source, target, method, args);
64 scheduleEvent(result);
65 return result;
66 }
67
68 }