Add factory generator

This commit is contained in:
hal8174 2025-01-31 23:37:45 +01:00
parent 295490858b
commit 6fbff67e61
14 changed files with 308 additions and 15 deletions

View file

@ -39,7 +39,7 @@ connections:
startpoint: 0
endblock: 0
endpoint: 0
lanes: 1
lanes: 2
beltspeed: Normal
- startblock: 0
startpoint: 0

View file

@ -0,0 +1,127 @@
size:
x: 50
y: 50
blocks:
- size:
x: 3
y: 2
input:
- offset:
x: 1
y: 1
dir: Up
output:
- offset:
x: 1
y: 0
dir: Up
- size:
x: 5
y: 2
input:
output:
- offset:
x: 1
y: 1
dir: Down
- size:
x: 5
y: 7
input:
- offset:
x: 0
y: 1
dir: Right
output:
- size:
x: 5
y: 5
input:
- offset:
x: 0
y: 1
dir: Right
output:
- offset:
x: 0
y: 3
dir: Left
- size:
x: 10
y: 10
input:
- offset:
x: 0
y: 1
dir: Right
- offset:
x: 0
y: 3
dir: Right
output:
- offset:
x: 9
y: 1
dir: Right
- offset:
x: 9
y: 3
dir: Right
- size:
x: 10
y: 5
input:
- offset:
x: 0
y: 1
dir: Right
- offset:
x: 0
y: 3
dir: Right
output:
- offset:
x: 9
y: 1
dir: Right
- offset:
x: 9
y: 3
dir: Right
connections:
- startblock: 1
startpoint: 0
endblock: 0
endpoint: 0
lanes: 2
beltspeed: Normal
- startblock: 0
startpoint: 0
endblock: 3
endpoint: 0
lanes: 1
beltspeed: Normal
- startblock: 3
startpoint: 0
endblock: 4
endpoint: 0
lanes: 1
beltspeed: Normal
- startblock: 4
startpoint: 0
endblock: 5
endpoint: 0
lanes: 1
beltspeed: Normal
- startblock: 4
startpoint: 1
endblock: 5
endpoint: 1
lanes: 1
beltspeed: Normal
- startblock: 5
startpoint: 0
endblock: 2
endpoint: 0
lanes: 1
beltspeed: Normal

View file

@ -31,12 +31,12 @@ fn main() {
};
let p = ConflictAvoidance {
timeout: Some(std::time::Duration::from_millis(100)),
timeout: Some(std::time::Duration::from_millis(5)),
};
let mut rng = SmallRng::seed_from_u64(args.seed);
let r = l.layout(&problem, &p, &mut rng);
dbg!(r);
// dbg!(r);
}

View file

@ -152,20 +152,20 @@ pub fn valid_path_layout<'a, R: Rng + ?Sized>(
}
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub(crate) struct MacroBlock {
pub(crate) size: Position,
pub(crate) input: Vec<Interface>,
pub(crate) output: Vec<Interface>,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub(crate) struct Interface {
pub(crate) offset: Position,
pub(crate) dir: Direction,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub(crate) struct Connection {
pub(crate) startblock: usize,
pub(crate) startpoint: usize,
@ -173,7 +173,7 @@ pub(crate) struct Connection {
pub(crate) endpoint: usize,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Problem {
pub(crate) size: Position,
pub(crate) blocks: Vec<MacroBlock>,

View file

@ -3,21 +3,20 @@ use factorio_pathfinding::Pathfinder;
use rand::Rng;
use serde::{Deserialize, Serialize};
pub mod block;
pub mod genetic_algorithm_v1;
pub mod genetic_algorithm_v2;
pub mod layout;
pub mod misc;
pub mod valid_layout;
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct MacroBlock {
pub size: Position,
pub input: Vec<Interface>,
pub output: Vec<Interface>,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub struct Interface {
pub offset: Position,
pub dir: Direction,