Modify bench and performance improvements.
This commit is contained in:
parent
b5dcbccf02
commit
96a86779f4
2 changed files with 25 additions and 45 deletions
|
|
@ -1,23 +1,10 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
use factorio_blueprint::belt_finding::{brute_force::*, Direction, Position};
|
||||
use factorio_blueprint::belt_finding::brute_force::problems::{simple, snake};
|
||||
|
||||
fn brute_force(c: &mut Criterion) {
|
||||
c.bench_function("simple", |b| {
|
||||
let mut p = BruteforceBuilder::new(6, 8);
|
||||
|
||||
p.add_path(
|
||||
(Position::new(1, 0), Direction::Down),
|
||||
(Position::new(0, 0), Direction::Up),
|
||||
);
|
||||
p.add_path(
|
||||
(Position::new(4, 0), Direction::Down),
|
||||
(Position::new(1, 7), Direction::Up),
|
||||
);
|
||||
|
||||
p.set_blocked_range(0, 2, 5, 5, true);
|
||||
|
||||
let p = p.build();
|
||||
let p = simple();
|
||||
|
||||
b.iter(|| {
|
||||
let mut g = p.clone();
|
||||
|
|
@ -28,24 +15,7 @@ fn brute_force(c: &mut Criterion) {
|
|||
});
|
||||
});
|
||||
c.bench_function("weaving", |b| {
|
||||
let mut p = BruteforceBuilder::new(14, 3);
|
||||
|
||||
p.add_path(
|
||||
(Position::new(0, 0), Direction::Right),
|
||||
(Position::new(13, 0), Direction::Right),
|
||||
);
|
||||
p.add_path(
|
||||
(Position::new(0, 1), Direction::Right),
|
||||
(Position::new(13, 1), Direction::Right),
|
||||
);
|
||||
p.add_path(
|
||||
(Position::new(0, 2), Direction::Right),
|
||||
(Position::new(13, 2), Direction::Right),
|
||||
);
|
||||
|
||||
p.set_blocked_range(3, 2, 10, 2, true);
|
||||
|
||||
let p = p.build();
|
||||
let p = snake();
|
||||
|
||||
b.iter(|| {
|
||||
let mut g = p.clone();
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ pub enum PathField {
|
|||
}
|
||||
|
||||
impl PathField {
|
||||
// fn pos(&self) -> &Position {
|
||||
// match self {
|
||||
// PathField::Belt { pos, dir: _ } => pos,
|
||||
// PathField::Underground {
|
||||
// pos,
|
||||
// dir: _,
|
||||
// len: _,
|
||||
// } => pos,
|
||||
// }
|
||||
// }
|
||||
fn pos(&self) -> &Position {
|
||||
match self {
|
||||
PathField::Belt { pos, dir: _ } => pos,
|
||||
PathField::Underground {
|
||||
pos,
|
||||
dir: _,
|
||||
len: _,
|
||||
} => pos,
|
||||
}
|
||||
}
|
||||
|
||||
fn dir(&self) -> &Direction {
|
||||
match self {
|
||||
|
|
@ -430,12 +430,22 @@ impl Bruteforce {
|
|||
if second_last.dir().counter_clockwise() == dir
|
||||
&& self.modify_underground(&pos, second_last.dir(), 2)
|
||||
{
|
||||
return true;
|
||||
let (p, d) = self.path_field_end(self.modify_path().last().unwrap());
|
||||
if self.is_next_free(&p, &d) {
|
||||
return true;
|
||||
} else {
|
||||
return self.modify_remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
PathField::Underground { pos, dir, len } => {
|
||||
if self.modify_underground(&pos, &dir, len + 1) {
|
||||
return true;
|
||||
let (p, d) = self.path_field_end(self.modify_path().last().unwrap());
|
||||
if self.is_next_free(&p, &d) {
|
||||
return true;
|
||||
} else {
|
||||
return self.modify_remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue