Skip to content

Commit

Permalink
Set the edge weights to be the distance between nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
anorthall committed Aug 10, 2023
1 parent 8fbbae6 commit 19cb8ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
authors = ["Andrew Northall <andrew@northall.me.uk>"]
keywords = ["caving", "caves", "cave-survey", "survex", "bindings"]
categories = ["api-bindings", "external-ffi-bindings", "science::geo"]
version = "0.1.6"
version = "0.1.7"
edition = "2021"
include = ["**/*.rs", "lib/**/*", "Cargo.toml", "README.md", "LICENCE"]

Expand Down
20 changes: 8 additions & 12 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ pub fn load_from_path(path: PathBuf) -> Result<SurveyData, Box<dyn Error>> {
connections.len()
);

// Survex file reading is complete. We now need to compile our list of connections between
// two points into a list of connections between two nodes in the graph. To do this, we will
// loop through the connections vector and find the index of the node in the graph which
// corresponds to each set of coordinates. We will then add the connection to the graph.
let mut node_connections = Vec::new();
// Survex file reading is complete. We now need to iterate over the connections vector and
// add the connections to the graph by looking up the node index for each station and adding
// an edge between them with the distance between the two stations as the weight.
for (p1, p2) in connections.iter() {
let from_station_node_index = data
.get_by_coords(p1)
Expand All @@ -203,15 +201,13 @@ pub fn load_from_path(path: PathBuf) -> Result<SurveyData, Box<dyn Error>> {
.unwrap_or_else(|| panic!("Could not find station with coordinates {:?}", p2))
.borrow()
.index;
node_connections.push((from_station_node_index, to_station_node_index));
data.graph.add_edge(
from_station_node_index,
to_station_node_index,
p1.distance(p2),
);
}

data.graph.extend_with_edges(&node_connections);

trace!(
"Extended graph with {} connections.",
node_connections.len()
);
trace!(
"Graph now has {} nodes and {} edges.",
data.graph.node_count(),
Expand Down

0 comments on commit 19cb8ff

Please sign in to comment.