Rename waypoints

pull/1/head v0.4.1
Max Kannenberg 2021-12-08 21:54:46 +01:00
parent d71a1e882b
commit fb942260d2
7 changed files with 215 additions and 207 deletions

View File

@ -23,18 +23,26 @@ See folder examples.
# History
## Version 0.4.1
Rename waypoints
- rename "waypoints" to "dataPoints" and "Waypoint" to "DataPoint"
## Version 0.4
Refactor and fix modules EnergySaving, OperationModes and MovingPhases
The general used level of accuracy from v0.3 was added to EnergySaving and OperationModes. OperationModes and MovingPhases were fixed for steep ascents were a train runs with maximum tractive effort while the driving resistances are even higher.
- add the general used level of accuracy from v0.3 to EnergySaving and OperationModes.
- fix OperationModes and MovingPhases for steep ascents where a train runs with maximum tractive effort while the driving resistances are even higher.
## Version 0.3
Refactor module MovingPhases
Repeatedly occuring code lines were extracted and smaller functions created (e.g. the function moveAStep). A new approach for calculating the waypoints near intersections was integrated (e.g. including an editable level of accuracy).
- extract repeatedly occuring code lines and create smaller functions (e.g. the function moveAStep)
- integrate a new approach for calculating the waypoints near intersections (e.g. including an editable level of accuracy).
## Version 0.2

View File

@ -89,7 +89,7 @@ function calculateRecoveryTime(s_MS::AbstractFloat, t_MS::AbstractFloat, train::
end # if train.trainType
end #function calculateRecoveryTime
function increaseCoastingSection(csOriginal::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCSs::Vector{CharacteristicSection}, t_recoveryAvailable::AbstractFloat)
function increaseCoastingSection(csOriginal::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCSs::Vector{CharacteristicSection}, t_recoveryAvailable::AbstractFloat)
if haskey(csOriginal.behaviorSections, "cruising") && haskey(csOriginal.behaviorSections, "braking")
cruisingReduction=settings.stepSize
while cruisingReduction>=settings.stepSize/10^approximationLevel
@ -97,15 +97,15 @@ function increaseCoastingSection(csOriginal::CharacteristicSection, drivingCours
while cruisingReduction>=settings.stepSize/10^approximationLevel # will be done once and then depending on approximationLevel repeated with smaller cruisingReduction unless !(drivingCourseModified[end].v<=csModified.v_exit && drivingCourseModified[end].s<csModified.s_end) -> see below at the end of the while loop
# create a copy for the characteristic sections drivingCourse
energySavingStartId=get(csOriginal.behaviorSections, "cruising", BehaviorSection()).waypoints[1]
energySavingStartId=get(csOriginal.behaviorSections, "cruising", BehaviorSection()).dataPoints[1]
if energySavingStartId==0
error("ERROR at creating a new driving course for energy saving with coasting !")
end
# TODO: tried to insert copy on 15.07.2021 drivingCourseModified=[copy(drivingCourse[1])]
drivingCourseModified=[Waypoint(drivingCourse[1])]
drivingCourseModified=[DataPoint(drivingCourse[1])]
for i in 2:energySavingStartId
# TODO: tried to insert copy on 15.07.2021 push!(drivingCourseModified, copy(drivingCourse[i])) # List of waypoints till the start of energy saving
push!(drivingCourseModified, Waypoint(drivingCourse[i])) # List of waypoints till the start of energy saving
# TODO: tried to insert copy on 15.07.2021 push!(drivingCourseModified, copy(drivingCourse[i])) # List of data points till the start of energy saving
push!(drivingCourseModified, DataPoint(drivingCourse[i])) # List of data points till the start of energy saving
end
# calculating the new length of the cruising section
@ -115,7 +115,7 @@ function increaseCoastingSection(csOriginal::CharacteristicSection, drivingCours
# 09/20 old: doesn't work for non constant cruising
# t_cruising=get(csOriginal.behaviorSections, "cruising", BehaviorSection()).t_total-cruisingReduction
# s_cruising=t_cruising*drivingCourseModified[end].v
wayReduction=drivingCourse(get(csOriginal.behaviorSections, "cruising", BehaviorSection()).waypoints[end]).v*cruisingReduction
wayReduction=drivingCourse(get(csOriginal.behaviorSections, "cruising", BehaviorSection()).dataPoints[end]).v*cruisingReduction
s_cruising=get(csOriginal.behaviorSections, "cruising", BehaviorSection()).s_total-wayReduction
elseif settings.stepVariable=="v in m/s" # velocity step method
@ -185,10 +185,10 @@ end # function increaseCoastingSection
# method 2 with shortening the acceleration by stepsize
function decreaseMaximumVelocity(csOriginal::CharacteristicSection, drivingCourse, settings::Settings, train::Train, allCSs::Vector{CharacteristicSection}, t_recoveryAvailable::AbstractFloat)
#function decreaseMaximumVelocity(csOriginal::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCSs::Vector{CharacteristicSection}, t_recoveryAvailable::AbstractFloat)
#function decreaseMaximumVelocity(csOriginal::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCSs::Vector{CharacteristicSection}, t_recoveryAvailable::AbstractFloat)
if haskey(csOriginal.behaviorSections, "acceleration") && csOriginal.v_reach > csOriginal.v_entry && csOriginal.v_reach > csOriginal.v_exit
accelerationSection=BehaviorSection(get(csOriginal.behaviorSections, "acceleration", BehaviorSection()))
if drivingCourse[accelerationSection.waypoints[end]-1].v < csOriginal.v_exit
if drivingCourse[accelerationSection.dataPoints[end]-1].v < csOriginal.v_exit
return (CharacteristicSection(), [], false)
# TODO: or calculate a new acceleration phase with v_exit as v_reach? it will be very short, shorter than the step size.
end
@ -205,7 +205,7 @@ function decreaseMaximumVelocity(csOriginal::CharacteristicSection, drivingCours
#accelerationSection=BehaviorSection(get(csOriginal.behaviorSections, "acceleration", BehaviorSection()))
if length(accelerationSection.waypoints) > 2
if length(accelerationSection.dataPoints) > 2
if haskey(csOriginal.behaviorSections, "cruisingBeforeAcceleration")
cruisingBeforeAccelerationSection=BehaviorSection(get(csOriginal.behaviorSections, "cruisingBeforeAcceleration", BehaviorSection()))
merge!(csModified.behaviorSections, Dict("cruisingBeforeAcceleration"=>cruisingBeforeAccelerationSection))
@ -214,31 +214,31 @@ function decreaseMaximumVelocity(csOriginal::CharacteristicSection, drivingCours
end
# remove the last acceleration waypoint
pop!(accelerationSection.waypoints)
pop!(accelerationSection.dataPoints)
accelerationSection.v_exit=drivingCourse[accelerationSection.waypoints[end]].v # exit speed (in m/s)
accelerationSection.s_end=drivingCourse[accelerationSection.waypoints[end]].s # last position (in m)
accelerationSection.v_exit=drivingCourse[accelerationSection.dataPoints[end]].v # exit speed (in m/s)
accelerationSection.s_end=drivingCourse[accelerationSection.dataPoints[end]].s # last position (in m)
accelerationSection.s_total=accelerationSection.s_end-accelerationSection.s_start # total length (in m)
accelerationSection.t_total=drivingCourse[accelerationSection.waypoints[end]].t-drivingCourse[accelerationSection.waypoints[1]].t # total running time (in s)
accelerationSection.E_total=drivingCourse[accelerationSection.waypoints[end]].E-drivingCourse[accelerationSection.waypoints[1]].E # total energy consumption (in Ws)
accelerationSection.t_total=drivingCourse[accelerationSection.dataPoints[end]].t-drivingCourse[accelerationSection.dataPoints[1]].t # total running time (in s)
accelerationSection.E_total=drivingCourse[accelerationSection.dataPoints[end]].E-drivingCourse[accelerationSection.dataPoints[1]].E # total energy consumption (in Ws)
merge!(csModified.behaviorSections, Dict("acceleration"=>accelerationSection))
csModified.E_total=csModified.E_total+get(csModified.behaviorSections, "acceleration", BehaviorSection()).E_total
csModified.t_total=csModified.t_total+get(csModified.behaviorSections, "acceleration", BehaviorSection()).t_total
energySavingStartId=accelerationSection.waypoints[end]
energySavingStartId=accelerationSection.dataPoints[end]
else
# The acceleration section is only one step. This step is removed and if ther ist a cruisingBeforeAcceleration section it will be combined with the new cruising section.
energySavingStartId=get(csOriginal.behaviorSections, "cruisingBeforeAcceleration", get(csOriginal.behaviorSections, "acceleration", BehaviorSection())).waypoints[1]
energySavingStartId=get(csOriginal.behaviorSections, "cruisingBeforeAcceleration", get(csOriginal.behaviorSections, "acceleration", BehaviorSection())).dataPoints[1]
end
# TODO: should v_reach be reduced or is it enough to pop the waypoints?
# characteristicSection.v_reach=drivingCourse[end].v # setting v_reach to the last waypoints velocity which is the highest reachable value in this characteristic section
# TODO: should v_reach be reduced or is it enough to pop the data points?
# characteristicSection.v_reach=drivingCourse[end].v # setting v_reach to the last data points velocity which is the highest reachable value in this characteristic section
# copy the drivingCourse till the beginning of energy saving
drivingCourseModified=Vector{Waypoint}()
drivingCourseModified=Vector{DataPoint}()
for i in 1:energySavingStartId
push!(drivingCourseModified, Waypoint(drivingCourse[i])) # List of waypoints till the start of energy saving
push!(drivingCourseModified, DataPoint(drivingCourse[i])) # List of data points till the start of energy saving
end
#s_braking=max(0.0, ceil((csModified.v_exit^2-csModified.v_reach^2)/2/train.a_braking, digits=approximationLevel)) # ceil is used to be sure that the train stops at s_end in spite of rounding errors
@ -289,14 +289,14 @@ function decreaseMaximumVelocity(csOriginal::CharacteristicSection, drivingCours
end # function decreaseMaximumVelocity
# combination of method 1 and method 2
function combineEnergySavingMethods(csOriginal::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCSs::Vector{CharacteristicSection}, t_recoveryAvailable::AbstractFloat)
function combineEnergySavingMethods(csOriginal::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCSs::Vector{CharacteristicSection}, t_recoveryAvailable::AbstractFloat)
# if haskey(csOriginal.behaviorSections, "acceleration") && (haskey(csOriginal.behaviorSections, "braking") || haskey(csOriginal.behaviorSections, "coasting")) && csOriginal.v_reach>csOriginal.v_entry && csOriginal.v_reach>csOriginal.v_exit
if haskey(csOriginal.behaviorSections, "acceleration") && (haskey(csOriginal.behaviorSections, "braking") || haskey(csOriginal.behaviorSections, "coasting")) && drivingCourse[get(csOriginal.behaviorSections, "acceleration", BehaviorSection()).waypoints[end]].v > max(csOriginal.v_entry, csOriginal.v_exit)
if haskey(csOriginal.behaviorSections, "acceleration") && (haskey(csOriginal.behaviorSections, "braking") || haskey(csOriginal.behaviorSections, "coasting")) && drivingCourse[get(csOriginal.behaviorSections, "acceleration", BehaviorSection()).dataPoints[end]].v > max(csOriginal.v_entry, csOriginal.v_exit)
csCombined=CharacteristicSection(csOriginal)
drivingCourseCombined=Vector{Waypoint}()
drivingCourseCombined=Vector{DataPoint}()
for i in 1:length(drivingCourse)
# TODO: tried to insert copy on 15.07.2021 push!(drivingCourseCombined, copy(drivingCourse[i]))
push!(drivingCourseCombined, Waypoint(drivingCourse[i]))
push!(drivingCourseCombined, DataPoint(drivingCourse[i]))
end
ΔE=0.0 # saved energy (in Ws)
Δt=0.0 # time loss (in s)

View File

@ -115,38 +115,38 @@ function calculatePathResistance(s::AbstractFloat, massModel::String, train::Tra
end #function pathResistance
"""
calculate and return tractive and resisting forces for a waypoint
calculate and return tractive and resisting forces for a data point
"""
function calculateForces!(waypoint::Waypoint, train::Train, massModel::String, allCs::Vector{CharacteristicSection}, bsType::String)
function calculateForces!(dataPoint::DataPoint, train::Train, massModel::String, allCs::Vector{CharacteristicSection}, bsType::String)
# calculate resisting forces
waypoint.F_Rt=calculateTractionUnitResistance(waypoint.v, train)
waypoint.F_Rw=calculateWagonsResistance(waypoint.v, train)
waypoint.F_Runion=waypoint.F_Rt+waypoint.F_Rw
waypoint.F_Rp=calculatePathResistance(waypoint.s, massModel, train, allCs)
waypoint.F_R=waypoint.F_Runion+waypoint.F_Rp
dataPoint.F_Rt=calculateTractionUnitResistance(dataPoint.v, train)
dataPoint.F_Rw=calculateWagonsResistance(dataPoint.v, train)
dataPoint.F_Runion=dataPoint.F_Rt+dataPoint.F_Rw
dataPoint.F_Rp=calculatePathResistance(dataPoint.s, massModel, train, allCs)
dataPoint.F_R=dataPoint.F_Runion+dataPoint.F_Rp
#calculate tractive effort
if bsType == "acceleration"
waypoint.F_T = calculateTractiveEffort(waypoint.v, train.tractiveEffortArray)
dataPoint.F_T = calculateTractiveEffort(dataPoint.v, train.tractiveEffortArray)
elseif bsType == "cruising"
# 09/22 println("s=",waypoint.s, " v=",waypoint.v, " F_R=",waypoint.F_R, " F_T=",calculateTractiveEffort(waypoint.v, train.tractiveEffortArray))
waypoint.F_T = min(max(0.0, waypoint.F_R), calculateTractiveEffort(waypoint.v, train.tractiveEffortArray))
# 09/22 println("s=",dataPoint.s, " v=",dataPoint.v, " F_R=",dataPoint.F_R, " F_T=",calculateTractiveEffort(dataPoint.v, train.tractiveEffortArray))
dataPoint.F_T = min(max(0.0, dataPoint.F_R), calculateTractiveEffort(dataPoint.v, train.tractiveEffortArray))
else
waypoint.F_T = 0.0
dataPoint.F_T = 0.0
end
return waypoint
return dataPoint
end #function calculateForces
"""
TODO
"""
function moveAStep(previousPoint::Waypoint, stepVariable::String, stepSize::AbstractFloat, csId::Integer)
function moveAStep(previousPoint::DataPoint, stepVariable::String, stepSize::AbstractFloat, csId::Integer)
# stepSize is the currentStepSize depending on the accessing function
# TODO: csId is only for error messages. Should it be removed?
# creating the next waypoint
newPoint=Waypoint()
# creating the next data point
newPoint=DataPoint()
newPoint.i=previousPoint.i+1 # identifier
# calculate s, t, v, E
@ -197,7 +197,7 @@ end #function moveAStep
"""
# if the tail of the train is still located in a former characteristic section it has to be checked if its speed limit can be kept
"""
function detectFormerSpeedLimits(allCs::Vector{CharacteristicSection}, csWithTrainHeadId::Integer, currentPoint::Waypoint, l_union::AbstractFloat)
function detectFormerSpeedLimits(allCs::Vector{CharacteristicSection}, csWithTrainHeadId::Integer, currentPoint::DataPoint, l_union::AbstractFloat)
formerSpeedLimits=[]
if csWithTrainHeadId > 1 && currentPoint.s - l_union < allCs[csWithTrainHeadId].s_start
formerCsId=csWithTrainHeadId-1
@ -217,9 +217,9 @@ function detectFormerSpeedLimits(allCs::Vector{CharacteristicSection}, csWithTra
return formerSpeedLimits
end # function detectFormerSpeedLimits
function considerFormerSpeedLimits!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, formerSpeedLimits, accelerationSection::BehaviorSection)
# TODO: What is the type of formerSpeedLimits? function considerFormerSpeedLimits!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, formerSpeedLimits::Array{Array{AbstractFloat,1},1}, accelerationSection::BehaviorSection)
# would work: function considerFormerSpeedLimits!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, formerSpeedLimits::Array{Any,1}, accelerationSection::BehaviorSection)
function considerFormerSpeedLimits!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, formerSpeedLimits, accelerationSection::BehaviorSection)
# TODO: What is the type of formerSpeedLimits? function considerFormerSpeedLimits!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, formerSpeedLimits::Array{Array{AbstractFloat,1},1}, accelerationSection::BehaviorSection)
# would work: function considerFormerSpeedLimits!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, formerSpeedLimits::Array{Any,1}, accelerationSection::BehaviorSection)
if length(formerSpeedLimits) > 0
# if a former speed limit has been exceeded the acceleration steps of this CS will be removed and a cruising phase will be inserted before acceleration
if drivingCourse[end].v > formerSpeedLimits[end][2]
@ -266,19 +266,19 @@ function considerFormerSpeedLimits!(characteristicSection::CharacteristicSection
return (characteristicSection, drivingCourse, formerSpeedLimits, accelerationSection, false)
end # function considerFormerSpeedLimits!
## This function calculates the waypoints of the starting phase.
# Therefore it gets its first waypoint and the characteristic section and returns the characteristic section including the behavior section for starting if needed.
## This function calculates the data points of the starting phase.
# Therefore it gets its first data point and the characteristic section and returns the characteristic section including the behavior section for starting if needed.
# Info: currently the values of the starting phase will be calculated like in the acceleration phase
function addStartingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
function addStartingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
if drivingCourse[end].v==0.0 && drivingCourse[end].s<characteristicSection.s_end
startingSection=BehaviorSection()
startingSection.type="starting" # type of behavior section
startingSection.s_start=drivingCourse[end].s # first position (in m)
startingSection.v_entry=drivingCourse[end].v # entry speed (in m/s)
push!(startingSection.waypoints, drivingCourse[end].i) # list of containing waypoints
push!(startingSection.dataPoints, drivingCourse[end].i) # list of containing data points
# traction effort and resisting forces (in N):
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "acceleration")) # currently the tractive effort is calculated like in the acceleration phase
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "acceleration")) # currently the tractive effort is calculated like in the acceleration phase
# acceleration (in m/s^2):
drivingCourse[end].a=(drivingCourse[end].F_T-drivingCourse[end].F_R)/train.m_union/train.ξ_union
@ -288,11 +288,11 @@ function addStartingPhase!(characteristicSection::CharacteristicSection, driving
error("ERROR: a=0 m/s^2 in the starting phase !")
end
# creating the next waypoint
# creating the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, settings.stepSize, characteristicSection.id))
#= 07/30 TODO: the calculation is easier with these lines because the values that are 0 in the first step are not used in calculation but all in all the code gets easier without these lines:
push!(drivingCourse, Waypoint())
drivingCourse[end].i=drivingCourse[end-1].i+1 # incrementing the number of the waypoint
push!(drivingCourse, DataPoint())
drivingCourse[end].i=drivingCourse[end-1].i+1 # incrementing the number of the data point
# calculate s, t, v, E
if settings.stepVariable=="s in m" # distance step method
@ -318,14 +318,14 @@ function addStartingPhase!(characteristicSection::CharacteristicSection, driving
drivingCourse[end].ΔE=drivingCourse[end].ΔW_T # energy consumption in this step (in Ws)
drivingCourse[end].E=drivingCourse[end-1].E+drivingCourse[end].ΔE # energy consumption (in Ws)
=#
push!(startingSection.waypoints, drivingCourse[end].i)
push!(startingSection.dataPoints, drivingCourse[end].i)
# calculate the accumulated starting section information
startingSection.s_end=drivingCourse[end].s # last position (in m)
startingSection.s_total=startingSection.s_end-startingSection.s_start # total length (in m)
startingSection.v_exit=drivingCourse[end].v # exit speed (in m/s)
startingSection.t_total=drivingCourse[end].t-drivingCourse[startingSection.waypoints[1]].t # total running time (in s)
startingSection.E_total=drivingCourse[end].E-drivingCourse[startingSection.waypoints[1]].E # total energy consumption (in Ws)
startingSection.t_total=drivingCourse[end].t-drivingCourse[startingSection.dataPoints[1]].t # total running time (in s)
startingSection.E_total=drivingCourse[end].E-drivingCourse[startingSection.dataPoints[1]].E # total energy consumption (in Ws)
characteristicSection.t_total=characteristicSection.t_total+startingSection.t_total # total running time (in s)
characteristicSection.E_total=characteristicSection.E_total+startingSection.E_total # total energy consumption (in Ws)
@ -336,9 +336,9 @@ function addStartingPhase!(characteristicSection::CharacteristicSection, driving
end #function addStartingPhase!
## This function calculates the waypoints of the acceleration phase.
## This function calculates the data points of the acceleration phase.
# Therefore it gets its previous driving course and the characteristic section and returns the characteristic section and driving course including the acceleration section
function addAccelerationPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
function addAccelerationPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
if drivingCourse[end].v==0.0
(characteristicSection, drivingCourse)=addStartingPhase!(characteristicSection, drivingCourse, settings, train, allCs)
end #if
@ -352,7 +352,7 @@ function addAccelerationPhase!(characteristicSection::CharacteristicSection, dri
accelerationSection.type="acceleration" # type of behavior section
accelerationSection.s_start=drivingCourse[end].s # first position (in m)
accelerationSection.v_entry=drivingCourse[end].v # entry speed (in m/s)
push!(accelerationSection.waypoints, drivingCourse[end].i)
push!(accelerationSection.dataPoints, drivingCourse[end].i)
currentStepSize=settings.stepSize # initializing the step size that can be reduced near intersections
#= 08/23 old version for intersection approximation
@ -366,7 +366,7 @@ function addAccelerationPhase!(characteristicSection::CharacteristicSection, dri
# 09/09 new (for steep gradients "<=" is necessary but only in accelertion until braking due to Operation modes) TODO
# traction effort and resisting forces (in N)
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, accelerationSection.type))
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, accelerationSection.type))
# acceleration (in m/s^2):
drivingCourse[end].a=(drivingCourse[end].F_T-drivingCourse[end].F_R)/train.m_union/train.ξ_union
@ -374,9 +374,9 @@ function addAccelerationPhase!(characteristicSection::CharacteristicSection, dri
# error("ERROR: a=0 m/s^2 in the acceleration phase ! with F_T=",drivingCourse[end].F_T," F_Rt=",drivingCourse[end].F_Rt," F_Rw=",drivingCourse[end].F_Rw," F_Rp=",drivingCourse[end].F_Rp)
# end
# create the next waypoint
# create the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, characteristicSection.id))
push!(accelerationSection.waypoints, drivingCourse[end].i)
push!(accelerationSection.dataPoints, drivingCourse[end].i)
if length(formerSpeedLimits) > 0 # If the tail of the train is located in a former characteristic section with lower speed limit check if is is possible to accelerate as normal
(characteristicSection, drivingCourse, formerSpeedLimits, accelerationSection, endOfCsReached) = considerFormerSpeedLimits!(characteristicSection, drivingCourse, settings, train, allCs, formerSpeedLimits, accelerationSection)
@ -415,20 +415,20 @@ function addAccelerationPhase!(characteristicSection::CharacteristicSection, dri
else
error("ERROR at acceleration phase: With the step variable ",settings.stepVariable," the while loop will be left although v<v_reach and s<s_end in CS",characteristicSection.id," with s=" ,drivingCourse[end].s," m and v=",drivingCourse[end].v," m/s")
end
# delete last waypoint for recalculating the last step with reduced step size
# delete last data point for recalculating the last step with reduced step size
pop!(drivingCourse)
pop!(accelerationSection.waypoints)
pop!(accelerationSection.dataPoints)
else # if the level of approximation is reached
if drivingCourse[end].v<=0.0
# push!(accelerationSection.waypoints, drivingCourse[end].i)
# push!(accelerationSection.dataPoints, drivingCourse[end].i)
error("ERROR: The train stops during the acceleration phase in CS",characteristicSection.id," because the 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 F_Rt=",drivingCourse[end-1].F_Rt," N F_Rw=",drivingCourse[end-1].F_Rw," N F_Rp=",drivingCourse[end-1].F_Rp," N.")
elseif drivingCourse[end].v>characteristicSection.v_reach
pop!(drivingCourse)
pop!(accelerationSection.waypoints)
pop!(accelerationSection.dataPoints)
elseif drivingCourse[end].s>characteristicSection.s_end
drivingCourse[end].s=characteristicSection.s_end # rounding s down to s_end
@ -438,14 +438,14 @@ function addAccelerationPhase!(characteristicSection::CharacteristicSection, dri
end
end #for
# if length(accelerationSection.waypoints) > 1 # 09/09 new: it is possible that the acceleration starts at v_reach, accelerates a step, is to high and drops the last point. then there is only one waypoint which is not a section. | It should only be used in addAccelerationUntilBreaking! due to Operation Modes TODO
# if length(accelerationSection.dataPoints) > 1 # 09/09 new: it is possible that the acceleration starts at v_reach, accelerates a step, is to high and drops the last point. then there is only one data point which is not a section. | It should only be used in addAccelerationUntilBreaking! due to Operation Modes TODO
# calculation the accumulated acceleration section information
accelerationSection.v_exit=drivingCourse[end].v # exit speed (in m/s)
accelerationSection.s_end=drivingCourse[end].s # last position (in m)
accelerationSection.s_total=accelerationSection.s_end-accelerationSection.s_start # total length (in m)
accelerationSection.t_total=drivingCourse[end].t-drivingCourse[accelerationSection.waypoints[1]].t # total running time (in s)
accelerationSection.E_total=drivingCourse[end].E-drivingCourse[accelerationSection.waypoints[1]].E # total energy consumption (in Ws)
accelerationSection.t_total=drivingCourse[end].t-drivingCourse[accelerationSection.dataPoints[1]].t # total running time (in s)
accelerationSection.E_total=drivingCourse[end].E-drivingCourse[accelerationSection.dataPoints[1]].E # total energy consumption (in Ws)
characteristicSection.t_total=characteristicSection.t_total+accelerationSection.t_total # total running time (in s)
characteristicSection.E_total=characteristicSection.E_total+accelerationSection.E_total # total energy consumption (in Ws)
@ -456,14 +456,14 @@ function addAccelerationPhase!(characteristicSection::CharacteristicSection, dri
merge!(characteristicSection.behaviorSections, Dict("acceleration"=>accelerationSection))
# end
end # else: just return the given waypoint number without changes due to the acceleration phase
end # else: just return the given data point number without changes due to the acceleration phase
return (characteristicSection, drivingCourse)
end #function addAccelerationPhase!
## This function calculates the waypoints of the acceleration phase.
function addAccelerationPhaseUntilBraking!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
## This function calculates the data points of the acceleration phase.
function addAccelerationPhaseUntilBraking!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
if drivingCourse[end].v==0.0
(characteristicSection, drivingCourse)=addStartingPhase!(characteristicSection, drivingCourse, settings, train, allCs)
end #if
@ -514,7 +514,7 @@ function addAccelerationPhaseUntilBraking!(characteristicSection::Characteristic
accelerationSection.type="acceleration" # type of behavior section
accelerationSection.s_start=drivingCourse[end].s # first position (in m)
accelerationSection.v_entry=drivingCourse[end].v # entry speed (in m/s)
push!(accelerationSection.waypoints, drivingCourse[end].i)
push!(accelerationSection.dataPoints, drivingCourse[end].i)
currentStepSize=settings.stepSize # initializing the step size that can be reduced near intersections
# 08/23 : old for cycle in 1:5 # first cycle with normal step size, second cycle with reduced step size, third cycle with more reduced step size. fourth and fith are needed in case the velocity approaches 0.0 or v_reach
@ -524,7 +524,7 @@ function addAccelerationPhaseUntilBraking!(characteristicSection::Characteristic
# 09/09 old (for steep gradients <= is necessary): while drivingCourse[end].v<characteristicSection.v_reach && drivingCourse[end].s+s_braking<characteristicSection.s_end && drivingCourse[end].v>0.0 # as long as s_i + s_braking < s_CSend
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, accelerationSection.type))
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, accelerationSection.type))
# acceleration (in m/s^2):
drivingCourse[end].a=(drivingCourse[end].F_T-drivingCourse[end].F_R)/train.m_union/train.ξ_union
@ -532,9 +532,9 @@ function addAccelerationPhaseUntilBraking!(characteristicSection::Characteristic
error("ERROR: a=0 m/s^2 in the acceleration phase ! with F_T=",drivingCourse[end].F_T," F_Rt=",drivingCourse[end].F_Rt," F_Rw=",drivingCourse[end].F_Rw," F_Rp=",drivingCourse[end].F_Rp)
end
# create the next waypoint
# create the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, characteristicSection.id))
push!(accelerationSection.waypoints, drivingCourse[end].i)
push!(accelerationSection.dataPoints, drivingCourse[end].i)
if length(formerSpeedLimits) > 0 # If the tail of the train is located in a former characteristic section with lower speed limit check if is is possible to accelerate as normal
(characteristicSection, drivingCourse, formerSpeedLimits, accelerationSection, endOfCsReached) = considerFormerSpeedLimits!(characteristicSection, drivingCourse, settings, train, allCs, formerSpeedLimits, accelerationSection)
@ -570,64 +570,64 @@ function addAccelerationPhaseUntilBraking!(characteristicSection::Characteristic
else
error("ERROR at acceleration until braking phase: With the step variable ",settings.stepVariable," the while loop will be left although v<v_reach and s<s_end in CS",characteristicSection.id," with s=" ,drivingCourse[end].s," m and v=",drivingCourse[end].v," m/s")
end
# delete last waypoint for recalculating the last step with reduced step size
# delete last data point for recalculating the last step with reduced step size
pop!(drivingCourse)
pop!(accelerationSection.waypoints)
pop!(accelerationSection.dataPoints)
else # if the level of approximation is reached
if drivingCourse[end].v<=0.0
# push!(accelerationSection.waypoints, drivingCourse[end].i)
# push!(accelerationSection.dataPoints, drivingCourse[end].i)
error("ERROR: The train stops during the acceleration phase in CS",characteristicSection.id," because the 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 F_Rt=",drivingCourse[end-1].F_Rt," N F_Rw=",drivingCourse[end-1].F_Rw," N F_Rp=",drivingCourse[end-1].F_Rp," N.")
elseif drivingCourse[end].v>characteristicSection.v_reach
pop!(drivingCourse)
pop!(accelerationSection.waypoints)
pop!(accelerationSection.dataPoints)
elseif drivingCourse[end].s + s_braking > characteristicSection.s_end
pop!(drivingCourse)
pop!(accelerationSection.waypoints)
pop!(accelerationSection.dataPoints)
else
end
end
end #for
if length(accelerationSection.waypoints) > 1 # 09/09 new: it is possible that the acceleration starts at v_reach, accelerates a step, is to high and drops the last point. then there is only one waypoint which is not a section.
if length(accelerationSection.dataPoints) > 1 # 09/09 new: it is possible that the acceleration starts at v_reach, accelerates a step, is to high and drops the last point. then there is only one data point which is not a section.
# calculation the accumulated acceleration section information
accelerationSection.v_exit=drivingCourse[end].v # exit speed (in m/s)
accelerationSection.s_end=drivingCourse[end].s # last position (in m)
accelerationSection.s_total=accelerationSection.s_end-accelerationSection.s_start # total length (in m)
accelerationSection.t_total=drivingCourse[end].t-drivingCourse[accelerationSection.waypoints[1]].t # total running time (in s)
accelerationSection.E_total=drivingCourse[end].E-drivingCourse[accelerationSection.waypoints[1]].E # total energy consumption (in Ws)
accelerationSection.t_total=drivingCourse[end].t-drivingCourse[accelerationSection.dataPoints[1]].t # total running time (in s)
accelerationSection.E_total=drivingCourse[end].E-drivingCourse[accelerationSection.dataPoints[1]].E # total energy consumption (in Ws)
characteristicSection.v_reach=max(drivingCourse[end].v, characteristicSection.v_entry) # setting v_reach to the last waypoints velocity which is the highest reachable value in this characteristic section or to v_entry in case it is higher when driveng on a path with high resistances
characteristicSection.v_reach=max(drivingCourse[end].v, characteristicSection.v_entry) # setting v_reach to the last data points velocity which is the highest reachable value in this characteristic section or to v_entry in case it is higher when driveng on a path with high resistances
characteristicSection.t_total=characteristicSection.t_total+accelerationSection.t_total # total running time (in s)
characteristicSection.E_total=characteristicSection.E_total+accelerationSection.E_total # total energy consumption (in Ws)
merge!(characteristicSection.behaviorSections, Dict("acceleration"=>accelerationSection))
end
end # else: just return the given waypoint number without changes due to the acceleration phase
end # else: just return the given data point number without changes due to the acceleration phase
return (characteristicSection, drivingCourse)
end #function addAccelerationPhaseUntilBraking!
## This function calculates the waypoints of the cruising phase.
# Therefore it gets its first waypoint and the characteristic section and returns the characteristic section including the behavior section for cruising if needed.
function addCruisingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, s_cruising::AbstractFloat, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, cruisingType::String)
## This function calculates the data points of the cruising phase.
# Therefore it gets its first data point and the characteristic section and returns the characteristic section including the behavior section for cruising if needed.
function addCruisingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, s_cruising::AbstractFloat, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}, cruisingType::String)
if drivingCourse[end].v>0.0 && drivingCourse[end].v<=characteristicSection.v_reach && drivingCourse[end].s<characteristicSection.s_end
cruisingSection=BehaviorSection()
cruisingSection.type=cruisingType # type of behavior section
cruisingSection.s_start=drivingCourse[end].s # first position (in m)
cruisingSection.s_end=min(drivingCourse[end].s+s_cruising, characteristicSection.s_end) # last position (in m)
cruisingSection.v_entry=drivingCourse[end].v # entry speed (in m/s)
push!(cruisingSection.waypoints, drivingCourse[end].i)
push!(cruisingSection.dataPoints, drivingCourse[end].i)
# TODO: necessary?
s_cruising=min(s_cruising, characteristicSection.s_end-cruisingSection.s_start)
# traction effort and resisting forces (in N)
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "cruising")) # TODO: or give cruisingSection.type instead of "cruising"?
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "cruising")) # TODO: or give cruisingSection.type instead of "cruising"?
currentStepSize=settings.stepSize
for cycle in 1:approximationLevel+1 # first cycle with normal step size followed by cycles with reduced step size depending on the level of approximation
@ -642,22 +642,22 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
# acceleration (in m/s^2):
drivingCourse[end].a=0.0
# create the next waypoint
# create the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], "s_cruising in m", train.l_union/(10.0^cycle), characteristicSection.id)) # TODO welche Schrittweite nehm ich hier?
push!(cruisingSection.waypoints, drivingCourse[end].i)
push!(cruisingSection.dataPoints, drivingCourse[end].i)
else
# acceleration (in m/s^2):
drivingCourse[end].a=(drivingCourse[end].F_T-drivingCourse[end].F_R)/train.m_union/train.ξ_union
# create the next waypoint
# create the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, characteristicSection.id))
push!(cruisingSection.waypoints, drivingCourse[end].i)
push!(cruisingSection.dataPoints, drivingCourse[end].i)
end
# traction effort and resisting forces (in N)
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "cruising"))
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "cruising"))
end #while
# check which limit was reached and adjust the currentStepSize for the next cycle
@ -698,18 +698,18 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
# calculate the remaining cruising way
s_cruisingRemaining=cruisingSection.s_start+s_cruising-drivingCourse[end].s
# create the next waypoint
# create the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], "s_cruising in m", s_cruisingRemaining, characteristicSection.id))
push!(cruisingSection.waypoints, drivingCourse[end].i)
push!(cruisingSection.dataPoints, drivingCourse[end].i)
break
else # TODO copied from addAccelerationPhase -> probably not needed here !?
error("ERROR at cruising phase: With the step variable ",settings.stepVariable," the while loop will be left although the if cases don't apply in CS",characteristicSection.id," with s=" ,drivingCourse[end].s," m and v=",drivingCourse[end].v," m/s")
end
# delete last waypoint for recalculating the last step with reduced step size
# delete last data point for recalculating the last step with reduced step size
pop!(drivingCourse)
pop!(cruisingSection.waypoints)
pop!(cruisingSection.dataPoints)
else # if the level of approximation is reached
if drivingCourse[end].v<=0.0 # copied from addAccelerationPhase TODO: change error message?
@ -718,7 +718,7 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
" F_T=",drivingCourse[end-1].F_T," N F_Rt=",drivingCourse[end-1].F_Rt," N F_Rw=",drivingCourse[end-1].F_Rw," N F_Rp=",drivingCourse[end-1].F_Rp," N.")
#elseif drivingCourse[end].v > characteristicSection.v_reach # copied from addAccelerationPhase. TODO is it necessary for homogeneous strip?
# pop!(drivingCourse)
# pop!(cruisingSection.waypoints)
# pop!(cruisingSection.dataPoints)
#elseif drivingCourse[end].s>characteristicSection.s_end
# drivingCourse[end].s=characteristicSection.s_end # round s down to s_end
@ -727,7 +727,7 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
if cruisingSection.type == "cruisingBeforeAcceleration"
else
pop!(drivingCourse)
pop!(cruisingSection.waypoints)
pop!(cruisingSection.dataPoints)
end
@ -738,9 +738,9 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
# calculate the remaining cruising way
s_cruisingRemaining=cruisingSection.s_start+s_cruising-drivingCourse[end].s
# create the next waypoint
# create the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], "s_cruising in m", s_cruisingRemaining, characteristicSection.id))
push!(cruisingSection.waypoints, drivingCourse[end].i)
push!(cruisingSection.dataPoints, drivingCourse[end].i)
break
else
@ -752,9 +752,9 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
if drivingCourse[end].F_T>=drivingCourse[end].F_R
drivingCourse[end].a=0.0 # acceleration (in m/s^2)
push!(drivingCourse, Waypoint())
drivingCourse[end].i=drivingCourse[end-1].i+1 # incrementing the number of the waypoint
push!(cruisingSection.waypoints, drivingCourse[end].i)
push!(drivingCourse, DataPoint())
drivingCourse[end].i=drivingCourse[end-1].i+1 # incrementing the number of the data point
push!(cruisingSection.dataPoints, drivingCourse[end].i)
# calculate s, t, v, E
drivingCourse[end].Δs=min(s_cruising, characteristicSection.s_end-drivingCourse[end-1].s) # step size (in m)
@ -779,7 +779,7 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
while drivingCourse[end].v<=characteristicSection.v_reach && drivingCourse[end].s<characteristicSection.s_end && drivingCourse[end].v>0.0 # TODO: <= v_reach was inserted -> probably needed for homogeneous strip
# traction effort and resisting forces (in N)
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "cruising"))
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, "cruising"))
# acceleration (in m/s^2):
drivingCourse[end].a=(drivingCourse[end].F_T-drivingCourse[end].F_R)/train.m_union/train.ξ_union
@ -787,9 +787,9 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
# TODO: this part is important for mass strip
end
# create the next waypoint
# create the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, characteristicSection.id))
push!(cruisingSection.waypoints, drivingCourse[end].i)
push!(cruisingSection.dataPoints, drivingCourse[end].i)
#= TODO: the following has probably to be considered with homogeneous strip:
if length(formerSpeedLimits) > 0 # If the tail of the train is located in a former characteristic section with lower speed limit check if is is possible to accelerate as normal
@ -830,9 +830,9 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
else # TODO copied from addAccelerationPhase -> probably not needed here !?
error("ERROR at cruising phase: With the step variable ",settings.stepVariable," the while loop will be left although v<v_reach and s<s_end in CS",characteristicSection.id," with s=" ,drivingCourse[end].s," m and v=",drivingCourse[end].v," m/s")
end
# delete last waypoint for recalculating the last step with reduced step size
# delete last data point for recalculating the last step with reduced step size
pop!(drivingCourse)
pop!(cruisingSection.waypoints)
pop!(cruisingSection.dataPoints)
else # if the level of approximation is reached
if drivingCourse[end].v<=0.0 # copied from addAccelerationPhase TODO: change error message?
@ -841,7 +841,7 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
" F_T=",drivingCourse[end-1].F_T," N F_Rt=",drivingCourse[end-1].F_Rt," N F_Rw=",drivingCourse[end-1].F_Rw," N F_Rp=",drivingCourse[end-1].F_Rp," N.")
elseif drivingCourse[end].v > characteristicSection.v_reach # copied from addAccelerationPhase. TODO is it necessary for homogeneous strip?
pop!(drivingCourse)
pop!(cruisingSection.waypoints)
pop!(cruisingSection.dataPoints)
elseif drivingCourse[end].s>characteristicSection.s_end
drivingCourse[end].s=characteristicSection.s_end # round s down to s_end
else
@ -852,7 +852,7 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
end
=#
# 08/24 old push!(cruisingSection.waypoints, drivingCourse[end].i)
# 08/24 old push!(cruisingSection.dataPoints, drivingCourse[end].i)
## new 09/06 TODO: if no acceleration is following the cruising it could be called cruising
#if cruisingSection.type == "cruisingBeforeAcceleration" && drivingCourse[end].s == characteristicSection.s_end
@ -862,8 +862,8 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
# calculation the accumulated cruising section information
cruisingSection.v_exit=drivingCourse[end].v # exit speed (in m/s)
cruisingSection.s_total=cruisingSection.s_end-cruisingSection.s_start # total length (in m)
cruisingSection.t_total=drivingCourse[end].t-drivingCourse[cruisingSection.waypoints[1]].t # total running time (in s)
cruisingSection.E_total=drivingCourse[end].E-drivingCourse[cruisingSection.waypoints[1]].E # total energy consumption (in Ws)
cruisingSection.t_total=drivingCourse[end].t-drivingCourse[cruisingSection.dataPoints[1]].t # total running time (in s)
cruisingSection.E_total=drivingCourse[end].E-drivingCourse[cruisingSection.dataPoints[1]].E # total energy consumption (in Ws)
characteristicSection.t_total=characteristicSection.t_total+cruisingSection.t_total # total running time (in s)
characteristicSection.E_total=characteristicSection.E_total+cruisingSection.E_total # total energy consumption (in Ws)
@ -875,9 +875,9 @@ function addCruisingPhase!(characteristicSection::CharacteristicSection, driving
end #function addCruisingPhase!
## This function calculates the waypoints of the coasting phase.
## This function calculates the data points of the coasting phase.
# Therefore it gets its previous driving course and the characteristic section and returns the characteristic section and driving course including the coasting section
function addCoastingPhaseUntilBraking!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
function addCoastingPhaseUntilBraking!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection})
## if the tail of the train is still located in a former characteristic section it has to be checked if its speed limit can be kept
#formerSpeedLimits = detectFormerSpeedLimits(allCs, characteristicSection.id, drivingCourse[end], train.l_union)
@ -886,7 +886,7 @@ function addCoastingPhaseUntilBraking!(characteristicSection::CharacteristicSect
coastingSection.type="coasting" # type of behavior section
coastingSection.s_start=drivingCourse[end].s # first position (in m)
coastingSection.v_entry=drivingCourse[end].v # entry speed (in m/s)
push!(coastingSection.waypoints, drivingCourse[end].i)
push!(coastingSection.dataPoints, drivingCourse[end].i)
currentStepSize=settings.stepSize # initializing the step size that can be reduced near intersections
# 08/24 old for cycle in 1:3 # first cycle with normal step size, second cycle with reduced step size, third cycle with more reduced step size
@ -894,14 +894,14 @@ function addCoastingPhaseUntilBraking!(characteristicSection::CharacteristicSect
s_braking=ceil((characteristicSection.v_exit^2-drivingCourse[end].v^2)/2/train.a_braking, digits=approximationLevel)
while drivingCourse[end].v>characteristicSection.v_exit && drivingCourse[end].v<=characteristicSection.v_reach && drivingCourse[end].s + s_braking < characteristicSection.s_end # as long as s_i + s_braking < s_CSend
# traction effort and resisting forces (in N):
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, coastingSection.type))
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, coastingSection.type))
# acceleration (in m/s^2):
drivingCourse[end].a=(drivingCourse[end].F_T-drivingCourse[end].F_R)/train.m_union/train.ξ_union
# creating the next waypoint
# creating the next data point
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, characteristicSection.id))
push!(coastingSection.waypoints, drivingCourse[end].i)
push!(coastingSection.dataPoints, drivingCourse[end].i)
s_braking=ceil((characteristicSection.v_exit^2-drivingCourse[end].v^2)/2/train.a_braking)
@ -932,9 +932,9 @@ function addCoastingPhaseUntilBraking!(characteristicSection::CharacteristicSect
# TODO: not needed. just for testing
error("ERROR at coasting until braking phase: With the step variable ",settings.stepVariable," the while loop will be left although v<v_reach and s+s_braking<s_end in CS",characteristicSection.id," with s=" ,drivingCourse[end].s," m and v=",drivingCourse[end].v," m/s")
end
# delete last waypoint for recalculating the last step with reduced step size
# delete last data point for recalculating the last step with reduced step size
pop!(drivingCourse)
pop!(coastingSection.waypoints)
pop!(coastingSection.dataPoints)
else # if the level of approximation is reached
if drivingCourse[end].v<=0.0
@ -943,12 +943,12 @@ function addCoastingPhaseUntilBraking!(characteristicSection::CharacteristicSect
" F_T=",drivingCourse[end-1].F_T," N F_Rt=",drivingCourse[end-1].F_Rt," N F_Rw=",drivingCourse[end-1].F_Rw," N F_Rp=",drivingCourse[end-1].F_Rp," N and s_braking=",s_braking,"m.")
elseif drivingCourse[end].s + s_braking > characteristicSection.s_end
# delete last waypoint because it went to far
# delete last data point because it went to far
pop!(drivingCourse)
pop!(coastingSection.waypoints)
pop!(coastingSection.dataPoints)
elseif drivingCourse[end].v > characteristicSection.v_reach # 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
# while coasting the train brakes to hold v_reach (only one waypoint in the end of coasting is calculated like cruising at v_reach)
# while coasting the train brakes to hold v_reach (only one data point in the end of coasting is calculated like cruising at v_reach)
drivingCourse[end-1].a=0.0
s_braking=ceil((characteristicSection.v_exit^2-drivingCourse[end-1].v^2)/2/train.a_braking)
@ -980,37 +980,37 @@ function addCoastingPhaseUntilBraking!(characteristicSection::CharacteristicSect
coastingSection.v_exit=drivingCourse[end].v # exit speed (in m/s)
coastingSection.s_end=drivingCourse[end].s # last position (in m)
coastingSection.s_total=coastingSection.s_end-coastingSection.s_start # total length (in m)
coastingSection.t_total=drivingCourse[end].t-drivingCourse[coastingSection.waypoints[1]].t # total running time (in s)
coastingSection.E_total=drivingCourse[end].E-drivingCourse[coastingSection.waypoints[1]].E # total energy consumption (in Ws)
coastingSection.t_total=drivingCourse[end].t-drivingCourse[coastingSection.dataPoints[1]].t # total running time (in s)
coastingSection.E_total=drivingCourse[end].E-drivingCourse[coastingSection.dataPoints[1]].E # total energy consumption (in Ws)
characteristicSection.t_total=characteristicSection.t_total+coastingSection.t_total # total running time (in s)
characteristicSection.E_total=characteristicSection.E_total+coastingSection.E_total # total energy consumption (in Ws)
merge!(characteristicSection.behaviorSections, Dict("coasting"=>coastingSection))
end ## else: just return the given waypoint number without changes due to the coasting phase
end ## else: just return the given data point number without changes due to the coasting phase
return (characteristicSection, drivingCourse)
end #function addCoastingPhaseUntilBraking!
## This function calculates the waypoints of the braking phase. (standard braking phase with only two waypoints)
# Therefore it gets its first waypoint and the characteristic section and returns the characteristic section including the behavior section for braking if needed.
function addBrakingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}) #, s_braking::AbstractFloat)
# function addBrakingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, massModel::String, train::Train, allCs::Vector{CharacteristicSection}) #, s_braking::AbstractFloat)
## This function calculates the data points of the braking phase. (standard braking phase with only two data points)
# Therefore it gets its first data point and the characteristic section and returns the characteristic section including the behavior section for braking if needed.
function addBrakingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}) #, s_braking::AbstractFloat)
# function addBrakingPhase!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, massModel::String, train::Train, allCs::Vector{CharacteristicSection}) #, s_braking::AbstractFloat)
if drivingCourse[end].v>characteristicSection.v_exit && drivingCourse[end].s<characteristicSection.s_end
brakingSection=BehaviorSection()
brakingSection.type="braking" # type of behavior section
brakingSection.s_start=drivingCourse[end].s # first position (in m)
brakingSection.s_end=characteristicSection.s_end # last position (in m)
brakingSection.v_entry=drivingCourse[end].v # entry speed (in m/s)
push!(brakingSection.waypoints, drivingCourse[end].i) # refering from the breaking section to the first of its waypoints
push!(brakingSection.dataPoints, drivingCourse[end].i) # refering from the breaking section to the first of its data points
# traction effort and resisting forces (in N)
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, brakingSection.type))
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, brakingSection.type))
push!(drivingCourse, Waypoint())
drivingCourse[end].i=drivingCourse[end-1].i+1 # incrementing the number of the waypoint
push!(brakingSection.waypoints, drivingCourse[end].i) # refering from the breaking section to the last of its waypoints
push!(drivingCourse, DataPoint())
drivingCourse[end].i=drivingCourse[end-1].i+1 # incrementing the number of the data point
push!(brakingSection.dataPoints, drivingCourse[end].i) # refering from the breaking section to the last of its data points
# calculate s, t, v
drivingCourse[end].s=brakingSection.s_end # position (in m)
@ -1050,15 +1050,15 @@ end #function addBrakingPhase!
## This function calculates the waypoints of the braking phase. # 09/07 new braking phase with more than two waypoints
# Therefore it gets its first waypoint and the characteristic section and returns the characteristic section including the behavior section for braking if needed.
function addBrakingPhaseStepwise!(characteristicSection::CharacteristicSection, drivingCourse::Vector{Waypoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}) #, s_braking::AbstractFloat)
## This function calculates the data points of the braking phase. # 09/07 new braking phase with more than two data points
# Therefore it gets its first data point and the characteristic section and returns the characteristic section including the behavior section for braking if needed.
function addBrakingPhaseStepwise!(characteristicSection::CharacteristicSection, drivingCourse::Vector{DataPoint}, settings::Settings, train::Train, allCs::Vector{CharacteristicSection}) #, s_braking::AbstractFloat)
if drivingCourse[end].v>characteristicSection.v_exit && drivingCourse[end].s<characteristicSection.s_end
brakingSection=BehaviorSection()
brakingSection.type="braking" # type of behavior section
brakingSection.s_start=drivingCourse[end].s # first position (in m)
brakingSection.v_entry=drivingCourse[end].v # entry speed (in m/s)
push!(brakingSection.waypoints, drivingCourse[end].i) # refering from the breaking section to the first of its waypoints
push!(brakingSection.dataPoints, drivingCourse[end].i) # refering from the breaking section to the first of its data points
currentStepSize=settings.stepSize # initializing the step size that can be reduced near intersections
velocityIsPositive=true
@ -1066,12 +1066,12 @@ function addBrakingPhaseStepwise!(characteristicSection::CharacteristicSection,
while drivingCourse[end].v>characteristicSection.v_exit && drivingCourse[end].s < characteristicSection.s_end && velocityIsPositive
# println(" while-Durchlauf mit v=",drivingCourse[end].v," und v_exit=",characteristicSection.v_exit)
# traction effort and resisting forces (in N):
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, brakingSection.type))
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, allCs, brakingSection.type))
# acceleration (in m/s^2):
drivingCourse[end].a=train.a_braking
# creating the next waypoint
# creating the next data point
#TODO moveAStep should give back true or false for success or failure e.g. with dropping below v=0 m/s
#at the moment it is only for stepVariable=="s in m"
@ -1082,7 +1082,7 @@ function addBrakingPhaseStepwise!(characteristicSection::CharacteristicSection,
end
end
push!(drivingCourse, moveAStep(drivingCourse[end], settings.stepVariable, currentStepSize, characteristicSection.id))
push!(brakingSection.waypoints, drivingCourse[end].i)
push!(brakingSection.dataPoints, drivingCourse[end].i)
# s_braking=ceil((characteristicSection.v_exit^2-drivingCourse[end].v^2)/2/train.a_braking)
end # while
@ -1118,8 +1118,8 @@ function addBrakingPhaseStepwise!(characteristicSection::CharacteristicSection,
brakingSection.v_exit=drivingCourse[end].v # exit speed (in m/s)
brakingSection.s_end=drivingCourse[end].s # last position (in m)
brakingSection.s_total=brakingSection.s_end-brakingSection.s_start # total length (in m)
brakingSection.t_total=drivingCourse[end].t-drivingCourse[brakingSection.waypoints[1]].t # total running time (in s)
brakingSection.E_total=drivingCourse[end].E-drivingCourse[brakingSection.waypoints[1]].E # total energy consumption (in Ws)
brakingSection.t_total=drivingCourse[end].t-drivingCourse[brakingSection.dataPoints[1]].t # total running time (in s)
brakingSection.E_total=drivingCourse[end].E-drivingCourse[brakingSection.dataPoints[1]].E # total energy consumption (in Ws)
characteristicSection.t_total=characteristicSection.t_total+brakingSection.t_total # total running time (in s)
characteristicSection.E_total=characteristicSection.E_total+brakingSection.E_total # total energy consumption (in Ws)

View File

@ -13,10 +13,10 @@ approximationLevel = 6 # TODO: define it in TrainRun and give it to each fu
function simulateMinimumRunningTime!(movingSection::MovingSection, settings::Settings, train::Train)
# simulate a train run focussing on using the minimum possible running time
startingPoint=Waypoint()
startingPoint=DataPoint()
startingPoint.i=1
startingPoint.s=movingSection.characteristicSections[1].s_start
drivingCourse=[startingPoint] # List of waypoints
drivingCourse=[startingPoint] # List of data points
for csId in 1:length(movingSection.characteristicSections)
# println("CS",csId)
@ -87,8 +87,8 @@ function simulateMinimumRunningTime!(movingSection::MovingSection, settings::Set
end =#
end #for
# calculate the last waypoints resiting forces
drivingCourse[end]=Waypoint(calculateForces!(drivingCourse[end], train, settings.massModel, movingSection.characteristicSections, "braking"))
# calculate the last data points resiting forces
drivingCourse[end]=DataPoint(calculateForces!(drivingCourse[end], train, settings.massModel, movingSection.characteristicSections, "braking"))
movingSection.t_total=drivingCourse[end].t # total running time (in s)
movingSection.E_total=drivingCourse[end].E # total energy consumption (in Ws)
@ -97,7 +97,7 @@ function simulateMinimumRunningTime!(movingSection::MovingSection, settings::Set
end #function simulateMinimumRunningTime
function simulateMinimumEnergyConsumption(movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumRunningTime::Vector{Waypoint}, settings::Settings, train::Train)
function simulateMinimumEnergyConsumption(movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumRunningTime::Vector{DataPoint}, settings::Settings, train::Train)
# simulate a train run focussing on using the minimum possible energy consumption
# booleans for choosing which methods are used for saving energy
doMethod1=true
@ -111,9 +111,9 @@ function simulateMinimumEnergyConsumption(movingSectionMinimumRunningTime::Movin
movingSectionOriginal=MovingSection(movingSectionMinimumRunningTime)
# create a new driving course for the minimum energy consumption
drivingCourseOriginal=Waypoint[]
drivingCourseOriginal=DataPoint[]
for i in 1:length(drivingCourseMinimumRunningTime)
push!(drivingCourseOriginal, Waypoint(drivingCourseMinimumRunningTime[i])) # List of waypoints till the start of energy saving
push!(drivingCourseOriginal, DataPoint(drivingCourseMinimumRunningTime[i])) # List of data points till the start of energy saving
end
# calculate the recovery time
@ -224,12 +224,12 @@ function simulateMinimumEnergyConsumption(movingSectionMinimumRunningTime::Movin
movingSectionOriginal.t_recoveryAvailable = movingSectionOriginal.t_recoveryAvailable - movingSectionOriginal.energySavingModifications[end].Δt
lastIdOfSelectedCsOriginal = get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "braking", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "cruisingAfterCoasting", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "coasting", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "cruising", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "acceleration", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "cruisingBeforeAcceleration", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "starting", BehaviorSection()))))))).waypoints[end]
lastIdOfSelectedCsOriginal = get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "braking", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "cruisingAfterCoasting", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "coasting", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "cruising", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "acceleration", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "cruisingBeforeAcceleration", get(movingSectionOriginal.characteristicSections[csIdMax].behaviorSections, "starting", BehaviorSection()))))))).dataPoints[end]
# create new driving course
drivingCourseNew=Vector{Waypoint}()
drivingCourseNew=Vector{DataPoint}()
for i in 1:length(movingSectionOriginal.energySavingModifications[end].drivingCourseModified)
push!(drivingCourseNew, Waypoint(movingSectionOriginal.energySavingModifications[end].drivingCourseModified[i]))
push!(drivingCourseNew, DataPoint(movingSectionOriginal.energySavingModifications[end].drivingCourseModified[i]))
end
# # for testing if the modifications driving course and the original one have the same speed value at their transition point
@ -274,7 +274,7 @@ function simulateMinimumEnergyConsumption(movingSectionMinimumRunningTime::Movin
i=lastIdOfSelectedCsOriginal+1
while i <= length(drivingCourseOriginal)
push!(drivingCourseNew, Waypoint(drivingCourseOriginal[i]))
push!(drivingCourseNew, DataPoint(drivingCourseOriginal[i]))
drivingCourseNew[end].i=length(drivingCourseNew)
drivingCourseNew[end].t=drivingCourseNew[end-1].t+drivingCourseNew[end].Δt
drivingCourseNew[end].E=drivingCourseNew[end-1].E+drivingCourseNew[end].ΔE
@ -288,21 +288,21 @@ function simulateMinimumEnergyConsumption(movingSectionMinimumRunningTime::Movin
movingSectionOriginal.t_total=drivingCourseOriginal[end].t # total running time (in s)
movingSectionOriginal.E_total=drivingCourseOriginal[end].E # total energy consumption (in Ws)
# update all the waypoint references in the behaviour sections of the following characteristic sections and the other modified characteristic sections
# update all the data point references in the behaviour sections of the following characteristic sections and the other modified characteristic sections
if difference!= 0
# update the waypoint references in the behaviour sections of the following characteristic sections
# update the data point references in the behaviour sections of the following characteristic sections
allBs=["starting", "cruisingBeforeAcceleration", "acceleration", "cruising", "coasting", "cruisingAfterCoasting", "braking"]
for csId in csIdMax+1:length(movingSectionOriginal.characteristicSections)
for bs in 1: length(allBs)
if haskey(movingSectionOriginal.characteristicSections[csId].behaviorSections, allBs[bs])
for point in 1:length(get(movingSectionOriginal.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).waypoints)
get(movingSectionOriginal.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).waypoints[point]=get(movingSectionOriginal.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).waypoints[point]+difference
for point in 1:length(get(movingSectionOriginal.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).dataPoints)
get(movingSectionOriginal.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).dataPoints[point]=get(movingSectionOriginal.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).dataPoints[point]+difference
end
end #if
end #for
end #for
# update the waypoints in the following modified charateristic sections and the following points in the driving course
# update the data points in the following modified charateristic sections and the following points in the driving course
energySavingModificationsWithCoasting = updateEnergySavingModifications(energySavingModificationsWithCoasting, csIdMax, drivingCourseNew, endOfModificationId, lastIdOfSelectedCsOriginal)
energySavingModificationsWithMaximumSpeed = updateEnergySavingModifications(energySavingModificationsWithMaximumSpeed, csIdMax, drivingCourseNew, endOfModificationId, lastIdOfSelectedCsOriginal)
energySavingModificationsWithCombination = updateEnergySavingModifications(energySavingModificationsWithCombination, csIdMax, drivingCourseNew, endOfModificationId, lastIdOfSelectedCsOriginal)
@ -337,7 +337,7 @@ function simulateMinimumEnergyConsumption(movingSectionMinimumRunningTime::Movin
end #function simulateMinimumEnergyConsumption
function modifyCs(movingSectionOriginal::MovingSection, drivingCourseOriginal::Vector{Waypoint}, csId::Integer, modificationType::String, settings::Settings, train::Train)
function modifyCs(movingSectionOriginal::MovingSection, drivingCourseOriginal::Vector{DataPoint}, csId::Integer, modificationType::String, settings::Settings, train::Train)
#println("drin: ",modificationType)
if modificationType == "increasing coasting"
# method 1: increase coasting
@ -393,7 +393,7 @@ function findBestModification(energySavingModifications::Vector{EnergySavingModi
return (energySavingModifications, ratioMax, csIdMax, typeMax)
end #function findBestModification
function updateEnergySavingModifications(energySavingModifications::Vector{EnergySavingModification}, csIdMax::Integer, drivingCourseNew::Vector{Waypoint}, endOfModificationId::Integer, lastIdOfSelectedCsOriginal::Integer)
function updateEnergySavingModifications(energySavingModifications::Vector{EnergySavingModification}, csIdMax::Integer, drivingCourseNew::Vector{DataPoint}, endOfModificationId::Integer, lastIdOfSelectedCsOriginal::Integer)
allBs = ["starting", "cruisingBeforeAcceleration", "acceleration", "cruising", "coasting", "cruisingAfterCoasting", "braking"]
difference = endOfModificationId-lastIdOfSelectedCsOriginal
for modNr in csIdMax+1:length(energySavingModifications)
@ -401,20 +401,20 @@ function updateEnergySavingModifications(energySavingModifications::Vector{Energ
# update the behavior sections of the modified charateristic section
for bs in 1: length(allBs)
if haskey(energySavingModifications[modNr].csModified.behaviorSections, allBs[bs])
for point in 1:length(get(energySavingModifications[modNr].csModified.behaviorSections, allBs[bs], BehaviorSection()).waypoints)
get(energySavingModifications[modNr].csModified.behaviorSections, allBs[bs], BehaviorSection()).waypoints[point] = get(energySavingModifications[modNr].csModified.behaviorSections, allBs[bs], BehaviorSection()).waypoints[point]+difference
for point in 1:length(get(energySavingModifications[modNr].csModified.behaviorSections, allBs[bs], BehaviorSection()).dataPoints)
get(energySavingModifications[modNr].csModified.behaviorSections, allBs[bs], BehaviorSection()).dataPoints[point] = get(energySavingModifications[modNr].csModified.behaviorSections, allBs[bs], BehaviorSection()).dataPoints[point]+difference
end
end #if
end #for
# correct the points of previous CS in the modified driving course. Copy the new driving course till the beginning of the current CS and change total values of the current modified CS waypoints accordingly
drivingCourseModifiedNew=Vector{Waypoint}()
# correct the points of previous CS in the modified driving course. Copy the new driving course till the beginning of the current CS and change total values of the current modified CS data points accordingly
drivingCourseModifiedNew=Vector{DataPoint}()
for i in 1:endOfModificationId
push!(drivingCourseModifiedNew, Waypoint(drivingCourseNew[i]))
push!(drivingCourseModifiedNew, DataPoint(drivingCourseNew[i]))
end # for
i=lastIdOfSelectedCsOriginal+1
while i <= length(energySavingModifications[modNr].drivingCourseModified)
push!(drivingCourseModifiedNew, Waypoint(energySavingModifications[modNr].drivingCourseModified[i]))
push!(drivingCourseModifiedNew, DataPoint(energySavingModifications[modNr].drivingCourseModified[i]))
drivingCourseModifiedNew[end].i=length(drivingCourseModifiedNew)
drivingCourseModifiedNew[end].t=drivingCourseModifiedNew[end-1].t+drivingCourseModifiedNew[end].Δt
drivingCourseModifiedNew[end].E=drivingCourseModifiedNew[end-1].E+drivingCourseModifiedNew[end].ΔE

View File

@ -7,7 +7,7 @@ using CSV, DataFrames, Dates
export createOutput
export plotDrivingCourse, printImportantValues, printSectionInformation # functions for showing results during the development
function createOutput(settings::Settings, pathName::String, trainName::String, drivingCourse::Vector{Waypoint}, movingSection::MovingSection)
function createOutput(settings::Settings, pathName::String, trainName::String, drivingCourse::Vector{DataPoint}, movingSection::MovingSection)
# method of function createOutput for one operation mode
if settings.typeOfOutput == "CSV"
return createOutputCsv(settings, pathName, trainName, drivingCourse, movingSection)
@ -16,7 +16,7 @@ function createOutput(settings::Settings, pathName::String, trainName::String, d
end
end # funtion createOutput
function createOutput(settings::Settings, pathName::String, trainName::String, drivingCourseMinimumRunningTime::Vector{Waypoint}, movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumEnergyConsumption::Vector{Waypoint}, movingSectionMinimumEnergyConsumption::MovingSection)
function createOutput(settings::Settings, pathName::String, trainName::String, drivingCourseMinimumRunningTime::Vector{DataPoint}, movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumEnergyConsumption::Vector{DataPoint}, movingSectionMinimumEnergyConsumption::MovingSection)
# method of function createOutput for two operation modes
if settings.typeOfOutput == "CSV"
return createOutputCsv(settings, pathName, trainName, drivingCourseMinimumRunningTime, movingSectionMinimumRunningTime, drivingCourseMinimumEnergyConsumption, movingSectionMinimumEnergyConsumption)
@ -26,7 +26,7 @@ function createOutput(settings::Settings, pathName::String, trainName::String, d
end # funtion createOutput
function createOutputDict(settings::Settings, pathName::String, trainName::String, drivingCourse::Vector{Waypoint}, movingSection::MovingSection)
function createOutputDict(settings::Settings, pathName::String, trainName::String, drivingCourse::Vector{DataPoint}, movingSection::MovingSection)
# method of function createOutputDict for one operation mode
if settings.operationModeMinimumRunningTime
if settings.operationModeMinimumEnergyConsumption
@ -72,7 +72,7 @@ function createOutputDict(settings::Settings, pathName::String, trainName::Strin
return outputDict
end # function createOutputDict
function createOutputDict(settings::Settings, pathName::String, trainName::String, drivingCourseMinimumRunningTime::Vector{Waypoint}, movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumEnergyConsumption::Vector{Waypoint}, movingSectionMinimumEnergyConsumption::MovingSection)
function createOutputDict(settings::Settings, pathName::String, trainName::String, drivingCourseMinimumRunningTime::Vector{DataPoint}, movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumEnergyConsumption::Vector{DataPoint}, movingSectionMinimumEnergyConsumption::MovingSection)
# method of function createOutputDict for two operation modes
if settings.operationModeMinimumRunningTime
outputDict=createOutputDict(settings, pathName, trainName, drivingCourseMinimumRunningTime, movingSectionMinimumRunningTime)
@ -103,7 +103,7 @@ function createOutputDict(settings::Settings, pathName::String, trainName::Strin
end # function createOutputDict
function createOutputCsv(settings::Settings, pathName::String, trainName::String, drivingCourse::Vector{Waypoint}, movingSection::MovingSection)
function createOutputCsv(settings::Settings, pathName::String, trainName::String, drivingCourse::Vector{DataPoint}, movingSection::MovingSection)
# method of function createOutputDict for one operation mode
outputDict=createOutputDict(settings, pathName, trainName, drivingCourse, movingSection)
@ -156,7 +156,7 @@ function createOutputCsv(settings::Settings, pathName::String, trainName::String
return outputDict
end #function createOutputCsv
function createOutputCsv(settings::Settings, pathName::String, trainName::String, drivingCourseMinimumRunningTime::Vector{Waypoint}, movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumEnergyConsumption::Vector{Waypoint}, movingSectionMinimumEnergyConsumption::MovingSection)
function createOutputCsv(settings::Settings, pathName::String, trainName::String, drivingCourseMinimumRunningTime::Vector{DataPoint}, movingSectionMinimumRunningTime::MovingSection, drivingCourseMinimumEnergyConsumption::Vector{DataPoint}, movingSectionMinimumEnergyConsumption::MovingSection)
# method of function createOutputDict for two operation modes
outputDict=createOutputDict(settings, pathName, trainName, drivingCourseMinimumRunningTime, movingSectionMinimumRunningTime, drivingCourseMinimumEnergyConsumption, movingSectionMinimumEnergyConsumption)
@ -245,7 +245,7 @@ end #function createOutputCsv
function printImportantValues(drivingCourse::Vector{Waypoint})
function printImportantValues(drivingCourse::Vector{DataPoint})
println("i s in m v in km/h t in min a in m/s^2 F_R in k N F_T in k N E in k Wh")
for i in 1:length(drivingCourse)
println(drivingCourse[i].i,". ",drivingCourse[i].s," ",drivingCourse[i].v*3.6," ",drivingCourse[i].t/60," ",drivingCourse[i].a," ",drivingCourse[i].F_R/1000," ",drivingCourse[i].F_T/1000," ",drivingCourse[i].E/3600/1000)
@ -261,15 +261,15 @@ function printSectionInformation(movingSection::MovingSection)
for bs in 1: length(allBs)
if haskey(movingSection.characteristicSections[csId].behaviorSections, allBs[bs])
println("BS ",allBs[bs], " mit s_start=",get(movingSection.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).s_start, " und t_total=",get(movingSection.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).t_total)
# for point in 1:length(get(movingSection.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).waypoints)
# println(get(movingSection.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).waypoints[point])
# for point in 1:length(get(movingSection.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).dataPoints)
# println(get(movingSection.characteristicSections[csId].behaviorSections, allBs[bs], BehaviorSection()).dataPoints[point])
# end
end #if
end #for
end #for
end #function printSectionInformation
function plotDrivingCourse(drivingCourse::Vector{Waypoint})
function plotDrivingCourse(drivingCourse::Vector{DataPoint})
a=[]
E=[]
s=[]
@ -301,7 +301,7 @@ function plotDrivingCourse(drivingCourse::Vector{Waypoint})
println("Plots for different variables have been created.")
end #function plotDrivingCourse
function plotDrivingCourse(drivingCourseMinimumRunningTime::Vector{Waypoint},drivingCourseMinimumEnergyConsumption::Vector{Waypoint}) #,movingSection1::MovingSection,movingSection2::MovingSection)
function plotDrivingCourse(drivingCourseMinimumRunningTime::Vector{DataPoint},drivingCourseMinimumEnergyConsumption::Vector{DataPoint}) #,movingSection1::MovingSection,movingSection2::MovingSection)
a_minTime=[]
E_minTime=[]
s_minTime=[]

View File

@ -88,17 +88,16 @@ end #function secureBrakingBehavior!
function secureAccelerationBehavior!(movingSection::MovingSection, settings::Settings, train::Train)
# this function limits the entry and exit velocity of the characteristic sections in case that the train accelerates in every section and cruises aterwards
movingSection.characteristicSections[1].v_entry=0.0 # the entry velocity of the first characteristic section is 0.0 m/s
startingPoint=Waypoint()
startingPoint=DataPoint()
startingPoint.i=1
previousCSv_exit=movingSection.characteristicSections[1].v_entry
for csId in 1:length(movingSection.characteristicSections)
movingSection.characteristicSections[csId].v_entry=min(movingSection.characteristicSections[csId].v_entry, previousCSv_exit)
startingPoint.s=movingSection.characteristicSections[csId].s_start
startingPoint.v=movingSection.characteristicSections[csId].v_entry
accelerationCourse=[startingPoint] # List of waypoints
accelerationCourse=[startingPoint] # List of data points
if movingSection.characteristicSections[csId].v_entry<movingSection.characteristicSections[csId].v_reach
(movingSection.characteristicSections[csId], accelerationCourse)=addAccelerationPhase!(movingSection.characteristicSections[csId], accelerationCourse, settings, train, movingSection.characteristicSections) # this function changes the accelerationCourse
@ -120,7 +119,7 @@ end #function secureAccelerationBehavior!
## define the intersection velocities between the characterisitc sections to secure cruising behavior
function secureCruisingBehavior!(movingSection::MovingSection, settings::Settings, train::Train)
# limit the exit velocity of the characteristic sections in case that the train cruises in every section at v_reach
startingPoint=Waypoint()
startingPoint=DataPoint()
startingPoint.i=1
previousCSv_exit=movingSection.characteristicSections[1].v_entry
@ -130,7 +129,7 @@ function secureCruisingBehavior!(movingSection::MovingSection, settings::Setting
startingPoint.s=movingSection.characteristicSections[csId].s_start
startingPoint.v=movingSection.characteristicSections[csId].v_reach
cruisingCourse=[startingPoint] # List of waypoints
cruisingCourse=[startingPoint] # List of data points
(movingSection.characteristicSections[csId], cruisingCourse)=addCruisingPhase!(movingSection.characteristicSections[csId], cruisingCourse, movingSection.characteristicSections[csId].s_total, settings, train, movingSection.characteristicSections, "cruising") # this function changes the cruisingCourse
movingSection.characteristicSections[csId].v_exit=min(movingSection.characteristicSections[csId].v_exit, cruisingCourse[end].v)
@ -152,7 +151,7 @@ end #module Preparation
function secureAccelerationBehavior!(movingSection::MovingSection, settings::Settings, train::Train)
# this function limits the entry and exit velocity of the characteristic sections in case that the train accelerates in every section and cruises aterwards
movingSection.characteristicSections[1].v_entry=0.0 # the entry velocity of the first characteristic section is 0.0 m/s
startingPoint=Waypoint()
startingPoint=DataPoint()
startingPoint.i=1
previousCSv_exit=0.0
@ -162,7 +161,7 @@ function secureAccelerationBehavior!(movingSection::MovingSection, settings::Set
startingPoint.s=movingSection.characteristicSections[csId].s_start
startingPoint.v=movingSection.characteristicSections[csId].v_entry
cruisingCourse=[startingPoint] # List of waypoints
cruisingCourse=[startingPoint] # List of data points
if movingSection.characteristicSections[csId].v_entry<movingSection.characteristicSections[csId].v_reach
@ -176,7 +175,7 @@ function secureAccelerationBehavior!(movingSection::MovingSection, settings::Set
delete!(movingSection.characteristicSections[csId].behaviorSections, "acceleration")
movingSection.characteristicSections[csId].E_total=0.0
movingSection.characteristicSections[csId].t_total=0.0
accelerationCourse=[startingPoint] # List of waypoints
accelerationCourse=[startingPoint] # List of data points
(movingSection.characteristicSections[csId], accelerationCourse)=addAccelerationPhase!(movingSection.characteristicSections[csId], accelerationCourse, settings, train, movingSection.characteristicSections) # this function changes the accelerationCourse
end

View File

@ -1,6 +1,6 @@
module types
# definition of all the additional types and their constructors
export Settings, Train, PathSection, Path, Waypoint, BehaviorSection, CharacteristicSection, EnergySavingModification, MovingSection # tried to insert copy on 15.07.2021 , copy
export Settings, Train, PathSection, Path, DataPoint, BehaviorSection, CharacteristicSection, EnergySavingModification, MovingSection # tried to insert copy on 15.07.2021 , copy
## settings for the simulation
mutable struct Settings
@ -78,8 +78,8 @@ end # struct Path
Path()=("", 0, Vector{PathSection}())
## a waypoint is the smallest element of the driving course. A step of the step approach is between two waypoints
mutable struct Waypoint
## a data point is the smallest element of the driving course. One step of the step approach is between two data points
mutable struct DataPoint
i::Integer # identifier and counter variable of the dricing course
s::AbstractFloat # position (in m)
Δs::AbstractFloat # step size (in m)
@ -98,15 +98,15 @@ mutable struct Waypoint
F_Runion::AbstractFloat # vehicle resistance (in N)
F_Rt::AbstractFloat # traction unit resistance (in N)
F_Rw::AbstractFloat # set of wagons resistance (in N)
end # mutable struct Waypoint
Waypoint()=Waypoint(0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
# tried to insert copy on 15.07.2021 copy(original::Waypoint)=Waypoint(original.i, original.s, original.Δs, original.t, original.Δt, original.v, original.Δv, original.a, original.W_T, original.ΔW_T, original.E, original.ΔE, original.F_T, original.F_R, original.F_Rp, original.F_Runion, original.F_Rt, original.F_Rw)
Waypoint(original::Waypoint)=Waypoint(original.i, original.s, original.Δs, original.t, original.Δt, original.v, original.Δv, original.a, original.W_T, original.ΔW_T, original.E, original.ΔE, original.F_T, original.F_R, original.F_Rp, original.F_Runion, original.F_Rt, original.F_Rw)
end # mutable struct DataPoint
DataPoint()=DataPoint(0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
# tried to insert copy on 15.07.2021 copy(original::DataPoint)=DataPoint(original.i, original.s, original.Δs, original.t, original.Δt, original.v, original.Δv, original.a, original.W_T, original.ΔW_T, original.E, original.ΔE, original.F_T, original.F_R, original.F_Rp, original.F_Runion, original.F_Rt, original.F_Rw)
DataPoint(original::DataPoint)=DataPoint(original.i, original.s, original.Δs, original.t, original.Δt, original.v, original.Δv, original.a, original.W_T, original.ΔW_T, original.E, original.ΔE, original.F_T, original.F_R, original.F_Rp, original.F_Runion, original.F_Rt, original.F_Rw)
## different sections the whole path can be devided in the following
## smallest section of the path is the behavior section. It relates to the containing waypoints via their identifier.
## smallest section of the path is the behavior section. It relates to the containing data points via their identifier.
mutable struct BehaviorSection
type::String # type of behavior section: "starting", "cruisingBeforeAcceleration", "acceleration", "cruising", "coasting", "cruisingAfterCoasting" or "braking"
s_total::AbstractFloat # total length (in m)
@ -116,15 +116,15 @@ mutable struct BehaviorSection
E_total::AbstractFloat # total energy consumption (in Ws)
v_entry::AbstractFloat # entry speed (in m/s)
v_exit::AbstractFloat # exit speed (in m/s)
waypoints::Vector{Integer} # list of identifiers of the containing waypoints
dataPoints::Vector{Integer} # list of identifiers of the containing data points
end # mutable struct BehaviorSection
BehaviorSection()=BehaviorSection("", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, [])
function BehaviorSection(original::BehaviorSection)
bsWaypoints=[]
for i in 1:length(original.waypoints)
push!(bsWaypoints, original.waypoints[i])
bsDataPoints=[]
for i in 1:length(original.dataPoints)
push!(bsDataPoints, original.dataPoints[i])
end
return BehaviorSection(original.type, original.s_total, original.s_start, original.s_end, original.t_total, original.E_total, original.v_entry, original.v_exit, bsWaypoints)
return BehaviorSection(original.type, original.s_total, original.s_start, original.s_end, original.t_total, original.E_total, original.v_entry, original.v_exit, bsDataPoints)
end
## a characteristic section is a part of the moving section. It contains behavior sections.
@ -162,14 +162,14 @@ mutable struct EnergySavingModification
Δt::AbstractFloat # time loss (in s)
ratio::AbstractFloat # ratio of ΔE and Δt (in Ws/s)
csModified::CharacteristicSection # the modified characteristic section
drivingCourseModified::Vector{Waypoint} #drivingCourse for the modified characteristic section
drivingCourseModified::Vector{DataPoint} #drivingCourse for the modified characteristic section
end # mutable struct EnergySavingModification
EnergySavingModification()=EnergySavingModification(0, "", 0.0, 0.0, 0.0, CharacteristicSection(), [])
function EnergySavingModification(original::EnergySavingModification)
copy=EnergySavingModification(original.csId, original.type, original.ΔE, original.Δt, original.ratio, CharacteristicSection(), Waypoint[])
copy=EnergySavingModification(original.csId, original.type, original.ΔE, original.Δt, original.ratio, CharacteristicSection(), DataPoint[])
copy.csModified=CharacteristicSection(original.csModified)
for i in 1:length(original.drivingCourseModified)
push!(copy.drivingCourseModified, Waypoint(original.drivingCourseModified[i]))
push!(copy.drivingCourseModified, DataPoint(original.drivingCourseModified[i]))
end
return copy
end #function EnergySavingModification
@ -189,6 +189,7 @@ mutable struct MovingSection
energySavingModifications::Vector{EnergySavingModification} # list of containing all the used energy saving modifications
end # mutable struct MovingSection
MovingSection()=MovingSection(0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, [], [])
function MovingSection(original::MovingSection)
copy=MovingSection(original.id, original.s_total, original.s_start, original.s_end, original.t_total, original.E_total, original.t_recovery, original.t_recoveryAvailable, [], [])
for csId in 1:length(original.characteristicSections)