jasonrhansen / cut-optimizer-2d

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

No solution for layout for case "pighetti_b" #12

Closed lukepighetti closed 2 years ago

lukepighetti commented 2 years ago

Currently on cut-optimizer-2d git rev 80d7031

Here is the cut spec

case pighetti_b

kerf width of 2
1x Stock, 2440 x 1220
12x Piece A, 775 x 150
25x Piece B, 450 x 100

Here is the solution laid out by hand

Screen Shot 2022-03-13 at 11 08 24 AM

Here is the code

fn case_pighetti_b() {
    let plywood = StockPiece {
        quantity: Some(1),
        length: 2240,
        width: 1220,
        pattern_direction: PatternDirection::ParallelToLength,
        price: 130,
    };

    let cut_piece_a = CutPiece {
        quantity: 12,
        external_id: Some(1),
        length: 775,
        width: 150,
        can_rotate: false,
        pattern_direction: PatternDirection::ParallelToLength,
    };

    let cut_piece_b = CutPiece {
        quantity: 25,
        external_id: Some(2),
        length: 450,
        width: 100,
        can_rotate: false,
        pattern_direction: PatternDirection::ParallelToLength,
    };

    let mut optimizer = Optimizer::new();
    optimizer.add_stock_piece(plywood);
    optimizer.add_cut_piece(cut_piece_a);
    optimizer.add_cut_piece(cut_piece_b);
    optimizer.set_cut_width(2);

    optimizer.optimize_and_print("second_case");
}

trait OptimizeAndPrint {
    fn optimize_and_print(&self, case_name: &str);
}

impl OptimizeAndPrint for cut_optimizer_2d::Optimizer {
    fn optimize_and_print(&self, case_name: &str) {
        println!("[{}]", case_name);

        fn simple_callback(_: f64) {
            // print!("Progress {}", progress);
        }

        let result = self.optimize_guillotine(simple_callback);
        match result {
            Err(error) => println!("error!, {:?}", error),
            Ok(solution) => {
                println!("Fitness: {}", solution.fitness);
                println!("Stock pieces: {}", solution.stock_pieces.len());
                for stock_piece in solution.stock_pieces {
                    println!(
                        "Stock: {}x{}, cut pieces: {}",
                        stock_piece.length,
                        stock_piece.width,
                        stock_piece.cut_pieces.len()
                    );
                    for cut_piece in stock_piece.cut_pieces {
                        println!(
                            "Cut piece: {}x{} at X={} Y={}",
                            cut_piece.length, cut_piece.width, cut_piece.x, cut_piece.y
                        );
                    }
                }
            }
        }

        println!("");
    }
}

Result

error!, NoFitForCutPiece(CutPiece { quantity: 1, external_id: Some(2), width: 100, length: 450, pattern_direction: ParallelToLength, can_rotate: false })
lukepighetti commented 2 years ago

I wonder if this is related to https://github.com/jasonrhansen/cut-optimizer-2d/issues/13 ?

jasonrhansen commented 2 years ago

It looks like there's still an issue with optimizing with quantity 1 for the stock piece. I'm still looking into it.

Also I think you meant for the stock piece length to be 2440, not 2240.

jasonrhansen commented 2 years ago

Should be working now. Thanks for reporting these issues!

lukepighetti commented 2 years ago

Also I think you meant for the stock piece length to be 2440, not 2240.

Thanks for finding that typo for me!

lukepighetti commented 2 years ago

This is working as expected after resolving the typo and upgrading to rev https://github.com/jasonrhansen/cut-optimizer-2d/commit/e382e13ca537303d90ef54d517abc620f31d278a. Thanks!