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.OTSModelInterface;
12 import org.opentrafficsim.core.dsol.OTSReplication;
13
14 import nl.tudelft.simulation.dsol.SimRuntimeException;
15 import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
16 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent;
17 import nl.tudelft.simulation.dsol.simtime.SimTimeDoubleUnit;
18 import nl.tudelft.simulation.dsol.simulators.DEVSRealTimeClock;
19
20
21
22
23
24
25
26
27
28
29
30 public class SimpleAnimator extends DEVSRealTimeClock.TimeDoubleUnit 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 SimTimeDoubleUnit(startTime), warmupPeriod, runLength,
55 model), ReplicationMode.TERMINATING);
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public SimpleAnimator(final Time startTime, final Duration warmupPeriod, final Duration runLength,
71 final OTSModelInterface model, final int replication) throws SimRuntimeException, NamingException, PropertyException
72 {
73 setPauseOnError(true);
74 setAnimationDelay(20);
75 initialize(new OTSReplication("rep" + replication, new SimTimeDoubleUnit(startTime), warmupPeriod, runLength, model),
76 ReplicationMode.TERMINATING);
77 }
78
79
80 @Override
81 public final SimEvent<SimTimeDoubleUnit> scheduleEvent(final Time executionTime, final short priority, final Object source,
82 final Object target, final String method, final Object[] args) throws SimRuntimeException
83 {
84 SimEvent<SimTimeDoubleUnit> result = new SimEvent<SimTimeDoubleUnit>(
85 new SimTimeDoubleUnit(new Time(executionTime.getSI(), TimeUnit.BASE)), priority, source, target, method, args);
86 scheduleEvent(result);
87 return result;
88 }
89
90 }