bozokopic / opcut Goto Github PK
View Code? Open in Web Editor NEWCutting stock problem optimizer
Home Page: https://opcut.kopic.xyz
License: GNU General Public License v3.0
Cutting stock problem optimizer
Home Page: https://opcut.kopic.xyz
License: GNU General Public License v3.0
Hi can your algorithm be modified to incorporate the grain direction and to keep labels on the items to be cut after their rotations?
In wood industry it is needed to mark some sides of every item, and these side marking should be fixed on the items even if the item is rotated during the fitting process of your algorithm
pip install opcut failed on trying to build pycairo on Windows 10, tried in Ubuntu, same thing it failed. I used this work around.
In Ubuntu:
$ sudo apt install libcairo2-dev pkg-config python3-dev
then I did
$ pip3 install opcut
and opcut installed successfully with no more failed to build pycairo errors.
Hello!
I put these settings into the heroku app and it solves with 15 "panels"
When I use the same data on the command line, it solves with 16 "panels" and a lot wastage on one of them:
#################################### PARTS #####################################
tube_40x80x2: 40.00 80.00 2200.00 x 2
tube_40x80x2: 40.00 80.00 2500.00 x 6
tube_40x80x2: 40.00 80.00 2920.00 x 8
tube_40x80x2: 40.00 80.00 4048.16 x 3
tube_40x80x2: 40.00 80.00 5524.96 x 4
tube_40x80x2: 40.00 80.00 900.00 x 10
################################ SHOPPING LIST #################################
tube_40x80x2: 16.00
#################################### WASTE #####################################
tube_40x80x2-01: 472.04 40.00
tube_40x80x2-02: 472.04 40.00
tube_40x80x2-03: 472.04 40.00
tube_40x80x2-04: 472.04 40.00
tube_40x80x2-05: 574.00 40.00
tube_40x80x2-06: 574.00 40.00
tube_40x80x2-07: 574.00 40.00
tube_40x80x2-08: 142.84 40.00
tube_40x80x2-09: 574.00 40.00
tube_40x80x2-10: 874.00 40.00
tube_40x80x2-11: 874.00 40.00
tube_40x80x2-12: 142.84 40.00
tube_40x80x2-13: 142.84 40.00
tube_40x80x2-14: 3077.00 40.00
tube_40x80x2-15: 368.00 40.00
tube_40x80x2-16: 91.00 40.00
I call opcut
with only one panel to start with and add 'panels' until it solves.
Thanks for the great library! Do you have any plans to support macOS/arm64?
The calculations creates many waste.
test csv:
name;quantity;width;height
Panel;10;2070;2800
name;quantity;width;height;can_rotate
1. Korpusz oldal;2;570;786;false
2. Korpusz also/felso;2;557;1374;false
3. Hátlap null;1;1356;780;false
4. Front front;1;1371;303;true
5. Fiók oldal;2;540;125;true
6. Fiók eleje/hata;2;1296;125;true
7. Front front;1;1371;285;true
8. Fiók oldal;2;540;125;true
9. Fiók eleje/hata;2;1296;125;true
10. Front front;1;1371;189;true
11. Fiók oldal;2;540;85;true
12. Fiók eleje/hata;2;1296;85;true
With both the demo server and self hosted I am getting a 500 error when attempting to generate a PDF of the cut list. In my self hosted terminal I get this output:
[2022-10-02 14:18:27,026 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:27 +0000] "GET / HTTP/1.1" 302 188 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:27,077 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:27 +0000] "GET /index.html HTTP/1.1" 200 234 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:27,175 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:27 +0000] "GET /main.js HTTP/1.1" 200 253 "http://0.0.0.0:8080/index.html" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:27,494 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:27 +0000] "GET /fonts/Inter/Inter.woff2 HTTP/1.1" 200 241 "http://0.0.0.0:8080/index.html" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:27,501 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:27 +0000] "GET /favicon.ico HTTP/1.1" 200 238 "http://0.0.0.0:8080/index.html" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:29,481 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:29 +0000] "GET /fonts/FontAwesome/FontAwesome.woff2 HTTP/1.1" 200 240 "http://0.0.0.0:8080/index.html" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:43,428 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:42 +0000] "POST /calculate?method=forward_greedy_native HTTP/1.1" 200 2527 "http://0.0.0.0:8080/index.html" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:53,522 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:53 +0000] "POST /calculate?method=forward_greedy HTTP/1.1" 200 2632 "http://0.0.0.0:8080/index.html" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
[2022-10-02 14:18:55,952 ERROR aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
resp = await request_handler(request)
File "/usr/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
File "/home/ben/.local/lib/python3.10/site-packages/opcut/server.py", line 97, in _generate_handler
if output_format == common.OutputType.PDF:
AttributeError: module 'opcut.common' has no attribute 'OutputType'
[2022-10-02 14:18:55,952 INFO aiohttp.access] 127.0.0.1 [02/Oct/2022:19:18:55 +0000] "POST /generate?output_format=pdf HTTP/1.1" 500 245 "http://0.0.0.0:8080/index.html" "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"
I'm also unsure if the panel and cuts should be shown in the browser window after hitting calculate, but there is nothing shown in the center pane at all. There is a list of item coordinates on the right though.
I have my panels and items defined in a CSV but I'm not sure how to pass this on the CLI since it seems to want a single YAML or JSON? I can convert them later but don't have time at the moment to try it out.
Hi there, great stuff you published ! Thanks.
I found your code when researching an implementation of the cutting stock problem which seems to not be trivial. So I was wondering if you could point me in the direction to understand your python implementation a bit better.
I can see how you process the Items picking the "1 dimension biggest" first in _get_next_results()
function.
But then, when it comes to compare the solutions at each step before choosing the one to go on from, the _fitness()
"formula" of function is a bit obscure to me. Did you come up with that ? Would you have a mathematical expression of it ? Or any reference really explaining how that fitness
actually drive us in the "best" direction ?
Cheers
Hi,
I've seen many examples using pyomo/glpk for cutting stock example, can this helps reduce the amount of code in this example?
https://github.com/Pyomo/pyomo/tree/master/examples/doc/samples/comparisons/cutstock
https://github.com/lordofthec4ctus/stock_cutting_py
I'm trying to reproduce the doc example here.
I am trying t install opcut on my docker image with pip.
I have the following error :
Traceback (most recent call last):
File "/opt/venv/bin/opcut", line 5, in <module>
from opcut.main import main
File "/opt/venv/lib/python3.12/site-packages/opcut/main.py", line 13, in <module>
import opcut.server
File "/opt/venv/lib/python3.12/site-packages/opcut/server.py", line 7, in <module>
import aiohttp.web
File "/opt/venv/lib/python3.12/site-packages/aiohttp/__init__.py", line 6, in <module>
from .client import (
File "/opt/venv/lib/python3.12/site-packages/aiohttp/client.py", line 32, in <module>
from . import hdrs, http, payload
File "/opt/venv/lib/python3.12/site-packages/aiohttp/http.py", line 7, in <module>
from .http_parser import (
File "/opt/venv/lib/python3.12/site-packages/aiohttp/http_parser.py", line 15, in <module>
from .helpers import NO_EXTENSIONS, BaseTimerContext
File "/opt/venv/lib/python3.12/site-packages/aiohttp/helpers.py", line 98, in <module>
old_debug = coroutines._DEBUG # type: ignore
^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio.coroutines' has no attribute '_DEBUG'
Here is a part of my docker file (alpine linux):
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
## Install necessary system dependencies
RUN apk update && apk add --no-cache \
python3-dev \
py3-virtualenv \
build-base \
linux-headers
## Create a virtual environment
RUN python3 -m venv $VIRTUAL_ENV
RUN apk add --no-cache gcc pkgconfig cairo-dev
RUN pip install opcut
Panel 6000 mm x 100mm - 3 pieces
Item 1 - 3700 mm x 100 mm - 2 pieces
Item 2 - 2200 mm x 100 mm - 1 piece
The algorithm should use 2 panels, but it uses 3 panels.
I just noticed that you have a Docker Hub image, but hasn't been updated since December 17th (presumably v0.4.5) and that it doesn't have any documentation on how to run it. I'm not sure if you have a specific reason for it, but I would love to have docker as an install method.
Thanks for the great app!
Hello and thank you for this project.
How can I translate the web page?
And would it be possible to add a default panel with its dimensions and quantities?
Is there a way for the algorithm to discover the optimal solution without factoring in the panel inventory, given the significant time it consumes with a large inventory?
I installed opcut by building it from scratch
# Setup and build local opcut
## Set environment variables
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# ## Install necessary system dependencies
RUN apk update && apk add --no-cache \
python3-dev \
py3-virtualenv \
build-base \
linux-headers
## Create a virtual environment
RUN python3 -m venv $VIRTUAL_ENV
RUN apk add --no-cache gcc pkgconfig cairo-dev
RUN git clone https://github.com/bozokopic/opcut.git
WORKDIR /app/opcut
RUN pip install -r requirements.pip.txt
RUN doit
# mandaotry to allow python to use absolute imports
RUN export PYTHONPATH="${PYTHONPATH}:/app/opcut/src_py"
But when I try the usage example in the doc, I get the following error for the "greedy_native" method: Segmentation fault
I ran : python opcut/src_py/opcut/main.py calculate --method 'greedy_native' --input-format yaml input.yaml
the input.yaml file:
cut_width: 1
panels:
panel1:
width: 100
height: 100
items:
item1:
width: 10
height: 10
can_rotate: false
This works with the "greedy" method
I used opcut before the last update, and it worked like a charm with the 2023 versions
$ opcut calculate --params ply_9.yml --method GREEDY --result ply_9-result.yml --output ply_9.pdf
usage: opcut calculate [-h] --params path [--method {GREEDY,FORWARD_GREEDY}]
--result path [--output-type {PDF,SVG}]
[--output-panel panel_id] [--output path]
opcut calculate: error: argument --method: invalid Method value: 'GREEDY'
I also tried lowercase and it didn't work.
Thanks for sharing this brilliant project!
It could be useful and perhaps encourage PRs if you could add add a summary on your development cycle/workflow to the README file.
Can you please share a clear algorithm or paper used to apply this?
I encountered an issue with NATIVE methods , specifically an AttributeError: the function 'opcut_allocator_create' couldn't be found.
Can someone assist me with this problem?
I'm having trouble generating the svg output. If I have multiple panels, the svg will only be generated for the last panel. PDF is correct.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.