jasonrhansen / cut-optimizer-2d

2D Cut Optimizer
Apache License 2.0
19 stars 11 forks source link

Unexpected behavior with multiple stock pieces and cut pieces. #4

Closed kenianbei closed 3 years ago

kenianbei commented 3 years ago

Hi I'm having some strange behavior when adding multiple stock pieces and multiple cut pieces. The test below fails with this error:

NoFitForCutPiece(CutPiece { external_id: None, width: 64, length: 192, pattern_direction: None, can_rotate: false })

It seems like the optimizer is matching the a smaller cut piece to the larger stock piece, then failing with the larger one since it has no match. If you set the larger stock piece to quantity of 2 it will pass. Any ideas what's going on? I'll keep investigating...

#[test]
fn guillotine_stock_quantity_multiple_ok() {
    let solution = Optimizer::new()
        .add_stock_piece(StockPiece {
            width: 48,
            length: 96,
            pattern_direction: PatternDirection::None,
            price: 0,
            quantity: Some(2),
        })
        .add_stock_piece(StockPiece {
            width: 64,
            length: 192,
            pattern_direction: PatternDirection::None,
            price: 0,
            quantity: Some(1),
        })
        .add_cut_piece(CutPiece {
            external_id: None,
            width: 48,
            length: 96,
            pattern_direction: PatternDirection::None,
            can_rotate: false,
        })
        .add_cut_piece(CutPiece {
            external_id: None,
            width: 48,
            length: 96,
            pattern_direction: PatternDirection::None,
            can_rotate: false,
        })
        .add_cut_piece(CutPiece {
            external_id: None,
            width: 64,
            length: 192,
            pattern_direction: PatternDirection::None,
            can_rotate: false,
        })
        .set_cut_width(0)
        .set_random_seed(1)
        .optimize_guillotine(|_| {})
        .unwrap();

    sanity_check_solution(&solution, 3);
}