WSF
XWsfSeaTraffic.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#ifndef XWSFSEATRAFFIC_HPP
13#define XWSFSEATRAFFIC_HPP
14
15#include "wsf_export.h"
16
17#include <map>
18#include <vector>
19
20#include "UtCallbackHolder.hpp"
21class UtInput;
22#include "UtMath.hpp"
23#include "WsfEvent.hpp"
24#include "WsfMover.hpp"
25#include "WsfPlatform.hpp"
26#include "WsfProcessor.hpp"
27#include "WsfRoute.hpp"
28#include "WsfSimulation.hpp"
30#include "WsfStringId.hpp"
31class WsfWaypoint;
32class XWsfSeaTrafficExtension;
33
34//------------------------------------------------------------------------
39//------------------------------------------------------------------------
40
42{
43public:
45 class SeaRegion;
46 class SeaPort;
47 class SeaLane;
48 class Vehicle;
49
52 virtual XWsfSeaTraffic* Clone() const;
53
54 ~XWsfSeaTraffic() override;
55
56 virtual bool ProcessInput(UtInput& aInput);
57 bool Initialize() override;
58
59 void HandleDeparture(WsfStringId aPortId, double aSimTime);
60
61 void HandleEnterLoiter(WsfPlatform* aPlatformPtr, double aSimTime);
62
63 void GetSeaLaneIds(WsfStringId aPortId, std::vector<WsfStringId>& aLaneIds);
64
67 bool DoesPortExist(WsfStringId aNameId) const { return mSeaPorts.find(aNameId) != mSeaPorts.end(); }
68
71 bool DoesLaneExist(WsfStringId aNameId) const { return mSeaLanes.find(aNameId) != mSeaLanes.end(); }
72
75 bool DoesDepVehicleExist(WsfStringId aTypeId) const { return mDepVehicles.find(aTypeId) != mDepVehicles.end(); }
76
79 bool DoesLocVehicleExist(WsfStringId aTypeId) const { return mLocVehicles.find(aTypeId) != mLocVehicles.end(); }
80
84 {
85 return mSeaPorts.find(aNameId) != mSeaPorts.end() ? &mSeaPorts[aNameId] : nullptr;
86 }
87
91 {
92 return mSeaLanes.find(aNameId) != mSeaLanes.end() ? &mSeaLanes[aNameId] : nullptr;
93 }
94
98 {
99 return mDepVehicles.find(aTypeId) != mDepVehicles.end() ? &mDepVehicles[aTypeId] : nullptr;
100 }
101
105 {
106 return mLocVehicles.find(aTypeId) != mLocVehicles.end() ? &mLocVehicles[aTypeId] : nullptr;
107 }
108
109 static const double cEPSILON;
110
114 {
115 public:
117 : mLat(0.0)
118 , mLon(0.0)
119 , mRadius(0.0)
120 , mFraction(0.0)
121 {
122 }
123
124 SeaRegion(double aLat, double aLon, double aRadius, double aFraction = 0.0)
125 : mLat(aLat)
126 , mLon(aLon)
127 , mRadius(aRadius)
128 , mFraction(aFraction)
129 {
130 }
131
133
134 bool ProcessInput(UtInput& aInput);
135
136 double mLat;
137 double mLon;
138 double mRadius;
139 double mFraction;
140 };
141
147 {
148 public:
150 : mNameId()
151 {
152 // provided for map[]
153 }
154
156 : mNameId(aNameId)
157 , mDepartureInterval(0.0)
160 , mUseAllLanes(false)
161 {
162 }
163
165
166 bool ProcessInput(UtInput& aInput);
167 bool Initialize(XWsfSeaTraffic& aSeaTraffic);
168
169 bool operator==(const SeaPort& aRhs) const { return mNameId == aRhs.mNameId; }
170
173 std::vector<SeaRegion> mPortRoute;
174 std::vector<SeaRegion> mLocalTrafficRegions;
179 std::vector<WsfStringId> mSeaLaneIds;
180 std::vector<double> mDstPortWeights;
181 std::vector<WsfStringId> mAirportIds;
182 };
183
188 {
189 public:
191 {
192 // provided for map[]
193 }
195 : mNameId(aNameId)
196 , mPortCount(0)
197 {
198 mPortId[0] = nullptr;
199 mPortId[1] = nullptr;
200 mPortIgnoreRoute[0] = false;
201 mPortIgnoreRoute[1] = false;
202 }
203
205
206 bool ProcessInput(UtInput& aInput);
207 bool Initialize(XWsfSeaTraffic& aSeaTraffic);
208
212 {
213 return (aPortId == mPortId[0]) ? mPortId[1] : mPortId[0];
214 }
215
218 bool IgnorePortRoute(WsfStringId aPortId) const
219 {
220 return (aPortId == mPortId[0]) ? mPortIgnoreRoute[0] : mPortIgnoreRoute[1];
221 }
222
223 bool operator==(const SeaLane& aRhs) const { return mNameId == aRhs.mNameId; }
224
229 std::vector<SeaRegion> mLaneRoute;
230 };
231
235 {
236 public:
238 {
239 // provided for map[]
240 }
242 : mTypeId(aTypeId)
243 , mCount(0)
244 , mFraction(0.0)
245 , mLoiterTime(0.0)
246 , mDefaultLoiterTime(1800.0)
247 , // 1/2 hour
249 , mSpeed(0.0)
250 , mDefaultSpeed(10.0 * UtMath::cFT_PER_NM / UtMath::cFT_PER_M)
251 , // 10.0 knots
252 mSigmaSpeed(0.0)
253 {
254 }
255
257
258 bool ProcessInput(UtInput& aInput);
259 bool Initialize(XWsfSeaTraffic& aSeaTraffic);
260
261 bool operator==(const Vehicle& aRhs) const { return mTypeId == aRhs.mTypeId; }
262
265 double mFraction;
269 double mSpeed;
272
273 std::vector<WsfStringId> mRouteIds;
274 };
275
279 {
280 public:
281 DepartureEvent(XWsfSeaTraffic* aSeaTrafficPtr, WsfStringId aPortId, double aSimTime)
282 : WsfEvent(aSimTime)
283 , mSeaTrafficPtr(aSeaTrafficPtr)
284 , mPortId(aPortId)
285 {
286 }
287
289 {
290 mSeaTrafficPtr->HandleDeparture(mPortId, GetTime());
291 return cDELETE;
292 }
293
294 private:
295 XWsfSeaTraffic* mSeaTrafficPtr;
296 WsfStringId mPortId;
297 };
298
303 {
304 public:
305 ExitLoiterEvent(WsfStringId aPlatformId, double aSimTime)
306 : WsfEvent(aSimTime)
307 , mPlatformId(aPlatformId)
308 {
309 }
310
312 {
313 WsfPlatform* platformPtr = GetSimulation()->GetPlatformByName(mPlatformId);
314 if (platformPtr != nullptr)
315 {
316 WsfMover* moverPtr = platformPtr->GetMover();
317 if (moverPtr != nullptr)
318 {
319 moverPtr->GoToLabel(GetTime(), WsfStringId("XWSF_SEA_TRAFFIC_HOME_LABEL"));
320 }
321 }
322 return cDELETE;
323 }
324
325 private:
326 WsfStringId mPlatformId;
327 };
328
329private:
330 typedef std::map<WsfStringId, SeaPort> Ports;
331 typedef std::map<WsfStringId, SeaLane> Lanes;
332 typedef std::map<WsfStringId, Vehicle> Vehicles;
333
334 bool ProcessSeaTraffic(UtInput& aInput);
335
336 void ProcessDepartureTraffic(UtInput& aInput);
337
338 void ProcessLocalTraffic(UtInput& aInput);
339
340 void GenerateInitialEntities();
341
342 bool GenerateDeparture(SeaPort& aPort, bool aLocalDeparture, Vehicle& aVehicle, double aDistanceAlongRoute, double aSimTime);
343
344 bool GenerateEntity(Vehicle& aVehicle, WsfRoute& aRoute, double aSimTime);
345
346 void UpdateRoute(double aDistanceAlongRoute, WsfRoute& aRoute);
347
348 Vehicle* GetRandomVehicle(Vehicles& aVehicles);
349
350 SeaLane* GetRandomLane(SeaPort& aPort);
351
352 void GetRandomRoute(SeaLane& aLane,
353 SeaPort& aSrcPort,
354 SeaPort& aDstPort,
355 double aSpeed,
356 WsfRoute& aRoute,
357 bool aActualRoute = false);
358
359 void GetRandomRoute(SeaPort& aPort, SeaRegion& aRegion, Vehicle& aVehicle, double aSpeed, WsfRoute& aRoute);
360
361 void GetRandomWaypoint(SeaRegion& aRegion, WsfWaypoint& aWaypoint, bool aActualWaypoint = false);
362
363 void GetRandomRegion(SeaPort& aPort, SeaRegion& aRegion);
364
365 double GetRandomSpeed(Vehicle& aVehicle);
366
367 double GetRandomLoiterTime(Vehicle& aVehicle);
368
369 double CalcMaxTravelTime(SeaPort& aPort, Vehicles& aVehicles);
370
371 void WriteScenarioEditorFile();
372
373 // Disable copying and assignment.
374 XWsfSeaTraffic(const XWsfSeaTraffic& aSrc);
375 XWsfSeaTraffic& operator=(const XWsfSeaTraffic& aRhs);
376
377 bool mProcessedInput;
378
379 double mDepVehiclesFraction;
380 double mLocVehiclesFraction;
381
382 Ports mSeaPorts;
383 Lanes mSeaLanes;
384 Vehicles mDepVehicles;
385 Vehicles mLocVehicles;
386};
387
388#endif
WsfMover * moverPtr
Definition WsfScriptPlatformClass.cpp:2367
WsfPlatform * platformPtr
Definition WsfScriptTrackClass.cpp:507
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
double GetTime() const
Definition WsfEvent.hpp:71
WsfSimulation * GetSimulation() const
Definition WsfEvent.hpp:103
WsfEvent()=default
EventDisposition
Definition WsfEvent.hpp:37
@ cDELETE
Delete the event from the event queue.
Definition WsfEvent.hpp:38
Definition WsfMover.hpp:37
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
WsfSimulationExtension()
Definition WsfSimulationExtension.cpp:23
friend class WsfSimulation
Definition WsfSimulationExtension.hpp:43
virtual bool Initialize()
Definition WsfSimulationExtension.cpp:49
Definition WsfWaypoint.hpp:57
DepartureEvent(XWsfSeaTraffic *aSeaTrafficPtr, WsfStringId aPortId, double aSimTime)
Definition XWsfSeaTraffic.hpp:281
EventDisposition Execute() override
Definition XWsfSeaTraffic.hpp:288
EventDisposition Execute() override
Definition XWsfSeaTraffic.hpp:311
ExitLoiterEvent(WsfStringId aPlatformId, double aSimTime)
Definition XWsfSeaTraffic.hpp:305
Definition XWsfSeaTraffic.hpp:188
bool operator==(const SeaLane &aRhs) const
Definition XWsfSeaTraffic.hpp:223
~SeaLane()
Definition XWsfSeaTraffic.hpp:204
WsfStringId mNameId
Definition XWsfSeaTraffic.hpp:225
WsfStringId GetDestinationPort(WsfStringId aPortId) const
Definition XWsfSeaTraffic.hpp:211
bool IgnorePortRoute(WsfStringId aPortId) const
Definition XWsfSeaTraffic.hpp:218
std::vector< SeaRegion > mLaneRoute
Definition XWsfSeaTraffic.hpp:229
SeaLane(WsfStringId aNameId)
Definition XWsfSeaTraffic.hpp:194
WsfStringId mPortId[2]
Definition XWsfSeaTraffic.hpp:227
bool mPortIgnoreRoute[2]
Definition XWsfSeaTraffic.hpp:228
SeaLane()
Definition XWsfSeaTraffic.hpp:190
int mPortCount
Definition XWsfSeaTraffic.hpp:226
Definition XWsfSeaTraffic.hpp:147
~SeaPort()
Definition XWsfSeaTraffic.hpp:164
std::vector< WsfStringId > mSeaLaneIds
Definition XWsfSeaTraffic.hpp:179
WsfStringId mNameId
Definition XWsfSeaTraffic.hpp:171
std::vector< WsfStringId > mAirportIds
Definition XWsfSeaTraffic.hpp:181
std::vector< SeaRegion > mPortRoute
Definition XWsfSeaTraffic.hpp:173
double mDepVehiclesInterval
Definition XWsfSeaTraffic.hpp:176
SeaPort(WsfStringId aNameId)
Definition XWsfSeaTraffic.hpp:155
double mLocVehiclesInterval
Definition XWsfSeaTraffic.hpp:177
SeaRegion mPosition
Definition XWsfSeaTraffic.hpp:172
std::vector< SeaRegion > mLocalTrafficRegions
Definition XWsfSeaTraffic.hpp:174
bool operator==(const SeaPort &aRhs) const
Definition XWsfSeaTraffic.hpp:169
bool mUseAllLanes
Definition XWsfSeaTraffic.hpp:178
std::vector< double > mDstPortWeights
Definition XWsfSeaTraffic.hpp:180
double mDepartureInterval
Definition XWsfSeaTraffic.hpp:175
SeaPort()
Definition XWsfSeaTraffic.hpp:149
Definition XWsfSeaTraffic.hpp:114
SeaRegion(double aLat, double aLon, double aRadius, double aFraction=0.0)
Definition XWsfSeaTraffic.hpp:124
~SeaRegion()
Definition XWsfSeaTraffic.hpp:132
double mLat
Definition XWsfSeaTraffic.hpp:136
double mRadius
Definition XWsfSeaTraffic.hpp:138
double mFraction
Definition XWsfSeaTraffic.hpp:139
SeaRegion()
Definition XWsfSeaTraffic.hpp:116
double mLon
Definition XWsfSeaTraffic.hpp:137
bool ProcessInput(UtInput &aInput)
Definition XWsfSeaTraffic.hpp:235
double mDefaultLoiterTime
Definition XWsfSeaTraffic.hpp:267
double mSigmaLoiterTime
Definition XWsfSeaTraffic.hpp:268
~Vehicle()
Definition XWsfSeaTraffic.hpp:256
Vehicle(WsfStringId aTypeId)
Definition XWsfSeaTraffic.hpp:241
int mCount
Definition XWsfSeaTraffic.hpp:264
bool operator==(const Vehicle &aRhs) const
Definition XWsfSeaTraffic.hpp:261
double mSigmaSpeed
Definition XWsfSeaTraffic.hpp:271
WsfStringId mTypeId
Definition XWsfSeaTraffic.hpp:263
double mFraction
Definition XWsfSeaTraffic.hpp:265
std::vector< WsfStringId > mRouteIds
Definition XWsfSeaTraffic.hpp:273
double mDefaultSpeed
Definition XWsfSeaTraffic.hpp:270
double mSpeed
Definition XWsfSeaTraffic.hpp:269
Vehicle()
Definition XWsfSeaTraffic.hpp:237
double mLoiterTime
Definition XWsfSeaTraffic.hpp:266
Definition XWsfSeaTraffic.hpp:42
bool DoesLocVehicleExist(WsfStringId aTypeId) const
Definition XWsfSeaTraffic.hpp:79
bool DoesLaneExist(WsfStringId aNameId) const
Definition XWsfSeaTraffic.hpp:71
bool Initialize() override
Definition XWsfSeaTraffic.cpp:123
static const double cEPSILON
Definition XWsfSeaTraffic.hpp:109
bool DoesPortExist(WsfStringId aNameId) const
Definition XWsfSeaTraffic.hpp:67
void GetSeaLaneIds(WsfStringId aPortId, std::vector< WsfStringId > &aLaneIds)
Definition XWsfSeaTraffic.cpp:281
XWsfSeaTraffic(const XWsfSeaTraffic &aSrc, WsfSimulation *aSimPtr)
Vehicle * GetDepVehicle(WsfStringId aTypeId)
Definition XWsfSeaTraffic.hpp:97
virtual bool ProcessInput(UtInput &aInput)
Definition XWsfSeaTraffic.cpp:102
void HandleEnterLoiter(WsfPlatform *aPlatformPtr, double aSimTime)
Definition XWsfSeaTraffic.cpp:263
virtual XWsfSeaTraffic * Clone() const
Definition XWsfSeaTraffic.cpp:1158
Vehicle * GetLocVehicle(WsfStringId aTypeId)
Definition XWsfSeaTraffic.hpp:104
void HandleDeparture(WsfStringId aPortId, double aSimTime)
Definition XWsfSeaTraffic.cpp:192
bool DoesDepVehicleExist(WsfStringId aTypeId) const
Definition XWsfSeaTraffic.hpp:75
SeaLane * GetSeaLane(WsfStringId aNameId)
Definition XWsfSeaTraffic.hpp:90
XWsfSeaTraffic()
Definition XWsfSeaTraffic.cpp:70
friend class XWsfSeaTrafficExtension
Definition XWsfSeaTraffic.hpp:44
SeaPort * GetSeaPort(WsfStringId aNameId)
Definition XWsfSeaTraffic.hpp:83
Copyrights Multiple, All Rights Reserved