hi
i'm developing my app which be done by vb.net for calculating aluminum measures and profile cutting list
now i connect results with database and get list of different sizes in all profiles but i want to add code to optimize these measures for stock length ex. i have parts :
length-----number
45 cm --->20
120 cm --->15
75 cm --->25
110 cm --->5
-.....
and i have stock :
600 cm --->5
650 cm --->6
....

so i want code for cutting opimization of these parts with stock
i need help for code ...i searched alot on net no code found at least to start with...

Dani AI

Generated

This is a classic 1‑D cutting‑stock / bin‑packing problem (as already pointed out). The practical path is to separate "logic" from "UI/DB" (as suggested) and to build the app incrementally (as advised): import part sizes and stock inventory, implement a simple packer, measure waste, then refine.

Recommended, pragmatic approach:

  • Model each part as a length with a count and each stock length with available quantity. Include kerf (saw width) and any minimum-scrap rules up front.
  • Start with a greedy heuristic: sort parts descending and place each part into the best existing open stock where it fits (Best‑Fit Decreasing). If none fits, open a new stock of the smallest available length that can hold the part and decrement its inventory. This is fast, easy to debug, and often good enough for real jobs.
  • Measure total waste (#stocks used, leftover per stock). If results are unacceptable, try variations (First‑Fit Decreasing, try opening different stock sizes first) or move to an exact solver (integer programming / column generation) for smaller instances.

Example greedy packer (Python, easy to port to VB.NET):

def pack_1d(parts_counts, stocks_counts):
    # parts_counts: list of (length, count)
    # stocks_counts: dict {stock_length: count}
    parts = []
    for L,c in parts_counts:
        parts += [L]*c
    parts.sort(reverse=True)
    open_bins = []
    stock_avail = dict(stocks_counts)
    for p in parts:
        # best-fit into existing bins
        best = None; best_rem = None
        for b in open_bins:
            if p <= b['rem']:
                r = b['rem'] - p
                if best is None or r < best_rem:
                    best, best_rem = b, r
        if best:
            best['items'].append(p); best['rem'] -= p; continue
        # open smallest available stock that fits
        cand = [s for s in stock_avail if s >= p and stock_avail[s] > 0]
        if not cand:
            raise ValueError("No stock for part {}".format(p))
        s = min(cand); stock_avail[s] -= 1
        open_bins.append({'stock': s, 'rem': s - p, 'items': [p]})
    return open_bins

Notes and cautions: account for kerf and measurement rounding, keep stock inventory checks strict, and log outcomes so heuristic changes can be compared. Exact methods exist but are slower; greedy methods scale and are usually sufficient for shop-sized inputs like the example in the thread.

Recommended Answers

All 5 Replies

You need help with the code or with the logic of the optimization?

Maybe if you explain the logic somebody can help with the code.

the problem that i don't know when to start ..
what code i will use ..i made manual code to select measures from dvg and transfer to textboxes then calculate manually but i want to make something like "real cut 1d " or " smart 1d cutting" apps. i try to open code of them using reflector but i coudn't ...plz help

hello no answer or help???????

the problem that i don't know when to start

You start by writing the parts that you can and stubbing out the rest. Then you can ask specific questions about the stubbed out parts. When I see phrases such as "I want to make something like..." my first impression is that you haven't really thought about what you want to do. If that is the case then you are going to have to put some effort in up front.

Maybe you need to know what you are doing could be called. Here's a google using what I think you are looking for.

https://www.google.com/search?hl=en&as_q=1d+nesting+algorithm

As you can see this leads you to the old "bin packing problem" and now you have a lot of prior discussions you can check over. It's an old question with what must be centuries of thought on it.

But if you don't know what folk called it, you would be hard pressed to find priors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.