jasonrhansen / cut-optimizer-2d

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

Option to limit stock pieces by quantity #2

Closed kenianbei closed 3 years ago

kenianbei commented 3 years ago

I'm using this in a personal project, and I'm wondering if it would be difficult to limit stock pieces by a quantity?

I'm not a rust expert and I can't quite get my head around where in the code this should be handled. Any help or tips to get me started would be welcome. Thanks!

jasonrhansen commented 3 years ago

I think adding the ability to set a quantity per stock piece would be a great addition! I currently don't have a need for it, but I can see how it would be useful.

I don't think it would be extremely difficult to implement, but I believe it would complicate crossover quite a bit.

I would definitely like to retain the ability to have unlimited quantities on stock pieces. We could add a quantity field to StockPiece that is an Option<usize>. If it is set to None it would mean there is infinite quantity of that piece.

OptimizerUnit would need to keep track of the remaining quantities on all of the stock pieces. It could have a field like available_stock_pieces: Vec<StockPiece>. Then when adding a new Bin, the quantity of the StockPiece it was created from would need to be decremented.

Making crossover work might be tricky because it creates a new Bin from two existing ones. It would need to make sure the new Bin is constrained by the quantities and that available_stock_pieces is set with the correct quantities.

I welcome a PR if you want to take a shot at it. If not I'll probably get to it eventually.

kenianbei commented 3 years ago

Works like a charm! Thanks!