# TOMLAB  
# REGISTER (TOMLAB)
# LOGIN  
# myTOMLAB
TOMLAB LOGO

« Previous « Start » Next »

24  Loading and Cutting

24.1  Wagon load balancing

% function Result = wagonloadbalancingEx(PriLev)
%
% Creates a TOMLAB LP problem for wagon loading. Minimizes the max weight
%
% WAGON LOAD BALANCING
%
% Three railway wagons with a carrying capacity of 100 quintals (1
% quintal = 100 kg) have been reserved to transport sixteen boxes.
% The weight of the boxes in quintals is given in the following
% table. How shall the boxes be assigned to the wagons in order to
% keep to the limits on the maximum carrying capacity and to minimize
% the heaviest wagon load?
%
% Weight of boxes
%
% +------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
% |Box   | 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|
% +------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
% |Weight|34| 6| 8|17|16| 5|13|21|25|31|14|13|33| 9|25|25|
% +------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
%
% Before implementing a Mathematical Programming solution, one may
% wish to try to see whether it is possible to solve this problem
% instance with the following simple heuristic: until all boxes are
% distributed to the wagons we choose in turn the heaviest unassigned
% box and put it onto the wagon with the least load.
%
%
% VARIABLES
%
% minload                    Minimal load accepted per wagon
% maxload                    Maximal load accepted per wagon
% weights                    Weight of each box
%
% RESULTS
%
% For an interpretation of the results, set PriLev > 1,
% Result = wagonloadbalancingEx(2);
%
% REFERENCES
%
% Applications of optimization... Gueret, Prins, Seveaux
% http://web.univ-ubs.fr/lester/~sevaux/pl/index.php
%
% INPUT PARAMETERS
% PriLev       Print Level
%
% OUTPUT PARAMETERS
% Result       Result structure.

% Marcus Edvall, Tomlab Optimization Inc, E-mail: tomlab@tomopt.com
% Copyright (c) 2005-2006 by Tomlab Optimization Inc., $Release: 5.1.0$
% Written Oct 7, 2005.   Last modified Feb 3, 2006.

function Result = wagonloadbalancingEx(PriLev)

if nargin < 1
   PriLev = 1;
end

minload    = [  0;  0;  0;];
maxload    = [100;100;100;];
weights    = [34;6;8;17;16;5;13;21;25;31;14;13;33;9;25;25];

Prob = wagonloadbalancing(minload, maxload, weights);
Prob.SolverInf = 'cplex';
Result = infLinSolve(Prob, PriLev);

if PriLev > 1,
   boxes  = length(weights);
   wagons = length(minload);
   temp   = reshape(Result.x_k,boxes,wagons);
   for w = 1:wagons,
      idx = find(temp(:,w) > 0.5);
      disp(['wagon ' num2str(w) ...
            ' has a total load of ' num2str(sum(weights(idx))) ...
            ' by carrying the boxes: ' num2str(idx') ])
   end
end

% MODIFICATION LOG
%
% 051007 med   Created.
% 060111 per   Added documentation.
% 060125 per   Moved disp to end
% 060203 med   Printing updated

24.2  Barge loading

% function Result = bargeloadingEx(PriLev)
%
% Creates a TOMLAB LP problem for barge loading, maximizing the profit
%
% BARGE LOADING
%
% A shipper on the river Rhine owns a barge of carrying capacity 1500
% m3. Over time he has specialized in the transport of wheat. He has
% seven regular customers who load and unload practically at the same
% places. The shipper knows his costs of transport from long
% experience and according to his personal preferences has concluded
% agreements with his clients for the price charged to them for the
% transport of their wheat. The following table summarizes the
% information about the seven clients. Every client wishes to
% transport a certain number of lots, deciding himself the size of
% his lots in m3. The table lists the price charged by the shipper
% for every transported lot. The last column of the table contains
% the cost incurred by the shipper per transported m3. This cost
% differs depending on the distance covered.
%
% Lots to transport
%
% +------+------------------+--------+----------+--------------+
% |      |Available quantity|Lot size|Price per | Transport    |
% |Client| (no. of lots)    |(in m3) |lot (in $)|cost (in $/m3)|
% +------+------------------+--------+----------+--------------+
% |  1   |     12           |   10   |  1000    |     80       |
% |  2   |     31           |    8   |   600    |     70       |
% |  3   |     20           |    6   |   600    |     85       |
% |  4   |     25           |    9   |   800    |     80       |
% |  5   |     50           |   15   |  1200    |     73       |
% |  6   |     40           |   10   |   800    |     70       |
% |  7   |     60           |   12   |  1100    |     80       |
% +------+------------------+--------+----------+--------------+
%
% The objective of the shipper is to maximize his profit from
% transporting the wheat with lots that may be divided.
%
% Question 1:
% As a first step, assuming that every client has an unlimited
% quantity of wheat, which clients’ wheat should be transported?
%
% Question 2:
% If in addition the actual availability of wheat lots from the
% customers is taken into account, which strategy should the shipper
% adopt?
%
% Question 3:
% What happens if the lots cannot be divided?
%
% VARIABLES
%
% capacity                   = 1500;
% units                      = [12;31;20;25;50;40;60];
% sizes                      = [10;8;6;9;15;10;12];
% unitprice                  = [10;6;6;8;12;8;11]*100;
% cost                       = [80;70;85;80;73;70;80];
% var1                       30 plus
% var2                       30 minus
%
% RESULTS
%
% x_k is a long vector of values, and if we run
% Result      = bargeloadingEx(2);
%
% REFERENCES
%
% Applications of optimization... Gueret, Prins, Seveaux
% http://web.univ-ubs.fr/lester/~sevaux/pl/index.php
%
% INPUT PARAMETERS
% PriLev       Print Level
%
% OUTPUT PARAMETERS
% Result       Result structure.

% Marcus Edvall, Tomlab Optimization Inc, E-mail: tomlab@tomopt.com
% Copyright (c) 2005-2005 by Tomlab Optimization Inc., $Release: 5.0.0$
% Written Oct 7, 2005.   Last modified Oct 7, 2005.

function Result = bargeloadingEx(PriLev)

if nargin < 1
   PriLev = 1;
end

capacity    = 1500;
units       = [12;31;20;25;50;40;60];
sizes       = [10;8;6;9;15;10;12];
unitprice   = [10;6;6;8;12;8;11]*100;
cost        = [80;70;85;80;73;70;80];

Prob = bargeloading(capacity, units, sizes, unitprice, cost);
Result = tomRun('cplex', Prob, PriLev);

if PriLev > 1,
   disp('Best buy')
   for i = 1:length(units),
      if Result.x_k(i) > 0,
         disp([' ' num2str(Result.x_k(i)) ' unit(s) from ' num2str(i)])
      end
   end
end

% MODIFICATION LOG
%
% 051007 med   Created.
% 060111 per   Added documentation.
% 060125 per   Moved disp to end

24.3  Tank loading

% function Result = tankloadingEx(PriLev)
%
% Creates a TOMLAB MIP problem for tank loading, maximizing the left over
% capacity
%
% TANK LOADING
%
% Five tanker ships have arrived at a chemical factory. They are
% carrying loads of liquid products that must not be mixed: 1200
% tonnes of Benzol, 700 tonnes of Butanol, 1000 tonnes of Propanol,
% 450 tonnes of Styrene, and 1200 tonnes of THF. Nine tanks of
% different capacities are available on site. Some of them are
% already partially filled with a liquid. The following table lists
% the characteristics of the tanks (in tonnes). Into which tanks
% should the ships be unloaded (question 1) to maximize the capacity
% of the tanks that remain unused, or (question 2) to maximize the
% number of tanks that remain free?
%
% Characteristics of tanks
%
% +---------------+---+------+---+---+---+---+---+---+---+
% |Tank           |  1|    2 |  3|  4|  5|  6|  7|  8|  9|
% +---------------+---+------+---+---+---+---+---+---+---+
% |Capacity       |500|  400 |400|600|600|900|800|800|800|
% |Current product|  -|Benzol|  -|  -|  -|  -|THF|  -|  -|
% |Quantity       |  0|  100 |  0|  0|  0|  0|300|  0|  0|
% +---------------+---+------+---+---+---+---+---+---+---+
%
% VARIABLES
%
% capacity                   Capacity of Empty tanks
% products                   Amount of incoming chemicals
%
% RESULTS
%
% In order to interpret the results, try the following:
% Result = tankloadingEx(2);

% REFERENCES
%
% Applications of optimization... Gueret, Prins, Seveaux
% http://web.univ-ubs.fr/lester/~sevaux/pl/index.php
%
% INPUT PARAMETERS
% PriLev       Print Level
%
% OUTPUT PARAMETERS
% Result       Result structure.

% Marcus Edvall, Tomlab Optimization Inc, E-mail: tomlab@tomopt.com
% Copyright (c) 2005-2005 by Tomlab Optimization Inc., $Release: 5.0.0$
% Written Oct 10, 2005.   Last modified Dec 8, 2005.

function Result = tankloadingEx(PriLev)

if nargin < 1
   PriLev = 1;
end

capacity    = [500;0;400;600;600;900;0;800;800];
products    = [1200-300;700;1000;450;1200-500];

Prob = tankloading(capacity, products);
Result = tomRun('cplex', Prob, PriLev);
Result.remaining = sum(capacity)-Result.f_k;

if PriLev > 1,
   disp('NB: Tank 2 and tank 7 are filled before the optimization starts.')
   temp   = reshape(Result.x_k,9,5);
   ships  = length(products);
   for ship = 1:ships,
      tank = find(temp(:,ship));
      disp(['Ship number ' num2str(ship) ' unloads in tank(s) ' num2str(tank')])
   end
end

% MODIFICATION LOG
%
% 051010 med   Created
% 051208 med   Added remaining the return
% 060112 per   Added documentation.
% 060124 per   Interpretation of results upgraded.
% 060125 per   Moved disp to end

24.4  Backing up files

% function Result = backingupfilesEx(PriLev)
%
% Creates a TOMLAB MIP problem for backing up files
%
% BACKING UP FILES
%
% Before leaving on holiday, you wish to backup your most important
% files onto floppy disks. You have got empty disks of 1.44Mb
% capacity. The sixteen files you would like to save have the
% following sizes: 46kb, 55kb, 62kb, 87kb, 108kb, 114kb, 137kb,
% 164kb, 253kb, 364kb, 372kb, 388kb, 406kb, 432kb, 461kb, and 851kb.
%
% Assuming that you do not have any program at hand to compress the
% files and that you have got a sufficient number of floppy disks to
% save everything, how should the files be distributed in order to
% minimize the number of floppy disks used?
%
% VARIABLES
%
% maxuse                     A maximal number of disks
% capacity                   Storage available on each disk
% sizes                      Filesizes
%
% RESULTS
%
% Results are explained by running:
% Result       = backingupfilesEx(2);
%
% REFERENCES
%
% Applications of optimization... Gueret, Prins, Seveaux
% http://web.univ-ubs.fr/lester/~sevaux/pl/index.php
%
% INPUT PARAMETERS
% PriLev       Print Level
%
% OUTPUT PARAMETERS
% Result       Result structure.

% Marcus Edvall, Tomlab Optimization Inc, E-mail: tomlab@tomopt.com
% Copyright (c) 2005-2006 by Tomlab Optimization Inc., $Release: 5.2.0$
% Written Oct 10, 2005.   Last modified Mar 14, 2006.

function Result = backingupfilesEx(PriLev)

if nargin < 1
   PriLev = 1;
end

maxuse   = 10;
capacity = 1440;
sizes    = [46;55;62;87;108;114;137;164;253;364;372;388;406;432;461;851];

Prob = backingupfiles(maxuse, capacity, sizes);
Result = tomRun('cplex', Prob, PriLev);

if PriLev > 1,
   files        = length(sizes);
   filepos      = reshape(Result.x_k(1:files*maxuse),files,maxuse);
   disks_in_use = sum(Result.x_k(files*maxuse+1:files*maxuse+maxuse));
   disp(['a total of ' num2str(disks_in_use) ' disks are in use'])
   for d = 1:maxuse,
      files_on_disk = filepos(:,d);         % what files on disk d
      if (abs(sum(files_on_disk)) >= 0.5),         % disk d is not empty?
         file_ids = find(files_on_disk);
         disp(['  files on one of them: '  num2str(file_ids') ])
      end
   end
end

% MODIFICATION LOG
%
% 051010 med   Created.
% 060112 per   Added documentation
% 060125 per   Moved disp to end
% 060314 med   checking for empty disc changed

24.5  Cutting sheet metal

% function Result = cuttingsheetmetalEx(PriLev)
%
% Creates a TOMLAB MIP problem for cutting smaller parts from big ones.
%
% CUTTING SHEET METAL
%
% A sheet metal workshop cuts pieces of sheet metal from large
% rectangular sheets of 48 decimeters × 96 decimeters (dm). It has
% received an order for 8 rectangular pieces of 36 dm × 50 dm, 13
% sheets of 24 dm × 36 dm, 5 sheets of 20 dm × 60 dm, and 15 sheets
% of 18 dm × 30 dm. Theses pieces of sheet metal need to be cut from
% the available large pieces. How can this order by satisfied by
% using the least number of large sheets?
%
% VARIABLES
%
% patterns                   Each column represent a possible sheet.
% demand                     Wanted rectangles
%
% RESULTS
%
% To explain the results, run:
% Result = cuttingsheetmetalEx(2);
%
% REFERENCES
%
% Applications of optimization... Gueret, Prins, Seveaux
% http://web.univ-ubs.fr/lester/~sevaux/pl/index.php
%
% INPUT PARAMETERS
% PriLev       Print Level
%
% OUTPUT PARAMETERS
% Result       Result structure.

% Marcus Edvall, Tomlab Optimization Inc, E-mail: tomlab@tomopt.com
% Copyright (c) 2005-2005 by Tomlab Optimization Inc., $Release: 5.0.0$
% Written Oct 10, 2005.   Last modified Oct 10, 2005.

function Result = cuttingsheetmetalEx(PriLev)

if nargin < 1
   PriLev = 1;
end

% Have to manually evaluate all the possible patterns.

patterns = [1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0;...
      2 1 0 2 1 0 3 2 1 0 5 4 3 2 1 0;...
      0 0 0 2 2 2 1 1 1 1 0 0 0 0 0 0;...
      0 1 3 0 1 3 0 2 3 5 0 1 3 5 6 8];
demand = [8;13;5;15];

Prob = cuttingsheetmetal(demand, patterns);
Result = tomRun('cplex', Prob, PriLev);

if PriLev > 1,
   x      = Result.x_k;
   idx    = find(x);
   order  = [x(idx) idx];
   for i = 1:length(idx),
      disp(['cut ' num2str([order(i,1)]) ' sheet(s) in pattern ' num2str([order(i,2)])])
   end
end

% MODIFICATION LOG
%
% 051010 med   Created.
% 060112 per   Added documentation.
% 060125 per   Moved disp to end

24.6  Cutting steel bars for desk legs

% function Result = cuttingsteelbarsfordesklegsEx(PriLev)
%
% Creates a TOMLAB MIP problem for cutting steel bars for desk legs.
%
% CUTTING STEEL BARS FOR DESK LEGS
%
% The company SchoolDesk produces desks of different sizes for
% kindergartens, primary and secondary schools, and colleges. The
% legs of the desks all have the same diameter, with different
% lengths: 40 cm for the smallest ones, 60 cm for medium height, and
% 70 cm for the largest ones. These legs are cut from steel bars of
% 1.5 or 2 meters. The company has received an order for 108 small,
% 125 medium and 100 large desks. How should this order be produced
% if the company wishes to minimize the trim loss?
%
% VARIABLES
%
% patterns                   The different cutting patterns
% demand                     Demand of the different lengths
% loss                       Loss for each pattern
% lengths                    The lengths
%
% RESULTS
%
% To interpret the results run this:
% Result = cuttingsteelbarsfordesklegsEx(2);
%
% REFERENCES
%
% Applications of optimization... Gueret, Prins, Seveaux
% http://web.univ-ubs.fr/lester/~sevaux/pl/index.php
%
% INPUT PARAMETERS
% PriLev       Print Level
%
% OUTPUT PARAMETERS
% Result       Result structure.

% Marcus Edvall, Tomlab Optimization Inc, E-mail: tomlab@tomopt.com
% Copyright (c) 2005-2005 by Tomlab Optimization Inc., $Release: 5.0.0$
% Written Oct 10, 2005.   Last modified Dec 8, 2005.

function Result = cuttingsteelbarsfordesklegsEx(PriLev)

if nargin < 1
   PriLev = 1;
end

patterns = [0 0 2 0 2 3 0 0 1 3 0 5;...
      0 1 0 2 1 0 1 2 0 0 3 0;...
      2 1 1 0 0 0 2 1 2 1 0 0];

demand   = [108;125;100]*4;
loss     = [10 20  0 30 10 30  0 10 20 10 20  0]';
lengths  = [150;200];

Prob = cuttingsteelbarsfordesklegs(demand, patterns, lengths);
Prob.fConstant = -75280; % Constant to deduct from objective
Result = tomRun('cplex', Prob, PriLev);
Result.loss = sum(Result.x_k.*loss);

if PriLev > 1,
   x      = Result.x_k;
   idx    = find(x);
   order  = [x(idx) idx];
   disp(['a minimal loss of ' num2str(Result.loss) ' is found with this combination:' ])
   for i = 1:length(idx),
      disp([' cut ' num2str([order(i,1)]) ' bar(s) in pattern ' num2str([order(i,2)])])
   end
end

% MODIFICATION LOG
%
% 051010 med   Created
% 051208 med   Loss added to Result
% 060112 per   Added documentation.
% 060112 per   Minor update.
% 060125 per   Moved disp to end

« Previous « Start » Next »