Hello, I’m trying to make algorithm that by adding some parameters of train, I can calculate the maximum speed at each segment of the profile…
What I have as input:
-
I have calculated torque at each speed at 0 grade. For example at 0kmh I have 16.32 dN/t, at 10kmh I have 15.78 dN/t…
-
I have extracted the grade of the profile at each station_interval(I’m dividing it by 10m parts)
Imgur: The magic of the Internet -
I have extracted all stations at station_interval(I’m dividing it by 10m parts)
And now I’m trying to make at each station I’m trying to get the exact torque for the grade, then calculate the time that train needs to pass this station_interval(for the example is 10m) and then calculate the final speed at the interval. Then this final speed I need to use it for the next interval.
I think thats all about the working principle
Because every different alignment has different length, I will have different segments and I can not create loop like in the screenshot thousand of times…
I have tried by simple nodes to create the loop but not so successful.
I’m now trying by python script, but I’m again in the middle of nowhere because I do not have any experience with python.
Thats what I reached with little help of chatGPT:
import math
def estimating_speed(station, station_slope, station_interval, torque, torque_interval, start_speed):
"""
Estimate the train's speed at the end of each station.
Args:
station (list): List of station points (integer values).
station_slope (list): List of slopes corresponding to station points (in %).
station_interval (int): Distance between stations (in meters).
torque (list): List of torque values (in dN/t) at specific speeds.
torque_interval (int): Speed interval for torque values (in km/h).
start_speed (float): Initial speed of the train (in km/h).
Returns:
list: End speeds for each station.
"""
def get_exact_torque(speed, torque, torque_interval):
"""
Calculate the exact torque for a given speed using linear interpolation.
"""
if speed <= 0:
return torque[0] # Return the first torque value if speed is below the minimum
elif speed >= (len(torque) - 1) * torque_interval:
return torque[-1] # Return the last torque value if speed exceeds the max
# Find the lower and upper bounds for the given speed
lower_index = int(speed // torque_interval)
upper_index = lower_index + 1
# Speeds corresponding to the indices
lower_speed = lower_index * torque_interval
upper_speed = upper_index * torque_interval
# Torque values at these speeds
lower_torque = torque[lower_index]
upper_torque = torque[upper_index]
# Perform linear interpolation
exact_torque = lower_torque + (speed - lower_speed) * (upper_torque - lower_torque) / (upper_speed - lower_speed)
return exact_torque
# Initialize outputs
end_speeds = []
current_speed = start_speed # Set initial speed for the first station
# Iterate over each station
for i in range(len(station)):
# Step 1: Calculate exact torque for the current station
exact_torque = get_exact_torque(current_speed, torque, torque_interval)
# Step 2: Calculate a realistic station_time based on torque and distance
# Let's assume that torque affects the change in speed with a factor, e.g., speed increases with torque/200
station_time = station_interval / (exact_torque / 200)
# Step 3: Update end speed with a realistic delta
speed_delta = exact_torque * station_time / 1000 # Factor for scaling the speed change
end_speed = current_speed + speed_delta
# Append the result and update the current speed for the next station
end_speeds.append(end_speed)
current_speed = end_speed # Update for the next station
return end_speeds
# Example Inputs
station = IN[0]
station_slope = IN[1]
station_interval = IN[2]
torque = IN[3]
torque_interval = IN[4]
start_speed = IN[5]
end_speeds = estimating_speed(station, station_slope, station_interval, torque, torque_interval, start_speed)
# Call the function
OUT = end_speeds
Do you have any ideas how to make it work?
Thank you!