Remove the Dictionary for the behavior sections
parent
99a07094fc
commit
acf8cd0c3b
221
src/behavior.jl
221
src/behavior.jl
|
@ -13,8 +13,9 @@ function addBreakFreeSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags:
|
|||
trainIsHalting = drivingCourse[end][:v] == 0.0
|
||||
|
||||
if trainIsHalting && !endOfCSReached
|
||||
BS = BehaviorSection("breakFree", drivingCourse[end][:s], drivingCourse[end][:v], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingMode = "breakFree"
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
startingPoint = drivingCourse[end][:i]
|
||||
|
||||
# traction effort and resisting forces (in N)
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], "accelerating", train, settings.massModel) # currently the tractive effort is calculated like in the accelerating section
|
||||
|
@ -27,28 +28,13 @@ function addBreakFreeSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags:
|
|||
end
|
||||
|
||||
# delete every supportPoint except the first two
|
||||
while drivingCourse[end][:i] > drivingCourse[BS[:supportPoints][1]][:i] +1
|
||||
while drivingCourse[end][:i] > startingPoint +1
|
||||
pop!(drivingCourse)
|
||||
end
|
||||
|
||||
# change the accelerating data to break free
|
||||
drivingCourse[end-1][:behavior] = BS[:type]
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
|
||||
# remove the accelerating section from the CS
|
||||
CS[:t] = CS[:t] - get(CS[:behaviorSections], :accelerating, Dict(:t=>0.0))[:t] # total running time (in s)
|
||||
delete!(CS[:behaviorSections], :accelerating)
|
||||
|
||||
# calculate the accumulated breakFree section information
|
||||
merge!(BS, Dict(:length => drivingCourse[end][:s] - BS[:s_entry], # total length (in m)
|
||||
:s_exit => drivingCourse[end][:s], # last position (in m)
|
||||
:t => drivingCourse[end][:t] - drivingCourse[BS[:supportPoints][1]][:t], # total running time (in s)
|
||||
:v_exit => drivingCourse[end][:v])) # exit speed (in m/s)))
|
||||
|
||||
CS[:t] = CS[:t] + BS[:t] # total running time (in s)
|
||||
|
||||
merge!(CS[:behaviorSections], Dict(:breakFree => BS))
|
||||
drivingCourse[end-1][:behavior] = drivingMode
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
end # else: return the characteristic section without a breakFree section
|
||||
|
||||
# determine state flags
|
||||
|
@ -107,7 +93,7 @@ end #function addClearingSection
|
|||
## This function calculates the support points of the accelerating section.
|
||||
# Therefore it gets its previous driving course and the characteristic section and returns the characteristic section and driving course including the accelerating section
|
||||
function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::Dict, settings::Settings, train::Train, CSs::Vector{Dict})
|
||||
#= TODO: instead of CS just give csId?
|
||||
#= TODO: instead of CS just give csId?
|
||||
-> CS = CSs[csId] =#
|
||||
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], "accelerating", train, settings.massModel)
|
||||
|
@ -129,8 +115,8 @@ function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFla
|
|||
|
||||
# use the conditions for the accelerating section
|
||||
if !targetSpeedReached && !endOfCSReached && tractionSurplus && !brakingStartReached
|
||||
BS = BehaviorSection("accelerating", drivingCourse[end][:s], drivingCourse[end][:v], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingMode = "accelerating"
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
currentSpeedLimit = getCurrentSpeedLimit(CSs, CS[:id], drivingCourse[end][:s], train.length)
|
||||
previousSpeedLimitReached = currentSpeedLimit[:v] != CS[:v_limit] && drivingCourse[end][:v] >= currentSpeedLimit[:v]
|
||||
|
@ -159,10 +145,9 @@ function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFla
|
|||
|
||||
# create the next support point
|
||||
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, CS[:id]))
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], BS[:type], train, settings.massModel)
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], drivingMode, train, settings.massModel)
|
||||
|
||||
# conditions for the next while cycle
|
||||
if !ignoreBraking
|
||||
|
@ -249,7 +234,6 @@ function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFla
|
|||
end
|
||||
# delete last support point for recalculating the last step with reduced step size
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next for cycle
|
||||
brakingStartReached = false
|
||||
|
@ -264,7 +248,6 @@ function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFla
|
|||
if drivingCourse[end][:v] > CS[:v_peak]
|
||||
testFlag && println("in CS",CS[:id]," accelerating cycle",cycle," case: v=", drivingCourse[end][:v]," > v_peak=",CS[:v_peak]) # for testing
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next section
|
||||
brakingStartReached = false
|
||||
|
@ -273,7 +256,6 @@ function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFla
|
|||
testFlag && println("in CS",CS[:id]," accelerating cycle",cycle," case: s +s_braking=", drivingCourse[end][:s],",+",s_braking," = ",drivingCourse[end][:s] +s_braking," > s_exit=",CS[:s_exit]) # for testing
|
||||
if s_braking > 0.0
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
else
|
||||
drivingCourse[end][:s] = CS[:s_exit] # round s down to CS[:s_exit]
|
||||
|
@ -291,7 +273,6 @@ function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFla
|
|||
previousSpeedLimitReached = true
|
||||
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
else
|
||||
if drivingCourse[end][:s] + s_braking == CS[:s_exit]
|
||||
|
@ -318,19 +299,6 @@ function addAcceleratingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFla
|
|||
end
|
||||
|
||||
end #while
|
||||
|
||||
if length(BS[:supportPoints]) > 1
|
||||
# calculate the accumulated accelerating section information
|
||||
merge!(BS, Dict(:length => drivingCourse[end][:s] - BS[:s_entry], # total length (in m)
|
||||
:s_exit => drivingCourse[end][:s], # last position (in m)
|
||||
:t => drivingCourse[end][:t] - drivingCourse[BS[:supportPoints][1]][:t], # total running time (in s)
|
||||
:v_exit => drivingCourse[end][:v])) # exit speed (in m/s)))
|
||||
|
||||
# 03/10 old: CS[:v_peak] = max(drivingCourse[end][:v], CS[:v_entry]) # setting v_peak to the last support points velocity which is the highest reachable value in this characteristic section or to v_entry in case it is higher when running on a path with high resistances
|
||||
CS[:t] = CS[:t] + BS[:t] # total running time (in s)
|
||||
|
||||
mergeBehaviorSection!(CS[:behaviorSections], BS)
|
||||
end
|
||||
end
|
||||
|
||||
# set state flags
|
||||
|
@ -353,7 +321,7 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
trainIsBrakingDownhill = cruisingType == "downhillBraking"
|
||||
|
||||
# traction effort and resisting forces (in N)
|
||||
if !trainIsBrakingDownhill # TODO: or just give BS[:type] instead of "cruising"/"braking"?
|
||||
if !trainIsBrakingDownhill # TODO: or just give drivingMode instead of "cruising"/"braking"?
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], "cruising", train, settings.massModel)
|
||||
else
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], "braking", train, settings.massModel)
|
||||
|
@ -374,17 +342,16 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
tractionDeficit = drivingCourse[end][:F_T] < drivingCourse[end][:F_R]
|
||||
targetPositionReached = s_cruising == 0.0
|
||||
resistingForceNegative = drivingCourse[end][:F_R] < 0
|
||||
#println(" vor if speedIsValid=",speedIsValid ," brakingStartReached=", brakingStartReached," tractionDeficit=", tractionDeficit," targetPositionReached=", targetPositionReached)
|
||||
|
||||
if speedIsValid && !brakingStartReached && !tractionDeficit && !targetPositionReached
|
||||
# 03/04 old: if drivingCourse[end][:v]>0.0 && drivingCourse[end][:v]<=CS[:v_peak] && !brakingStartReached && drivingCourse[end][:F_T] >= drivingCourse[end][:F_R]
|
||||
BS = BehaviorSection(cruisingType, drivingCourse[end][:s], drivingCourse[end][:v], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingMode = cruisingType
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
# TODO: necessary?
|
||||
s_cruising = min(s_cruising, CS[:s_exit]-BS[:s_entry])
|
||||
targetPosition = min(drivingCourse[end][:s] + s_cruising, CS[:s_exit])
|
||||
# 07/12 old: s_cruising = min(s_cruising, CS[:s_exit]-drivingCourse[end][:s])
|
||||
|
||||
# traction effort and resisting forces (in N)
|
||||
#03/25 calculateForces!(drivingCourse[end], CSs, CS[:id], "cruising", train, settings.massModel)
|
||||
if !trainIsBrakingDownhill
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], "cruising", train, settings.massModel)
|
||||
else
|
||||
|
@ -394,7 +361,7 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
if settings.massModel == :homogeneous_strip && CS[:id] > 1
|
||||
# conditions for cruising section
|
||||
trainInPreviousCS = drivingCourse[end][:s] < CS[:s_entry] + train.length
|
||||
targetPositionReached = drivingCourse[end][:s] >= BS[:s_entry] +s_cruising
|
||||
targetPositionReached = drivingCourse[end][:s] >= targetPosition
|
||||
resistingForceNegative = drivingCourse[end][:F_R] < 0.0
|
||||
# targetSpeedReached = stateFlags[:speedLimitReached] || drivingCourse[end][:v] >= CS[:v_peak]
|
||||
# TODO: change? to correctCruisingType = (trainIsClearing || (trainIsBrakingDownhill == drivingCourse[end][:F_R] < 0)) # while clearing tractive or braking force can be used
|
||||
|
@ -407,11 +374,9 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
|
||||
for cycle in 1:settings.approxLevel+1 # first cycle with normal step size followed by cycles with reduced step size depending on the level of approximation
|
||||
while trainInPreviousCS && !targetPositionReached && !pointOfInterestReached && !tractionDeficit && (trainIsClearing || (trainIsBrakingDownhill == resistingForceNegative)) # while clearing tractive or braking force can be used
|
||||
# 03/09 old: while drivingCourse[end][:s] < CS[:s_entry] + train.length && drivingCourse[end][:s] < BS[:s_entry] +s_cruising && drivingCourse[end][:s] < nextPointOfInterest[1] && drivingCourse[end][:F_T]>=drivingCourse[end][:F_R]
|
||||
# the tractive effort is lower than the resisiting forces and the train has use the highest possible effort to try to stay at v_peak OR the mass model homogeneous strip is used and parts of the train are still in former CS
|
||||
#TODO: maybe just consider former CS with different path resistance?
|
||||
# tractive effort (in N):
|
||||
#03/25 drivingCourse[end][:F_T] = min(drivingCourse[end][:F_T], max(0.0, drivingCourse[end][:F_R]))
|
||||
if !trainIsBrakingDownhill
|
||||
drivingCourse[end][:F_T] = min(drivingCourse[end][:F_T], max(0.0, drivingCourse[end][:F_R]))
|
||||
else
|
||||
|
@ -428,8 +393,7 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
else
|
||||
push!(drivingCourse, moveAStep(drivingCourse[end], position, train.length/(10.0^cycle), CS[:id])) # TODO which step size should be used?
|
||||
end
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
# traction effort and resisting forces (in N)
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], "default", train, settings.massModel)
|
||||
|
@ -443,7 +407,7 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
# conditions for the next while cycle
|
||||
pointOfInterestReached = drivingCourse[end][:s] >= nextPointOfInterest[1] # POIs include s_exit as well
|
||||
tractionDeficit = drivingCourse[end][:F_T] < drivingCourse[end][:F_R]
|
||||
targetPositionReached = drivingCourse[end][:s] >= BS[:s_entry] +s_cruising
|
||||
targetPositionReached = drivingCourse[end][:s] >= targetPosition
|
||||
trainInPreviousCS = drivingCourse[end][:s] < CS[:s_entry] + train.length
|
||||
resistingForceNegative = drivingCourse[end][:F_R] < 0.0
|
||||
end #while
|
||||
|
@ -466,14 +430,14 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
currentStepSize = settings.stepSize / 10.0^cycle
|
||||
end
|
||||
|
||||
elseif drivingCourse[end][:s] > BS[:s_entry] + s_cruising # TODO also the following? drivingCourse[end][:s] > CSs[CS[:id]][:s_entry] + train.length))
|
||||
elseif drivingCourse[end][:s] > targetPosition # TODO also the following? drivingCourse[end][:s] > CSs[CS[:id]][:s_entry] + train.length))
|
||||
if settings.stepVariable == :distance
|
||||
currentStepSize=BS[:s_entry] + s_cruising-drivingCourse[end-1][:s]
|
||||
currentStepSize = targetPosition - drivingCourse[end-1][:s]
|
||||
else
|
||||
currentStepSize = settings.stepSize / 10.0^cycle
|
||||
end
|
||||
|
||||
elseif drivingCourse[end][:s] == BS[:s_entry] + s_cruising # || drivingCourse[end][:s]==CS[:s_exit]
|
||||
elseif drivingCourse[end][:s] == targetPosition # || drivingCourse[end][:s]==CS[:s_exit]
|
||||
break
|
||||
|
||||
elseif drivingCourse[end][:s] >= CS[:s_entry] + train.length
|
||||
|
@ -491,7 +455,6 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
|
||||
# delete last support point for recalculating the last step with reduced step size
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next for cycle
|
||||
pointOfInterestReached = false
|
||||
|
@ -503,12 +466,11 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
else # if the level of approximation is reached
|
||||
if drivingCourse[end][:s] > nextPointOfInterest[1]
|
||||
drivingCourse[end][:s] = nextPointOfInterest[1] # round s down to nextPointOfInterest
|
||||
elseif drivingCourse[end][:s] > BS[:s_entry]+s_cruising
|
||||
if BS[:type] != "clearing"
|
||||
elseif drivingCourse[end][:s] > targetPosition
|
||||
if drivingMode != "clearing"
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
end
|
||||
elseif drivingCourse[end][:s] == BS[:s_entry]+s_cruising
|
||||
elseif drivingCourse[end][:s] == targetPosition
|
||||
break
|
||||
elseif drivingCourse[end][:F_T] < drivingCourse[end][:F_R]
|
||||
break
|
||||
|
@ -533,15 +495,15 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
end #if
|
||||
|
||||
# conditions for the next while cycle
|
||||
targetPositionReached = drivingCourse[end][:s] >= BS[:s_entry] +s_cruising
|
||||
targetPositionReached = drivingCourse[end][:s] >= targetPosition
|
||||
tractionDeficit = drivingCourse[end][:F_T] < drivingCourse[end][:F_R]
|
||||
resistingForceNegative = drivingCourse[end][:F_R] < 0.0
|
||||
|
||||
while !targetPositionReached && !tractionDeficit && (trainIsClearing || (trainIsBrakingDownhill == resistingForceNegative)) # while clearing tractive or braking force can be used
|
||||
# 03/09 old: while drivingCourse[end][:s] < BS[:s_entry]+s_cruising && drivingCourse[end][:F_T] >= drivingCourse[end][:F_R]
|
||||
# 03/09 old: while drivingCourse[end][:s] < targetPosition && drivingCourse[end][:F_T] >= drivingCourse[end][:F_R]
|
||||
nextPointOfInterest = getNextPointOfInterest(CS[:pointsOfInterest], drivingCourse[end][:s])
|
||||
if nextPointOfInterest[1] > BS[:s_entry]+s_cruising
|
||||
nextPointOfInterest = [BS[:s_entry]+s_cruising, ""]
|
||||
if nextPointOfInterest[1] > targetPosition
|
||||
nextPointOfInterest = [targetPosition, ""]
|
||||
end
|
||||
|
||||
# tractive effort (in N):
|
||||
|
@ -557,16 +519,15 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
drivingCourse[end][:a] = 0.0 # acceleration (in m/s^2)
|
||||
|
||||
# calculate the remaining cruising way
|
||||
#s_cruisingRemaining=BS[:s_entry] + s_cruising-drivingCourse[end][:s]
|
||||
s_cruisingRemaining = min(nextPointOfInterest[1] -drivingCourse[end][:s], BS[:s_entry] +s_cruising -drivingCourse[end][:s])
|
||||
#s_cruisingRemaining=targetPosition-drivingCourse[end][:s]
|
||||
s_cruisingRemaining = min(nextPointOfInterest[1] -drivingCourse[end][:s], targetPosition -drivingCourse[end][:s])
|
||||
|
||||
# create the next support point
|
||||
push!(drivingCourse, moveAStep(drivingCourse[end], :distance, s_cruisingRemaining, CS[:id]))
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
if drivingCourse[end][:s] == nextPointOfInterest[1]
|
||||
drivingCourse[end][:label] = nextPointOfInterest[2]
|
||||
end
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], "default", train, settings.massModel)
|
||||
# calculateForces!(drivingCourse[end], CSs, CS[:id], "cruising", train, settings.massModel)
|
||||
|
@ -577,23 +538,11 @@ function addCruisingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
#end
|
||||
|
||||
# conditions for the next while cycle
|
||||
targetPositionReached = drivingCourse[end][:s] >= BS[:s_entry] +s_cruising
|
||||
targetPositionReached = drivingCourse[end][:s] >= targetPosition
|
||||
tractionDeficit = drivingCourse[end][:F_T] < drivingCourse[end][:F_R]
|
||||
resistingForceNegative = drivingCourse[end][:F_R] < 0
|
||||
end #while
|
||||
|
||||
# TODO: realize this better inside the upper loops?
|
||||
|
||||
|
||||
# calculate the accumulated cruising section information
|
||||
merge!(BS, Dict(:length => drivingCourse[end][:s] - BS[:s_entry], # total length (in m)
|
||||
:s_exit => drivingCourse[end][:s], # last position (in m)
|
||||
:t => drivingCourse[end][:t] - drivingCourse[BS[:supportPoints][1]][:t], # total running time (in s)
|
||||
:v_exit => drivingCourse[end][:v])) # exit speed (in m/s)))
|
||||
|
||||
CS[:t] = CS[:t] + BS[:t] # total running time (in s)
|
||||
|
||||
mergeBehaviorSection!(CS[:behaviorSections], BS)
|
||||
end # else: return the characteristic section without a cruising section
|
||||
|
||||
# set state flags
|
||||
|
@ -633,8 +582,8 @@ function addDiminishingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlag
|
|||
|
||||
# use the conditions for the diminishing section
|
||||
if tractionDeficit && !targetSpeedReached && !endOfCSReached
|
||||
BS = BehaviorSection("diminishing", drivingCourse[end][:s], drivingCourse[end][:v], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingMode = "diminishing"
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
while tractionDeficit && !targetSpeedReached && !endOfCSReached && !brakingStartReached
|
||||
currentStepSize=settings.stepSize # initialize the step size that can be reduced near intersections
|
||||
|
@ -649,10 +598,9 @@ function addDiminishingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlag
|
|||
|
||||
# create the next support point
|
||||
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, CS[:id]))
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], BS[:type], train, settings.massModel)
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], drivingMode, train, settings.massModel)
|
||||
|
||||
# conditions for the next while cycle
|
||||
if !ignoreBraking
|
||||
|
@ -717,7 +665,6 @@ function addDiminishingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlag
|
|||
end
|
||||
# delete last support point for recalculating the last step with reduced step size
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next for cycle
|
||||
brakingStartReached = false
|
||||
|
@ -729,7 +676,6 @@ function addDiminishingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlag
|
|||
else # if the level of approximation is reached
|
||||
if drivingCourse[end][:v] <= 0.0
|
||||
testFlag && println("in CS",CS[:id]," diminishing cycle",cycle," case: v=", drivingCourse[end][:v]," <= 0.0") # for testing
|
||||
# push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
error("ERROR: The train stops during diminishing run in CS",CS[:id]," because the maximum tractive effort is lower than the resistant forces.",
|
||||
" Before the stop the last point has the values s=",drivingCourse[end-1][:s]," m v=",drivingCourse[end-1][:v]," m/s a=",drivingCourse[end-1][:a]," m/s^2",
|
||||
" F_T=",drivingCourse[end-1][:F_T]," N R_traction=",drivingCourse[end-1][:R_traction]," N R_wagons=",drivingCourse[end-1][:R_wagons]," N R_path=",drivingCourse[end-1][:R_path]," N.")
|
||||
|
@ -737,7 +683,6 @@ function addDiminishingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlag
|
|||
elseif s_braking > 0.0 && drivingCourse[end][:s] + s_braking > CS[:s_exit]
|
||||
testFlag && println("in CS",CS[:id]," diminishing cycle",cycle," case: s +s_braking=", drivingCourse[end][:s],"+",s_braking," = ",drivingCourse[end][:s] +s_braking," > s_exit=",CS[:s_exit]) # for testing
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
pointOfInterestReached = false
|
||||
targetSpeedReached = false
|
||||
|
@ -773,18 +718,6 @@ function addDiminishingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlag
|
|||
drivingCourse[end][:label] = nextPointOfInterest[2]
|
||||
end
|
||||
end #while
|
||||
|
||||
if length(BS[:supportPoints]) > 1 # TODO: necessary? May it be possible that there is no diminishing because braking has to start?
|
||||
# calculate the accumulated diminishing section information
|
||||
merge!(BS, Dict(:length => drivingCourse[end][:s] - BS[:s_entry], # total length (in m)
|
||||
:s_exit => drivingCourse[end][:s], # last position (in m)
|
||||
:t => drivingCourse[end][:t] - drivingCourse[BS[:supportPoints][1]][:t], # total running time (in s)
|
||||
:v_exit => drivingCourse[end][:v])) # exit speed (in m/s)))
|
||||
|
||||
CS[:t] = CS[:t] + BS[:t] # total running time (in s)
|
||||
|
||||
mergeBehaviorSection!(CS[:behaviorSections], BS)
|
||||
end
|
||||
end
|
||||
|
||||
# set state flags
|
||||
|
@ -814,8 +747,8 @@ function addCoastingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
|
||||
# use the conditions for the coasting section
|
||||
if !targetSpeedReached && !endOfCSReached
|
||||
BS = BehaviorSection("coasting", drivingCourse[end][:s], drivingCourse[end][:v], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingMode = "coasting"
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
while !targetSpeedReached && !endOfCSReached && !brakingStartReached
|
||||
currentStepSize=settings.stepSize # initialize the step size that can be reduced near intersections
|
||||
|
@ -826,15 +759,14 @@ function addCoastingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
while !targetSpeedReached && !brakingStartReached && !pointOfInterestReached
|
||||
# 03/09 old : while drivingCourse[end][:v] > CS[:v_exit] && drivingCourse[end][:v] <= CS[:v_peak] && !brakingStartReached && drivingCourse[end][:s] < nextPointOfInterest[1]
|
||||
# traction effort and resisting forces (in N):
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], BS[:type], train, settings.massModel)
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], drivingMode, train, settings.massModel)
|
||||
|
||||
# acceleration (in m/s^2):
|
||||
drivingCourse[end][:a] = acceleration(drivingCourse[end][:F_T], drivingCourse[end][:F_R], train.m_train_full, train.ξ_train)
|
||||
|
||||
# create the next support point
|
||||
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, CS[:id]))
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
# conditions for the next while cycle
|
||||
s_braking = brakingDistance(drivingCourse[end][:v], CS[:v_exit], train.a_braking, settings.approxLevel)
|
||||
|
@ -892,7 +824,6 @@ function addCoastingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
end
|
||||
# delete last support point for recalculating the last step with reduced step size
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next for cycle
|
||||
brakingStartReached = false
|
||||
|
@ -909,7 +840,6 @@ function addCoastingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
elseif drivingCourse[end][:s] + s_braking > CS[:s_exit]
|
||||
# delete last support point because it went to far
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next for cycle
|
||||
# brakingStartReached = true
|
||||
|
@ -919,7 +849,6 @@ function addCoastingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
elseif drivingCourse[end][:v] > CS[:v_peak] # if the train gets to fast it has to brake # TODO: if accelereation and coasting functions will be combined this case is different for coasting and also the order of if cases is different
|
||||
# delete last support point because it went to far
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next for cycle
|
||||
brakingStartReached = false
|
||||
|
@ -941,16 +870,6 @@ function addCoastingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::
|
|||
end #while
|
||||
|
||||
stateFlags[:speedLimitReached] = false
|
||||
|
||||
# calculate the accumulated coasting section information
|
||||
merge!(BS, Dict(:length => drivingCourse[end][:s] - BS[:s_entry], # total length (in m)
|
||||
:s_exit => drivingCourse[end][:s], # last position (in m)
|
||||
:t => drivingCourse[end][:t] - drivingCourse[BS[:supportPoints][1]][:t], # total running time (in s)
|
||||
:v_exit => drivingCourse[end][:v])) # exit speed (in m/s)))
|
||||
|
||||
CS[:t] = CS[:t] + BS[:t] # total running time (in s)
|
||||
|
||||
merge!(CS[:behaviorSections], Dict(:coasting=>BS))
|
||||
end
|
||||
|
||||
# set state flags
|
||||
|
@ -973,8 +892,8 @@ function addBrakingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::D
|
|||
|
||||
# use the conditions for the braking section
|
||||
if !targetSpeedReached && !endOfCSReached
|
||||
BS = BehaviorSection("braking", drivingCourse[end][:s], drivingCourse[end][:v], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingMode = "braking"
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
while !targetSpeedReached && !endOfCSReached
|
||||
currentStepSize = settings.stepSize # initialize the step size that can be reduced near intersections
|
||||
|
@ -985,7 +904,7 @@ function addBrakingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::D
|
|||
while !targetSpeedReached && !endOfCSReached && !pointOfInterestReached
|
||||
# 03/09 old: while drivingCourse[end][:v] > CS[:v_exit] && !targetSpeedReached && drivingCourse[end][:s] < CS[:s_exit] && drivingCourse[end][:s] < nextPointOfInterest[1]
|
||||
# traction effort and resisting forces (in N):
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], BS[:type], train, settings.massModel)
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], drivingMode, train, settings.massModel)
|
||||
|
||||
# acceleration (in m/s^2):
|
||||
drivingCourse[end][:a] = train.a_braking
|
||||
|
@ -995,14 +914,12 @@ function addBrakingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::D
|
|||
# create empty support point and set it for the values of s_exit and v_exit
|
||||
push!(drivingCourse, SupportPoint())
|
||||
drivingCourse[end][:i] = drivingCourse[end-1][:i]+1
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
recalculateLastBrakingPoint!(drivingCourse, CS[:s_exit], CS[:v_exit])
|
||||
else
|
||||
# create the next support point
|
||||
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, CS[:id]))
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
push!(BS[:supportPoints], drivingCourse[end][:i])
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
end
|
||||
#println(drivingCourse[end][:i],". s=",drivingCourse[end][:s]," s_exit=", CS[:s_exit]," v_exit=", CS[:v_exit]," v=",drivingCourse[end][:v])
|
||||
|
||||
|
@ -1046,7 +963,6 @@ function addBrakingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::D
|
|||
|
||||
# delete last support point for recalculating the last step with reduced step size
|
||||
pop!(drivingCourse)
|
||||
pop!(BS[:supportPoints])
|
||||
|
||||
# conditions for the next for cycle
|
||||
pointOfInterestReached = false
|
||||
|
@ -1098,16 +1014,6 @@ function addBrakingSection!(CS::Dict, drivingCourse::Vector{Dict}, stateFlags::D
|
|||
end
|
||||
|
||||
end #while
|
||||
|
||||
# calculate the accumulated coasting section information
|
||||
merge!(BS, Dict(:length => drivingCourse[end][:s] - BS[:s_entry], # total length (in m)
|
||||
:s_exit => drivingCourse[end][:s], # last position (in m)
|
||||
:t => drivingCourse[end][:t] - drivingCourse[BS[:supportPoints][1]][:t], # total running time (in s)
|
||||
:v_exit => drivingCourse[end][:v])) # exit speed (in m/s)))
|
||||
|
||||
CS[:t] = CS[:t] + BS[:t] # total running time (in s)
|
||||
|
||||
merge!(CS[:behaviorSections], Dict(:braking=>BS))
|
||||
end # else: return the characteristic section without a braking section
|
||||
|
||||
# set state flags
|
||||
|
@ -1127,35 +1033,15 @@ end #function addBrakingSection!
|
|||
# Therefore it gets its first support point and the characteristic section and returns the characteristic section including the halt if needed.
|
||||
function addHalt!(CS::Dict, drivingCourse::Vector{Dict}, settings::Settings, train::Train, CSs::Vector{Dict})
|
||||
if drivingCourse[end][:v] == 0.0
|
||||
BS = BehaviorSection("standstill", drivingCourse[end][:s], drivingCourse[end][:v], drivingCourse[end][:i])
|
||||
merge!(BS, Dict(:length => 0.0, # total length (in m)
|
||||
:t => 0.0, # total running time (in s)
|
||||
:s_exit => drivingCourse[end][:s], # last position (in m)
|
||||
:v_exit => drivingCourse[end][:v])) # exit speed (in m/s)))
|
||||
drivingCourse[end][:behavior] = BS[:type]
|
||||
drivingMode = "halt"
|
||||
drivingCourse[end][:behavior] = drivingMode
|
||||
|
||||
# traction effort and resisting forces (in N)
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], BS[:type], train, settings.massModel)
|
||||
|
||||
merge!(CS[:behaviorSections], Dict(:halt => BS))
|
||||
calculateForces!(drivingCourse[end], CSs, CS[:id], drivingMode, train, settings.massModel)
|
||||
end # else: return the characteristic section without a halt section section
|
||||
return (CS, drivingCourse)
|
||||
end #function addHalt!
|
||||
|
||||
function mergeBehaviorSection!(BSs::Dict, BS::Dict)
|
||||
if !haskey(BSs, Symbol(BS[:type]))
|
||||
merge!(BSs, Dict(Symbol(BS[:type]) => BS))
|
||||
else
|
||||
number = "2"
|
||||
while haskey(BSs, Symbol(BS[:type]*number))
|
||||
number = string(parse(Int, number)+1)
|
||||
end
|
||||
merge!(BSs, Dict(Symbol(BS[:type]*number) => BS))
|
||||
# println("INFO: The ",number,". ",BS[:type]," section has been created. ! ! ! ! ! ! ! ! !")
|
||||
end
|
||||
return BSs
|
||||
end #function mergeBehaviorSection!
|
||||
|
||||
function recalculateLastBrakingPoint!(drivingCourse, s_target, v_target)
|
||||
currentPoint = drivingCourse[end]
|
||||
previousPoint = drivingCourse[end-1]
|
||||
|
@ -1188,11 +1074,6 @@ function secureBrakingBehavior!(CSs::Vector{Dict}, a_braking::Real, approxLevel:
|
|||
CS[:v_entry] = min(CS[:v_limit], v_entryMax)
|
||||
CS[:v_peak] = CS[:v_entry]
|
||||
|
||||
|
||||
# reset the characteristic section (CS), delete behavior sections (BS) that were used during the preperation for setting v_entry, v_peak and v_exit
|
||||
CS[:behaviorSections] = Dict()
|
||||
CS[:t] = 0.0
|
||||
|
||||
followingCSv_entry = CS[:v_entry]
|
||||
csId = csId - 1
|
||||
end #while
|
||||
|
@ -1253,10 +1134,6 @@ function secureAcceleratingBehavior!(CSs::Vector{Dict}, settings::Settings, trai
|
|||
end #if
|
||||
|
||||
previousCSv_exit = CS[:v_exit]
|
||||
|
||||
# reset the characteristic section (CS), delete behavior sections (BS) that were used during the preperation for setting v_entry, v_peak and v_exit
|
||||
CS[:behaviorSections] = Dict()
|
||||
CS[:t] = 0.0
|
||||
end #for
|
||||
|
||||
return CSs
|
||||
|
|
|
@ -639,18 +639,16 @@ end #function CharacteristicSections
|
|||
## create a characteristic section for a path section. A characteristic section is a part of the moving section. It contains behavior sections.
|
||||
function CharacteristicSection(id::Integer, s_entry::Real, section::Dict, v_limit::Real, s_trainLength::Real, MS_poi::Vector{Tuple})
|
||||
# Create and return a characteristic section dependent on the paths attributes
|
||||
characteristicSection= Dict(:id => id, # identifier
|
||||
:s_entry => s_entry, # first position (in m)
|
||||
:s_exit => section[:s_end], # last position (in m)
|
||||
:length => section[:s_end] -s_entry, # total length (in m)
|
||||
:r_path => section[:f_Rp], # path resistance (in ‰)
|
||||
:behaviorSections => Dict(), # list of containing behavior sections
|
||||
:t => 0.0, # total running time (in s)
|
||||
:v_limit => v_limit, # speed limit (in m/s)
|
||||
# initializing :v_entry, :v_peak and :v_exit with :v_limit
|
||||
:v_peak => v_limit, # maximum reachable speed (in m/s)
|
||||
:v_entry => v_limit, # maximum entry speed (in m/s)
|
||||
:v_exit => v_limit) # maximum exit speed (in m/s)
|
||||
characteristicSection::Dict{Symbol, Any} = Dict(:id => id, # identifier
|
||||
:s_entry => s_entry, # first position (in m)
|
||||
:s_exit => section[:s_end], # last position (in m)
|
||||
:length => section[:s_end] -s_entry, # total length (in m)
|
||||
:r_path => section[:f_Rp], # path resistance (in ‰)
|
||||
:v_limit => v_limit, # speed limit (in m/s)
|
||||
# initializing :v_entry, :v_peak and :v_exit with :v_limit
|
||||
:v_peak => v_limit, # maximum reachable speed (in m/s)
|
||||
:v_entry => v_limit, # maximum entry speed (in m/s)
|
||||
:v_exit => v_limit) # maximum exit speed (in m/s)
|
||||
|
||||
# list of positions of every point of interest (POI) in this charateristic section for which support points should be calculated
|
||||
s_exit = characteristicSection[:s_exit]
|
||||
|
@ -673,23 +671,6 @@ function CharacteristicSection(id::Integer, s_entry::Real, section::Dict, v_limi
|
|||
return characteristicSection
|
||||
end #function CharacteristicSection
|
||||
|
||||
"""
|
||||
BehaviorSection() TODO!
|
||||
"""
|
||||
function BehaviorSection(type::String, s_entry::Real, v_entry::Real, startingPoint::Integer)
|
||||
BS= Dict(
|
||||
:type => type, # type of behavior section: "breakFree", "clearing", "accelerating", "cruising", "downhillBraking", "diminishing", "coasting", "braking" or "standstill"
|
||||
:length => 0.0, # total length (in m)
|
||||
:s_entry => s_entry, # first position (in m)
|
||||
:s_exit => 0.0, # last position (in m)
|
||||
:t => 0.0, # total running time (in s)
|
||||
:v_entry => v_entry, # entry speed (in m/s)
|
||||
:v_exit => 0.0, # exit speed (in m/s)
|
||||
:supportPoints => [startingPoint] # list of identifiers of the containing support points starting with the initial point
|
||||
)
|
||||
return BS
|
||||
end #function BehaviorSection
|
||||
|
||||
"""
|
||||
a SupportPoint is the smallest element of the driving course. One step of the step approach is between two support points
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue