1 package org.opentrafficsim.road.network.factory.xml.parser;
2
3 import java.util.LinkedHashMap;
4 import java.util.List;
5 import java.util.Map;
6
7 import javax.naming.NamingException;
8
9 import org.djunits.value.vdouble.scalar.Duration;
10 import org.djunits.value.vdouble.scalar.Time;
11 import org.opentrafficsim.core.dsol.OTSReplication;
12 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
13 import org.opentrafficsim.road.network.OTSRoadNetwork;
14 import org.opentrafficsim.road.network.factory.xml.XmlParserException;
15 import org.opentrafficsim.road.network.factory.xml.utils.StreamInformation;
16 import org.opentrafficsim.xml.generated.RANDOMSTREAM;
17 import org.opentrafficsim.xml.generated.RANDOMSTREAM.REPLICATION;
18 import org.opentrafficsim.xml.generated.RUN;
19
20 import nl.tudelft.simulation.dsol.experiment.Experiment;
21 import nl.tudelft.simulation.dsol.experiment.Treatment;
22 import nl.tudelft.simulation.jstats.streams.StreamInterface;
23
24
25
26
27
28
29
30
31
32 public final class RunParser
33 {
34
35 private RunParser()
36 {
37
38 }
39
40
41
42
43
44
45
46
47
48
49 public static Experiment.TimeDoubleUnit<OTSSimulatorInterface> parseRun(final OTSRoadNetwork otsNetwork, final RUN run,
50 final Map<String, StreamInformation> streamMap, final OTSSimulatorInterface simulator) throws XmlParserException
51 {
52 int numberReplications = run.getNUMBERREPLICATIONS() == null ? 1 : run.getNUMBERREPLICATIONS().intValue();
53 Time startTime = run.getSTARTTIME() == null ? Time.ZERO : run.getSTARTTIME();
54 Duration warmupPeriod = run.getWARMUPPERIOD() == null ? Duration.ZERO : run.getWARMUPPERIOD();
55 Duration runLength = run.getRUNLENGTH() == null ? Duration.ZERO : run.getRUNLENGTH();
56
57 Map<String, StreamInterface> streams = new LinkedHashMap<>();
58 if (run.getRANDOMSTREAMS() == null)
59 {
60 for (String streamId : new String[] {"default", "generation"})
61 {
62 Map<Integer, Long> seedMap = new LinkedHashMap<>();
63 for (int rep = 1; rep <= numberReplications; rep++)
64 {
65 seedMap.put(rep, (long) streamId.hashCode() + rep);
66 }
67 StreamInformationml/utils/StreamInformation.html#StreamInformation">StreamInformation streamInformation = new StreamInformation(streamId, seedMap);
68 streamMap.put(streamId, streamInformation);
69 streams.put(streamId, streamInformation.getStream());
70 }
71 }
72 else
73 {
74 List<RANDOMSTREAM> streamTags = run.getRANDOMSTREAMS().getRANDOMSTREAM();
75 for (RANDOMSTREAM streamTag : streamTags)
76 {
77 String streamId = streamTag.getID();
78 Map<Integer, Long> seedMap = new LinkedHashMap<>();
79 for (REPLICATION rep : streamTag.getREPLICATION())
80 {
81 seedMap.put(rep.getID().intValue(), rep.getSEED().longValue());
82 }
83 StreamInformationml/utils/StreamInformation.html#StreamInformation">StreamInformation streamInformation = new StreamInformation(streamId, seedMap);
84 streamMap.put(streamId, streamInformation);
85 streams.put(streamId, streamInformation.getStream());
86 }
87 }
88
89 Experiment.TimeDoubleUnit<OTSSimulatorInterface> experiment = new Experiment.TimeDoubleUnit<>();
90
91 Treatment.TimeDoubleUnit treatment = new Treatment.TimeDoubleUnit(experiment, "Treatment for " + otsNetwork.getId(),
92 startTime, warmupPeriod, runLength);
93 experiment.setTreatment(treatment);
94 for (
95
96 int replicationNr = 1; replicationNr <= numberReplications; replicationNr++)
97 {
98 try
99 {
100 OTSReplication replication = new OTSReplication("Replication " + replicationNr, experiment);
101 replication.setStreams(streams);
102
103 }
104 catch (NamingException exception)
105 {
106 throw new XmlParserException("Problems generating replicaton", exception);
107 }
108 }
109
110 return experiment;
111 }
112 }