0% found this document useful (0 votes)
147 views

Matlog - Logistics Engineering Using Matlab PDF

Uploaded by

Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Matlog - Logistics Engineering Using Matlab PDF

Uploaded by

Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Süleyman

Demirel Üniversitesi Suleyman Demirel University


Mühendislik Bilimleri ve Tasarım Dergisi Journal of Engineering Sciences and Design
4(1), 15-20, 2016 4(1), 15-20, 2016
e-ISSN: 1308-6693 e-ISSN: 1308-6693
Araştırma Makalesi Research Article

MATLOG: LOGISTICS ENGINEERING USING MATLAB

Michael G. Kay*

Fitts Department of Industrial and Systems Engineering North Carolina State University, Raleigh, NC, USA

Keywords Abstract
Matlog, Matlog is a collection of computational routines and data that can be used within
Matlab, Matlab to implement a variety of different logistics-engineering-related tasks and
Facility Location, provides a means to script the pre- and post-processing needed to interface with
Freight Transport, solvers like CPLEX. A detailed example of the use of Matlog to solve a facility location
Vehicle Routing, and allocation problem is presented and the use of Matlog in an educational
Networks. environment is discussed.

1. Introduction Data: U.S. cities, U.S. highway network (Oak Ridge


National Highway Network); U.S. 3- and 5-digit ZIP
Matlog is a collection of computational routines and codes; U.S. Census Block Group data
data that can be used within Matlab to implement a
variety of different logistics-engineering-related tasks. Matlog was developed initially for teaching purposes
It consists of Matlab functions that either directly in a graduate-level Logistics Engineering course as a
implement solution techniques or provide a means to replacement for CAPS Logistics’ commercial products
script the pre- and post-processing needed to Supply Chain Designer and RoutePro. The problem
interface with solvers like CPLEX. It provides a with using the CAPS products for teaching purposes
uniform, platform-independent environment and is was their lack of flexibility and the lack of
available for download at Kay (2015). The routines in transparency with respect to algorithmic details (see
Matlog can be grouped into the following categories: Campbell (2000) for another report of the CAPS
products in an educational environment). Although
Facility location: Continuous minisum facility the products had an easy-to-use GUI interface, when a
location, alternate location-allocation (ALA) new logistics network was to be analyzed, the
procedure, discrete uncapacitated facility location, required processing had to be specified using a
longitude and latitude to nearest city, Mercator specialized set of procedures, the CAPS Logistics
projection plotting, and location aggregation based on Toolbox. In industrial applications, either trained
distance CAPS engineers would use the Toolkit to customize the
products to each customer’s particular network as
Freight transport: Transport charges for TL and LTL, part of the purchase price of the product, or for a large
minimum total logistics cost, and aggregate multiple customer, like Wal-Mart for example, CAPS could train
shipments the customer’s own engineers in use of the Toolkit. As
long as the changes to a customer’s network were
Vehicle routing: VRP, VRP with time windows, incremental modifications from the initial
traveling salesman problem (TSP), dial-a-ride, and configuration, then CAPS would remain usable from
long-haul truck routing problems just a GUI interface. In an educational environment,
especially when teaching logistics engineering, it is
Networks: Shortest path, transportation, min cost import that students have a flexible computational
network flow, minimum spanning tree, and multi- tool and, when possible, that they can drill down if
period multi-product production planning problems necessary and see all of the algorithmic details
associated with the procedures that they are using.
General purpose: Linear programming using the Instead of trying to teach students to use the Toolkit,
revised simplex method procedure, mixed-integer Matlab was chosen as a suitable platform to try to
linear programming, algebraic interface to formulate develop a reasonable substitute for CAPS. As
MILP for CPLEX, and steepest descent pairwise compared to the Toolkit, Matlab would provide
interchange (SDPI) heuristic for QAP students with knowledge of a general purpose
computational environment that nicely complements
Excel (what is easy to do in Matlab can be hard to do


*
Corresponding author: [email protected]
15

M. G. Kay, Matlog: Logistics Engineering Using Matlab

in Excel, and vice versa) and is easily available in most


