<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 
    <xs:element name="SimulationOutput">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="SceneryFile"/>
                <xs:element ref="RunResults"/>
            </xs:sequence>
            <xs:attribute type="xs:string" name="FrameworkVersion"/>
            <xs:attribute type="xs:string" name="SchemaVersion"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="SceneryFile" type="xs:NCName"/>
    <xs:element name="RunResults">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="RunResult" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="RunResult">
        <xs:complexType>
            <xs:all>
                <xs:element ref="RunStatistics"/>
                <xs:element ref="Events"/>
                <xs:element ref="Agents"/>
                <xs:element ref="Cyclics"/>
            </xs:all>
            <xs:attribute type="xs:nonNegativeInteger" name="RunId"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="RunStatistics">
        <xs:complexType>
            <xs:all>
                <xs:element ref="RandomSeed"/>
                <xs:element ref="VisibilityDistance"/>
                <xs:element ref="StopReason"/>
                <xs:element ref="StopTime"/>
                <xs:element ref="EgoAccident"/>
                <xs:element ref="TotalDistanceTraveled"/>
                <xs:element ref="EgoDistanceTraveled"/>
            </xs:all>
        </xs:complexType>
    </xs:element>
    <xs:element name="RandomSeed" type="xs:integer"/>
    <xs:element name="VisibilityDistance" type="xs:double"/>
    <xs:element name="StopReason" type="xs:string"/>
    <xs:element name="StopTime" type="xs:integer"/>
    <xs:element name="EgoAccident" type="xs:string"/>
    <xs:element name="TotalDistanceTraveled" type="xs:double"/>
    <xs:element name="EgoDistanceTraveled" type="xs:double"/>
    <xs:element name="Events">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Event" maxOccurs="unbounded" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Event">
        <xs:complexType>
            <xs:all>
                <xs:element ref="TriggeringEntities"/>
                <xs:element ref="AffectedEntities"/>
                <xs:element ref="Parameters"/>
            </xs:all>
            <xs:attribute type="xs:nonNegativeInteger" name="Time" use="required"/>
            <xs:attribute type="xs:string" name="Source" use="required"/>
            <xs:attribute type="xs:string" name="Name" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="TriggeringEntities">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Entity" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="AffectedEntities">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Entity" minOccurs="0"  maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Entity">
        <xs:complexType>
            <xs:attribute type="xs:integer" name="Id" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="Parameters">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Parameter" maxOccurs="unbounded" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Parameter">
        <xs:complexType>
            <xs:attribute type="xs:string" name="Key" use="required"/>
            <xs:attribute type="xs:string" name="Value" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="Agents">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Agent" maxOccurs="unbounded" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Agent">
        <xs:complexType>
            <xs:all>
                <xs:element ref="VehicleAttributes"/>
                <xs:element ref="Components" minOccurs="0"/>
                <xs:element ref="Sensors" minOccurs="0"/>
            </xs:all>
            <xs:attribute type="xs:string" name="Id" use="required"/>
            <xs:attribute type="xs:string" name="AgentTypeGroupName" use="required"/>
            <xs:attribute type="xs:string" name="AgentTypeName" use="required"/>
            <xs:attribute type="xs:string" name="VehicleModelType" use="required"/>
            <xs:attribute type="xs:string" name="DriverProfileName" use="required"/>
            <xs:attribute type="xs:string" name="AgentType" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="VehicleAttributes">
        <xs:complexType>
            <xs:attribute type="xs:double" name="Width" use="required"/>
            <xs:attribute type="xs:double" name="Length" use="required"/>
            <xs:attribute type="xs:double" name="Height" use="required"/>
            <xs:attribute type="xs:double" name="LongitudinalPivotOffset" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="Components">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Component" maxOccurs="unbounded" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Component">
        <xs:complexType>
            <xs:attribute type="xs:string" name="Type"/>
            <xs:attribute type="xs:string" name="Profile"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="Sensors">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Sensor" maxOccurs="unbounded" minOccurs="0"/>
            </xs:sequence>
         </xs:complexType>
    </xs:element>
    <xs:element name="Sensor">
        <xs:complexType>
            <xs:attribute type="xs:string" name="Id" use="required"/>
            <xs:attribute type="xs:string" name="Type" use="required"/>
            <xs:attribute type="xs:double" name="MountingPosLongitudinal" use="required"/>
            <xs:attribute type="xs:double" name="MountingPosLateral" use="required"/>
            <xs:attribute type="xs:double" name="MountingPosHeight" use="required"/>
            <xs:attribute type="xs:double" name="OrientationYaw" use="required"/>
            <xs:attribute type="xs:double" name="OrientationPitch" use="required"/>
            <xs:attribute type="xs:double" name="OrientationRoll" use="required"/>
            <xs:attribute type="xs:double" name="Latency" use="required"/>
            <xs:attribute type="xs:double" name="OpeningAngleH" use="optional"/>
            <xs:attribute type="xs:double" name="Range" use="optional"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="Cyclics">
        <xs:complexType>
            <xs:choice minOccurs="1" maxOccurs="1">
                <xs:sequence>
                    <xs:element ref="Header"/>
                    <xs:element ref="Samples"/>
                </xs:sequence>
                <xs:element ref="CyclicsFile"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:element name="Header" type="xs:string"/>
    <xs:element name="Samples">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Sample" maxOccurs="unbounded" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Sample">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute type="xs:nonNegativeInteger" name="Time" use="required"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="CyclicsFile" type="xs:string"/>
</xs:schema>
