Resolve warnings.
This commit is contained in:
parent
2bf648f657
commit
5575cb134a
6 changed files with 103 additions and 143 deletions
|
|
@ -42,19 +42,20 @@ fn main() {
|
||||||
|
|
||||||
let mut b = args.problem.get_problem();
|
let mut b = args.problem.get_problem();
|
||||||
|
|
||||||
println!("{b}");
|
b.print();
|
||||||
|
|
||||||
match args.mode {
|
match args.mode {
|
||||||
Mode::Solutions => {
|
Mode::Solutions => {
|
||||||
while b.next_finish_state() {
|
while b.next_finish_state() {
|
||||||
println!("{}\n{}\n{}\n{}", b.count(), b.solution_count(), b.cost(), b);
|
println!("{}\n{}\n{}", b.count(), b.solution_count(), b.cost());
|
||||||
|
b.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Solutions: {}\nStates: {}", b.solution_count(), b.count());
|
println!("Solutions: {}\nStates: {}", b.solution_count(), b.count());
|
||||||
}
|
}
|
||||||
Mode::Step => {
|
Mode::Step => {
|
||||||
while b.next_state() {
|
while b.next_state() {
|
||||||
println!("{}", b);
|
b.print();
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let _ = io::stdin().read_line(&mut s);
|
let _ = io::stdin().read_line(&mut s);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::io;
|
|
||||||
|
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use factorio_blueprint::belt_finding::{conflict_avoidance::ConflictAvoidance, problems, Problem};
|
use factorio_blueprint::belt_finding::{conflict_avoidance::ConflictAvoidance, problems, Problem};
|
||||||
|
use std::io;
|
||||||
|
|
||||||
#[derive(ValueEnum, Clone)]
|
#[derive(ValueEnum, Clone)]
|
||||||
enum Mode {
|
enum Mode {
|
||||||
|
|
@ -44,40 +43,40 @@ fn main() {
|
||||||
|
|
||||||
match args.mode {
|
match args.mode {
|
||||||
Mode::Solve => {
|
Mode::Solve => {
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
}
|
}
|
||||||
Mode::ConflictAvoidance => {
|
Mode::ConflictAvoidance => {
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
let mut c = ConflictAvoidance::new(p);
|
let mut c = ConflictAvoidance::new(p);
|
||||||
println!("{}", c);
|
c.print();
|
||||||
while c.remove_conflict() {
|
while c.remove_conflict() {
|
||||||
println!("{}", c)
|
c.print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::ConflictStep => {
|
Mode::ConflictStep => {
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
p.find_path();
|
p.find_path();
|
||||||
println!("{}", p);
|
p.print();
|
||||||
let mut c = ConflictAvoidance::new(p);
|
let mut c = ConflictAvoidance::new(p);
|
||||||
println!("{}", c);
|
c.print();
|
||||||
while c.remove_conflict() {
|
while c.remove_conflict() {
|
||||||
println!("{}", c);
|
c.print();
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let _ = io::stdin().read_line(&mut s);
|
let _ = io::stdin().read_line(&mut s);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,9 @@
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
use termcolor::ColorSpec;
|
|
||||||
|
|
||||||
use crate::misc::Map;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
common::{print_map, Dimension, Direction, PathField, PositionType},
|
common::{print_map, Dimension, Direction, PathField, PositionType},
|
||||||
Position, COLORS,
|
Position, COLORS,
|
||||||
};
|
};
|
||||||
|
use crate::misc::Map;
|
||||||
|
use termcolor::ColorSpec;
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone)]
|
#[derive(Default, Debug, Clone)]
|
||||||
pub struct BruteforceField {
|
pub struct BruteforceField {
|
||||||
|
|
@ -446,9 +442,8 @@ impl Bruteforce {
|
||||||
});
|
});
|
||||||
if self.is_next_free(&pos, &second_last.dir().clockwise()) {
|
if self.is_next_free(&pos, &second_last.dir().clockwise()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return self.modify_remove();
|
|
||||||
}
|
}
|
||||||
|
return self.modify_remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if second_last.dir().clockwise() == dir {
|
if second_last.dir().clockwise() == dir {
|
||||||
|
|
@ -458,9 +453,8 @@ impl Bruteforce {
|
||||||
});
|
});
|
||||||
if self.is_next_free(&pos, &second_last.dir().counter_clockwise()) {
|
if self.is_next_free(&pos, &second_last.dir().counter_clockwise()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return self.modify_remove();
|
|
||||||
}
|
}
|
||||||
|
return self.modify_remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if second_last.dir().counter_clockwise() == dir
|
if second_last.dir().counter_clockwise() == dir
|
||||||
|
|
@ -470,9 +464,8 @@ impl Bruteforce {
|
||||||
|
|
||||||
if self.is_next_free(&p, &d) {
|
if self.is_next_free(&p, &d) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return self.modify_remove();
|
|
||||||
}
|
}
|
||||||
|
return self.modify_remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PathField::Underground { pos, dir, len } => {
|
PathField::Underground { pos, dir, len } => {
|
||||||
|
|
@ -481,9 +474,8 @@ impl Bruteforce {
|
||||||
|
|
||||||
if self.is_next_free(&p, &d) {
|
if self.is_next_free(&p, &d) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return self.modify_remove();
|
|
||||||
}
|
}
|
||||||
|
return self.modify_remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -598,13 +590,7 @@ impl Bruteforce {
|
||||||
pub fn solution_count(&self) -> u128 {
|
pub fn solution_count(&self) -> u128 {
|
||||||
self.solution_count
|
self.solution_count
|
||||||
}
|
}
|
||||||
}
|
pub fn print(&self) {
|
||||||
|
|
||||||
impl Display for Bruteforce {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let width_digits = self.map.width.ilog10() + 1;
|
|
||||||
let height_digits = self.map.height.ilog10() + 1;
|
|
||||||
|
|
||||||
let mut m: Map<Option<(usize, &str)>> = Map::new(self.map.width, self.map.height);
|
let mut m: Map<Option<(usize, &str)>> = Map::new(self.map.width, self.map.height);
|
||||||
|
|
||||||
for (i, problem) in self.problems.iter().enumerate() {
|
for (i, problem) in self.problems.iter().enumerate() {
|
||||||
|
|
@ -681,8 +667,6 @@ impl Display for Bruteforce {
|
||||||
(ColorSpec::new(), " ")
|
(ColorSpec::new(), " ")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,10 @@
|
||||||
use std::{
|
|
||||||
fmt::Display,
|
|
||||||
ops::{RangeBounds, RangeInclusive},
|
|
||||||
};
|
|
||||||
|
|
||||||
use clap::builder::PathBufValueParser;
|
|
||||||
use termcolor::ColorSpec;
|
|
||||||
|
|
||||||
use crate::{belt_finding::brute_force::BruteforceBuilder, misc::Map};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
common::{print_map, Dimension, Direction, PathField, Position, PositionType},
|
common::{print_map, Direction, PathField, Position, PositionType},
|
||||||
Problem, COLORS,
|
Problem, COLORS,
|
||||||
};
|
};
|
||||||
|
use crate::{belt_finding::brute_force::BruteforceBuilder, misc::Map};
|
||||||
|
use std::ops::RangeInclusive;
|
||||||
|
use termcolor::ColorSpec;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Field {
|
struct Field {
|
||||||
|
|
@ -274,8 +267,8 @@ impl ConflictAvoidance {
|
||||||
|
|
||||||
let mut b = b.build();
|
let mut b = b.build();
|
||||||
|
|
||||||
println!("{}", b);
|
b.print();
|
||||||
println!("{}", self);
|
self.print();
|
||||||
|
|
||||||
let mut min_cost = f64::INFINITY;
|
let mut min_cost = f64::INFINITY;
|
||||||
let mut solutions = Vec::new();
|
let mut solutions = Vec::new();
|
||||||
|
|
@ -315,7 +308,7 @@ impl ConflictAvoidance {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
let mut candidate = Candidate::new(
|
let mut candidate = Candidate::new(
|
||||||
Position::new(
|
Position::new(
|
||||||
xrange.start().saturating_sub(1) as PositionType,
|
xrange.start().saturating_sub(1) as PositionType,
|
||||||
|
|
@ -363,20 +356,14 @@ impl ConflictAvoidance {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
candidate.extend_range(&conflicts);
|
candidate.extend_range(&conflicts);
|
||||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
|
||||||
candidates.push(candidate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_all_conflicts(&mut self) {
|
pub fn remove_all_conflicts(&mut self) {
|
||||||
while self.remove_conflict() {}
|
while self.remove_conflict() {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for ConflictAvoidance {
|
pub fn print(&self) {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let mut m: Map<Option<(usize, &str)>> = Map::new(self.map.width, self.map.height);
|
let mut m: Map<Option<(usize, &str)>> = Map::new(self.map.width, self.map.height);
|
||||||
|
|
||||||
for (i, problem) in self.belts.iter().enumerate() {
|
for (i, problem) in self.belts.iter().enumerate() {
|
||||||
|
|
@ -474,7 +461,5 @@ impl Display for ConflictAvoidance {
|
||||||
(color, " ")
|
(color, " ")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
use termcolor::{Color, ColorSpec};
|
|
||||||
|
|
||||||
use crate::belt_finding::{brute_force::BruteforceBuilder, common::Direction};
|
|
||||||
use crate::graph::wheighted_graph::shortest_path::dijkstra;
|
use crate::graph::wheighted_graph::shortest_path::dijkstra;
|
||||||
use crate::graph::wheighted_graph::WheightedGraph;
|
use crate::graph::wheighted_graph::WheightedGraph;
|
||||||
use crate::misc::Map;
|
use crate::misc::Map;
|
||||||
use crate::priority_queue::BinaryHeap;
|
use crate::priority_queue::BinaryHeap;
|
||||||
use std::fmt::Display;
|
use std::ops::Index;
|
||||||
use std::ops::{Deref, Index};
|
use termcolor::{Color, ColorSpec};
|
||||||
|
|
||||||
use self::common::{print_map, Position, PositionType};
|
use self::common::{print_map, Position, PositionType};
|
||||||
|
|
||||||
|
|
@ -88,29 +85,8 @@ impl Problem {
|
||||||
self.map.get_mut(p.x as usize, p.y as usize).wheight += 200.0;
|
self.map.get_mut(p.x as usize, p.y as usize).wheight += 200.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static COLORS: Cyclic<Color, 6> = Cyclic([
|
pub fn print(&self) {
|
||||||
Color::Red,
|
|
||||||
Color::Green,
|
|
||||||
Color::Yellow,
|
|
||||||
Color::Blue,
|
|
||||||
Color::Magenta,
|
|
||||||
Color::Cyan,
|
|
||||||
]);
|
|
||||||
|
|
||||||
struct Cyclic<T, const N: usize>([T; N]);
|
|
||||||
|
|
||||||
impl<T, const N: usize> Index<usize> for Cyclic<T, N> {
|
|
||||||
type Output = T;
|
|
||||||
|
|
||||||
fn index(&self, index: usize) -> &Self::Output {
|
|
||||||
&self.0[index % N]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for Problem {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
print_map(self.map.width as i32, self.map.height as i32, |x, y| {
|
print_map(self.map.width as i32, self.map.height as i32, |x, y| {
|
||||||
let mut color = ColorSpec::new();
|
let mut color = ColorSpec::new();
|
||||||
if let Some(i) = self
|
if let Some(i) = self
|
||||||
|
|
@ -152,8 +128,25 @@ impl Display for Problem {
|
||||||
(color, " ")
|
(color, " ")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
static COLORS: Cyclic<Color, 6> = Cyclic([
|
||||||
|
Color::Red,
|
||||||
|
Color::Green,
|
||||||
|
Color::Yellow,
|
||||||
|
Color::Blue,
|
||||||
|
Color::Magenta,
|
||||||
|
Color::Cyan,
|
||||||
|
]);
|
||||||
|
|
||||||
|
struct Cyclic<T, const N: usize>([T; N]);
|
||||||
|
|
||||||
|
impl<T, const N: usize> Index<usize> for Cyclic<T, N> {
|
||||||
|
type Output = T;
|
||||||
|
|
||||||
|
fn index(&self, index: usize) -> &Self::Output {
|
||||||
|
&self.0[index % N]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
#![feature(slice_first_last_chunk)]
|
|
||||||
|
|
||||||
pub mod belt_finding;
|
pub mod belt_finding;
|
||||||
pub mod blueprint;
|
pub mod blueprint;
|
||||||
pub mod graph;
|
pub mod graph;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue