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

Ndr/cleanup #30

Merged
merged 11 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
5 changes: 2 additions & 3 deletions .github/workflows/deploy-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
paths:
- docs/**
- .github/workflows/deploy-docs.yml

jobs:
deploy-docs:
Expand All @@ -20,9 +21,7 @@ jobs:

- name: Install dependencies
shell: bash -el {0}
run: |
conda install rasterio gdal
pip install ".[dev]"
run: conda install nrel.routee.compass jupyter-book

- name: Build book
shell: bash -el {0}
Expand Down
12 changes: 6 additions & 6 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

### conda (recommended)

The recommended way to get started with RouteE Compass is to use [conda](https://docs.conda.io/en/latest/) and [pip](https://pypi.org/project/pip/) to install the python package:
The recommended way to get started with RouteE Compass is to use [conda](https://docs.conda.io/en/latest/) to install the python package:

```console
conda create -n routee-compass -c conda-forge python=3.10 toml rasterio gdal osmnx
conda activate routee-compass
pip install nrel.routee.compass
conda create -n routee-compass -c conda-forge python=3.11 nrel.routee.compass
```

This creates a new conda environment and then installs several dependencies into it. After that, we activate the environment and then install RouteE Compass into it.
This creates a new conda environment with python 3.11 and then installs RouteE Compass into it.

The conda distribution includes several optional dependencies and is recommended if you want everything included or don't already have any road network data on your system.

This method is recommended if you want everything included or don't already have any road network data on your system.
(pip-install)=

### pip

Expand Down
18 changes: 3 additions & 15 deletions docs/notebooks/open_street_maps_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@
"\n",
"## requirements\n",
"\n",
"To download an open street maps dataset, you'll need a couple of extra dependencies: \n",
" - [osmnx](https://osmnx.readthedocs.io/en/stable/)\n",
" - [toml](https://pypi.org/project/toml/) (Python<3.11).\n",
" - [rasterio](https://rasterio.readthedocs.io/en/latest/index.html)\n",
" - [gdal](https://pypi.org/project/GDAL/) \n",
"\n",
"You can install these doing: \n",
"To download an open street maps dataset, we'll need some extra dependnecies which are included with the conda distribution of this pacakge: \n",
"\n",
"```console\n",
"conda create -n routee-compass -c conda-forge python=3.10 toml rasterio gdal osmnx\n",
"conda activate routee-compass\n",
"pip install nrel.routee.compass\n",
"conda create -n routee-compass -c conda-forge python=3.11 nrel.routee.compass \n",
"```"
]
},
Expand All @@ -35,8 +27,7 @@
"source": [
"import osmnx as ox\n",
"from nrel.routee.compass.io import generate_compass_dataset\n",
"from nrel.routee.compass import CompassApp\n",
"from pathlib import Path"
"from nrel.routee.compass import CompassApp"
]
},
{
Expand Down Expand Up @@ -353,9 +344,6 @@
"metadata": {},
"outputs": [],
"source": [
"import shapely\n",
"import json\n",
"\n",
"from nrel.routee.compass.plot import plot_route_folium, plot_routes_folium"
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can also just build the rust application and run it from the command line.
After following the [installation instructions](installation), you can run the application like this:

```bash
path/to/routee-compass/rust/target/release/compass-app --config path/to/config.toml path/to/query.json
path/to/routee-compass/rust/target/release/routee-compass --config path/to/config.toml path/to/query.json
```

This will load the graph and then run the query (or queries) from your `query.json` file, outputing results to a file called `results.json` in the current working directory.
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ keywords = ["eco routing"]
dependencies = []
[project.optional-dependencies]
dev = [
"nrel.routee.compass",
"black",
"pytest",
"maturin",
Expand All @@ -32,7 +31,7 @@ dev = [
]

[project.urls]
Homepage = "https://github.nrel.gov/MBAP/routee-compass"
Homepage = "https://github.com/NREL/routee-compass"

[tool.maturin]
python-source = "python"
Expand Down
1 change: 0 additions & 1 deletion python/nrel/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion python/nrel/routee/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ input_plugins = [
]
output_plugins = [
{ type = "summary" },
{ type = "traversal", route = "geo_json", tree = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "traversal", route = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "uuid", uuid_input_file = "vertices-uuid-enumerated.txt.gz" },
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ input_plugins = [
]
output_plugins = [
{ type = "summary" },
{ type = "traversal", route = "geo_json", tree = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "traversal", route = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "uuid", uuid_input_file = "vertices-uuid-enumerated.txt.gz" },
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ input_plugins = [
]
output_plugins = [
{ type = "summary" },
{ type = "traversal", route = "geo_json", tree = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "traversal", route = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "uuid", uuid_input_file = "vertices-uuid-enumerated.txt.gz" },
]
14 changes: 7 additions & 7 deletions rust/routee-compass-core/src/algorithm/component/scc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::model::graph::graph::Graph;
use crate::model::graph::graph_struct::Graph;
use crate::model::graph::{graph_error::GraphError, vertex_id::VertexId};
use std::collections::HashSet;

Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn depth_first_search(
///
/// Returns an error if the `graph` has an issue like a non-existing vertex.
///
fn reverse_depth_first_search(
pub fn reverse_depth_first_search(
graph: &Graph,
vertex: VertexId,
visited: &mut HashSet<VertexId>,
Expand Down Expand Up @@ -94,7 +94,7 @@ fn reverse_depth_first_search(
///
/// Returns an error if the `graph` has an issue like a non-existing vertex.
///
fn all_strongly_connected_componenets(graph: &Graph) -> Result<Vec<Vec<VertexId>>, GraphError> {
pub fn all_strongly_connected_componenets(graph: &Graph) -> Result<Vec<Vec<VertexId>>, GraphError> {
let mut visited: HashSet<VertexId> = HashSet::new();
let mut container: Vec<VertexId> = Vec::new();

Expand Down Expand Up @@ -131,7 +131,7 @@ fn all_strongly_connected_componenets(graph: &Graph) -> Result<Vec<Vec<VertexId>
///
/// Returns an error if the `graph` has an issue like a non-existing vertex.
///
fn largest_strongly_connected_component(graph: &Graph) -> Result<Vec<VertexId>, GraphError> {
pub fn largest_strongly_connected_component(graph: &Graph) -> Result<Vec<VertexId>, GraphError> {
let components = all_strongly_connected_componenets(graph)?;

let mut largest_component: Vec<VertexId> = Vec::new();
Expand Down Expand Up @@ -186,13 +186,13 @@ mod tests {
}

// Construct the Graph instance.
let graph = Graph {

Graph {
adj: adj.into_boxed_slice(),
rev: rev.into_boxed_slice(),
edges: edges.into_boxed_slice(),
vertices: vertices.into_boxed_slice(),
};
graph
}
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::algorithm::search::edge_traversal::EdgeTraversal;
use crate::algorithm::search::search_error::SearchError;
use crate::algorithm::search::search_tree_branch::SearchTreeBranch;
use crate::algorithm::search::MinSearchTree;
use crate::model::cost::cost::Cost;
use crate::model::cost::Cost;
use crate::model::frontier::frontier_model::FrontierModel;
use crate::model::graph::edge_id::EdgeId;
use crate::model::graph::graph::Graph;
use crate::model::graph::graph_struct::Graph;
use crate::model::termination::termination_model::TerminationModel;
use crate::model::traversal::state::traversal_state::TraversalState;
use crate::model::traversal::traversal_model::TraversalModel;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn run_a_star(
for (src_id, edge_id, dst_id) in neighbor_triplets {
// first make sure we have a valid edge
let e = g.get_edge(edge_id).map_err(SearchError::GraphError)?;
if !f.valid_frontier(&e, &current.state)? {
if !f.valid_frontier(e, &current.state)? {
continue;
}
let et = EdgeTraversal::new(edge_id, current.prev_edge_id, &current.state, &g, &m)?;
Expand Down Expand Up @@ -166,9 +166,9 @@ pub fn run_a_star(

// match (costs.pop(), target) {
// (None, Some(target_vertex_id)) => {
// return Err(SearchError::NoPathExists(source, target_vertex_id))
// Err(SearchError::NoPathExists(source, target_vertex_id))
// }
// (None, None) => return Ok(solution),
// (None, None) => Ok(solution),
// Some((current_vertex_id, _)) if current_vertex_id == target => {
// break;
// }
Expand All @@ -183,7 +183,7 @@ pub fn run_a_star(
solution.len()
);

return Ok(solution);
Ok(solution)
}

/// convenience method when origin and destination are specified using
Expand Down Expand Up @@ -238,7 +238,7 @@ pub fn run_a_star_edge_oriented(

if source == target_edge {
let empty: HashMap<VertexId, SearchTreeBranch> = HashMap::new();
return Ok(empty);
Ok(empty)
} else if source_edge_dst_vertex_id == target_edge_src_vertex_id {
// route is simply source -> target
let init_state = m.initial_state();
Expand Down Expand Up @@ -303,7 +303,7 @@ pub fn run_a_star_edge_oriented(
tree.extend([(target_edge_dst_vertex_id, dst_traversal)]);
}

return Ok(tree);
Ok(tree)
}
}
}
Expand All @@ -318,8 +318,8 @@ pub fn h_cost(
) -> Result<Cost, SearchError> {
let src_vertex = g.get_vertex(src)?;
let dst_vertex = g.get_vertex(dst)?;
let cost_estimate = m.cost_estimate(&src_vertex, &dst_vertex, &state)?;
return Ok(cost_estimate);
let cost_estimate = m.cost_estimate(src_vertex, dst_vertex, state)?;
Ok(cost_estimate)
}

#[cfg(test)]
Expand All @@ -328,7 +328,7 @@ mod tests {
use super::*;
use crate::algorithm::search::backtrack::vertex_oriented_route;
use crate::model::frontier::default::no_restriction;
use crate::model::graph::graph::Graph;
use crate::model::graph::graph_struct::Graph;
use crate::model::property::edge::Edge;
use crate::model::property::vertex::Vertex;
use crate::model::traversal::default::distance::DistanceModel;
Expand Down Expand Up @@ -364,13 +364,12 @@ mod tests {
rev[edge.dst_vertex_id.0].insert(edge.edge_id, edge.src_vertex_id);
}

let graph = Graph {
Graph {
adj: adj.into_boxed_slice(),
rev: rev.into_boxed_slice(),
edges: edges.into_boxed_slice(),
vertices: vertices.into_boxed_slice(),
};
graph
}
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod a_star;
pub mod a_star_algorithm;
pub mod a_star_frontier;
4 changes: 2 additions & 2 deletions rust/routee-compass-core/src/algorithm/search/backtrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use crate::{
model::graph::{edge_id::EdgeId, graph::Graph, vertex_id::VertexId},
model::graph::{edge_id::EdgeId, graph_struct::Graph, vertex_id::VertexId},
util::read_only_lock::ExecutorReadOnlyLock,
};

Expand All @@ -22,7 +22,7 @@ pub fn vertex_oriented_route(
) -> Result<Vec<EdgeTraversal>, SearchError> {
let mut result: Vec<EdgeTraversal> = vec![];
let mut visited: HashSet<EdgeId> = HashSet::new();
let mut this_vertex = target_id.clone();
let mut this_vertex = target_id;
loop {
if this_vertex == source_id {
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use serde::Serialize;

use crate::model::graph::edge_id::EdgeId;
use crate::model::graph::graph::Graph;
use crate::model::graph::graph_struct::Graph;
use crate::model::traversal::access_result::AccessResult;
use crate::model::traversal::traversal_model::TraversalModel;

use super::search_error::SearchError;
use crate::model::cost::cost::Cost;
use crate::model::cost::Cost;
use crate::model::traversal::state::traversal_state::TraversalState;
use std::sync::Arc;
use std::{fmt::Display, sync::RwLockReadGuard};
Expand All @@ -21,7 +21,7 @@ pub struct EdgeTraversal {

impl EdgeTraversal {
pub fn edge_cost(&self) -> Cost {
return self.access_cost + self.traversal_cost;
self.access_cost + self.traversal_cost
}
}

Expand Down Expand Up @@ -56,7 +56,7 @@ impl EdgeTraversal {
Some(prev_e) => {
let prev_edge = g.get_edge(prev_e).map_err(SearchError::GraphError)?;
let prev_src_v = g.get_vertex(prev_edge.src_vertex_id)?;
m.access_cost(&prev_src_v, &prev_edge, &src, &edge, &dst, &prev_state)
m.access_cost(prev_src_v, prev_edge, src, edge, dst, prev_state)
}
None => Ok(AccessResult::no_cost()),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::a_star::a_star;
use super::a_star::a_star_algorithm;
use super::search_error::SearchError;
use super::MinSearchTree;
use crate::algorithm::search::search_algorithm_type::SearchAlgorithmType;
use crate::model::frontier::frontier_model::FrontierModel;
use crate::model::graph::graph::Graph;
use crate::model::graph::graph_struct::Graph;
use crate::model::graph::{edge_id::EdgeId, vertex_id::VertexId};
use crate::model::termination::termination_model::TerminationModel;
use crate::model::traversal::traversal_model::TraversalModel;
Expand Down Expand Up @@ -36,7 +36,7 @@ impl SearchAlgorithm {
termination_model: Arc<ExecutorReadOnlyLock<TerminationModel>>,
) -> Result<MinSearchTree, SearchError> {
match self {
SearchAlgorithm::AStarAlgorithm => a_star::run_a_star(
SearchAlgorithm::AStarAlgorithm => a_star_algorithm::run_a_star(
origin,
destination,
graph,
Expand All @@ -56,7 +56,7 @@ impl SearchAlgorithm {
termination_model: Arc<ExecutorReadOnlyLock<TerminationModel>>,
) -> Result<MinSearchTree, SearchError> {
match self {
SearchAlgorithm::AStarAlgorithm => a_star::run_a_star_edge_oriented(
SearchAlgorithm::AStarAlgorithm => a_star_algorithm::run_a_star_edge_oriented(
origin,
destination,
graph,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::algorithm::search::search_error::SearchError;
use std::str::FromStr;
use std::{fmt::Display, str::FromStr};

pub enum SearchAlgorithmType {
AStar,
Expand All @@ -12,8 +12,11 @@ impl SearchAlgorithmType {
A::AStar => "a*",
}
}
pub fn to_string(&self) -> String {
self.to_str().to_string()
}

impl Display for SearchAlgorithmType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_str())
}
}

Expand Down
Loading