Cutting Stock Problem (CSP) deals with planning the cutting of items (rods / sheets) from given stock items (which are usually of fixed size).
This implementation of CSP tries to answer
How to minimize number of stock items used while cutting customer order
while doing so, it also caters
How to cut the stock for customer orders so that waste is minimum
The OR Tools also helps us in calculating the number of possible solutions for your problem. So in addition, we can also compute
In how many ways can we cut given order from fixed size Stock?
This is how CSP Tools looks in action. Click CSP Tool to use it
Install Pipenv, if not already installed
$ pip3 install --user pipenv
Clone this project and install packages
$ git clone https://github.com/emadehsan/csp
$ cd csp
$ pipenv install
# activate env
$ pipenv shell
If you run the stock_cutter_1d.py
file directly, it runs the example which uses 120 as length of stock Rod and generates some customer rods to cut. You can update these at the end of stock_cutter_1d.py
.
(csp) $ python csp/stock_cutter_1d.py
Output:
numRollsUsed 5
Status: OPTIMAL
Roll #0: [0.0, [33, 33, 18, 18, 18]]
Roll #1: [2.9999999999999925, [33, 30, 18, 18, 18]]
Roll #2: [5.999999999999993, [30, 30, 18, 18, 18]]
Roll #3: [2.9999999999999987, [33, 33, 33, 18]]
Roll #4: [21.0, [33, 33, 33]]```
If you want to describe your inputs in a file, infile.txt describes the expected format
(csp) $ python3 csp/stock_cutter_1d.py infile.txt
- Works with integers only: IP (Integer Programming) problems working with integers only. If you have some values that have decimal part, you can multiply all of your inputs with some number that will make them integers (or close estimation).
- You cannot specify units: Whether your input is in Inches or Meters, you have to keep a record of that yourself and conversions if any.
Code for 2-dimensional Cutting Stock Problem is in deployment/stock_cutter.py
file. The deployment
directory also contains code for the API server and deploying it on Heroku.
The whole code for this project is taken from Serge Kruk's