Parameterize priority queue
This commit is contained in:
parent
6f74f1345e
commit
ffe51bede9
14 changed files with 276 additions and 183 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::Connection;
|
||||
use crate::Map as _;
|
||||
use crate::SinglePathInput;
|
||||
|
|
@ -5,8 +7,9 @@ use crate::SinglePathfinder;
|
|||
use crate::examples::HashMapMap;
|
||||
use factorio_core::misc::Map;
|
||||
use factorio_core::{prelude::*, visualize::Visualize};
|
||||
use factorio_graph::priority_queue::binary_heap::FastBinaryHeap;
|
||||
use factorio_graph::priority_queue::PriorityQueue;
|
||||
use factorio_graph::wheighted_graph::WheightedGraph;
|
||||
use factorio_graph::wheighted_graph::shortest_path::QueueObject;
|
||||
use factorio_graph::wheighted_graph::shortest_path::a_star;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::Level;
|
||||
|
|
@ -16,11 +19,16 @@ pub mod brute_force;
|
|||
|
||||
pub mod conflict_avoidance;
|
||||
|
||||
pub struct ConflictAvoidance {
|
||||
pub struct ConflictAvoidance<P> {
|
||||
pub timeout: Option<std::time::Duration>,
|
||||
pub priority_queue: PhantomData<P>,
|
||||
}
|
||||
|
||||
impl SinglePathfinder for ConflictAvoidance {
|
||||
impl<P> SinglePathfinder for ConflictAvoidance<P>
|
||||
where
|
||||
P: PriorityQueue<QueueObject<(Position, Direction)>> + std::fmt::Debug,
|
||||
P::Handle: std::fmt::Debug,
|
||||
{
|
||||
fn find_paths<M: crate::Map>(
|
||||
&self,
|
||||
input: SinglePathInput<M>,
|
||||
|
|
@ -47,7 +55,7 @@ impl SinglePathfinder for ConflictAvoidance {
|
|||
|
||||
// p.print_visualization();
|
||||
|
||||
if p.find_path() {
|
||||
if p.find_path::<P>() {
|
||||
let mut c = conflict_avoidance::ConflictAvoidance::new(&p);
|
||||
// c.print_visualization();
|
||||
|
||||
|
|
@ -270,7 +278,11 @@ impl WheightedGraph for MapInternal<'_> {
|
|||
}
|
||||
|
||||
impl Problem {
|
||||
pub fn find_path(&mut self) -> bool {
|
||||
pub fn find_path<P>(&mut self) -> bool
|
||||
where
|
||||
P: PriorityQueue<QueueObject<(Position, Direction)>> + std::fmt::Debug,
|
||||
P::Handle: std::fmt::Debug,
|
||||
{
|
||||
let _span = span!(Level::TRACE, "find_path").entered();
|
||||
for i in 0..self.start.len() {
|
||||
self.calculate_wheights(i);
|
||||
|
|
@ -280,7 +292,7 @@ impl Problem {
|
|||
};
|
||||
let p = {
|
||||
// dijkstra::<MapInternal, FastBinaryHeap<_>>(&m, self.start[i], self.end[i])
|
||||
a_star::<MapInternal, FastBinaryHeap<_>, _, _>(
|
||||
a_star::<MapInternal, P, _, _>(
|
||||
&m,
|
||||
self.start[i],
|
||||
|&n| n == self.end[i],
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use factorio_blueprint::{encode, Blueprint, BlueprintString};
|
||||
use factorio_blueprint::{Blueprint, BlueprintString, encode};
|
||||
use factorio_core::{beltoptions::Beltspeed, visualize::Visualize};
|
||||
use factorio_graph::priority_queue::binary_heap::FastBinaryHeap;
|
||||
use factorio_pathfinding::{
|
||||
belt_finding::{conflict_avoidance::ConflictAvoidance, Problem},
|
||||
belt_finding::{Problem, conflict_avoidance::ConflictAvoidance},
|
||||
examples,
|
||||
};
|
||||
use std::{io, path::PathBuf};
|
||||
|
|
@ -70,14 +71,14 @@ fn main() {
|
|||
match args.mode {
|
||||
Mode::Solve => {
|
||||
p.print_visualization();
|
||||
p.find_path();
|
||||
p.find_path::<FastBinaryHeap<_>>();
|
||||
p.print_visualization();
|
||||
}
|
||||
Mode::ConflictAvoidance => {
|
||||
p.print_visualization();
|
||||
p.find_path();
|
||||
p.find_path::<FastBinaryHeap<_>>();
|
||||
p.print_visualization();
|
||||
p.find_path();
|
||||
p.find_path::<FastBinaryHeap<_>>();
|
||||
p.print_visualization();
|
||||
let mut c = ConflictAvoidance::new(&p);
|
||||
c.print_visualization();
|
||||
|
|
@ -88,7 +89,7 @@ fn main() {
|
|||
}
|
||||
Mode::ConflictStep => {
|
||||
p.print_visualization();
|
||||
p.find_path();
|
||||
p.find_path::<FastBinaryHeap<_>>();
|
||||
p.print_visualization();
|
||||
let mut c = ConflictAvoidance::new(&p);
|
||||
c.print_visualization();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue