I have a rather mathematical problem I need to solve:
The task is to cut a predefined number of tubes out of fixed length tubes with a minimum amount of waste material.
So let's say I want to cut 10 1m tubes and 20 2,5m tubes out of tubes with a standardized length of 6m.
I'm not sure what an algorithm for this kind of problem would look like?
I was thinking to create a list of variations of the different sized tubes, fit them into the standard sized tubes and
then choose the variation with the minimal waste.
First I'm not sure if there are not other and better ways to attack the problem.
Second I did not find a solution HOW I would create such a variations list.
Any help is greatly appreciated, thanks!
I believe you are describing the cutting stock problem. Some additional information can be found here.
This is known as the Cutting Stock problem. Wikipedia has a number of references that might help you find clues to an algorithm that works.
Related
When researching exercises to practice truncate and modulo I’ve come across a group
of similar problems. For example:
Make change using quarters, dimes, nickels
To fill a barrel, use minimum pours from containers of gal, qt, pint
Transport grain efficiently given capacity & limitations of barges, trains and trucks
Is there a name for this class of problems or of the algorithm to solve? I’m looking
for a title analogous to the “Traveling Salesman Problem”
these are problem of Dynamic programming.
They all specifically resembling to COIN CHANGE PROBLEM.
please explain the tasks if i am worng.
link of coin change: https://www.geeksforgeeks.org/coin-change-dp-7/
This type of problem is known, in my experience, as the Knapsack problem. The general idea being, given a list of things with certain dimensions (like size, value, or weight), optimize their fill into a limited space. The "make change" problem is a special case of the Knapsack problem.
I have quite a strange question on my hands.
I have a list (~500 entries) of lengths of wooden beams in different sizes, such as 3400mm, 1245mm, 900mm, etc.
The maximum length of a wooden beam is 5400mm and in order to reduce the amount of wood being wasted I want to find an algorithm that tries every possible way to combine the smaller sizes to fit into 5400mm beams or as close as possible.
So let's say I have five different lengths: 3000, 1000, 300, 2000, 900 I would end up with:
3000+2000+300 = 5300 // The closest combination to 5400, meaning the amount of wood being wasted is only 100mm on this beam.
1000+900 = 1900 // The rest
I'm not sure if this qualifies for the traveling salesman problem and I have only begun to imagine what the algorithm might look like. But since there are so many smart people with combinatory skills here I just wanted to throw it out there before I bang my head bloody.
To make things even worse
Let's say we do find a solution to the problem above. The guys over at the wood shop rarely delivers 5400mm beams but it can range from 3000 to 5000 in 100mm intervals.
So I'll get a list of beam lengths from them on delivery.
Would it be possible to match the list "this is the beams I got" with the list "find out the best combination of the required beam lengths"?
I'm not sure if it's worth it in the end but any help is appreciated.
Kind regards
Richard
This is the Cutting Stock Problem in 1 dimension. It's reducible to the Knapsack problem so it is in fact NP-complete, but it's generally tractable and in cases where it isn't many good approximate solutions exist, because this is an insanely important problem in industry.
It's typically solved exactly using dynamic programming, which is kind of a mindfuck, but you can find plenty of example implementations to help you out. Approximate polynomial time solutions typically call the dynamic programming code (which has pseudo-polynomial complexity) at various points, and the surrounding code is simpler. I guess the take home message here is don't try to write it yourself, find someone else's code and port it to your language and application environment.
I'm working on an app that's going to estimate building material for my business. The part I'm working on right now deals specifically with trim that goes around windows.
The best way to explain this is to give an example:
Window trim is purchased in lengths of 14 feet (168 inches). Let say I have 5 rectangular windows of various sizes, all of which consist of 4 pieces of trim each (the top and bottom, and right and left). I'm trying to build an algorithm that will determine the best way to cut these pieces with the least amount of waste.
I've looked into using permutations to calculate every possibly outcome and keep track of waste, but the number of permutations where beyond the trillions once I got past 5 windows (20 different pieces of trim).
Does anyone have any insight on how I might do this.
Thanks.
You are looking at a typical case of the cutting stock problem.
I find this lecture from the University of North Carolina (pdf) is rather clear. More oriented towards implementing, with an example throughout, and few requirements -- maybe just looking up a few acronyms. But there are also 2 hours of video lectures from the university of Madras on the topic, if you want more details and at a reasonably slow pace.
It relies on solving the knapsack problem several times, which you can grab directly from Rosetta Code if you don't want to go through a second linear optimization problem.
In short, you want to select some ways (how many pieces of each length) in which to cut stock (in your case the window trim), and how many times to use each way.
You start with a trivial set : for each length you need, make a way of cutting with just that size. You then iterate : the knapsack problem gives the least favourable way to cut stock from your current configuration, and the simplex method then "removes" this combination from your set of ways to cut stock, by pivoting.
To optimize the casements on windows and bi-fold doors for the company i worked for, i used this simple matrix - i simply took the most common openings and decided what would be the most reasonable and optimal cut lengths.
for example a 3050 window could be trimmed with waste by using one 8' cut and one 12'cut.
This question was asked in a recent interview. please suggest something:
A picture of 16x16 is divided into pieces with sizes of 4x4 (16 pieces) and shuffled. Suggest an algorithm to rearrange it back.
If it's a software engineering type of problem and you divide it yourself you can cheat and store each location with each piece. ;)
They're probably looking for some pattern-matching solution though. Perhaps compare the last row of pixels on each side (top/bottom/left/right) with the other (horizontal/vertical) sides (with a certain tolerance). Each side will get a certain score against the others, progressively matching until all are done.
Without going into the Pixel matching algorithms, I think I would take a Dynamic Programming bottom up approach here. First find 8 sets of 2 pieces which are most likely adjacent and then try to build the whole thing from the smaller subsets.
I hope each of these pieces will have a identification (like a number to order/rearrange them). I can think this problem as a analogy to Reception of UDP Packets(Usually UDP Packets might get received out of order and then we need to order them.)
So any sorting algorithm should work.
Please correct me if I have misunderstood the question.
Assuming nothing is available expect the pixels of the pieces, this is a great approach at solving it probabilistically
http://people.csail.mit.edu/taegsang/JigsawPuzzle.html
I am looking for a pseudo-code solution to what is effectively the Multiple Knapsack Problem (optimisation statement is halfway down the page). I think this problem is NP Complete so the solution doesn't need to be optimal, rather if it is fairly efficient and easily implemented that would be good.
The problem is this:
I have many work items, with each taking a different (but fixed and known) amount of time to complete.
I need to divide these work items into groups so as to have the smallest number of groups (ideally), with each group of work items taking no longer than a given total threshold - say 1 hour.
I am flexible about the threshold - it doesnt need to be rigidly applied, though should be close. My idea was to allocate work items into bins where each bin represents 90% of the threshold, 80%, 70% and so on. I could then match items that take 90% to those that take 10%, and so on.
Any better ideas?
You need http://www.or.deis.unibo.it/knapsack.html, chapter 6.6 "Multiple knapscack problem - Approximate algorithms". There is pseudo-code (Pascal style) in the text and Fortran implementations (yes, it's an old book) as a ZIP file.
As far as I know, the problem is NP complete (Wikipedia confirms), so there's probably not much sense in attempting to solve it exactly.
However, any number of approaches might be good enough for you: greedy, genetic algorithms, simulate annealing...greedy is probably the easiest to implement:
while (time available in block greater than smallest task duration)
find the longest fitting task
add it
...you get the idea.