Add tracing support for layouting
This commit is contained in:
parent
b53d1e87bc
commit
cebdee4ec7
8 changed files with 254 additions and 53 deletions
|
|
@ -7,6 +7,7 @@ use std::{
|
|||
ops::RangeInclusive,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use tracing::{span, Level};
|
||||
|
||||
use super::Problem;
|
||||
|
||||
|
|
@ -456,6 +457,7 @@ impl ConflictAvoidance {
|
|||
}
|
||||
|
||||
pub fn remove_all_conflicts(&mut self, timeout: Option<Duration>) -> bool {
|
||||
let _span = span!(Level::TRACE, "remove_all_conflicts").entered();
|
||||
let end = timeout.map(|t| std::time::Instant::now() + t);
|
||||
while self.remove_conflict(end) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ use crate::SinglePathInput;
|
|||
use crate::{graph::wheighted_graph::shortest_path::dijkstra, SinglePathfinder};
|
||||
use factorio_core::{prelude::*, visualize::Visualize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::span;
|
||||
use tracing::Level;
|
||||
|
||||
pub mod brute_force;
|
||||
|
||||
|
|
@ -24,6 +26,8 @@ impl SinglePathfinder for ConflictAvoidance {
|
|||
&self,
|
||||
input: SinglePathInput<M>,
|
||||
) -> Option<Vec<Vec<factorio_core::pathfield::PathField>>> {
|
||||
let _span = span!(Level::TRACE, "find_paths").entered();
|
||||
|
||||
let (pos, size) = input.map.area();
|
||||
let mut p = Problem::new(size.x as usize, size.y as usize);
|
||||
|
||||
|
|
@ -264,23 +268,27 @@ impl WheightedGraph for MapInternal<'_> {
|
|||
|
||||
impl Problem {
|
||||
pub fn find_path(&mut self) -> bool {
|
||||
let _span = span!(Level::TRACE, "find_path").entered();
|
||||
for i in 0..self.start.len() {
|
||||
self.calculate_wheights(i);
|
||||
let m = MapInternal {
|
||||
map: &self.map,
|
||||
end: self.end[i],
|
||||
};
|
||||
// let p = dijkstra::<MapInternal, FastBinaryHeap<_>>(&m, self.start[i], self.end[i]);
|
||||
let p = a_star::<MapInternal, FastBinaryHeap<_>, _>(
|
||||
&m,
|
||||
self.start[i],
|
||||
self.end[i],
|
||||
|&(p, _)| {
|
||||
1.5 * (PositionType::abs_diff(p.x, self.end[i].0.x)
|
||||
+ PositionType::abs_diff(p.y, self.end[i].0.y))
|
||||
as f64
|
||||
},
|
||||
);
|
||||
let p = {
|
||||
let _pathfinding_span = span!(Level::TRACE, "graph").entered();
|
||||
// dijkstra::<MapInternal, FastBinaryHeap<_>>(&m, self.start[i], self.end[i])
|
||||
a_star::<MapInternal, FastBinaryHeap<_>, _>(
|
||||
&m,
|
||||
self.start[i],
|
||||
self.end[i],
|
||||
|&(p, _)| {
|
||||
1.5 * (PositionType::abs_diff(p.x, self.end[i].0.x)
|
||||
+ PositionType::abs_diff(p.y, self.end[i].0.y))
|
||||
as f64
|
||||
},
|
||||
)
|
||||
};
|
||||
if let Some(p) = p {
|
||||
self.path[i] = p;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue