当前位置: 代码迷 >> 综合 >> 计算机仿真中的HLA技术中的餐馆例子分析 (2) Transport
  详细解决方案

计算机仿真中的HLA技术中的餐馆例子分析 (2) Transport

热度:61   发布时间:2023-12-16 08:22:32.0

相比起来,Transport联邦与manager联邦有些相似,都是TAR方式推进时间的,步长都是1.0,lookahead都是0.01

 

程序结构也很相似。 不同的是,transport实质性地参与了联邦的仿真过程,而manager仅仅是一个仿真过程的控制联邦。

 

主要的流程都在mainThread函数中:

 

(1)读取配置数据,产生联邦,加入联邦;

 

(2)使能时间调节和时间受限;

 

(3)获取各种handles,订阅和发布。transport发布了Boat对象类和Serving对象类,发布TransferAccepted交互类,订阅了Serving对象类,订阅了SimulationEnds交互类。

 

(4)在第一个同步点完成同步;

 

(5)注册所发布对象类的实例,更新实例的属性;--makeInitialInstances();

 

(6)在第二个同步点ReadyToRun完成同步;

 

(7)进入主循环:

 

 

      //advance time in steps until SimulationEnds received

      _targetTime = new LogicalTimeDouble(0.0);

      _targetTime.setTo(_logicalTime);    //设置要TAR的时间点初始时间为0.0

    timeLoop:

      while (!_simulationEndsReceived) {

        //advance by a step

        _targetTime.increaseBy(_advanceInterval);   //时间请求按步长进行,每次1.0

        _userInterface.setTimeStateAdvancing();

_userInterface.post("This is before TAR:  "+_targetTime);

        _rti.timeAdvanceRequest(_targetTime);        //时间推进请求TAR

        //chew through all the events we receive from the RTI

        boolean wasTimeAdvanceGrant;

        do {

          Callback callback = _callbackQueue.dequeue();   //获取外部时间队列中的第一个事件(注意callbackQueue是排序的)

          wasTimeAdvanceGrant = callback.dispatch();      //通过调用该事件的dispatch函数来处理事件,并返回是否是time grant的布尔量

          if (_simulationEndsReceived) break timeLoop;    //如果是SimulationEnds交互则推出外层循环

        } while (!wasTimeAdvanceGrant);                         //直到收到time grant事件 

        updateInternalStateAtNewTime();                         //在新的time grant时间点,更新所有对象实例(transport联邦发布的Boat和Serving)的属性 

      }

 

 

(8)在第三个同步点ReadyToResign完成同步。

 

----------------------------------------------------------------------------------------------------------------------------

下面是一个transport联邦运行过程中输出的log及其分析

 

RTIambassador created

Federation execution restaurant_1 already exists.

Joined as federate 9

Enabling time constraint...

...constraint enabled at time<0.0>

Enabling time regulation...

...regulation enabled at time<0.0>

Waiting for ReadyToPopulate...                               //注意下面,在同步时调用 result = barrier.await();将导致可能的控制权转移,因此下面出现了几个回调函数的调用。

?5.10)startRegistrationForObjectClass:4  

?5.12)turnInteractionsOn:1

?5.10)startRegistrationForObjectClass:3

...federation synchronized.

Waiting for ReadyToRun...

...federation synchronized.

This is before TAR:  time<1.0>                               //TAR 1.0,步长为1.0

This is GrantEvent 's dispatch  

...granted to time<1.0>                                         //直接获得了RTI的time grant回调

This is before TAR:  time<2.0>                              //TAR 2.0

This is DiscoverObjectInstanceCallback's dispatch  S_8_0  167    //回调,发现了所订阅的对象实例

Discovered Serving 167(S_8_0)

This is DiscoverObjectInstanceCallback's dispatch  S_8_1  168   //同上

Discovered Serving 168(S_8_1)

This is DiscoverObjectInstanceCallback's dispatch  S_8_2  169   //同上

Discovered Serving 169(S_8_2)   

This is ReflectAttributeValuesEvent 's dispatch  169   se.pitch.prti.prti302@18488ef   //所发现对象实例的属性更新回调

This is ReflectAttributeValuesEvent 's dispatch  168   se.pitch.prti.prti302@b1cd0      //同上

This is ReflectAttributeValuesEvent 's dispatch  167   se.pitch.prti.prti302@2f729e    //同上

This is GrantEvent 's dispatch  

...granted to time<2.0>                                        //time grant回调                

This is before TAR:  time<3.0>                             //TAR 3.0

This is RAOAcallback 's dispatch  168    HashSet( 100 )   //回调,production联邦发现transport联邦发布的某Boat对象实例和位置(达到足够近的要求),请求装载某Serving实例。

Boat 150 agrees to acquire servingS_8_1                      //transport联邦同意用某Boat实例装载某Serving实例

This is AOANcallback's dispatch  168  HashSet( 100 )     //回调,production实例同意把某Serving实例的position属性的ownership交付给transport联邦

Acquired serving S_8_1                                   

This is GrantEvent 's dispatch           

...granted to time<3.0>                                            //time grant 回调

This is before TAR:  time<4.0>

This is DiscoverObjectInstanceCallback's dispatch  S_8_3  170

Discovered Serving 170(S_8_3)

This is DiscoverObjectInstanceCallback's dispatch  S_8_4  171

Discovered Serving 171(S_8_4)

This is DiscoverObjectInstanceCallback's dispatch  S_8_5  172

Discovered Serving 172(S_8_5)

This is ReflectAttributeValuesEvent 's dispatch  172   se.pitch.prti.prti302@1980630

This is ReflectAttributeValuesEvent 's dispatch  171   se.pitch.prti.prti302@1be4777

This is ReflectAttributeValuesEvent 's dispatch  170   se.pitch.prti.prti302@12f1bf0

This is GrantEvent 's dispatch  

...granted to time<4.0>

---------------------------------------------------------------------------------------------------------------------

 

从上述log信息来看,在主消息循环中,transport主要做三件事情:(0)按TAR方式,步长为1.0,lookahead为0.01推进时间;(1)发现所订阅对象类Serving的实例并反射其属性;(2)接收production联邦的回调请求,装载其提供的Serving对象类实例到自己的对象类Boat的实例上,并取得该Serving对象类实例的position属性的所有权,更新position属性;(3)需要时,完成Serving对象类实例的position属性所有权到Consumptio联邦的转换。

 

下面运行log中有关于AODNcallback的调用--time grant <17.0>之后

------------------------------------------------------------------

 

RTIambassador created

Federation execution restaurant_1 already exists.

Joined as federate 4

Enabling time constraint...

...constraint enabled at time<0.0>

Enabling time regulation...

...regulation enabled at time<0.0>

Waiting for ReadyToPopulate...

?5.10)startRegistrationForObjectClass:4

?5.12)turnInteractionsOn:1

?5.10)startRegistrationForObjectClass:3

...federation synchronized.

Waiting for ReadyToRun...

...federation synchronized.

This is before TAR:  time<1.0>

This is GrantEvent 's dispatch  

...granted to time<1.0>

This is before TAR:  time<2.0>

This is DiscoverObjectInstanceCallback's dispatch  S_3_0  125

Discovered Serving 125(S_3_0)

This is DiscoverObjectInstanceCallback's dispatch  S_3_1  126

Discovered Serving 126(S_3_1)

This is DiscoverObjectInstanceCallback's dispatch  S_3_2  127

Discovered Serving 127(S_3_2)

This is ReflectAttributeValuesEvent 's dispatch  127   se.pitch.prti.prti302@20f443

This is ReflectAttributeValuesEvent 's dispatch  126   se.pitch.prti.prti302@18488ef

This is ReflectAttributeValuesEvent 's dispatch  125   se.pitch.prti.prti302@3a1834

This is GrantEvent 's dispatch  

...granted to time<2.0>

This is before TAR:  time<3.0>

This is RAOAcallback 's dispatch  126    HashSet( 100 )

Boat 112 agrees to acquire servingS_3_1

This is AOANcallback's dispatch  126  HashSet( 100 )

Acquired serving S_3_1

This is DiscoverObjectInstanceCallback's dispatch  S_3_3  128

Discovered Serving 128(S_3_3)

This is ReflectAttributeValuesEvent 's dispatch  128   se.pitch.prti.prti302@28305d

This is GrantEvent 's dispatch  

...granted to time<3.0>