Colleges of Engineering,

Instead of trying to describe all of the features of
Matlog at a high level, a single example of the use of
Matlog will be discussed in detail and all of the code
needed to duplicate the example will be described.
This example is a very common task and will help
illustrate the use of Matlog as a tool for solving a very
common logistics engineering problem. If you are not
familiar with Matlab, you can review the example to
get the basic flavor of Matlog or, after reviewing a
Figure 1. 880 ZIP Code Locations
short tutorial on Matlab, Kay (2010), you will be able

to understand most all of the code details. After the
Continuous Location: ALA Procedure
example, this paper concludes with a discussion of for
Given initial NF locations, the Alternate Location–
using Matlog in an educational environment.
Allocation (ALA) procedure (Cooper, 1963) finds

optimal EF allocations and then finds optimal NF
2. Example: Facility Location and Allocation
locations for these allocations, continuing to alternate

until no further EF allocation changes are made. The
Four new facilities (NFs) are to be located anywhere
following is a pseudocode description of the ALA
in the continental U.S. to serve retail customers. The
algorithm:
best locations for the facilities are those that minimize
the average distance of a customer from its closest
facility, where, for example, each facility could be ALA PROCEDURE: ( NF ,W ) ← ALA ( NF0 , EF , w)
distribution center and each customer a retail store. 1. Given initial NF locations NF0
Since no other information or data is available, the 2. TC ← ∞
centroid of each 3-digit ZIP code is used to represent
each customer’s location (EF, for existing facility) and 3. W ′ ← allocate ( NF , EF , w)
the population of the ZIP code is used to represent 4. NF ′ ← locate (W ′, EF )
relative demand. In the following solution, the shaded
boxes contain Matlab code and the san-serif text and 5. ( NF ′,W ′) > TC , stop; otherwise
If TC
figures represent the resulting output associated with
executing the code. In each code box, Matlog functions TC ← TC ( NF ′,W ′) , NF ← NF ′ ,
are italicized W ← W ′ , and go to step 3

Create Data There is a close correspondence possible between the
Load 3-digit ZIP codes with positive population in ALA pseudocode and how it can be coded in Matlab,
continental U.S., where EF is an 880 × 2 matrix of the where the anonymous functions TCh, allocate, and
longitude and latitude of each ZIP code centroid and locate provide a means of creating simple in-line
pop is an 880-element vector of population. The functions without having to create separate files.
Matlog function uszip3 is used to read specific fields of
ZIP code data as specified by the arguments ‘XY’ and
TCh = @(W,NF) sum(sum(W.*dists(NF,EF,'mi')));
‘pop’, where ZIP codes outside of the continental U.S. allocate = @(NF)
(in Alaska, Hawaii, and Puerto Rico) are removed full(sparse(argmin(dists(NF,EF,'mi')),1:m,pop',n,m));
using Matlog’s mor (multiple OR) command. opt =
optimset(fminsearch('defaults'),'Display','off','TolFun',1,'TolX',1);
locate = @(W,NF0) fminsearch(@(NF) TCh(W,NF),NF0,opt);

[EF,pop] = uszip3('XY','Pop',~mor({'AK','HI','PR'},uszip3('ST')) &


uszip3('Pop') > 0);

m = size(EF,1) % number of codes TCh determines the total people-miles given the
m = 880
allocations defined in the p × m matrix W, allocate
determines the allocation based on the closest NF to
Plot the resulting EF locations and then set the each EF, and locate performs n 2-dimensional location
number of NFs. searches using fminsearch, which is Matlab’s default
routine for nonlinear unconstrained optimization.


makemap(EF) % open new figure for subsequent plotting
pplot(EF,'r.'); % projective plot of EF locations rng(1234) % set random number seed so can duplicate
title([num2str(m) ' ZIP Code Locations']) results
p = 4; % number of NF NF = randX(EF,p); % generate random initial locations
TC = Inf;
done = false;
while ~done
Wi = allocate(NF);
NFi = locate(Wi,NF);
TCi = TCh(Wi,NFi);

16
Kay M. G., 2016. SDU-JESD-152932-15-20
M. G. Kay, Matlog: Logistics Engineering Using Matlab

fprintf('%e\n',TCi); Discrete + Continuous Location: p-Median


if TCi < TC
TC = TCi; NF = NFi; W = Wi; Heuristic + ALA
else
done = true;

end An alternative to just using the ALA procedure is to
end
lonlat2city(NF,uscity) % determine closest city to each location first use the p-Median heuristic to find the best NF
avgdist = TC/sum(pop) % detemine average distance locations from among the set of EF locations and then
makemap(EF) % plot locations and allocations
pplot(lev2list(W),[NF;EF],'g-'); use these NF locations as the initial locations for the
pplot(EF,'r.'); ALA procedure.
pplot(NF,'kv')
title([num2str(p) ' NF Locations and Allocations to EFs'])
C = repmat(pop',m,1) .* dists(EF,EF,'mi'); % m by m variable
1.012094e+11 cost matrix
9.790048e+10 [y,TC] = pmedian(p,C);
9.778027e+10 NF = EF(y,:); % select NFs from EFs
9.765950e+10 lonlat2city(NF,uscity)
9.744964e+10 avgdist = TC/sum(pop)
9.727697e+10
9.717181e+10 Add: 95695328508.251694
9.686568e+10 Xchg: 94496036279.333450
9.661784e+10 Drop: 97544509467.758331
9.637384e+10 Xchg: 93896189493.826721
9.603856e+10 Final: 93896189493.826721
9.567937e+10
9.480952e+10 NF 1 is in Doylestown, PA
9.423325e+10 NF 2 is in Nellieburg, MS
9.421143e+10 NF 3 is in Hometown, IL
9.421143e+10 NF 4 is 5.48 mi NE of Rosamond, CA
9.421143e+10
9.421143e+10 avgdist =
306.1802
NF 1 is 11.33 mi SE of Ponderosa, CA
NF 2 is 4.08 mi W of Lawrenceburg, KY
NF 3 is 4.00 mi W of Richardson, TX
NF 4 is in Summit, NJ [NF,TC] = ala(NF,pop',EF,'mi'); % Use NF’s from PMEDIAN as
intial locations
avgdist = lonlat2city(NF,uscity)
307.2082 avgdist = TC/sum(pop)

NF 1 is 4.37 mi SW of Stockton, NJ
NF 2 is 6.49 mi SE of Meridian, MS
NF 3 is in Merrionette Park, IL
NF 4 is 16.55 mi NE of Pearsonville, CA

avgdist =
304.7786

Both the initial p-Median and the ALA improvement
resulted in better average distance results than just
the single ALA run. Although multiple runs of ALA
would improve its results, they would still not likely be
better than p-Median with ALA improvement. The
reason that ALA is still valuable is the flexibility with
which the allocation and location subprocedures can
be defined. If the NFs are capacitated, then the
Figure 2. 4 NF Locations and Allocations to EFs
anonymous function allocate can be a call to trans, the
This average distance result of 307.2082 miles transportation problem procedure in Matlog; if some
represents only a single run. Since the ALA procedure the NF’s locations are fixed, then it is easy to modify
finds only a local optima, the procedure should be anonymous function locate.
applied multiple times using different initial NF
locations, keeping the best solution found as the final To understand the p-Median heuristic, see Daskin
solution. (1995); to understand how the heuristic has been
implemented in Matlog, the type command in Matlab
The Matlog function ALA implements the ALA can be used to list all of the code for pmedian. The
procedure and produces the same results. heuristic first adds 1 to p NFs using a greedy add
procedure ufladd, followed by the uflxchg pairwise
rng(1234) % using same seed as before exchange improvement procedure; this result is then
[NF,TC] = ala(randX(EF,p),pop',EF,'mi');
lonlat2city(NF,uscity)
compared to the result of the greedy drop procedure
ufldrop and uflxchg and the best result is reported.
NF 1 is 11.33 mi SE of Ponderosa, CA
NF 2 is 4.08 mi W of Lawrenceburg, KY
NF 3 is 4.00 mi W of Richardson, TX type pmedian
NF 4 is in Summit, NJ



17
Kay M. G., 2016. SDU-JESD-152932-15-20
M. G. Kay, Matlog: Logistics Engineering Using Matlab

function [y,TC,X] = pmedian(p,C,dodisp)


location and then adds together both population
%PMEDIAN Hybrid algorithm for p-median location. values, continuing until a third of the locations (294)
% [y,TC,X] = pmedian(p,C) are left.
% = pmedian(p,C,dodisp), display intermediate results
% p = scalar number of NFs to locate
% C = n x m variable cost matrix,
% where C(i,j) is the cost of serving EF j from NF i D = triu(dists(EF,EF,'mi'));
%dodisp = true, default D(D==0) = Inf;
% y = p-element NF site index vector maxsize = ceil(size(D,1)*(1/3)); % aggregate to 1/3 original
% TC = total cost size
% = sum(sum(C(X))) while size(D,1) > maxsize
% X = n x m logical matrix, where X(i,j) = 1 if EF j allocated [i,j] = argmin(D);
to NF i popij = pop([i j]);
% EF(i,:) = (popij(:)'*EF([i j],:))/sum(popij); % pop-weighted
% Algorithm: Report the minimum of UFLADD(0,C,[],p) followed centroid location
by EF(j,:) = [];
% UFLXCHG(O,C,yADD) and UFLDROP(0,C,[],p) followed by pop(i) = pop(i) + pop(j);
UFLXCHG(O,C,yDROP), pop(j) = [];
% where yADD and yDROP are the p-element NF site index D = triu(dists(EF,EF,'mi'));
vector returned by D(D==0) = Inf;
% UFLADD and UFLDROP for a fixed number of NFs end
% makemap(EF)
% Example (Example 8.8 in Francis, Fac Layout and Loc, 2nd pplot(EF,'r.');
ed.): m = size(EF,1)
%p=2 title([num2str(m) ' ZIP Codes Locations after Aggregation'])
% C = [0 3 7 10 6 4
% 3 0 4 7 6 7
m=
% 7 4 0 3 6 8
294
% 10 7 3 0 7 8
% 6 6 6 7 0 2
% 4 7 8 8 2 0]
% [y,TC,X] = pmedian(p,C); y,TC,full(X)

% Copyright (c) 1994-2014 by Michael G. Kay


% Matlog Version 16 03-Jan-2014
(http://www.ise.ncsu.edu/kay/matlog)

% Input Error Checking


***************************************************
*
error(nargchk(2,3,nargin));

[n,m] = size(C);
if nargin < 3 || isempty(dodisp), dodisp = true; end

if ~isscalar(p) || p > n || p < 1


error('"p" must be between 1 and "n".')
elseif ~isscalar(dodisp) || ~islogical(dodisp)
error('"dodisp" must be a logical scalar.')
end
% End (Input Error Checking) Figure 3. 4 249 ZIP Codes Locations after Aggregation
**********************************************
[y,TC] = ufladd(0,C,[],p); if dodisp, fprintf(' Add: %f\n',TC), Re-run p-Median on Aggregated Data
end In order to get a baseline for the MILP result, the p-
[y,TC,X] = uflxchg(0,C,y); if dodisp, fprintf(' Xchg: %f\n',TC),
end Median and ALA improvement are re-run using the
new variable cost data.
[y1,TC1] = ufldrop(0,C,[],p); if dodisp, fprintf(' Drop:
%f\n',TC1), end
[y1,TC1,X] = uflxchg(0,C,y1); if dodisp, fprintf(' Xchg: C = repmat(pop',m,1) .* dists(EF,EF,'mi'); % m by m variable
%f\n',TC1), end cost matrix
[y,TC] = pmedian(p,C);
if TC1 < TC, TC = TC1; y = y1; end NF = EF(y,:); % select NFs from EFs
if dodisp, fprintf('Final: %f\n',TC), end lonlat2city(NF,uscity)
avgdist = TC/sum(pop)
y = sort(y);
X = logical(sparse(y(argmin(C(y,:),1)),1:m,1,n,m)); Add: 95815142943.656967
Xchg: 94051364921.479156
Drop: 96038290150.573212
Xchg: 93622738138.367325
Final: 93622738138.367325


Aggregate Demand Data to Reduce Size NF 1 is 4.07 mi E of Hoboken, NJ
NF 2 is 7.42 mi NW of Orrville, AL
In order to determine if the p-Median result is the NF 3 is in La Grange Park, IL
optimal result, the problem can be formulated as a NF 4 is 5.48 mi NE of Rosamond, CA
mixed-integer linear program (MILP) and solved to avgdist =
optimality using a MILP solver like CPLEX. Based on 305.2885
experience, the 880 × 880 variable cost matrix C will
cause CPLEX to run out of memory. To avoid this, [NF,TC] = ala(NF,pop',EF,'mi');
locations can be aggregated to reduce the number of lonlat2city(NF,uscity)
avgdist = TC/sum(pop)
EF locations. The procedure combining the pair of
locations that are closest together and replacing both
locations by their population-weighted average
18
Kay M. G., 2016. SDU-JESD-152932-15-20
M. G. Kay, Matlog: Logistics Engineering Using Matlab

NF 1 is in Martinsville, NJ mp.addcstr({i},'>=',{i,j}); % add m^2 constraints (strong


NF 2 is 8.74 mi W of Demopolis, AL formulation)
NF 3 is in La Grange Park, IL end
NF 4 is 14.73 mi NE of Pearsonville, CA end
mp.addcstr(1,0,'=',p) % add constraint to force p NFs
avgdist = mp.addub(Inf,1) % upper bounds
303.6785 mp.addctype('B','C') % c is binary, C is continuous

Discrete + Continuous Location: Cplex + ALA
Given m EFs and n sites at which NFs can be If CPLEX is available on your computer (using version
established, the p-Median problem can be formulated 12.5 in this example), then the Milp model can be
as the following MILP: copied to a Cplex object and then, using the basic
CPLEX API methods, the model can be solved.

n m
Min TC = ∑∑ cij xij cp = Cplex;
cp.Model = mp.Model;
% constructor for Cplex object
% copy Milp model to Cplex model
i =1 j =1 cp.solve(); % solve Cplex model

subject to
n

∑ xij = 1
Table 1. Parameters
j = 1, ,m

Parameters Value
i =1 Tried aggregator 1 time.
yi ≥ xij i = 1, , n; j = 1, , m Presolve time 0.19 sec. (91.45 ticks)
Found incumbent of value 3.4020985e+011 after 0.33 sec.
n (169.65 ticks)
∑ yi = p Probing time
Tried aggregator
0.02 sec. (8.37 ticks)
1 time.
i =1
Presolve time 0.11 sec. (92.20 ticks)
0 ≤ xij ≤ 1 i = 1, , n; j = 1, , m Probing time 0.03 sec. (8.37 ticks)

yi ∈{0,1}
MIP emphasis: balance optimality and feasibility.
i = 1, , n MIP search method: dynamic search.
Parallel mode: deterministic, using up to 8 threads.
Root relaxation solution 21.84 sec. (7303.04 ticks)
where time


cij variable cost to serve all of EF j’s demand from site i
yi 1, if NF established at site i; 0, otherwise
xij fraction of EF j’s demand served from NF at site i.


This MILP for p-Median is termed a “strong
formulation” due to the second set of 𝑛𝑚 constraints,
which results in an LP relaxation that gives a tight
lower bound that quite often is optimal. When these

constraints are replaced with the n constraints
m
m yi ≥ ∑ xij

j =1 Figure 4. Result’s screen
,
i = 1, , n . The solution can then be displayed, where the Milp
method namesolution is used to extract the y variables
The formulation is termed “weak” since the lower
of the solution corresponding to the zero-valued
bound from the LP relaxation is not very tight,
coefficients c in the objective function.
resulting in a large branch-and-bound tree.

The MILP for this example can be created using disp(cp.Solution.statusstring)


Matlog’s Milp class, which provides a means of TC = cp.Solution.objval
x = mp.namesolution(cp.Solution.x);
inputting data similar to an algebraic modeling y = find(x.c);
language like OPL. NF = EF(y,:);
lonlat2city(NF,uscity)
avgdist = TC/sum(pop)

mp = Milp('pMedian'); % constructor for Milp object


c = repmat(0,1,m); % no fixed cost
mp.addobj('min',c,C) % Add cost arrays to objective
function integer optimal solution
for j = 1:m TC =
mp.addcstr(0,{':',j},'=',1) % add m constraints 9.3623e+10
end
for i = 1:m NF 1 is 4.07 mi E of Hoboken, NJ
for j = 1:m NF 2 is 7.42 mi NW of Orrville, AL
NF 3 is in La Grange Park, IL

19
Kay M. G., 2016. SDU-JESD-152932-15-20
M. G. Kay, Matlog: Logistics Engineering Using Matlab

NF 4 is 5.48 mi NE of Rosamond, CA Conflict of Interest


avgdist =
305.2885 No conflict of interest was declared by the authors.

This result matches the reduced p-Median result and
confirms that it is the optimal result. References

If CPLEX is not available, then the Matlab’s MILP solver Campbell, A., Goentzel, J., Savelsbergh, M. (2000),
intlinprog can be used. Its input format is similar to “Experiences with the use of supply chain
Matlab’s LP solver linprog, with the addition of a management software in education,” Production and
second input vector of indices corresponding to the Operations Management, Vol. 9, No. 1, pp. 66–80.
integer variables. The Milp method milp2lp is used to
convert the instance to LP arguments. In the p-Median L. Cooper, L. (1963), “Location-allocation problems,”
formulation, only the y variables are integer, Operations Research, Vol. 11, pp. 331–343.
corresponding to indices 1 to n, which are inserted as
the second input argument to intlinprog. Daskin, M. (1995), Network and Discrete Location:
Models, Algorithms, and Applications, Wiley, New York.

lp = mp.milp2lp;
n = length(c) Kay, M. (2015), “Matlog: Logistics Engineering Matlab
intcon = 1:n; % only firts n are integer Toolbox,” http://www.ise.ncsu.edu/kay/matlog (last
milp = {lp{1},intcon,lp{2:end}} % add incon to make lp into
milp accessed on July 9, 2015).
[x,TC2,exitflag,output] = intlinprog(milp{:});
Funaki, K. (2009), “State of the Art Survey of
n= Commercial Software for Supply Chain Design,”
294
milp = Supply Chain and Logistics Institute, Georgia Tech,
Columns 1 through 4 https://www.scl.gatech.edu/downloads/
[86730x1 double] [1x294 double] [86436x86730 double]
[86436x1 double]
Columns 5 through 8 GTSCL_SCDesign_Software_Survey.pdf (last accessed
[295x86730 double] [295x1 double] [86730x1 double]
[86730x1 double] on July 9, 2015).
LP: Optimal objective value is 9.362274e+10.

Optimal solution found.

Intlinprog stopped at the root node because the


objective value is within a gap tolerance of the optimal value,
options.TolGapAbs = 0
(the default value). The intcon variables are integer within
tolerance,
options.TolInteger = 1e-05 (the default value).

This result matches the CPLEX result.

3. Conclusions

One of the major unexpected benefits of using Matlog
in educational environment for the past fifteen years
is the stability that it has provided. Over this time
period, CAPS Logistics was first purchased by Baan
and now is part of Infor’s Strategic Network Design
software product (Funaki, 2009). Trying to keep up
with these changes while trying to provide a stable
software environment would have been a challenge.
Matlab has been a very stable coding environment.
Many of the Matlog functions developed over fifteen
years ago still run unchanged. The major difficulty is
using Matlog has been a steep learning curve for those
students without programming experience, even
though most of the functions in Matlog eliminate
detailed programming. It remains a challenge to try to
find the right level of detail for each procedure,
balancing ease of use with flexibility.


20
Kay M. G., 2016. SDU-JESD-152932-15-20

You might also like