8000 Rjf/isolate traversal models by robfitzgerald · Pull Request #318 · NREL/routee-compass · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Rjf/isolate traversal models #318

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

Open
wants to merge 100 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
1038d06
add state feature types
robfitzgerald Apr 22, 2025
22fe054
expand derivations + implementations
robfitzgerald Apr 22, 2025
bf46908
cleanup
robfitzgerald Apr 22, 2025
0896f59
revised ICE vehicle modeling
robfitzgerald Apr 22, 2025
75a3b73
prep for removal
robfitzgerald Apr 22, 2025
c340416
revised distance traversal modeling
robfitzgerald Apr 22, 2025
7c1cca4
revised siloed traversal modeling
robfitzgerald Apr 22, 2025
b17f874
rename constant
robfitzgerald Apr 22, 2025
23da780
add state feature types
robfitzgerald Apr 22, 2025
7e28b08
revised ICE vehicle modeling
robfitzgerald Apr 22, 2025
36b9d89
improve APIs
robfitzgerald Apr 22, 2025 8000
ed1760b
stub out remaining traversal models
robfitzgerald Apr 22, 2025
88c5df3
clippy
robfitzgerald Apr 22, 2025
375daa5
bad edit
robfitzgerald Apr 22, 2025
1ab1d4d
grade model
robfitzgerald Apr 23, 2025
fb97802
speed model
robfitzgerald Apr 23, 2025
f6e5a1c
speed model
robfitzgerald Apr 23, 2025
6289413
distance model
robfitzgerald Apr 23, 2025
6e4af49
rename models + namespaces
robfitzgerald Apr 23, 2025
4c44a2e
input/output state features
robfitzgerald Apr 24, 2025
43fb01e
clippy
robfitzgerald Apr 24, 2025
b79f1f5
changed semantics in tests
robfitzgerald Apr 24, 2025
6134755
add input features to StateModel.register
robfitzgerald Apr 25, 2025
3aba391
handle input/output features
robfitzgerald Apr 28, 2025
a6209ab
combined traversal model
robfitzgerald Apr 28, 2025
1697c4f
clippy
robfitzgerald Apr 28, 2025
f2c3e93
Merge branch 'main' into rjf/isolate-traversal-models
robfitzgerald Apr 28, 2025
a7aecbb
Merge branch 'main' into rjf/isolate-traversal-models
robfitzgerald May 5, 2025
a2b7293
From OutputFeature
robfitzgerald May 1, 2025
8690e92
include variable name in invalid index error
robfitzgerald May 1, 2025
525d45a
update soc without state context
robfitzgerald May 1, 2025
c5e893c
test mock module
robfitzgerald May 1, 2025
57845ce
vehicle energy models as TraversalModel instances
robfitzgerald May 1, 2025
83c9067
identify index assignment off-by-1 error
robfitzgerald May 6, 2025
d23fd4c
missing logic for adding newly registered output features
robfitzgerald May 6, 2025
c8de11a
do not add input features to upstream mock
robfitzgerald May 6, 2025
3d4fdc0
a few soc update tests
robfitzgerald May 6, 2025
5922b0d
cleanup
robfitzgerald May 6, 2025
0fb9179
soc is percent, not decimal
robfitzgerald May 6, 2025
3786e76
remove mock lib entry
robfitzgerald May 6, 2025
7d2f158
revise namespaces
robfitzgerald May 6, 2025
bb3ea9d
clippy
robfitzgerald May 6, 2025
2be2d50
unravel other dimensions from speed modeling
robfitzgerald May 7, 2025
b574809
share vector with nonzero vector error
robfitzgerald May 7, 2025
60c36cf
remove duplicated logic
robfitzgerald May 7, 2025
6cb36a5
expand core traits
robfitzgerald May 7, 2025
fe357aa
update powertrain traversal modeling for singular responsibility + si…
robfitzgerald May 7, 2025
99efb87
update to traversal model changes
robfitzgerald May 7, 2025
73048b1
clippy
robfitzgerald May 7, 2025
7415bfb
Merge branch 'main' into rjf/isolate-traversal-models
robfitzgerald May 7, 2025
b0f8396
fmt
robfitzgerald May 7, 2025
9e5dc2d
clippy
robfitzgerald May 7, 2025
60f3259
e2e distance/speed/time test fixes
robfitzgerald May 8, 2025
4a37afd
clippy
robfitzgerald May 8, 2025
2112c4c
fix speed tests, remove out of scope tests
robfitzgerald May 8, 2025
527b046
fix e2e a* test
robfitzgerald May 8, 2025
c921822
typo on merge
robfitzgerald May 8, 2025
a3248a4
allow building dummy grade models (stopgap)
robfitzgerald May 8, 2025
078e78b
update to revised traversal configuration
robfitzgerald May 8, 2025
5000d44
clippy
robfitzgerald May 8, 2025
458ed97
fix feature names
robfitzgerald May 8, 2025
40946c7
fix feature names
robfitzgerald May 8, 2025
c2c63fc
hard-coded time feature name
robfitzgerald May 8, 2025
3381f36
traversal model updates
robfitzgerald May 8, 2025
71c7bb6
re-add models in denver test case
robfitzgerald May 8, 2025
ad4f846
fix feature names
robfitzgerald May 8, 2025
88b9630
fieldname module shared across default traversal models
robfitzgerald May 8, 2025
7ad40da
fieldname module shared across powertrain traversal models
robfitzgerald May 8, 2025
df986d7
clippy
robfitzgerald May 8, 2025
8f755b2
documentation
robfitzgerald May 8, 2025
21b22e7
Update docs/examples/03_time_energy_tradeoff_example.py
robfitzgerald May 8, 2025
6736504
remove redundant unit conversions
robfitzgerald May 9, 2025
4e12481
cleanup
robfitzgerald May 9, 2025
7247020
comments
robfitzgerald May 9, 2025
3289b93
clippy warnings
robfitzgerald May 9, 2025
2b0293b
clippy
robfitzgerald May 9, 2025
b6de5a4
monotonicity test
robfitzgerald May 12, 2025
af033a9
replace existing python test with monotonicity test (superset of prev…
robfitzgerald May 12, 2025
0a57a9a
ruff
robfitzgerald May 12, 2025
24d3221
fix target to point to energy accumulator
robfitzgerald May 12, 2025
bcabd72
assertion failure messages
robfitzgerald May 12, 2025
aaf8ad5
support gge
robfitzgerald May 12, 2025
b78f7db
add unified "{edge|trip}_energy" field
robfitzgerald May 12, 2025
202c2e7
clippy
robfitzgerald May 12, 2025
6d5558c
docstring
robfitzgerald May 12, 2025
6ebb902
monotonicity test for speed models (no energy)
robfitzgerald May 13, 2025
f509f48
ruff format
robfitzgerald May 13, 2025
2d7898f
reformat w smaller names
robfitzgerald May 13, 2025
e6d860c
remove unused
robfitzgerald May 13, 2025
78ea0dd
use "trip_energy" key
robfitzgerald May 13, 2025
d99c4b4
features without cost factors are not aggregated/summarized
robfitzgerald May 13, 2025
d2d4cda
track accumulating features
robfitzgerald May 13, 2025
3b3187c
refactor model + rates in one spot
robfitzgerald May 13, 2025
f515a81
drop energy suffixes
robfitzgerald May 13, 2025
0f09308
drop energy suffixes
robfitzgerald May 13, 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
162 changes: 85 additions & 77 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,39 @@ queries_without_destinations = true
matching_type = "point"

[traversal]
type = "energy_model"
# the units of the speed table
time_model_speed_unit = "kph"
# the file that has grades for each edge in the graph
grade_table_input_file = "edges-grade-enumerated.txt.gz"
# the units of the grade table
grade_table_grade_unit = "decimal"

# the internal units of the energy model
time_unit = "minutes"
# the traversal section can either be a single model configuration, or, if "combined"
# is specified, it can be a collection of models listed at [[traversal.models]]
type = "combined"
[[traversal.models]]
# model distances in miles
type = "distance"
distance_unit = "miles"

# Here we specify the time model to use for the energy model
[traversal.time_model]
type = "speed_table"
[[traversal.models]]
type = "speed"
# the file that has speeds for each edge in the graph
speed_table_input_file = "edges-posted-speed-enumerated.txt.gz"
# the units of the speed table
# the units of the values in the speed table
speed_unit = "kph"

# the internal units of the speed table
distance_unit = "miles"
[[traversal.models]]
# model time in minutes using the above distances and speeds
type = "time"
time_unit = "minutes"

[[traversal.models]]
type = "grade"
# the file that has grades for each edge in the graph
grade_table_input_file = "edges-grade-enumerated.txt.gz"
# the units of the grade table
grade_unit = "decimal"

[[traversal.models]]
type = "energy"

# here, we specify which vehicles to make available at query time
# if you wanted to add more models, you would make a new [[traversal.vehicles]] section.
[[traversal.vehicles]]
# if you wanted to add more models, you would make a new [[traversal.models.vehicles]] section.
[[traversal.models.vehicles]]
# the name of the model that can be passed in from a query as "model_name"
name = "2012_Ford_Focus"
# the type of the vehicle, currently either:
Expand All @@ -83,7 +89,7 @@ real_world_energy_adjustment = 1.166

# what underlying machine learn framework to use [smartcore | interpolate | onnx]
# in this case we use a model that interpolates the underlying model type over a regular grid
[traversal.vehicles.model_type.interpolate]
[traversal.models.vehicles.model_type.interpolate]
underlying_model_type = "smartcore"
speed_lower_bound = 0
speed_upper_bound = 100
Expand All @@ -97,32 +103,32 @@ grade_bins = 41
# The vehicle rates get applied to each component of the cost

# based on 65.5 cents per mile 2023 IRS mileage rate, $/mile
[cost.vehicle_rates.distance]
[cost.vehicle_rates.trip_distance]
type = "factor"
factor = 0.655

# based on $20/hr approximation of 2023 median hourly wages, $/second
[cost.vehicle_rates.time]
[cost.vehicle_rates.trip_time]
type = "factor"
factor = 0.333336

# based on AAA regular unleaded gas prices sampled 12/21/2023
[cost.vehicle_rates.energy_liquid]
[cost.vehicle_rates.trip_energy_liquid]
type = "factor"
factor = 3.120

# based on $0.50/kWh approximation of DCFC charge rates, $/kWhtype = "factor"
[cost.vehicle_rates.energy_electric]
[cost.vehicle_rates.trip_energy_electric]
type = "factor"
factor = 0.50

# Each cost component get multiplied by the corresponding vehicle weight.
# So, you could make time more important than distance by increasing the time weight.
[cost.weights]
distance = 1
time = 1
energy_liquid = 1
energy_electric = 1
trip_distance = 1
trip_time = 1
trip_energy_liquid = 1
trip_energy_electric = 1

## Access costs

Expand Down Expand Up @@ -153,7 +159,7 @@ input_plugins = [
]
output_plugins = [
# The traversal plugin appends various items to the result.
{ type = "traversal", route = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "traversal", route = "geo_json", },
# The uuid plugin adds a map specific id (like Open Street Maps Nodes) onto the compass verticies
{ type = "uuid", uuid_input_file = "vertices-uuid-enumerated.txt.gz" },
]
Expand Down Expand Up @@ -228,57 +234,64 @@ Here are the default traversal models that come with the `CompassApp`:
The distance traversal model is a very simple model that just uses distance for computing a route, producing the route that has the shortest distance.

```toml
[traversal]
[[traversal.models]]
type = "distance"
distance_unit = "miles"
```

### Speed Table
### Speed

The speed table traversal model uses a speed lookup table to compute the fastest (or shortest time) route.
The speed table traversal model uses a speed lookup table to assign edge speeds.

```toml
[traversal]
type = "speed_table"
[[traversal.models]]
type = "speed"
speed_table_input_file = "edges-posted-speed-enumerated.txt.gz"
speed_unit = "kph"
distance_unit = "miles"
```

### Time

This simple model computes traversal time based on upstream distance and speed models.

```toml
[[traversal.models]]
type = "time"
time_unit = "minutes"
```

### Energy Model
### Grade

The energy model computes energy (with a routee-powertrain vehicle model) and speed over an edge.
Uses a lookup table to assign grade values.

```toml
[traversal]
type = "energy_model"
# the units of the speed table
time_model_speed_unit = "kph"
# the file that has grades for each edge in the graph
grade_table_input_file = "edges-grade-enumerated.txt.gz"
# the units of the grade table
grade_table_grade_unit = "decimal"
[[traversal.models]]
type = "grade"
grade_input_file = "edges-grade-enumerated.txt.gz"
grade_unit = "decimal"
```

# the internal units of the energy model
time_unit = "minutes"
distance_unit = "miles"
### Elevation

# Here we specify the time model to use for the energy model
[traversal.time_model]
type = "speed_table"
# the file that has speeds for each edge in the graph
speed_table_input_file = "edges-posted-speed-enumerated.txt.gz"
# the units of the speed table
speed_unit = "kph"
Assigns elevation gain and loss calculated from the grade value and distance.

# the internal units of the speed table
distance_unit = "miles"
time_unit = "minutes"
```toml
[[traversal.models]]
type = "elevation"
distance_unit = "feet"
```

### Energy

The energy model computes energy (with a routee-powertrain vehicle model) and speed over an edge.

```toml
[[traversal.models]]
type = "energy"

# here, we specify which vehicles to make available at query time
# if you wanted to add more models, you would make a new [[traversal.vehicles]] section.
[[traversal.vehicles]]
# if you wanted to add more models, you would make a new [[traversal.models.vehicles]] section.
[[traversal.models.vehicles]]
# the name of the model that can be passed in from a query as "model_name"
name = "2012_Ford_Focus"
# the type of the vehicle, currently either:
Expand All @@ -301,15 +314,14 @@ real_world_energy_adjustment = 1.166

# what underlying machine learn framework to use [smartcore | interpolate | onnx]
# in this case we use a model that interpolates the underlying model type over a regular grid
[traversal.vehicles.model_type.interpolate]
[traversal.models.vehicles.model_type.interpolate]
underlying_model_type = "smartcore"
speed_lower_bound = 0
speed_upper_bound = 100
speed_bins = 101
grade_lower_bound = -0.2
grade_upper_bound = 0.2
grade_bins = 41

```

## Plugins
Expand Down Expand Up @@ -339,19 +351,17 @@ The grid search plugin allows you to specify a `grid_search` key in the query an
{
"name": "shortest_time",
"weights": {
"distance": 0.0,
"time": 1.0,
"energy_liquid": 0.0,
"energy_electric": 0.0
"trip_distance": 0.0,
"trip_time": 1.0,
"trip_energy": 0.0
}
},
{
"name": "least_energy",
"weights": {
"distance": 0.0,
"time": 0.0,
"energy_liquid": 1.0,
"energy_electric": 1.0
"trip_distance": 0.0,
"trip_time": 0.0,
"trip_energy": 1.0,
}
}
]
Expand All @@ -373,10 +383,9 @@ The grid search plugin would take this single query and generate two queries tha
"model_name": "2016_TOYOTA_Camry_4cyl_2WD",
"name": "shortest_time",
"weights": {
"distance": 0.0,
"time": 1.0,
"energy_liquid": 0.0,
"energy_electric": 0.0
"trip_distance": 0.0,
"trip_time": 1.0,
"trip_energy": 0.0
}
},
{
Expand All @@ -389,10 +398,9 @@ The grid search plugin would take this single query and generate two queries tha
"name": "least_energy",
"model_name": "2016_TOYOTA_Camry_4cyl_2WD",
"weights": {
"distance": 0.0,
"time": 0.0,
"energy_liquid": 1.0,
"energy_electric": 1.0
"trip_distance": 0.0,
"trip_time": 0.0,
"trip_energy": 1.0,
}
}
]
Expand Down
48 changes: 31 additions & 17 deletions docs/examples/01_open_street_maps_example.py
D2FC
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,35 @@
"destination_y": 39.693005,
"model_name": "2016_TOYOTA_Camry_4cyl_2WD",
"vehicle_rates": {
"distance": {"type": "factor", "factor": 0.655},
"time": {"type": "factor", "factor": 0.33},
"energy_liquid": {"type": "factor", "factor": 3.0},
"trip_distance": {"type": "factor", "factor": 0.655},
"trip_time": {"type": "factor", "factor": 0.33},
"trip_energy": {"type": "factor", "factor": 3.0},
},
"grid_search": {
"test_cases": [
{
"name": "least_time",
"weights": {"distance": 0, "time": 1, "energy_liquid": 0},
"weights": {
"trip_distance": 0,
"trip_time": 1,
"trip_energy": 0,
},
},
{
"name": "least_energy",
"weights": {"distance": 0, "time": 0, "energy_liquid": 1},
"weights": {
"trip_distance": 0,
"trip_time": 0,
"trip_energy": 1,
},
},
{
"name": "least_cost",
"weights": {"distance": 1, "time": 1, "energy_liquid": 1},
"weights": {
"trip_distance": 1,
"trip_time": 1,
"trip_energy": 1,
},
},
]
},
Expand Down Expand Up @@ -263,24 +275,26 @@ def pretty_print(dict):


dist_diff = (
shortest_time_result["route"]["traversal_summary"]["distance"]
- least_energy_result["route"]["traversal_summary"]["distance"]
shortest_time_result["route"]["traversal_summary"]["trip_distance"]
- least_energy_result["route"]["traversal_summary"]["trip_distance"]
)
time_diff = (
shortest_time_result["route"]["traversal_summary"]["time"]
- least_energy_result["route"]["traversal_summary"]["time"]
shortest_time_result["route"]["traversal_summary"]["trip_time"]
- least_energy_result["route"]["traversal_summary"]["trip_time"]
)
enrg_diff = (
shortest_time_result["route"]["traversal_summary"]["energy_liquid"]
- least_energy_result["route"]["traversal_summary"]["energy_liquid"]
shortest_time_result["route"]["traversal_summary"]["trip_energy"]
- least_energy_result["route"]["traversal_summary"]["trip_energy"]
)
cost_diff = (
shortest_time_result["route"]["cost"]["total_cost"]
- least_energy_result["route"]["cost"]["total_cost"]
)
dist_unit = shortest_time_result["route"]["state_model"]["distance"]["distance_unit"]
time_unit = shortest_time_result["route"]["state_model"]["time"]["time_unit"]
enrg_unit = shortest_time_result["route"]["state_model"]["energy_liquid"]["energy_unit"]
dist_unit = shortest_time_result["route"]["state_model"]["trip_distance"][
"distance_unit"
]
time_unit = shortest_time_result["route"]["state_model"]["trip_time"]["time_unit"]
enrg_unit = shortest_time_result["route"]["state_model"]["trip_energy"]["energy_unit"]
print(f" - distance: {dist_diff:.2f} {dist_unit} further with time-optimal")
print(f" - time: {-time_diff:.2f} {time_unit} longer with energy-optimal")
print(f" - energy: {enrg_diff:.2f} {enrg_unit} more with time-optimal")
Expand Down Expand Up @@ -360,7 +374,7 @@ def print_keys(d, indent=0):

folium_map = plot_routes_folium(
results,
value_fn=lambda r: r["route"]["traversal_summary"]["energy_liquid"],
value_fn=lambda r: r["route"]["traversal_summary"]["trip_energy"],
color_map="plasma",
)
folium_map
Expand All @@ -386,7 +400,7 @@ def print_keys(d, indent=0):

folium_map = plot_routes_folium(
new_results,
value_fn=lambda r: r["route"]["traversal_summary"]["energy_liquid"],
value_fn=lambda r: r["route"]["traversal_summary"]["trip_energy"],
color_map="plasma",
folium_map=folium_map,
)
Expand Down
Loading
0