WSF
XWsfRoadTraffic.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11// ****************************************************************************
12// Updated by Infoscitex, a DCS Company.
13// ****************************************************************************
14
15#ifndef XWSFROADTRAFFIC_HPP
16#define XWSFROADTRAFFIC_HPP
17
18#include "wsf_export.h"
19
20#include <string>
21#include <vector>
22
23class UtInput;
24#include "UtCallbackHolder.hpp"
25#include "UtRandom.hpp"
26class WsfMover;
27class WsfPlatform;
28class WsfRoadMover;
29#include "WsfRoute.hpp"
30class WsfRouteNetwork;
32#include "XWsfRouteNetwork.hpp"
33
42{
43public:
44 struct Data;
45
46 XWsfRoadTraffic(const Data& aData)
47 : mData(aData)
48 {
49 }
50
51 ~XWsfRoadTraffic() override;
52
53 bool Initialize() override;
54
55 void AdvanceTime(double aSimTime);
56
58
60 {
61 int mIdentifier = 0;
63 bool mAlive = false;
64 bool mVehicleOffRoad = false;
65 bool mStationary = false;
66 int mNetwork = -1;
67 double mRouteDist = 0.0;
68 double mSpeed = 0.0;
69 double mTravelTime = 0.0;
70 double mStartTime = 0.0;
71 double mDeadTime = 0.0;
72 double mOffRoadTime = 0.0;
75 bool mConvoyVehicle = false;
76 };
77
82 {
83 double mLatitude = 0.0;
84 double mLongitude = 0.0;
85 double mInnerRadius = 0.0;
86 double mOuterRadius = 0.0;
87 double mInnerWeight = 0.0;
88 double mOuterWeight = 0.0;
89 };
90
95 {
96 public:
97 VehicleInput() = default;
99 : mTypeId(aTypeId)
100 {
101 }
102
104 int mCount = 0;
105 double mFraction = 0.0;
106 double mMeanSpeed = 0.0;
107 double mSigmaSpeed = 0.0;
108 };
109
114 {
115 double mStartLatitude = 0.0;
116 double mStartLongitude = 0.0;
117 double mEndLatitude = 0.0;
118 double mEndLongitude = 0.0;
119 double mSpacing = 0.0;
120 double mSpeed = 0.0;
121 double mPauseTime = 0.0;
123 std::vector<VehicleInput> mVehicleInput;
124 };
125
131 {
132 public:
134 WeightedRouteSegment(WsfRoute* aRoutePtr, const WsfWaypoint& aNode1, const WsfWaypoint& aNode2)
135 : mRoutePtr(aRoutePtr)
136 , mNode1(aNode1)
137 , mNode2(aNode2)
138 {
139 }
140
141 WsfRoute* mRoutePtr = nullptr;
144 double mNode1Weight = 0.0;
145 double mNode2Weight = 0.0;
146 double mSegmentWeight = 0.0;
147 double mCumulativeWeight = 0.0;
148
150 bool operator==(double aWeight) const
151 {
152 return ((aWeight >= mCumulativeWeight) && (aWeight < (mCumulativeWeight + mSegmentWeight)));
153 }
154
155 bool operator<(const WeightedRouteSegment& aSegment) const { return (mSegmentWeight < aSegment.mSegmentWeight); }
156 };
157
161 {
162 public:
165 : NetworkInput(aNetworkId)
166 {
167 }
168
169 NetworkInput* Clone() const noexcept override { return new RoadTrafficNetworkInput{*this}; }
170
171 void VerifyData(UtInput& aInput) override
172 {
173 NetworkInput::VerifyData(aInput);
174
175 double sum = 0.0;
176 std::vector<VehicleInput>::iterator vehItr;
177 for (vehItr = mVehicleInput.begin(); vehItr != mVehicleInput.end(); ++vehItr)
178 {
179 sum += vehItr->mFraction;
180 }
181 if (fabs(1.0 - sum) > 10E-3)
182 {
183 throw UtInput::BadValue(aInput, "XWsfRoadTraffic the sum of all the vehicle 'fraction' values must be 1.0");
184 }
185 }
186
187 double mMinDistOffRoad = 0.0;
188 double mMaxDistOffRoad = 0.0;
189 double mPauseTime = 0.0;
190 double mMaxSpeed = 0.0;
191 double mMeanTravelTime = 0.0;
192 double mSigmaTravelTime = 0.0;
193 double mTotalDist = 0.0;
194 std::vector<VehicleInput> mVehicleInput;
195 std::vector<WeightedRegionInput> mWeightedRegionInput;
196
199 std::vector<WeightedRouteSegment> mWeightedRouteSegments;
200
201 std::vector<ConvoyInput> mConvoyInput;
202
203 protected:
205 };
206
212
214 struct Data : public XWsfRouteNetwork
215 {
216 bool mProcessedInput = false;
217 bool mDebug = false;
218 bool mVerbose = false;
220 // Vector of vehicles.
221 std::vector<SGroundTraffic> mTraffic;
222 double mNextUpdateTime = 0.0; // Simulation time when the next update
223 // (platform add, delete, pause, etc) is required.
227
233 const Networks& GetNetworks() const { return mNetworks; }
234
236 };
237
238protected:
240 XWsfRoadTraffic(const XWsfRoadTraffic& aSrc) = delete;
242
243private:
244 void BuildWeightedRouteSegmentList(WsfRouteNetwork& aRouteNetwork, RoadTrafficNetworkInput& aNetwork);
245
246 double CalculateNodeWeight(const WeightedRegionInput& aWeightedRegion, const WsfWaypoint& aNode);
247
248 void AddPlatformToSimulation(double aSimTime, int aVehicleNumber);
249
250 int AllocateVehicle(WsfStringId aVehicleTypeId);
251
252 bool GetRandomWaypoint(const RoadTrafficNetworkInput& aNetwork,
253 WsfWaypoint& aWaypoint,
254 WsfWaypoint& aRouteSegEndWpt1,
255 WsfWaypoint& aRouteSegEndWpt2);
256
257 bool CreateRandomPath(const RoadTrafficNetworkInput& aNetwork, WsfRoute& aPath);
258
259 double CreateRandomPathForVehicle(const RoadTrafficNetworkInput& aNetwork, int aVehicleNumber);
260
261 void GoOffRoad(const RoadTrafficNetworkInput& aNetwork, int aVehicleNumber);
262
263 void ClearVehicleList();
264
265 bool CreateVehicle(const RoadTrafficNetworkInput& aNetworkInput, double aCreateTime, int& aVehicleNumber);
266
267 bool CreateConvoyVehicle(WsfStringId aVehicleType, int& aVehicleNumber);
268
269 void DeletePlatformFromSimulation(double aSimTime, int aVehicleNumber);
270
271 void ReverseVehicleRoute(int aVehicleNumber, double aSimTime);
272
273 bool ValidateVehicleTypes(RoadTrafficNetworkInput& aNetwork);
274
275 WsfMover* GetMover(WsfPlatform* aMoverPtr);
276
279 Data mData;
280 UtCallbackHolder mCallbacks;
281};
282
283#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfMover.hpp:37
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Definition WsfRoadMover.hpp:32
A collection of WsfRoute object that represents a connected network (such as a road network).
Definition WsfRouteNetwork.hpp:40
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
const WsfScenario & GetScenario() const
Definition WsfSimulationExtension.cpp:31
WsfSimulationExtension()
Definition WsfSimulationExtension.cpp:23
virtual bool Initialize()
Definition WsfSimulationExtension.cpp:49
Definition WsfWaypoint.hpp:57
Definition XWsfRoadTraffic.hpp:161
double mMaxDistOffRoad
Minimum distance vehicle travels off road (meters).
Definition XWsfRoadTraffic.hpp:188
double mSigmaTravelTime
Mean travel time of vehicles (s).
Definition XWsfRoadTraffic.hpp:192
NetworkInput * Clone() const noexcept override
Definition XWsfRoadTraffic.hpp:169
RoadTrafficNetworkInput(WsfStringId aNetworkId)
Definition XWsfRoadTraffic.hpp:164
double mMeanTravelTime
Maximum speed of any vehicle (m/s).
Definition XWsfRoadTraffic.hpp:191
void VerifyData(UtInput &aInput) override
Definition XWsfRoadTraffic.hpp:171
double mPauseTime
Maximum distance vehicle travels off road (meters).
Definition XWsfRoadTraffic.hpp:189
RoadTrafficNetworkInput(const RoadTrafficNetworkInput &aSrc)=default
Data for each of the convoys in this road network.
std::vector< ConvoyInput > mConvoyInput
Definition XWsfRoadTraffic.hpp:201
std::vector< WeightedRegionInput > mWeightedRegionInput
Data for each of the vehicle types on this road network.
Definition XWsfRoadTraffic.hpp:195
double mTotalDist
Sigma travel time of vehicles (s).
Definition XWsfRoadTraffic.hpp:193
std::vector< VehicleInput > mVehicleInput
The sum of the lengths of all the roads (meters).
Definition XWsfRoadTraffic.hpp:194
double mMinDistOffRoad
Definition XWsfRoadTraffic.hpp:187
std::vector< WeightedRouteSegment > mWeightedRouteSegments
Data for each of the weighted regions in this road network.
Definition XWsfRoadTraffic.hpp:199
double mMaxSpeed
Pause time after completing travel (seconds).
Definition XWsfRoadTraffic.hpp:190
double mSigmaSpeed
Mean velocity in m/s.
Definition XWsfRoadTraffic.hpp:107
double mMeanSpeed
The percentage of this vehicle type that should exist in the simulation.
Definition XWsfRoadTraffic.hpp:106
WsfStringId mTypeId
Definition XWsfRoadTraffic.hpp:103
double mFraction
The number of vehicles that should be created of this type.
Definition XWsfRoadTraffic.hpp:105
VehicleInput(WsfStringId aTypeId)
Definition XWsfRoadTraffic.hpp:98
int mCount
String Id of the type of the vehicle.
Definition XWsfRoadTraffic.hpp:104
double mSegmentWeight
Definition XWsfRoadTraffic.hpp:146
bool operator<(const WeightedRouteSegment &aSegment) const
Definition XWsfRoadTraffic.hpp:155
double mCumulativeWeight
Definition XWsfRoadTraffic.hpp:147
double mNode2Weight
Definition XWsfRoadTraffic.hpp:145
WeightedRouteSegment(WsfRoute *aRoutePtr, const WsfWaypoint &aNode1, const WsfWaypoint &aNode2)
Definition XWsfRoadTraffic.hpp:134
WsfRoute * mRoutePtr
Definition XWsfRoadTraffic.hpp:141
WsfWaypoint mNode2
Definition XWsfRoadTraffic.hpp:143
WsfWaypoint mNode1
Definition XWsfRoadTraffic.hpp:142
double mNode1Weight
Definition XWsfRoadTraffic.hpp:144
bool operator==(double aWeight) const
Equal if the provided weight is enclosed by this segment's boundary weights.
Definition XWsfRoadTraffic.hpp:150
Definition XWsfRoadTraffic.hpp:42
XWsfRoadTraffic & operator=(const XWsfRoadTraffic &aRhs)=delete
EndOfPath
Definition XWsfRoadTraffic.hpp:208
@ cRESPAWN
Definition XWsfRoadTraffic.hpp:209
@ cREVERSE_DIRECTION
Definition XWsfRoadTraffic.hpp:210
XWsfRoadTraffic(const Data &aData)
Definition XWsfRoadTraffic.hpp:46
XWsfRoadTraffic(const XWsfRoadTraffic &aSrc)=delete
Copy constructor and assignment operator are declared but not defined in order to prevent use.
Definition XWsfRouteNetwork.hpp:55
NetworkInput(WsfStringId aNetworkId)
Definition XWsfRouteNetwork.hpp:57
XWsfRouteNetwork()=default
virtual bool ProcessCommand(UtInput &aInput, NetworkInput &aNetworkInput)
Definition XWsfRouteNetwork.cpp:110
Networks mNetworks
Definition XWsfRouteNetwork.hpp:104
std::vector< ut::CloneablePtr< NetworkInput > > Networks
Definition XWsfRouteNetwork.hpp:101
Definition XWsfRoadTraffic.hpp:114
double mEndLongitude
Definition XWsfRoadTraffic.hpp:118
double mSpeed
Definition XWsfRoadTraffic.hpp:120
bool mUseClosestWaypoint
Definition XWsfRoadTraffic.hpp:122
double mSpacing
Definition XWsfRoadTraffic.hpp:119
double mStartLatitude
Definition XWsfRoadTraffic.hpp:115
double mPauseTime
Definition XWsfRoadTraffic.hpp:121
double mEndLatitude
Definition XWsfRoadTraffic.hpp:117
double mStartLongitude
Definition XWsfRoadTraffic.hpp:116
std::vector< VehicleInput > mVehicleInput
Definition XWsfRoadTraffic.hpp:123
Holds the data for XWsfRoadTraffic populated during the ProcessInput phase.
Definition XWsfRoadTraffic.hpp:215
const Networks & GetNetworks() const
Definition XWsfRoadTraffic.hpp:233
bool mVerbose
Definition XWsfRoadTraffic.hpp:218
Networks & GetNetworks()
Definition XWsfRoadTraffic.hpp:230
std::vector< SGroundTraffic > mTraffic
Definition XWsfRoadTraffic.hpp:221
bool mProcessedInput
Definition XWsfRoadTraffic.hpp:216
bool mDebug
Definition XWsfRoadTraffic.hpp:217
EndOfPath mEndOfPathOption
Definition XWsfRoadTraffic.hpp:219
int mNumVehiclesActive
Definition XWsfRoadTraffic.hpp:225
int mMaxVehiclesActive
Definition XWsfRoadTraffic.hpp:226
double mNextUpdateTime
Definition XWsfRoadTraffic.hpp:222
int mNextVehicleIdentifier
Definition XWsfRoadTraffic.hpp:224
Definition XWsfRoadTraffic.hpp:60
double mRouteDist
Index value of network vehicle is traveling on.
Definition XWsfRoadTraffic.hpp:67
double mSpeed
The length of the path (meters).
Definition XWsfRoadTraffic.hpp:68
WsfPlatform * mRoadPlatform
Time vehicle starts moving off the road (sec).
Definition XWsfRoadTraffic.hpp:73
bool mStationary
Is this vehicle now off-road?
Definition XWsfRoadTraffic.hpp:65
int mIdentifier
Definition XWsfRoadTraffic.hpp:61
double mOffRoadTime
Time vehicle stops moving and is removed (sec).
Definition XWsfRoadTraffic.hpp:72
size_t mRoadPlatformIndex
Definition XWsfRoadTraffic.hpp:74
double mDeadTime
Time vehicle starts moving (sec).
Definition XWsfRoadTraffic.hpp:71
int mNetwork
Is this vehicle stationary?
Definition XWsfRoadTraffic.hpp:66
bool mVehicleOffRoad
Is this vehicle alive?
Definition XWsfRoadTraffic.hpp:64
bool mConvoyVehicle
Definition XWsfRoadTraffic.hpp:75
bool mAlive
Vehicle type.
Definition XWsfRoadTraffic.hpp:63
double mStartTime
Amount of time vehicle is moving along road (sec).
Definition XWsfRoadTraffic.hpp:70
WsfStringId mVehicleTypeId
Unique identifier for ground vehicle.
Definition XWsfRoadTraffic.hpp:62
double mTravelTime
Speed (meters/sec).
Definition XWsfRoadTraffic.hpp:69
Definition XWsfRoadTraffic.hpp:82
double mOuterWeight
Definition XWsfRoadTraffic.hpp:88
double mInnerRadius
Definition XWsfRoadTraffic.hpp:85
double mLatitude
Definition XWsfRoadTraffic.hpp:83
double mLongitude
Definition XWsfRoadTraffic.hpp:84
double mOuterRadius
Definition XWsfRoadTraffic.hpp:86
double mInnerWeight
Definition XWsfRoadTraffic.hpp:87
Copyrights Multiple, All Rights Reserved