Add a star for shortest path
This commit is contained in:
parent
b96ef6f2c1
commit
b53d1e87bc
4 changed files with 65 additions and 19 deletions
|
|
@ -29,20 +29,20 @@ fn main() {
|
|||
let l = ValidLayout {
|
||||
max_tries: 4,
|
||||
retries: 4,
|
||||
start_size: Position::new(128, 128),
|
||||
start_size: Position::new(256, 256),
|
||||
growth: Position::new(16, 16),
|
||||
};
|
||||
|
||||
let l = GeneticAlgorithm {
|
||||
mutation_retries: 20,
|
||||
population_size: 40,
|
||||
population_size: 5,
|
||||
population_keep: 8,
|
||||
population_new: 2,
|
||||
generations: 40,
|
||||
generations: 5,
|
||||
valid_layout: l,
|
||||
};
|
||||
let p = ConflictAvoidance {
|
||||
timeout: Some(std::time::Duration::from_millis(20)),
|
||||
timeout: Some(std::time::Duration::from_millis(100)),
|
||||
};
|
||||
|
||||
let mut rng = SmallRng::seed_from_u64(args.seed);
|
||||
|
|
|
|||
|
|
@ -90,14 +90,14 @@ pub fn generate_factory<L: Layouter, P: Pathfinder>(
|
|||
input_connections.first_chunk()
|
||||
{
|
||||
let c0_bigger = c0.amount > c1.amount + c2.amount;
|
||||
intermediate_connections.push(dbg!((
|
||||
intermediate_connections.push((
|
||||
HashMap::from([
|
||||
(connection_id0, (block_index, if c0_bigger { 1 } else { 0 })),
|
||||
(connection_id1, (block_index + 1, 0)),
|
||||
(connection_id2, (block_index + 1, 1)),
|
||||
]),
|
||||
intermediate_output_connection,
|
||||
)));
|
||||
));
|
||||
|
||||
let beltspeed =
|
||||
Beltspeed::from_items_per_second(2.0 * f64::max(c1.amount, c2.amount));
|
||||
|
|
@ -144,13 +144,13 @@ pub fn generate_factory<L: Layouter, P: Pathfinder>(
|
|||
} else if let Some(&[(connection_id0, c0), (connection_id1, c1)]) =
|
||||
input_connections.first_chunk()
|
||||
{
|
||||
intermediate_connections.push(dbg!((
|
||||
intermediate_connections.push((
|
||||
HashMap::from([
|
||||
(connection_id0, (block_index, 0)),
|
||||
(connection_id1, (block_index, 1)),
|
||||
]),
|
||||
intermediate_output_connection,
|
||||
)));
|
||||
));
|
||||
(
|
||||
Beltspeed::from_items_per_second(c0.amount),
|
||||
Some(Beltspeed::from_items_per_second(c1.amount)),
|
||||
|
|
@ -201,17 +201,18 @@ pub fn generate_factory<L: Layouter, P: Pathfinder>(
|
|||
}
|
||||
}
|
||||
Building::ExternalConnection { inputs, outputs } => {
|
||||
let step = 4;
|
||||
blocks.push(MacroBlock {
|
||||
size: Position::new(1, (inputs + outputs) as PositionType),
|
||||
size: Position::new(1, step * (inputs + outputs) as PositionType),
|
||||
input: (0..*inputs)
|
||||
.map(|y| Interface {
|
||||
offset: Position::new(0, y as PositionType),
|
||||
offset: Position::new(0, step * y as PositionType),
|
||||
dir: Direction::Left,
|
||||
})
|
||||
.collect(),
|
||||
output: (0..*outputs)
|
||||
.map(|y| Interface {
|
||||
offset: Position::new(0, (inputs + y) as PositionType),
|
||||
offset: Position::new(0, step * (inputs + y) as PositionType),
|
||||
dir: Direction::Right,
|
||||
})
|
||||
.collect(),
|
||||
|
|
@ -279,7 +280,12 @@ pub fn generate_factory<L: Layouter, P: Pathfinder>(
|
|||
let mut blueprint = Blueprint::new();
|
||||
blueprint.add_entity(Entity::new_splitter(
|
||||
Beltspeed::from_items_per_second(
|
||||
input_connections.iter().map(|&(_, c)| c.amount).sum(),
|
||||
input_connections
|
||||
.iter()
|
||||
.chain(output_connections.iter())
|
||||
.map(|&(_, c)| c.amount)
|
||||
.max_by(|x, y| x.partial_cmp(y).unwrap())
|
||||
.unwrap_or(1.0),
|
||||
),
|
||||
Position::new(2, 1),
|
||||
Direction::Up,
|
||||
|
|
@ -324,10 +330,10 @@ pub fn generate_factory<L: Layouter, P: Pathfinder>(
|
|||
}
|
||||
}
|
||||
}
|
||||
dbg!(&intermediate_connections);
|
||||
// dbg!(&intermediate_connections);
|
||||
|
||||
for (i, c) in factory_graph.factory_connections.iter().enumerate() {
|
||||
dbg!(i, c);
|
||||
// dbg!(i, c);
|
||||
connections.push(Connection {
|
||||
startblock: intermediate_connections[c.from].1[&i].0,
|
||||
startpoint: intermediate_connections[c.from].1[&i].1,
|
||||
|
|
@ -338,8 +344,8 @@ pub fn generate_factory<L: Layouter, P: Pathfinder>(
|
|||
});
|
||||
}
|
||||
|
||||
dbg!(&blocks);
|
||||
dbg!(&connections);
|
||||
// dbg!(&blocks);
|
||||
// dbg!(&connections);
|
||||
|
||||
let layout_input = LayoutInput {
|
||||
blocks,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue