averbraeck / opentrafficsim

Open Source Multi-Level Traffic Simulator
BSD 3-Clause "New" or "Revised" License
28 stars 8 forks source link

Enhance use of random streams in XML parsing #47

Closed WJSchakel closed 1 year ago

WJSchakel commented 1 year ago

In GeneratorSinkParser a default "generation" stream is used. It is used for: ROUTEMIX, SHORTESTROUTEMIX, IdmPlusFactory, Distribution<LaneBasedTemplateGtuType>, Generator<Duration> headwayGenerator and GeneratorPositions.create(...).

The GTUTEMPLATE tag has a distributed LENGTH, WIDTH and MAXSPEED that are each specified with an optional RANDOMSTREAM tag, defaulting to "default".

The GTUTEMPLATEMIX tag (currently not implemented, see issue #46) has a RANDOMSTREAM tag, defaulting to "generation".

In some places the input StreamInformation is used, in other cases the "generation" stream is directly taken from the simulator.

This all needs to be made consistent, and where needed, RANDOMSTREAM attributes need to be added in the XML specification. That should be part of issue #40.

WJSchakel commented 1 year ago

Random stream are now pointed to by type RandomStreamSource. This contains an option with 3 nodes: Default for the "default" stream, Generation for the "generation" stream, and Defined which has a value that points to a Run.RandomStreams.RandomStream. The value of Defined is checked with an xsd:keyref. This works on type level, which makes all separate checks for RouteMix, GtuTemplateMix etc. redundant.

The parser will parse all streams defined in Run.RandomStreams. If none are named "default", a stream with that id is added. The same holds for "generation".

WJSchakel commented 1 year ago

The Generator tag now has a RandomStream element. The resulting stream is used instead of all hard-coded cases above, except for elements that define their own random stream such as RouteMix. Such elements now use their specified random stream.