Supplementary materialPart 1: Model code

''' <summary>

''' All models should inherit this class

''' </summary>

''' <remarks>

''' .Item(ParamName) contains Model Specific Custom Parameters [Model_XYZ] section

''' .pGlobals(ParamName) conatins Data from [Globals] section

''' .pAircraftTrial contains Aircraft Pair Data

''' </remarks>

PublicMustInheritClass clsModel

Inherits Dictionary(OfString, Object)

PublicMustOverrideFunction CheckParameters() AsBoolean

PublicMustOverrideFunction GetRef(ByVal AircraftPair As clsAircraftPair, ByVal AircraftPairTimeData As clsAircraftPairTimeData) AsDouble

#Region"Private Data"

Private pParameterType As Dictionary(OfString, ParameterType)

Private pFilename AsString

Private pINIParametersSection AsString

Private pINIGlobalSection AsString

Private pINIAircraftSection AsString

Private pLoaded AsBoolean

Private pDelimiter AsString

Friend pRandom As clsRandom

Private pRunTime As TimeSpan

Private pModelName AsString

'Private pINIPairSection As String

FriendShared ModelExtraResultsString As System.Text.StringBuilder

''' <summary>

''' Dictionary of Objects for Global Vars

''' </summary>

''' <remarks</remarks>

Private pGlobal As Dictionary(OfString, Object)

''' <summary>

''' Dictionary of Data Types (One for each item in a Data line)

''' </summary>

''' <remarks</remarks>

Private pGlobalType As Dictionary(OfInteger, ParameterType)

''' <summary>

''' Dictionary of Data Key Names (One for each item in a Data line)

''' </summary>

''' <remarks</remarks>

Private pGlobalKey As Dictionary(OfInteger, String)

''' <summary>

''' Dictionary of Dictionaries (One for each PairData line)

''' </summary>

''' <remarks</remarks>

Friend pAircraftTrial As Dictionary(OfInteger, clsTrial)

#EndRegion

#Region"Enums"

''' <summary>

''' Variable Type

''' </summary>

''' <remarks</remarks>

PublicEnum ParameterType

''' <summary>

''' String Type

''' </summary>

''' <remarks</remarks>

STR = 0

''' <summary>

''' Integer Type

''' </summary>

''' <remarks</remarks>

INT = 1

''' <summary>

''' Double Type

''' </summary>

''' <remarks</remarks>

DBL = 2

EndEnum

#EndRegion

''' <summary>

''' Create new Model

''' </summary>

''' <param name="Filename">INI File which contains [Data] and [ModelName] sections.</param>

''' <param name="ModelName">Section name in INI File which contains paramters for the model.</param>

''' <remarks>This must be called from New of Sub Class which should also contain AddParameter and AddDataTemplate calls

''' Should never really be called directly

''' </remarks>

ProtectedFriendSubNew(ByVal Filename AsString, ByVal ModelName AsString)

' New Inherited Dictionary

MyBase.New()

' Prepare Vars

pParameterType = New Dictionary(OfString, ParameterType)

pGlobalType = New Dictionary(OfInteger, ParameterType)

pGlobalKey = New Dictionary(OfInteger, String)

pAircraftTrial = New Dictionary(OfInteger, clsTrial)

pFilename = Filename

pRunTime = New TimeSpan(0)

If ModelExtraResultsString IsNothingThen

ModelExtraResultsString = New System.Text.StringBuilder

EndIf

' Check file exists

If IO.File.Exists(pFilename) = FalseThenThrowNew Exception("Couldn't load file '" & pFilename & "'.")

' Set Vars

pModelName = ModelName

pINIParametersSection = pModelName

pINIGlobalSection = "Global"

pINIAircraftSection = "Aircraft"

pDelimiter = DEFAULT_ITEM_DELIMITER

' Add Global Parameters that all Models should expect in [Global] section

AddGlobalParameter("Iterations", ParameterType.INT)

AddGlobalParameter("Samples", ParameterType.INT)

AddGlobalParameter("Deadline", ParameterType.INT)

AddGlobalParameter("Decrement", ParameterType.DBL)

AddGlobalParameter("Seed", ParameterType.INT)

AddGlobalParameter("CriterionForceInteger", ParameterType.INT)

' Indicate Model is not yet loaded [i.e. must call Load()]

pLoaded = False

EndSub

#Region"Load Data"

''' <summary>

''' Load Variables and Data from Input INI File

''' </summary>

''' <returns>True on success</returns>

''' <remarks</remarks>

PublicFunction Load() AsBoolean

Dim RetVal AsBoolean

Try

' Prepare IniFile

Dim IniFile As clsINIFile

IniFile = New clsINIFile(pFilename)

' Get Global Vars

LoadAndCheckGlobalVars(IniFile)

' Get Model Specific Variables

LoadAndCheckModelVars(IniFile)

' Get Trial Data

LoadTrialData(IniFile)

' Generate all refs

GenerateRefs()

RetVal = True

Catch ex As Exception

frmConsole.WriteLine("Error: " & ex.Message.Replace(vbCrLf, vbCrLf & " " & vbTab))

ErrorCall("Error Loading Model [" & pModelName & "]. " & vbCrLf & ex.Message)

ThrowNew Exception("Error loading input file." & vbCrLf & "[" & pFilename & "]" & vbCrLf & ex.Message)

EndTry

pLoaded = RetVal

Return RetVal

EndFunction

''' <summary>

''' Load and Check variables from [Globals] section

''' </summary>

''' <param name="IniFile"</param>

''' <remarks</remarks>

Sub LoadAndCheckGlobalVars(ByVal IniFile As clsINIFile)

Dim IniValue AsString

'Get Global Parameters

pGlobal = New Dictionary(OfString, Object)

ForEach KVP As KeyValuePair(OfInteger, ParameterType) In pGlobalType

IniValue = IniFile.GetString(pINIGlobalSection, pGlobalKey(KVP.Key), "")

If IniValue > ""Then

If pGlobalType(KVP.Key) = ParameterType.INT Then

Try

pGlobal.Add(pGlobalKey(KVP.Key), CType(IniValue, Integer))

Catch ex As Exception

ThrowNew Exception("Cannot convert value for '" & pGlobalKey(KVP.Key) & "' to an Integer. [Value: '" & IniValue & "']")

EndTry

ElseIf pGlobalType(KVP.Key) = ParameterType.DBL Then

Try

pGlobal.Add(pGlobalKey(KVP.Key), CType(IniValue, Double))

Catch ex As Exception

ThrowNew Exception("Cannot convert value for '" & pGlobalKey(KVP.Key) & "' to a Double. [Value: '" & IniValue & "']")

EndTry

Else

Try

pGlobal.Add(pGlobalKey(KVP.Key), IniValue.Trim)

Catch ex As Exception

ThrowNew Exception("Cannot convert value for '" & pGlobalKey(KVP.Key) & "' to a string. [Value: '" & IniValue & "']")

EndTry

EndIf

Else

ThrowNew Exception("Cannot find value '" & pGlobalKey(KVP.Key) & "'")

EndIf

Next

'Check Globals

IfCType(pGlobal("Iterations"), Integer) < 1 Then

ThrowNew Exception("Iterations must be larger than 0")

EndIf

IfCType(pGlobal("Samples"), Integer) < 1 OrCType(pGlobal("Samples"), Integer) > 1000 Then

ThrowNew Exception("Samples must be in range 1 to 1000.")

EndIf

IfCType(pGlobal("Deadline"), Integer) < 1 Then

ThrowNew Exception("Deadline must be larger than 0")

EndIf

IfCType(pGlobal("Decrement"), Double) < 0 Then

ThrowNew Exception("Decrment must be larger than 0")

EndIf

IfCType(pGlobal("Seed"), Integer) < -1 Then

ThrowNew Exception("Seed must be integer value larger than 0. (Or -1 for random seed)")

EndIf

IfCType(pGlobal("CriterionForceInteger"), Integer) > 1 AndCType(pGlobal("CriterionForceInteger"), Integer) > 0 Then

ThrowNew Exception("CriterionForceInteger must be 0 (Don't force) or 1 (Force)")

EndIf

EndSub

''' <summary>

''' Load and Check variables from [Model_XYZ] section

''' </summary>

''' <param name="IniFile"</param>

''' <remarks</remarks>

Sub LoadAndCheckModelVars(ByVal IniFile As clsINIFile)

Dim IniValue AsString

' Get Model Specific Paramters Settings

Me.Clear()

ForEach KVP As KeyValuePair(OfString, ParameterType) In pParameterType

IniValue = IniFile.GetString(pINIParametersSection, KVP.Key.ToString, "")

If IniValue > ""Then

If pParameterType(KVP.Key.ToString) = ParameterType.INT Then

Try

Me.Item(KVP.Key.ToString) = CType(IniValue, Integer)

Catch ex As Exception

ThrowNew Exception("Cannot convert value for '" & KVP.Key.ToString & "' to an Integer. [Value: '" & IniValue & "']")

EndTry

ElseIf pParameterType(KVP.Key.ToString) = ParameterType.DBL Then

Try

Me.Item(KVP.Key.ToString) = CType(IniValue, Double)

Catch ex As Exception

ThrowNew Exception("Cannot convert value for '" & KVP.Key.ToString & "' to a Double. [Value: '" & IniValue & "']")

EndTry

Else

Try

Me.Item(KVP.Key.ToString) = IniValue.Trim

Catch ex As Exception

ThrowNew Exception("Cannot convert value for '" & KVP.Key.ToString & "' to a string. [Value: '" & IniValue & "']")

EndTry

EndIf

Else

ThrowNew Exception("Cannot find value '" & KVP.Key.ToString & "'")

EndIf

Next

' Check model specific parameters

CheckParameters()

EndSub

''' <summary>

''' Loads the Trial data ([Trial1], [Trial2] etc...)

''' </summary>

''' <param name="IniFile"</param>

''' <remarks>Loads AircraftPairs, Model Specific Data and Timeslots</remarks>

Sub LoadTrialData(ByVal IniFile As clsINIFile)

Dim IniValue AsString

Dim TempAircraftTrial As clsTrial

Dim TempAircraftTime As clsTime

Dim TimeCount AsLong

' Get all Trials ([Trial1],[Trial2],[Trial3]...)

Do

Try

' Get Aircraft Pairs Line

IniValue = IniFile.GetString("Trial" & (pAircraftTrial.Count + 1).ToString, "AircraftPairs", "")

If IniValue.Trim = ""ThenExitDo

' Load Data

IfCType(pGlobal("CriterionForceInteger"), Integer) = 1 Then

TempAircraftTrial = New clsTrial(IniValue, True)

Else

TempAircraftTrial = New clsTrial(IniValue, False)

EndIf

' Load Model Specific Data

For AircraftCount AsInteger = 1 To TempAircraftTrial.AircraftPair.Count

IniValue = IniFile.GetString("Trial" & (pAircraftTrial.Count + 1).ToString, pModelName & "_" & AircraftCount.ToString, "")

If IniValue.Trim = ""ThenThrowNew Exception("Couldn't find '" & pModelName & "_" & AircraftCount.ToString & "' value.")

TempAircraftTrial.AircraftPair(AircraftCount - 1).AddModelSpecificData(IniValue)

Next

' Save Object

pAircraftTrial.Add((pAircraftTrial.Count + 1), TempAircraftTrial)

Catch ex As Exception

ThrowNew Exception("Error Loading Trial " & (pAircraftTrial.Count + 1) & ". " & ex.Message)

EndTry

Try

' Do Timeslots (1,2,3...)

TimeCount = 1

Do

' Get Timeslot line

IniValue = IniFile.GetString("Trial" & (pAircraftTrial.Count).ToString, TimeCount.ToString, "")

If IniValue.Trim = ""ThenExitDo

TempAircraftTime = New clsTime(IniValue, pAircraftTrial(pAircraftTrial.Count).AircraftPair.Count)

'CType(pGlobal("Samples"), Integer)

pAircraftTrial(pAircraftTrial.Count).Time.Add(CInt(TimeCount), TempAircraftTime)

TimeCount += 1

LoopWhile pAircraftTrial(pAircraftTrial.Count).Time.Count < Integer.MaxValue

' Make sure go some times

