Add pathfinding benchmark binary
This commit is contained in:
parent
b8f83ec4eb
commit
34ff825ff0
3 changed files with 142 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -624,6 +624,7 @@ dependencies = [
|
|||
"serde_yaml",
|
||||
"termcolor",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -30,3 +30,4 @@ serde_json = "1.0.108"
|
|||
serde_yaml = "0.9.34"
|
||||
termcolor = "1.4.1"
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
|
||||
|
|
|
|||
140
factorio-pathfinding/src/bin/path_finding.rs
Normal file
140
factorio-pathfinding/src/bin/path_finding.rs
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
use clap::{Parser, ValueEnum};
|
||||
use factorio_core::{
|
||||
aabb::AABB,
|
||||
prelude::{Direction, Position, PositionType},
|
||||
};
|
||||
use factorio_graph::{
|
||||
priority_queue::{
|
||||
ByKey,
|
||||
binary_heap::{BinaryHeap, FastBinaryHeap},
|
||||
bucket_queue::BucketQueue,
|
||||
},
|
||||
wheighted_graph::shortest_path::QueueObject,
|
||||
};
|
||||
use factorio_pathfinding::{
|
||||
Connection, Map, PathInput, Pathfinder, belt_finding::ConflictAvoidance,
|
||||
};
|
||||
use tracing_subscriber::{EnvFilter, fmt::format::FmtSpan};
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
input: PathfindingInputArg,
|
||||
pathfinder: PathfinderArg,
|
||||
size: PositionType,
|
||||
}
|
||||
|
||||
#[derive(ValueEnum, Clone, Copy)]
|
||||
enum PathfinderArg {
|
||||
CaFbh,
|
||||
CaBh,
|
||||
CaBq,
|
||||
}
|
||||
|
||||
#[derive(ValueEnum, Clone, Copy)]
|
||||
enum PathfindingInputArg {
|
||||
EmptyDiagonal,
|
||||
EmptyStraight,
|
||||
}
|
||||
|
||||
struct EmptyMap {
|
||||
area: AABB,
|
||||
}
|
||||
|
||||
impl Map for EmptyMap {
|
||||
fn get_position(&self, pos: Position) -> bool {
|
||||
self.area.contains_pos(pos)
|
||||
}
|
||||
|
||||
fn area(&self) -> (Position, Position) {
|
||||
(
|
||||
self.area.min(),
|
||||
self.area.max() - self.area.min() + Position::new(1, 1),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
tracing_subscriber::fmt::fmt()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
|
||||
.init();
|
||||
|
||||
match args.input {
|
||||
PathfindingInputArg::EmptyDiagonal => {
|
||||
let connections = vec![Connection {
|
||||
start_pos: Position::new(0, -1),
|
||||
start_dir: Direction::Down,
|
||||
end_pos: Position::new(args.size - 1, args.size),
|
||||
end_dir: Direction::Down,
|
||||
beltspeed: factorio_core::beltoptions::Beltspeed::Normal,
|
||||
lanes: 1,
|
||||
}];
|
||||
let map = EmptyMap {
|
||||
area: AABB::new(
|
||||
Position::new(0, 0),
|
||||
Position::new(args.size - 1, args.size - 1),
|
||||
),
|
||||
};
|
||||
let path_input = PathInput {
|
||||
connections: &connections,
|
||||
map,
|
||||
};
|
||||
execute(&args, path_input);
|
||||
}
|
||||
PathfindingInputArg::EmptyStraight => {
|
||||
let connections = vec![Connection {
|
||||
start_pos: Position::new(args.size / 2, -1),
|
||||
start_dir: Direction::Down,
|
||||
end_pos: Position::new(args.size / 2, args.size),
|
||||
end_dir: Direction::Down,
|
||||
beltspeed: factorio_core::beltoptions::Beltspeed::Normal,
|
||||
lanes: 1,
|
||||
}];
|
||||
let map = EmptyMap {
|
||||
area: AABB::new(
|
||||
Position::new(0, 0),
|
||||
Position::new(args.size - 1, args.size - 1),
|
||||
),
|
||||
};
|
||||
let path_input = PathInput {
|
||||
connections: &connections,
|
||||
map,
|
||||
};
|
||||
execute(&args, path_input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn execute<'a, M: Map>(args: &Args, path_input: PathInput<'a, M>) {
|
||||
match args.pathfinder {
|
||||
PathfinderArg::CaFbh => {
|
||||
let p = ConflictAvoidance {
|
||||
timeout: Some(std::time::Duration::from_millis(100)),
|
||||
priority_queue: std::marker::PhantomData::<
|
||||
FastBinaryHeap<ByKey<QueueObject<(Position, Direction)>>>,
|
||||
>,
|
||||
};
|
||||
p.find_paths(path_input);
|
||||
}
|
||||
PathfinderArg::CaBh => {
|
||||
let p = ConflictAvoidance {
|
||||
timeout: Some(std::time::Duration::from_millis(100)),
|
||||
priority_queue: std::marker::PhantomData::<
|
||||
BinaryHeap<ByKey<QueueObject<(Position, Direction)>>>,
|
||||
>,
|
||||
};
|
||||
p.find_paths(path_input);
|
||||
}
|
||||
PathfinderArg::CaBq => {
|
||||
let p = ConflictAvoidance {
|
||||
timeout: Some(std::time::Duration::from_millis(100)),
|
||||
priority_queue: std::marker::PhantomData::<
|
||||
BucketQueue<QueueObject<(Position, Direction)>>,
|
||||
>,
|
||||
};
|
||||
p.find_paths(path_input);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue