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

Route choice API, link loading, path file generation #515

Merged
merged 52 commits into from
May 29, 2024

Conversation

Jake-Moss
Copy link
Contributor

@Jake-Moss Jake-Moss commented Mar 1, 2024

TODO:

  • Basic path file computation
  • Basic link flow computation
  • Adjust existing tests to new API
  • API solidification, it should mirror existing APIs. I think I'll go with a thin wrapper around the existing route choice object
  • Support multiple matrix slices. Current implementation of link loading assumes a single slice, this isn't difficult to change
  • Separate path file generation and link loading for now. Currently the link loading implementation uses the path files as an intermediate result
  • Map all outputs back to network IDs, currently everything is in compact form
  • Saving of sparse path files into parquet
  • Saving of dense and sparse link flows into results database
  • New tests for user facing class
  • General code quality improvements, some methods are deeply intertwine with each other and generally too long, particularly the batched method, which is 252 lines
  • Documentation example

@pedrocamargo
Copy link
Contributor

@janzill , can you take a look at this PR sometime before next Tuesday? That would allow Jake to jump straight into it

@pedrocamargo
Copy link
Contributor

@Jake-Moss , the API looks pretty good. I think that with some minor tweaks and the example notebook, it will be perfect.

@pedrocamargo
Copy link
Contributor

@Jake-Moss , in order to save choice sets to disk, we would need to either save the relationship between compact graph link and link/direction or convert it to link_id/direction.

Compact graphs are not permanent, so this becomes dangerous when saving to disk

image

@Jake-Moss
Copy link
Contributor Author

@Jake-Moss , in order to save choice sets to disk, we would need to either save the relationship between compact graph link and link/direction or convert it to link_id/direction.

Compact graphs are not permanent, so this becomes dangerous when saving to disk

image

What file is that from? I can't see it on the latest commit, I thought that doc string was modified, either way any doc string that mentions the compact links is out of date, except apply_link_loading, which is used by get_load_results to return both

if uncompressed:
uncompressed_df = pd.DataFrame(
{"link_id": lids}
| {k + dir: np.zeros(lids.shape) for k in self.link_loads.keys() for dir in ["_ab", "_ba"]}
)
for k, v in self.link_loads.items():
# Directional Flows
uncompressed_df[k + "_ab"].values[m.network_ab_idx] = np.nan_to_num(v[m.graph_ab_idx])
uncompressed_df[k + "_ba"].values[m.network_ba_idx] = np.nan_to_num(v[m.graph_ba_idx])
# Tot Flow
uncompressed_df[k + "_tot"] = np.nan_to_num(uncompressed_df[k + "_ab"].values) + np.nan_to_num(
uncompressed_df[k + "_ba"].values
)
if compressed:
compressed_df = pd.DataFrame(
{"link_id": compact_lids}
| {
k + dir: np.zeros(compact_lids.shape)
for k in self.compact_link_loads.keys()
for dir in ["_ab", "_ba"]
}
)
for k, v in self.compact_link_loads.items():
compressed_df[k + "_ab"].values[m_compact.network_ab_idx] = np.nan_to_num(v[m_compact.graph_ab_idx])
compressed_df[k + "_ba"].values[m_compact.network_ba_idx] = np.nan_to_num(v[m_compact.graph_ba_idx])
# Tot Flow
compressed_df[k + "_tot"] = np.nan_to_num(compressed_df[k + "_ab"].values) + np.nan_to_num(
compressed_df[k + "_ba"].values
)

and the translation for the results table happens during its construction
for link in deref(route):
# Translate the compressed link IDs in route to network link IDs, this is a 1:n mapping
network_link_begin = self.mapping_idx[link]
network_link_end = self.mapping_idx[link + 1]
path_builder.AppendValues(
&self.mapping_data[network_link_begin],
network_link_end - network_link_begin
)
offset += network_link_end - network_link_begin

@Jake-Moss Jake-Moss changed the title Route choice API, link loading, path file generation, and select link analysis Route choice API, link loading, path file generation Apr 23, 2024
@Jake-Moss
Copy link
Contributor Author

I believe this is largely ready now, it is lacking select link analysis support, though that will come in a separate PR

@Jake-Moss Jake-Moss marked this pull request as ready for review April 23, 2024 07:47
Copy link
Contributor

@janzill janzill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, one small suggestion regarding testing assignment

tests/aequilibrae/paths/test_route_choice.py Show resolved Hide resolved
@Jake-Moss Jake-Moss mentioned this pull request Apr 30, 2024
@Jake-Moss
Copy link
Contributor Author

Hmm I thought the CI was fixed...

@pedrocamargo
Copy link
Contributor

Latest Mac-os is now M1...

@Jake-Moss
Copy link
Contributor Author

Latest Mac-os is now M1...

Hmm that'll do it

@Jake-Moss
Copy link
Contributor Author

Jake-Moss commented May 8, 2024

Latest Mac-os is now M1...

I'm not sure what's going on now, the logs files said that the system was build a x86_64 wheel running on arm but deallocate doesn't seem have had an update in the last couple months. I wouldn't have expected that to break it. We'll see how this CI runs, testing locally gave me nothing to go on.

It doesn't seem to be respecting the `--ignore-missing-dependencies``

@Jake-Moss
Copy link
Contributor Author

This PR is long enough, going to merge into the feature branch and merge develop, hopefully that'll fix some of the CI

@Jake-Moss Jake-Moss merged commit fa7a4a1 into AequilibraE:route_choice May 29, 2024
3 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants