Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable car-km counting #82

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1cd6292
fixed rust get functions
Jul 17, 2024
f922fb4
separate counts for empty and loaded
Jul 26, 2024
797ddae
Made drag coeff a function instead of list
Sep 10, 2024
b5692ab
Merge branch 'main' into car_counting
Sep 11, 2024
5d0bab8
Completed intermodal empty car generations
FDsteven Sep 12, 2024
3e7338e
Completed return demand based on the three different train types
FDsteven Sep 13, 2024
4b56ac7
Enabled mixed consist, consolidated final traind demand df
FDsteven Sep 13, 2024
df8239a
Corrected the drag function implementation
Sep 13, 2024
7089701
Added gap size to defaults and proposed minor edits in train_planner.py
Sep 16, 2024
6f6e0b2
Corrected case for 'Loaded' suffix
Sep 17, 2024
b2aa1d4
changed to `dataclass` for readability
calbaker Sep 18, 2024
e094532
removed some of the non-generic stuff
calbaker Sep 18, 2024
8399956
integrating private repo changes
Sep 23, 2024
92a20f4
floordiv tweak
Sep 23, 2024
df40d23
loco_pool generation fix
Sep 23, 2024
9197e89
Corrected return type for drag_coeff_function field
Sep 23, 2024
f168fec
revert default value
Sep 24, 2024
31157e3
Update utilities.py
Sep 24, 2024
66ed655
Merge branch 'fix/drag_coeff_func' into car_counting
Sep 24, 2024
7ac968c
Merge branch 'mixed-consist-plus-wang-dev' into car_counting
Sep 24, 2024
7d5cdcd
car counting metrics working
Sep 24, 2024
c59fd8d
metrics text fix
Sep 24, 2024
37eb8b7
initial LIFTS check-in
Nov 7, 2024
2d94977
polars version updates, initial lifts integration
Dec 2, 2024
a8794d3
moved LIFTS to subdir
Dec 2, 2024
cf35408
in-progress check-in
Dec 10, 2024
c914562
update
Dec 19, 2024
e9aa573
Merge branch 'main' into car_counting
Jan 10, 2025
9ac64b9
Merge branch 'feature/lifts' into car_counting
Jan 10, 2025
ba4385f
partial port of train planner from private repo
Jan 12, 2025
c93ebb1
train planner refactored into multiple files
Jan 12, 2025
d4390de
refactoring
Jan 12, 2025
1ca7827
fix for unit test
Jan 13, 2025
615f8e0
more fixes for unit tests
Jan 13, 2025
b2cbc4f
refactoring
Jan 14, 2025
832271e
train planner restructuring
Jan 16, 2025
f756c4d
updates for demand calculations
Jan 16, 2025
84501e6
hourly demand code
Jan 16, 2025
f9bb799
Refactoring and improvements
Jan 17, 2025
c909094
Train planner config refactoring
Jan 18, 2025
5027670
refactoring
Jan 18, 2025
65f7cab
added hourly dispatch function
Jan 18, 2025
4339989
partially implemented calculate_dispatch_data for diesel
Jan 20, 2025
f4df392
fixed calculate_dispatch_data for diesel
Jan 20, 2025
33b4a88
more partial fixes
Jan 20, 2025
55e31d4
debugging
Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,10 @@ code\ meetings
altrios/resources/networks/Scenic - ALTRIOS Confidential.yaml
altrios/dispatch/*.json
activate.sh
*.xlsx
altrios/*.txt
truck_work_log.txt
vehicle_average_times.txt
avg_time_per_train.txt
crane_work_log.txt
hostler_work_log.txt
2 changes: 1 addition & 1 deletion applications/calibration/zanzeff_bel_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_bel_trip_mods(df: pd.DataFrame) -> pd.DataFrame:
"""
# df['dt [s]'] = pd.to_datetime(df['PacificTime']).dt.tz_convert('UTC')
df['timestamp'] = pd.to_datetime(df['PacificTime']).dt.to_pydatetime()
df['time [s]'] = cval.get_delta_seconds(df['timestamp']).cumsum()
df['time [s]'] = cval.get_delta_seconds(df['timestamp']).cum_sum()

df3000 = df[['PacificTime', 'time [s]']].copy()
df3000['Tractive Power [W]'] = (
Expand Down
4 changes: 2 additions & 2 deletions applications/calibration/zanzeff_conv_loco_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_conv_trip_mods(df: pd.DataFrame) -> pd.DataFrame:
df = df.drop_duplicates('PacificTime').copy()
df['timestamp'] = pd.to_datetime(
df['PacificTime']).dt.to_pydatetime()
df['time [s]'] = cval.get_delta_seconds(df['timestamp']).cumsum()
df['time [s]'] = cval.get_delta_seconds(df['timestamp']).cum_sum()



Expand Down Expand Up @@ -69,7 +69,7 @@ def get_conv_trip_mods(df: pd.DataFrame) -> pd.DataFrame:
df39xx["Fuel Energy [J]"] = (df39xx["Fuel Power [W]"] *
cval.get_delta_seconds(
df39xx['timestamp'])
).cumsum().copy()
).cum_sum().copy()
df39xx["engine_on"] = df['Engine Speed (RPM) BNSF ' + str(trailing_loc)] > 100
return df39xx

Expand Down
6 changes: 3 additions & 3 deletions applications/calibration/zanzeff_set_speed_train_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_train_sim_df_mods(
df_train_sim.drop_duplicates(subset='PacificTime', inplace=True)

df_train_sim['time [s]'] = cval.get_delta_seconds(
df_train_sim['PacificTime']).cumsum()
df_train_sim['PacificTime']).cum_sum()
df_train_sim['Total Tractive Force [N]'] = df_train_sim[[
'Tractive Effort Feedback BNSF 3940',
'Tractive Effort Feedback BNSF 3965',
Expand All @@ -56,13 +56,13 @@ def get_train_sim_df_mods(
df_train_sim['Total Cumu. Tractive Energy [J]'] = (
df_train_sim['Total Tractive Power [W]'] *
df_train_sim['time [s]'].diff().fillna(0.0)
).cumsum()
).cum_sum()

df_train_sim['Total Pos. Cumu. Tractive Energy [J]'] = (
(df_train_sim['Total Tractive Power [W]'] *
df_train_sim['time [s]'].diff().fillna(0.0))
.where(df_train_sim['Total Tractive Power [W]'] > 0, 0.0)
.cumsum()
.cum_sum()
)

speed = savgol_filter(
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ dependencies = [
"plotly",
"typing_extensions",
"pyyaml",
"polars==0.20.25",
"polars >= 1.20.0",
"pyarrow",
"requests",
"PyYAML==6.0.2",
"simpy"
]

[project.urls]
Expand Down
3 changes: 3 additions & 0 deletions python/altrios/altrios_pyo3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ class SpeedLimitTrainSim(SerdeAPI):
origs: List[Location]
dests: List[Location]
loco_con: Consist
n_cars_by_type: Dict[str, int]
state: TrainState
# train_res: TrainRes # not accessible in Python
path_tpc: PathTpc
Expand All @@ -833,6 +834,7 @@ class SpeedLimitTrainSim(SerdeAPI):
def __init__(
cls,
loco_con: Consist,
n_cars_by_type: Dict[str, int],
state: TrainState,
train_res_file: Optional[str],
path_tpc_file: Optional[str],
Expand Down Expand Up @@ -931,6 +933,7 @@ class RailVehicle(SerdeAPI):
braking_ratio_empty: float
braking_ratio_loaded: float
car_type: str
freight_type: str
davis_b_seconds_per_meter: float
cd_area_empty_square_meters: float
cd_area_loaded_square_meters: float
Expand Down
1 change: 1 addition & 0 deletions python/altrios/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

LOCO_LIFESPAN = 20
ANNUAL_LOCO_TURNOVER = 1.0/LOCO_LIFESPAN
DEFAULT_GAP_SIZE = 0.604

DEMAND_FILE = alt.resources_root() / "Default Demand.csv"
FUEL_EMISSIONS_FILE = alt.resources_root() / "metrics_inputs" / "GREET-CA_Emissions_Factors.csv"
Expand Down
9 changes: 5 additions & 4 deletions python/altrios/demos/rollout_demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# %%
import altrios as alt
from altrios import rollout, defaults, train_planner
from altrios import rollout, defaults

from altrios.train_planner import planner, planner_config
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
Expand All @@ -21,9 +22,9 @@
plot_dir.mkdir(exist_ok=True)
File = defaults.DEMAND_FILE
#targets = [0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75, 0.8]
train_planner_config = train_planner.TrainPlannerConfig(
cars_per_locomotive=50,
target_cars_per_train=90)
train_planner_config = planner_config.TrainPlannerConfig(
cars_per_locomotive={"Default": 50},
target_cars_per_train={"Default": 90})
targets = [0.5]
for target in targets:
scenario_infos, metrics = rollout.simulate_prescribed_rollout(
Expand Down
16 changes: 12 additions & 4 deletions python/altrios/demos/sim_manager_demo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# %%
from altrios import sim_manager
from altrios import utilities, defaults, train_planner
from altrios import utilities, defaults
import altrios as alt
from altrios.lifts import lifts_simulator
from altrios.train_planner import planner_config
import numpy as np
import polars as pl
import matplotlib.pyplot as plt
import time
import seaborn as sns
Expand Down Expand Up @@ -34,9 +37,9 @@
f"Elapsed time to import rail vehicles, locations, and network: {t1_import - t0_import:.3g} s"
)

train_planner_config = train_planner.TrainPlannerConfig(
cars_per_locomotive=50,
target_cars_per_train=90)
train_planner_config = planner_config.TrainPlannerConfig(
cars_per_locomotive={"Default": 50},
target_cars_per_train={"Default": 90})

t0_main = time.perf_counter()

Expand All @@ -56,6 +59,11 @@
debug=True,
)

train_consist_plan_csv = pl.read_csv('C:/Users/mbruchon/Downloads/simulation_operation/lifts/results/train_consist_plan.csv')
container_data = lifts_simulator.run_simulation(
train_consist_plan = train_consist_plan_csv,
terminal = "Allouez")

t1_main = time.perf_counter()
print(f"Elapsed time to run `sim_manager.main()`: {t1_main-t0_main:.3g} s")

Expand Down
2 changes: 2 additions & 0 deletions python/altrios/lifts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pkg_resources import get_distribution
__version__ = get_distribution("altrios").version
Loading