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.base.modelproperties.PropertyException;
11 import org.opentrafficsim.core.dsol.OTSDEVSRealTimeClock;
12 import org.opentrafficsim.core.dsol.OTSModelInterface;
13 import org.opentrafficsim.core.dsol.OTSReplication;
14 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
15
16 import nl.tudelft.simulation.dsol.SimRuntimeException;
17 import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
18 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent;
19
20
21
22
23
24
25
26
27
28
29
30 public class SimpleAnimator extends OTSDEVSRealTimeClock implements SimpleSimulatorInterface, Serializable
31 {
32
33 private static final long serialVersionUID = 20150511L;
34
35
36 private int lastReplication = 0;
37
38
39
40
41
42
43
44
45
46
47
48
49 public SimpleAnimator(final Time startTime, final Duration warmupPeriod, final Duration runLength,
50 final OTSModelInterface model) throws SimRuntimeException, NamingException, PropertyException
51 {
52 setPauseOnError(true);
53 setAnimationDelay(20);
54 initialize(new OTSReplication("rep" + ++this.lastReplication, new OTSSimTimeDouble(startTime), warmupPeriod,
55 runLength, model), ReplicationMode.TERMINATING);
56 }
57
58
59
60
61 public final SimEvent<OTSSimTimeDouble> scheduleEvent(final Time executionTime, final short priority,
62 final Object source, final Object target, final String method, final Object[] args) throws SimRuntimeException
63 {
64 SimEvent<OTSSimTimeDouble> result =
65 new SimEvent<OTSSimTimeDouble>(new OTSSimTimeDouble(new Time(executionTime.getSI(), TimeUnit.SECOND)),
66 priority, source, target, method, args);
67 scheduleEvent(result);
68 return result;
69 }
70
71 }