Skip to content

Commit

Permalink
feat: got the main algorithm mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
CalliEve committed Oct 1, 2024
1 parent 18d9bf1 commit 765d451
Show file tree
Hide file tree
Showing 18 changed files with 980 additions and 151 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ serde = { version = "1", features = ["derive"] }
csscolorparser = "0.7"
rand = "0.8"
priority-queue = "2.1"
ordered-float = "4.3"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
Expand Down
33 changes: 32 additions & 1 deletion benches/map_algo_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use criterion::{
black_box,
criterion_group,
Expand All @@ -7,6 +9,9 @@ use criterion::{
use metro_map_editor::{
algorithm::run_a_star,
models::GridNode,
utils::json,
CanvasState,
MapState,
};

pub fn a_star_benchmark(c: &mut Criterion) {
Expand All @@ -18,5 +23,31 @@ pub fn a_star_benchmark(c: &mut Criterion) {
});
}

pub fn full_recalculation_benchmark(c: &mut Criterion) {
let mut canvas = CanvasState::new();
canvas.set_square_size(5);

let test_file_content = std::fs::read_to_string("exisiting_maps/routing_test.json")
.expect("test data file does not exist");
let map = json::decode_map(&test_file_content, canvas).expect("failed to decode graphml");

let state = MapState::new(map);

c.bench_function("full_recalculation", |b| {
b.iter(|| {
let mut alg_state = state.clone();
MapState::run_algorithm(black_box(&mut alg_state))
})
});
}

criterion_group!(
name = full_recalculation_benches;
config = Criterion::default().measurement_time(Duration::from_secs(20)).sample_size(20);
targets = full_recalculation_benchmark
);
criterion_group!(a_star_benches, a_star_benchmark);
criterion_main!(a_star_benches);
criterion_main!(
a_star_benches,
full_recalculation_benches
);
22 changes: 22 additions & 0 deletions exisiting_maps/disjointed_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"stations": [
{ "id": "s4", "name": null, "x": 140.0, "y": 84.0 },
{ "id": "s5", "name": null, "x": 175.0, "y": 84.0 },
{ "id": "s7", "name": null, "x": 49.0, "y": 35.0 },
{ "id": "s6", "name": null, "x": 210.0, "y": 140.0 },
{ "id": "s1", "name": null, "x": 70.0, "y": 70.0 },
{ "id": "s2", "name": null, "x": 105.0, "y": 105.0 },
{ "id": "s3", "name": null, "x": 140.0, "y": 175.0 }
],
"lines": [
{ "id": "l1", "name": "Line 1", "color": "#FF0000" },
{ "id": "l2", "name": "Line 2", "color": "#00FF00" },
{ "id": "l3", "name": "Line 3", "color": "#0000FF" }
],
"edges": [
{ "source": "s5", "target": "s4", "lines": ["l2"] },
{ "source": "s6", "target": "s5", "lines": ["l2"] },
{ "source": "s2", "target": "s1", "lines": ["l1"] },
{ "source": "s3", "target": "s2", "lines": ["l1"] }
]
}
Loading

0 comments on commit 765d451

Please sign in to comment.