Skip to content

Commit

Permalink
Merge pull request #42 from NREL/dispatch-in-speed-limit-demo
Browse files Browse the repository at this point in the history
Dispatch in speed limit demo
  • Loading branch information
calbaker authored Feb 26, 2024
2 parents 4bf7d0c + c2225aa commit 0941eee
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 214 deletions.
9 changes: 8 additions & 1 deletion python/altrios/altrios_pyo3.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, List, Optional
import polars as pl
from typing_extensions import Self
from typing import Union
from typing import Union, Tuple
from dataclasses import dataclass


Expand Down Expand Up @@ -904,6 +904,13 @@ def run_dispatch(
) -> List[TimedLinkPath]: ...


def make_est_times(
speed_limit_train_sim: SpeedLimitTrainSim,
network: List[Link],
) -> Tuple[EstTimeNet, Consist]:
...


@dataclass
class TimedLinkPath(SerdeAPI):
@classmethod
Expand Down
16 changes: 8 additions & 8 deletions python/altrios/demos/set_speed_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,38 @@
fig, ax = plt.subplots(3, 1, sharex=True)
ax[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.pwr_whl_out_watts,
np.array(train_sim.history.pwr_whl_out_watts) / 1e6,
label="tract pwr",
)
ax[0].set_ylabel('Power')
ax[0].set_ylabel('Power [MW]')
ax[0].legend()

ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_aero_newtons,
np.array(train_sim.history.res_aero_newtons) / 1e3,
label='aero',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_rolling_newtons,
np.array(train_sim.history.res_rolling_newtons) / 1e3,
label='rolling',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_curve_newtons,
np.array(train_sim.history.res_curve_newtons) / 1e3,
label='curve',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_bearing_newtons,
np.array(train_sim.history.res_bearing_newtons) / 1e3,
label='bearing',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_grade_newtons,
np.array(train_sim.history.res_grade_newtons) / 1e3,
label='grade',
)
ax[1].set_ylabel('Force [N]')
ax[1].set_ylabel('Force [MN]')
ax[1].legend()

ax[-1].plot(
Expand Down
27 changes: 18 additions & 9 deletions python/altrios/demos/speed_limit_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@
)
train_sim.set_save_interval(SAVE_INTERVAL)

timed_link_path = alt.TimedLinkPath.from_file(alt.resources_root() / "demo_data/timed_path.yaml")
est_time_net, _consist = alt.make_est_times(train_sim, network)

timed_link_path = alt.run_dispatch(
network.tolist(),
alt.SpeedLimitTrainSimVec([train_sim]),
[est_time_net],

False,
False,
)[0]

t0 = time.perf_counter()
train_sim.walk_timed_path(
Expand All @@ -85,38 +94,38 @@
fig, ax = plt.subplots(3, 1, sharex=True)
ax[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.pwr_whl_out_watts,
np.array(train_sim.history.pwr_whl_out_watts) / 1e6,
label="tract pwr",
)
ax[0].set_ylabel('Power')
ax[0].set_ylabel('Power [MW]')
ax[0].legend()

ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_aero_newtons,
np.array(train_sim.history.res_aero_newtons) / 1e3,
label='aero',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_rolling_newtons,
np.array(train_sim.history.res_rolling_newtons) / 1e3,
label='rolling',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_curve_newtons,
np.array(train_sim.history.res_curve_newtons) / 1e3,
label='curve',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_bearing_newtons,
np.array(train_sim.history.res_bearing_newtons) / 1e3,
label='bearing',
)
ax[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.res_grade_newtons,
np.array(train_sim.history.res_grade_newtons) / 1e3,
label='grade',
)
ax[1].set_ylabel('Force [N]')
ax[1].set_ylabel('Force [MN]')
ax[1].legend()

ax[-1].plot(
Expand Down
181 changes: 0 additions & 181 deletions python/altrios/resources/demo_data/timed_path.yaml

This file was deleted.

14 changes: 8 additions & 6 deletions rust/altrios-core/src/consist/locomotive/locomotive_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,19 @@ impl Locomotive {
pub fn default_battery_electric_loco() -> Self {
// TODO: add `pwr_aux_offset` and `pwr_aux_traction_coeff` based on calibration
let bel_type = PowertrainType::BatteryElectricLoco(BatteryElectricLoco::default());
let mut bel = Locomotive::default();
bel.loco_type = bel_type;
bel
Locomotive {
loco_type: bel_type,
..Default::default()
}
}

pub fn default_hybrid_electric_loco() -> Self {
// TODO: add `pwr_aux_offset` and `pwr_aux_traction_coeff` based on calibration
let hel_type = PowertrainType::HybridLoco(Box::default());
let mut hel = Locomotive::default();
hel.loco_type = hel_type;
hel
Locomotive {
loco_type: hel_type,
..Default::default()
}
}

pub fn get_pwr_rated(&self) -> si::Power {
Expand Down
Loading

0 comments on commit 0941eee

Please sign in to comment.