This is before TAR:  time<4.0>

This is GrantEvent 's dispatch  

...granted to time<4.0>

This is before TAR:  time<5.0>

This is DiscoverObjectInstanceCallback's dispatch  S_3_4  129

Discovered Serving 129(S_3_4)

This is DiscoverObjectInstanceCallback's dispatch  S_3_5  130

Discovered Serving 130(S_3_5)

This is ReflectAttributeValuesEvent 's dispatch  130   se.pitch.prti.prti302@1f02b85

This is ReflectAttributeValuesEvent 's dispatch  129   se.pitch.prti.prti302@15d4de6

This is RAOAcallback 's dispatch  129    HashSet( 100 )

Boat 121 agrees to acquire servingS_3_4

This is AOANcallback's dispatch  129  HashSet( 100 )

Acquired serving S_3_4

This is GrantEvent 's dispatch  

...granted to time<5.0>

This is before TAR:  time<6.0>

This is DiscoverObjectInstanceCallback's dispatch  S_3_6  131

Discovered Serving 131(S_3_6)

This is ReflectAttributeValuesEvent 's dispatch  131   se.pitch.prti.prti302@ee3aa7

This is GrantEvent 's dispatch  

...granted to time<6.0>

This is before TAR:  time<7.0>

This is DiscoverObjectInstanceCallback's dispatch  S_3_7  132

Discovered Serving 132(S_3_7)

This is ReflectAttributeValuesEvent 's dispatch  132   se.pitch.prti.prti302@1d9e282

This is GrantEvent 's dispatch  

...granted to time<7.0>

This is before TAR:  time<8.0>

This is GrantEvent 's dispatch  

...granted to time<8.0>

This is before TAR:  time<9.0>

This is GrantEvent 's dispatch  

...granted to time<9.0>

This is before TAR:  time<10.0>

This is RAOAcallback 's dispatch  127    HashSet( 100 )

Boat 116 agrees to acquire servingS_3_2

This is RAOAcallback 's dispatch  130    HashSet( 100 )

Boat 122 agrees to acquire servingS_3_5

This is AOANcallback's dispatch  127  HashSet( 100 )

Acquired serving S_3_2

This is AOANcallback's dispatch  130  HashSet( 100 )

Acquired serving S_3_5

This is GrantEvent 's dispatch  

...granted to time<10.0>

This is before TAR:  time<11.0>

This is DiscoverObjectInstanceCallback's dispatch  S_3_8  133

Discovered Serving 133(S_3_8)

This is ReflectAttributeValuesEvent 's dispatch  133   se.pitch.prti.prti302@c5aa00

This is GrantEvent 's dispatch  

...granted to time<11.0>

This is before TAR:  time<12.0>

This is GrantEvent 's dispatch  

...granted to time<12.0>

This is before TAR:  time<13.0>

This is DiscoverObjectInstanceCallback's dispatch  S_3_9  134

Discovered Serving 134(S_3_9)

This is ReflectAttributeValuesEvent 's dispatch  134   se.pitch.prti.prti302@1be2893

This is GrantEvent 's dispatch  

...granted to time<13.0>

This is before TAR:  time<14.0>

This is GrantEvent 's dispatch  

...granted to time<14.0>

This is before TAR:  time<15.0>

This is GrantEvent 's dispatch  

...granted to time<15.0>

This is before TAR:  time<16.0>

This is GrantEvent 's dispatch  

...granted to time<16.0>

This is before TAR:  time<17.0>

This is AODNcallback's dispatch  126  HashSet( 100 )

Divesting serving S_3_1

This is RAOAcallback 's dispatch  125    HashSet( 100 )

Boat 124 agrees to acquire servingS_3_0

This is RAOAcallback 's dispatch  128    HashSet( 100 )

Boat 119 agrees to acquire servingS_3_3

This is AOANcallback's dispatch  125  HashSet( 100 )

Acquired serving S_3_0

This is AOANcallback's dispatch  128  HashSet( 100 )

Acquired serving S_3_3

This is ReflectAttributeValuesEvent 's dispatch  126   se.pitch.prti.prti302@3bc20e

This is GrantEvent 's dispatch  

...granted to time<17.0>

 

------------------------------------------------------------------

 

 

  相关解决方案