Message Boards Message Boards

0
|
2394 Views
|
6 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Cut wood to minimize loss

Posted 1 year ago

Wondering how one can solve using Mathematica...

Lots of two board lengths needed: 19" and 7" Using multiple 2x4s, 8' long, or 96" each.

What's the best combination of the 19" and 7" pieces to cut per 2x4 so as to minimize loss?

19x + 7y <= 96

Thanks!

6 Replies

Here is one way:

model = 96 - 19 x - 7 y;
sols0 = List @@ Reduce[model >= 0, {x, y}, NonNegativeIntegers];
sols = SortBy[{#, Simplify[model, #]} & /@ sols0, Last];
(* result: *)
First[sols]
(*  Out{x\[Equal]1&&y\[Equal]11,0}   *)
POSTED BY: Henrik Schachner

Don't forget the kerf of the saw. And you might want to square the end of the 2x4 before you start depending on the project. And "lots" probably might not lead to a good answer (e.g. eleven times as many 7" pieces as 19" ones).

POSTED BY: Michael Rogers
Posted 1 year ago

Here's how you can do it in Mathematica:

Define the problem and variables: Let x be the number of 19" pieces to cut from each 2x4, and y be the number of 7" pieces to cut from each 2x4.

Define the objective function: The objective is to minimize the waste, which can be represented as (96 - (19x + 7y)), as 96 is the length of each 2x4 and (19x + 7y) is the total length of pieces cut from it.

Set up the constraints: You have the constraint that the total length of pieces cut from each 2x4 cannot exceed 96 inches, so the constraint is (19x + 7y <= 96).

Use Mathematica to solve the linear programming problem:

(* Load the LinearProgramming package *) Needs["LinearProgramming`"]

(* Define the objective function coefficients and constraints *) objectiveCoefficients = {19, 7}; constraintsMatrix = {{19, 7}}; constraintsVector = {96};

(* Set up the optimization problem *) solution = LinearProgramming[objectiveCoefficients, constraintsMatrix, constraintsVector];

(* Extract the values of x and y from the solution *) {x, y} = solution;

(* Calculate the waste *) waste = 96 - (19x + 7y);

(* Print the results *) Print["Number of 19\" pieces (x) per 2x4: ", x]; Print["Number of 7\" pieces (y) per 2x4: ", y]; Print["Waste: ", waste, " inches"];

POSTED BY: Mark lee

I forgot I had chosen 19" because 96"/5 already minimizes the waste in cutting a 2x4 of that length.

But I'm still curious how Mathematica would solve such an optimization problem.

Plugged your suggestion in and got:

{x == 1 && y == 11, 0}

Hmmm....

Thanks Mark. Really clear.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract