atmkoh@yahoo.co.uk
6/18/2011 5:48:00 PM
Thank you all for helpful explanations! I am less muddled as when I
first asked the question so kudos to you for helping out.
I am able to use both classic VB (vb6) as well as VB dot Net and we
have not decided which one yet.
In the eventuality that we might need a console, maybe dot Net is the
way to go.
On Jun 18, 10:09 am, Schmidt <s...@online.de> wrote:
> Am 18.06.2011 01:53, schrieb atm...@yahoo.co.uk:
>
> > Hi, this is a really strange question to ask. I need to simulate the
> > arrival of an aircraft at an airport and the unloading of cargo and
> > things like that. I am going to do that myself but I need to
> > understand something...and ask this question. Suppose I am simulating
> > the 1 busiest hour say 7-8 am in the morning and I know that at 7:10 a
> > flight takes off for Paris say and at 7:15 a flight takes off for
> > Brussels..etc etc ..how do I tell my program to be written in visual
> > basic that it is 7:10 or 7:15..etc..this is not real time obviously so
> > my program won't run for 1 hour but how do I get around this?? I am
> > utterly confused now with do events etc
>
> You don't need DoEvents, just a simple timer is enough,
> which triggers a repeated "adjust Objects-State" Event.
>
> So (as in each computer-generated Sim) you have
> something like a MainLoop-Function (triggered
> from the Timer-Event in your case) - and it
> is your choice what TimeDelta you apply/add to
> a "progressing, simulated RealTime-Variable".
>
> This 'dT' can be left constant for each "timer-
> triggered round" - and mayhap in your case
> should be 1sec - or maybe 0.1sec.
>
> Now what remains is the switching of the already
> mentioned "Object-States" of all "participating
> entities" in your simulation (followed by the
> reflection of possibly changes states in the GUI).
>
> Objects and States... best done over normal
> Classes for the Objects and internal Enums
> for the different states (some States, which
> are defined in the Enum should be accompanied
> by Private userdefined Types, which describe
> a complex State then in more detail).
>
> For example make a Class cAirPlane, having
> a rough StateEnum inside like this:
>
> Public Enum AP_StateEnm
> InFlightArriving
> InLandingPhase
> InRollOutPhase
> InWaitForCargoTrainPhase
> InCargoUnLoadPhase
> InParkingPhase
>
> InCargoLoadPhase
> InStartPositioningPhase
> InStartAccelPhase
> InFlightDeparting
> End Enum
>
> 'and of course a set of Public Variables
> '(Properties) and Methods...
>
> Public CurrentState As AP_StateEnum
> Public CurrentDelayTime as Date
> Public UsualLandingTime As Date
> Public UsualRollOutTime as Date
> Public UsualCargoTrainArrivalTime As Date
> Public ExpectedArrival As Date, ExpectedUnloadTimeAfterArrival as Date
> Public ExpectedDeparture as Date
> Public TravelledFrom As String, TravellingTo as String
> Public FlightIDArrival As String, FlightIDDeparture As String
> '...
>
> 'Then you need a Public Method, which is able to switch
> 'internal states of the Airplane, depending on "Time"
> Public Sub DoSimulationStep(dT as Date, RealTime as Date)
> If RealTime < ExpectedArrival + _
> CurrentDelayTime Then
> CurrentState = InFlightArriving
>
> ElseIf RealTime < ExpectedArrival + _
> CurrentDelayTime + _
> UsualLandingTime Then
> CurrentState = InLandingPhase
>
> ElseIf RealTime < ExpectedArrival + _
> CurrentDelayTime + _
> UsualLandingTime + _
> UsualRollOutTime Then
> CurrentState = InRollOutPhase
>
> ElseIf RealTime < ExpectedArrival + _
> CurrentDelayTime + _
> UsualLandingTime + _
> UsualRollOutTime + _
> UsualCargoTrainArrivalTime Then
> CurrentState = InWaitForCargoTrainPhase
>
> elseif ... a.s.o.
>
> End If
>
> 'One can then calculate further (more granular)
> 'details within a given "Raw-State", using the
> 'passed dT-Interval, to calculate "SubStates"
> 'to shade some more light on the Unloading-Process
> 'for example, or the "LiftOff-Process" or whatever
> Select Case CurrentState
> Case InCargoUnLoadPhase
> 'calculate details here for SubStates in UnloadPhase
>
> Case InStartAccelPhase
> 'calculate details, based on dT here for the
> 'Start-Phase - for example the expected LiftOff-
> 'Point or whatever one wants, based on the physics
> 'of a given airplane-type
>
> case a.s.o
> End Select
> End Sub
>
> So, the above was something "inside" of a predefined
> 'cAirPlane'-VB-Class - you can also introduce other
> participants (more simulated Objects) and define appropriate
> Classes for them in a similar way.
>
> Each Class should have such a '.DoSimulationStep' method
> as just shown above.
>
> So that you can do the following in the above mentioned
> "trigger-loop":
>
> Private Sub tmrStep_Timer()
> Dim AirPlane As cAirPlane
> glbDT = 1 / 86400 'a constant dT, here one second in VBs DateFormat
> glbRealTime = glbRealTime + glbDT
>
> For Each AirPlane In AirPlanesCollection
> AirPlane.DoSimulationStep glbDT, glbRealTime
> Next AirPlane
> End Sub
>
> Before you enable the tmrStep-Timer, you should
> decide about the speed - for example if your
> glbDT-Interval is set to one second, and you
> set the Timer.Interval to 1000 (msec) then the
> Simulation runs roughly in Realtime - if you
> set it to only 100msec, then the Simulation runs
> 10 times as fast as in "reality" - also
> make sure to set the glbRealTime-Variable to
> your Starting-DateTime of choice, before enabling
> the Timer.
>
> That's it basically with regards to structuring -
> just flesh out the details yourself.
>
> Olaf