{"id":19840102,"url":"https://github.com/emadehsan/csp","last_synced_at":"2025-05-01T19:30:38.021Z","repository":{"id":37462769,"uuid":"277080037","full_name":"emadehsan/csp","owner":"emadehsan","description":"Algorithm for Cutting Stock Problem using Google OR-Tools. Link to the tool:","archived":false,"fork":false,"pushed_at":"2024-01-10T18:22:46.000Z","size":1618,"stargazers_count":147,"open_issues_count":11,"forks_count":39,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-06T17:05:55.730Z","etag":null,"topics":["cutting-stock","cutting-stock-problem","google","operations-research","optimization","optimization-algorithms","ortools","python"],"latest_commit_sha":null,"homepage":"https://emadehsan.com/csp/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emadehsan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-04T09:34:34.000Z","updated_at":"2025-04-05T19:00:37.000Z","dependencies_parsed_at":"2024-11-12T12:39:21.023Z","dependency_job_id":null,"html_url":"https://github.com/emadehsan/csp","commit_stats":{"total_commits":24,"total_committers":4,"mean_commits":6.0,"dds":0.625,"last_synced_commit":"ece925f81e3a0a71ea7af58eaeec681c54e3f5e9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadehsan%2Fcsp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadehsan%2Fcsp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadehsan%2Fcsp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadehsan%2Fcsp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emadehsan","download_url":"https://codeload.github.com/emadehsan/csp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251932559,"owners_count":21667166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cutting-stock","cutting-stock-problem","google","operations-research","optimization","optimization-algorithms","ortools","python"],"created_at":"2024-11-12T12:25:36.439Z","updated_at":"2025-05-01T19:30:37.588Z","avatar_url":"https://github.com/emadehsan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cutting Stock Problem\nCutting Stock Problem (CSP) deals with planning the cutting of items (rods / sheets) from given stock items (which are usually of fixed size).\n\n## New to Cutting Stock Problem? Understand Visually\n\u003ca href=\"https://www.youtube.com/watch?v=4WXtfO9JB20\"\u003e\n\t\u003cimg src=\"./github/video-thumb.jpg\" alt=\"Video Tutorial on Cutting Stock Problem\"\u003e\n\u003c/a\u003e\n\n\nThis implementation of CSP tries to answer\n\u003e How to minimize number of stock items used while cutting customer order\n\n\nwhile doing so, it also caters\n\u003e How to cut the stock for customer orders so that waste is minimum\n\n\nThe OR Tools also helps us in calculating the number of possible solutions for your problem. So in addition, we can also compute\n\u003e In how many ways can we cut given order from fixed size Stock?\n\n\n## Quick Usage\nThis is how CSP Tools looks in action. Click [CSP Tool](https://emadehsan.com/csp/) to use it\n\u003ca href=\"https://emadehsan.com/csp/\"\u003e\n\t\u003cimg src=\"./github/CSP-Tool.PNG\" alt=\"CSP Tool\"\u003e\n\u003c/a\u003e\n\n## Libraries\n* [Google OR-Tools](https://developers.google.com/optimization)\n\n## Quick Start\nInstall [Pipenv](https://pipenv.pypa.io/en/latest/), if not already installed\n```sh\n$ pip3 install --user pipenv\n```\n\nClone this project and install packages\n```sh\n$ git clone https://github.com/emadehsan/csp\n$ cd csp\n$ pipenv install\n\n# activate env\n$ pipenv shell\n```\n\n## Run\nIf 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`.\n```sh\n(csp) $ python csp/stock_cutter_1d.py\n```\n\nOutput:\n\n```sh\nnumRollsUsed 5\nStatus: OPTIMAL\nRoll #0: [0.0, [33, 33, 18, 18, 18]]\nRoll #1: [2.9999999999999925, [33, 30, 18, 18, 18]]\nRoll #2: [5.999999999999993, [30, 30, 18, 18, 18]]\nRoll #3: [2.9999999999999987, [33, 33, 33, 18]]\nRoll #4: [21.0, [33, 33, 33]]```\n```\n\n![Graph of Output](./github/graph-1d-b.PNG)\n\n\n### Using input file\nIf you want to describe your inputs in a file, [infile.txt](./infile.txt) describes the expected format\n\n```sh\n(csp) $ python3 csp/stock_cutter_1d.py infile.txt\n```\n\n\n## Thinks to keep in mind\n* 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).\n* 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.\n\n\n## CSP 2D\nCode for 2-dimensional Cutting Stock Problem is in [`deployment/stock_cutter.py`](deployment/stock_cutter.py) file. The `deployment` directory also contains code for the API server and deploying it on Heroku.\n\n## Resources\nThe whole code for this project is taken from Serge Kruk's\n* [Practical Python AI Projects: Mathematical Models of Optimization Problems with Google OR-Tools](https://amzn.to/3iPceJD)\n* [Repository of the code in Serge's book](https://github.com/sgkruk/Apress-AI/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femadehsan%2Fcsp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femadehsan%2Fcsp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femadehsan%2Fcsp/lists"}