cutting stock problem: problem-凯发k8网页登录
this example shows how to solve a using linear programming with an integer linear programming subroutine. the example uses the problem-based optimization setup approach. for the solver-based approach, see .
problem overview
a lumber mill starts with trees that have been trimmed to fixed-length logs. specify the fixed log length.
loglength = 40;
the mill then cuts the logs into fixed lengths suitable for further processing. the problem is how to make the cuts so that the mill satisfies a set of orders with the fewest logs.
specify these fixed lengths and the order quantities for the lengths.
lengthlist = [8; 12; 16; 20]; quantity = [90; 111; 55; 30]; nlengths = length(lengthlist);
assume that there is no material loss in making cuts, and no cost for cutting.
linear programming formulation
several authors, including ford and fulkerson [1] and gilmore and gomory [2], suggest the following procedure, which you implement in the next section. a cutting pattern is a set of lengths to which a single log can be cut.
instead of generating every possible cutting pattern, it is more efficient to generate cutting patterns as the solution of a subproblem. starting from a base set of cutting patterns, solve the linear programming problem of minimizing the number of logs used subject to the constraint that the cuts, using the existing patterns, satisfy the demands.
after solving that problem, generate a new pattern by solving an integer linear programming subproblem. the subproblem is to find the best new pattern, meaning the number of cuts from each length in lengthlist
that add up to no more than the total possible length loglength
. the quantity to optimize is the reduced cost of the new pattern, which is one minus the sum of the lagrange multipliers for the current solution times the new cutting pattern. if this quantity is negative, then bringing that pattern into the linear program will improve its objective. if not, then no better cutting pattern exists, and the patterns used so far give the optimal linear programming solution. the reason for this conclusion is exactly parallel to the reason for when to stop the primal simplex method: the method terminates when there is no variable with a negative reduced cost. the problem in this example terminates when there is no pattern with negative reduced cost. for details and an example, see and its references.
after solving the linear programming problem in this way, you can have noninteger solutions. therefore, solve the problem once more, using the generated patterns and constraining the variables to have integer values.
matlab problem-based formulation
a pattern, in this formulation, is a vector of integers containing the number of cuts of each length in lengthlist
. arrange a matrix named patterns
to store the patterns, where each column in the matrix gives a pattern. for example,
the first pattern (column) represents two cuts of length 8 and one cut of length 20. the second pattern represents two cuts of length 12 and one cut of length 16. each is a feasible pattern because the total of the cuts is no more than loglength
= 40.
in this formulation, if x
is a column vector of integers containing the number of times each pattern is used, then patterns*x
is a column vector giving the number of cuts of each type. the constraint of meeting demand is patterns*x >= quantity
. for example, using the previous patterns
matrix, suppose that . (this x uses 101 logs.) then
which represents a feasible solution because the result exceeds the demand
to have an initial feasible cutting pattern, use the simplest patterns, which have just one length of cut. use as many cuts of that length as feasible for the log.
patterns = diag(floor(loglength./lengthlist)); npatterns = size(patterns,2);
to generate new patterns from the existing ones based on the current lagrange multipliers, solve a subproblem. call the subproblem in a loop to generate patterns until no further improvement is found. the subproblem objective depends only on the current lagrange multipliers. the variables are nonnegative integers representing the number of cuts of each length. the only constraint is that the sum of the lengths of the cuts in a pattern is no more than the log length.
subproblem = optimproblem(); cuts = optimvar('cuts', nlengths, 1, 'type','integer','lowerbound',zeros(nlengths,1)); subproblem.constraints = dot(lengthlist,cuts) <= loglength;
to avoid unnecessary feedback from the solvers, set the display
option to 'off'
for both the outer loop and the inner subproblem solution.
lpopts = optimoptions('linprog','display','off'); ipopts = optimoptions('intlinprog',lpopts);
initialize the variables for the loop.
reducedcost = -inf; reducedcosttolerance = -0.0001; exitflag = 1;
call the loop.
while reducedcost < reducedcosttolerance && exitflag > 0 logprob = optimproblem('description','cut logs'); % create variables representing the number of each pattern used x = optimvar('x', npatterns, 1, 'lowerbound', 0); % the objective is the number of logs used logprob.objective.logsused = sum(x); % the constraint is that the cuts satisfy the demand logprob.constraints.demand = patterns*x >= quantity; [values,nlogs,exitflag,~,lambda] = solve(logprob,'options',lpopts); if exitflag > 0 fprintf('using %g logs\n',nlogs); % now generate a new pattern, if possible subproblem.objective = 1.0 - dot(lambda.constraints.demand,cuts); [values,reducedcost,pexitflag] = solve(subproblem,'options',ipopts); newpattern = round(values.cuts); if double(pexitflag) > 0 && reducedcost < reducedcosttolerance patterns = [patterns newpattern]; npatterns = npatterns 1; end end end
using 97.5 logs using 92 logs using 89.9167 logs using 88.3 logs
you now have the solution of the linear programming problem. to complete the solution, solve the problem again with the final patterns, changing the solution variable x
to the integer type. also, compute the waste, which is the quantity of unused logs (in feet) for each pattern and for the problem as a whole.
if exitflag <= 0 disp('error in column generation phase') else x.type = 'integer'; [values,logsused,exitflag] = solve(logprob,'options',ipopts); if double(exitflag) > 0 values.x = round(values.x); % in case some values were not exactly integers logsused = sum(values.x); fprintf('optimal solution uses %g logs\n', logsused); totalwaste = sum((patterns*values.x - quantity).*lengthlist); % waste due to overproduction for j = 1:size(values.x) if values.x(j) > 0 fprintf('cut %g logs with pattern\n',values.x(j)); for w = 1:size(patterns,1) if patterns(w,j) > 0 fprintf(' %g cut(s) of length %d\n', patterns(w,j),lengthlist(w)); end end wastej = loglength - dot(patterns(:,j),lengthlist); % waste due to pattern inefficiency totalwaste = totalwaste wastej; fprintf(' waste of this pattern is %g\n',wastej); end end fprintf('total waste in this problem is %g.\n',totalwaste); else disp('error in final optimization') end end
optimal solution uses 89 logs
cut 15 logs with pattern
2 cut(s) of length 20
waste of this pattern is 0
cut 18 logs with pattern
1 cut(s) of length 8 2 cut(s) of length 16
waste of this pattern is 0
cut 37 logs with pattern
2 cut(s) of length 8 2 cut(s) of length 12
waste of this pattern is 0
cut 19 logs with pattern
2 cut(s) of length 12 1 cut(s) of length 16
waste of this pattern is 0
total waste in this problem is 28.
create a table showing the lengths, number required of each length, and the number produced of each length.
table(lengthlist,quantity,patterns*values.x,'variablenames',["length" "number required" "number produced"])
ans=4×3 table
length number required number produced
______ _______________ _______________
8 90 92
12 111 112
16 55 55
20 30 30
the solution produces two extra pieces of length 8 and one extra piece of length 12, for a total overproduction of 28 feet.
references
[1] ford, l. r., jr. and d. r. fulkerson. a suggested computation for maximal multi-commodity network flows. management science 5, 1958, pp. 97-101.
[2] gilmore, p. c., and r. e. gomory. a linear programming approach to the cutting stock problem--part ii. operations research 11, no. 6, 1963, pp. 863-888.
凯发官网入口首页 copyright 2012–2022 the mathworks, inc.