If pAircraftTrial(pAircraftTrial.Count).Time.Count = 0 ThenThrowNew Exception("No valid times found.")

Catch ex As Exception

ThrowNew Exception("Error Loading Trial " & pAircraftTrial.Count & ", Timeslot " & TimeCount & ". " & ex.Message)

EndTry

LoopWhile pAircraftTrial.Count < Integer.MaxValue

' Make sure got some trials

If pAircraftTrial.Count = 0 ThenThrowNew Exception("No valid trials found.")

EndSub

''' <summary>

''' Generate all Ref values for this Model

''' </summary>

''' <remarks</remarks>

Sub GenerateRefs()

Dim TrialCount AsInteger

Dim TimeCount AsInteger

Dim PairCount AsInteger

For TrialCount = 1 To pAircraftTrial.Count

For TimeCount = 1 To pAircraftTrial(TrialCount).Time.Count

For PairCount = 0 To pAircraftTrial(TrialCount).Time(TimeCount).AircraftPairTimeData.Count - 1

Try

pAircraftTrial(TrialCount).Time(TimeCount).AircraftPairTimeData(PairCount).CalculatedRef = _

GetRef(pAircraftTrial(TrialCount).AircraftPair(PairCount), pAircraftTrial(TrialCount).Time(TimeCount).AircraftPairTimeData(PairCount))

Catch ex As Exception

ThrowNew Exception("Trial " & TrialCount & ", Time " & TimeCount & ", Pair " & PairCount + 1 & ". " & vbCrLf & ex.Message)

EndTry

Next

Next

Next

EndSub

#EndRegion

#Region"Add Variables"

''' <summary>

''' Add an expected parameter

''' </summary>

''' <param name="Key"</param>

''' <param name="ValueType"</param>

''' <remarks</remarks>

FriendSub AddParameter(ByVal Key AsString, ByVal ValueType As ParameterType)

pParameterType.Add(Key, ValueType)

EndSub

''' <summary>

''' Add an Item to the Global Parameters for all models

''' </summary>

''' <param name="Key"</param>

''' <param name="Valuetype"</param>

''' <remarks>This will be in the [Global] section</remarks>

FriendSub AddGlobalParameter(ByVal Key AsString, ByVal Valuetype As ParameterType)

pGlobalKey.Add(pGlobalKey.Count + 1, Key)

pGlobalType.Add(pGlobalType.Count + 1, Valuetype)

EndSub

#EndRegion

#Region"Run"

''' <summary>

''' Run this Model

''' </summary>

''' <returns>True on successful run</returns>

''' <remarks</remarks>

PublicFunction Run() AsBoolean

Try

Dim TimeSlot AsInteger ' Current Timeslot within a Trial

Dim SampleCount AsInteger ' Current Sample (within SamplesPerTimeslot)

Dim AircraftPairIndex AsInteger ' Current randomly selected aircraftpair index

Dim ThresholdDecrement AsInteger ' How much to decrement threshold by each no decision

Dim RefValue AsDouble ' Holds current Ref Value for a given pair

Dim SamplesPerTimeslot AsInteger ' Number of sample before moving to next timeslot

Dim Deadline AsInteger ' Maximum times to sample in a given interation

Dim DeadlineCount AsInteger ' Number of samples so far in the iteration

Dim TotalIterations AsInteger ' Number of iterations to do on each timeslot

Dim ResultsString AsString ' Output Data string

Dim Starttime As DateTime ' Time started processing

Dim DoubleFormatString AsString = "0.00000" ' Used to format Double values in output

Dim LastEvent AsDate ' Time of last screen update (attempt to make application responsive)

Dim TrueTime AsDouble ' Pretend true time for results (not used by model)

Dim ConflictDecSumRT AsDouble ' Calculated field for results (not used by model)

Dim ConflictDecSumRTTally As Dictionary(OfLong, Double)

Dim ConflictDecSumTally As Dictionary(OfLong, Double)

' Make sure Model has been loaded before running

If Loaded = FalseThenThrowNew Exception("Model not Loaded.")

' Prepare Random Number Generator

pRandom = New clsRandom(CType(pGlobal("Seed"), Integer))

' Prepare Timing

Starttime = Now

LastEvent = Now

pRunTime = New TimeSpan(0)

' Load Global Data

Deadline = CType(pGlobal("Deadline"), Integer)

ThresholdDecrement = CType(pGlobal("Decrement"), Integer)

TotalIterations = CType(pGlobal("Iterations"), Integer)

SamplesPerTimeslot = CType(pGlobal("Samples"), Integer)

' Write Header to Results

WriteResultLine(pModelName & DEFAULT_ITEM_DELIMITER & IO.Path.GetFileName(pFilename) & DEFAULT_ITEM_DELIMITER & pRandom.Seed)

ResultsString = "Trial" & DEFAULT_ITEM_DELIMITER _

& "Time" & DEFAULT_ITEM_DELIMITER _

& "Sample" & DEFAULT_ITEM_DELIMITER _

& "CallSignA" & DEFAULT_ITEM_DELIMITER _

& "CallSignB" & DEFAULT_ITEM_DELIMITER _

& "Conflict" & DEFAULT_ITEM_DELIMITER _

& "NonConflict" & DEFAULT_ITEM_DELIMITER _

& "NoDecision" & DEFAULT_ITEM_DELIMITER _

& "ConflictStrength" & DEFAULT_ITEM_DELIMITER _

& "NonConflictStrength" & DEFAULT_ITEM_DELIMITER _

& "Ref" & DEFAULT_ITEM_DELIMITER _

& "TrueTime" & DEFAULT_ITEM_DELIMITER _

& "ConflictDecSumRT" & DEFAULT_ITEM_DELIMITER _

& "ConflictDecMeanRT"

WriteResultLine(ResultsString)

If ModelExtraResultsString IsNothingThen ModelExtraResultsString = New System.Text.StringBuilder

' Loop through all Trials

For TrialNumber AsInteger = 1 To pAircraftTrial.Count

' Update Console and Screen

frmConsole.Write(".")

frmConsole.lblProgress.Text = "Trial: " & TrialNumber

Application.DoEvents()

LastEvent = Now

' Loop through Iterations for this Trial

For IterationCount AsInteger = 1 To TotalIterations

' Update Screen (and process events) if required

If Now.Subtract(LastEvent).TotalMilliseconds > 1000 Then

frmConsole.lblProgress.Text = "Trial: " & TrialNumber & " (" & IterationCount & " of " & TotalIterations & ")"

Application.DoEvents()

LastEvent = Now

EndIf

If gAbort = TrueThenGoTo Abort

' Clear Outcomes from last run for each Aircraft Pair

pAircraftTrial(TrialNumber).ClearIteration()

' Prepare Iteration

TimeSlot = 1

SampleCount = 0

DeadlineCount = 0

' Loop through all Timeslots in this Trial

Do

' Step 2: Get Random Aircraft Pair (from undecided ones)

AircraftPairIndex = pAircraftTrial(TrialNumber).GetRandomAircraftPairIndex(pRandom)

' Check if any Aircraft Pairs left, finish Iteration if not

If AircraftPairIndex = -1 ThenExitDo

' Step 3: Calculate Ref

If pAircraftTrial(TrialNumber).Time(TimeSlot).AircraftPairTimeData(AircraftPairIndex).CalculatedRefIsSet = TrueThen

RefValue = pAircraftTrial(TrialNumber).Time(TimeSlot).AircraftPairTimeData(AircraftPairIndex).CalculatedRef

Else

RefValue = GetRef(pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex), pAircraftTrial(TrialNumber).Time(TimeSlot).AircraftPairTimeData(AircraftPairIndex))

pAircraftTrial(TrialNumber).Time(TimeSlot).AircraftPairTimeData(AircraftPairIndex).CalculatedRef = RefValue

EndIf

' Step 4: Calculate Evidence, S = S + (C-Ref) + Gauss (0, N)

pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentSignal = _

pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentSignal _

+ (pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).Criterion - RefValue) _

+ pRandom.GetGaussian(0, pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).Noise)

' Step 5: Compare evidence to threshold (Signal to Threshold)

If Math.Abs(pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentSignal) > pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentThreshold Then

' Record Decision for this Pair (includes updating tallies for entire timeslot)

If pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentSignal > pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentThreshold Then

' Conflict (Signal > Threshold)

pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).SetDecision( _

TimeSlot, _

SampleCount, _

clsAircraftPair.Outcome.Conflict, _

Math.Abs(pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentSignal) - pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentThreshold _

)

Else

' Non Conflict (Signal <= Threshold)

pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).SetDecision( _

TimeSlot, _

SampleCount, _

clsAircraftPair.Outcome.NonConflict, _

Math.Abs(pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentSignal) - pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentThreshold _

)

EndIf

Else

' No Decision: Reduce Threshold for this pair (for future processing)

pAircraftTrial(TrialNumber).AircraftPair(AircraftPairIndex).CurrentThreshold -= ThresholdDecrement

EndIf

' Find all undecided pairs for scoring purposes

ForEach KVP As KeyValuePair(OfInteger, clsAircraftPair) In pAircraftTrial(TrialNumber).AircraftPair

If KVP.Value.Decision = clsAircraftPair.Outcome.Unknown Then

' No Decision Made

KVP.Value.SetDecision(TimeSlot, SampleCount, clsAircraftPair.Outcome.NoDecision, 0)

EndIf

Next

' Check whether time for new Timeslot

DeadlineCount += 1

SampleCount += 1

If SampleCount >= SamplesPerTimeslot Then

' New Timeslot required

SampleCount = 0

TimeSlot += 1

EndIf

' Check whether Deadline is reached or run out of timeslots

LoopWhile TimeSlot <= pAircraftTrial(TrialNumber).Time.Count _

And DeadlineCount < Deadline

Next' Iterations Loop

' Save Results for this Trial

DeadlineCount = 0

ResultsString = ""

ConflictDecSumRTTally = New Dictionary(OfLong, Double)

ConflictDecSumTally = New Dictionary(OfLong, Double)

' Loop through Timeslots

For TimeSlot = 1 To pAircraftTrial(TrialNumber).Time.Count

' Loop through Samples

For SampleCount = 0 To SamplesPerTimeslot - 1

DeadlineCount += 1

If DeadlineCount > Deadline ThenExitFor

ResultsString &= TrialNumber & DEFAULT_ITEM_DELIMITER _

& TimeSlot & DEFAULT_ITEM_DELIMITER _

& SampleCount

' Loop through each pair

For PairIndex = 0 To pAircraftTrial(TrialNumber).AircraftPair.Count - 1

With pAircraftTrial(TrialNumber).AircraftPair(PairIndex)

' Changed 13/10/2010

' TrueTime = (TimeSlot - 1) + (SampleCount / SamplesPerTimeslot)

TrueTime = (TimeSlot) + (SampleCount / SamplesPerTimeslot)

ConflictDecSumRT = TrueTime * (.GetTallyDecisions(clsAircraftPair.Outcome.Conflict, TimeSlot, SampleCount))

If ConflictDecSumRTTally.ContainsKey(PairIndex) = FalseThen ConflictDecSumRTTally.Add(PairIndex, 0)

ConflictDecSumRTTally(PairIndex) += ConflictDecSumRT

If ConflictDecSumTally.ContainsKey(PairIndex) = FalseThen ConflictDecSumTally.Add(PairIndex, 0)

ConflictDecSumTally(PairIndex) += .GetTallyDecisions(clsAircraftPair.Outcome.Conflict, TimeSlot, SampleCount)

'ConflictDecMeanRT = SUM of all the ConflictDecSum RT values divided by the (Sum of the ConflictDec values column)

ResultsString &= DEFAULT_ITEM_DELIMITER & _

.AircraftA.CallSign & DEFAULT_ITEM_DELIMITER _

& .AircraftB.CallSign & DEFAULT_ITEM_DELIMITER _

& Format(.GetTallyDecisions(clsAircraftPair.Outcome.Conflict, TimeSlot, SampleCount) / TotalIterations, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& Format(.GetTallyDecisions(clsAircraftPair.Outcome.NonConflict, TimeSlot, SampleCount) / TotalIterations, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& Format(.GetTallyDecisions(clsAircraftPair.Outcome.NoDecision, TimeSlot, SampleCount) / TotalIterations, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& Format(.GetTallyDecisionStrength(clsAircraftPair.Outcome.Conflict, TimeSlot, SampleCount) / TotalIterations, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& Format(.GetTallyDecisionStrength(clsAircraftPair.Outcome.NonConflict, TimeSlot, SampleCount) / TotalIterations, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& Format(pAircraftTrial(TrialNumber).Time(TimeSlot).AircraftPairTimeData(PairIndex).CalculatedRef, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& Format(TrueTime, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& Format(ConflictDecSumRT, DoubleFormatString) & DEFAULT_ITEM_DELIMITER _

& "###HOLDER" & PairIndex & "###"

EndWith

Next

ResultsString &= vbCrLf

Next

Next

For PairIndex = 0 To pAircraftTrial(TrialNumber).AircraftPair.Count - 1

'If ConflictDecSumTally(PairIndex) = 0 Then

'ResultsString = ResultsString.Replace("###HOLDER" & PairIndex & "###", Format(Integer.MaxValue, DoubleFormatString))

'Else

ResultsString = ResultsString.Replace("###HOLDER" & PairIndex & "###", Format(ConflictDecSumRTTally(PairIndex) / (ConflictDecSumTally(PairIndex) * 1), DoubleFormatString))

'End If

Next

WriteResult(ResultsString)

Next' TrialNumber Loop

WriteResultLine("")

pRunTime = Now.Subtract(Starttime)

Abort:

Catch ex As Exception

frmConsole.lblProgress.Text = ""

frmConsole.WriteLine("Error: " & ex.Message.Replace(vbCrLf, vbCrLf & " " & vbTab))

ErrorCall("Error Running Model. " & ex.Message)

ThrowNew Exception("Error Running Model. " & ex.Message)

EndTry

frmConsole.lblProgress.Text = ""

ReturnTrue

EndFunction

''' <summary>

''' Get the Model Type of this Model Object

''' </summary>

''' <param name="ModelName"</param>

''' <returns</returns>

''' <remarks</remarks>

SharedFunction GetModelType(ByVal ModelName AsString) As Type

Dim RetVal As Type = Nothing

Dim ca As Reflection.Assembly = Reflection.Assembly.GetEntryAssembly()

Dim KnownTypes() As Type = ca.GetTypes()

ForEach KT As Type In KnownTypes

If KT.Name = "clsModel_" & ModelName Then

RetVal = KT

ExitFor

EndIf

Next

Return RetVal

EndFunction

''' <summary>

''' Shared Generic to Load and Run 'ModelName' model

''' </summary>

''' <param name="ModelName">Name of Model</param>

''' <param name="InputFilename">Filename of Input File</param>

''' <returns</returns>

''' <remarks</remarks>

SharedFunction LoadAndRunModel(ByVal ModelName AsString, ByVal InputFilename AsString) AsBoolean

Dim RetVal AsBoolean = False

Dim ModelType As Type

Dim Model AsObject

Dim Args() AsObject = {InputFilename}

Dim ConstructorArgTypes() As System.Type = {"".GetType}

Dim Constructor As Reflection.ConstructorInfo

Dim PI As Reflection.PropertyInfo

Try

' Check Model Type

ModelType = GetModelType(ModelName)

If ModelType IsNothingThenThrowNew Exception("Model '" & ModelName & "' is unknown.")

' Load Model

frmConsole.Write("Loading " & ModelName & " Model...", True)

Constructor = ModelType.GetConstructor(ConstructorArgTypes)

Model = Constructor.Invoke(Args)

ModelType.InvokeMember("Load", Reflection.BindingFlags.Public Or Reflection.BindingFlags.InvokeMethod Or Reflection.BindingFlags.Instance, Nothing, Model, Nothing)

If gAbort = FalseThen frmConsole.WriteLine("Done.")

' Run Model

frmConsole.Write("Running " & ModelName & " Model...", True)

ModelType.InvokeMember("Run", Reflection.BindingFlags.Public Or Reflection.BindingFlags.InvokeMethod Or Reflection.BindingFlags.Instance, Nothing, Model, Nothing)