Applications

Facility Layout Design using PSO in MATLAB

Get the code
Comments

Design a facility layout in MATLAB with PSO, block positions and rotations, material-flow costs, clearance gaps, and overlap penalties.

Illustration for Facility Layout Design and Location Allocation in MATLAB
On this page

This package is a MATLAB implementation of facility layout design using Particle Swarm Optimization (PSO). The project title in the code is “Facility Layout Design using PSO in MATLAB”.

The model describes eight blocks (machines). Each block has a width, a height, a gap and the positions of its input and output gates. The solver searches for block positions that give a good layout.

In a facility layout problem, the task is to place machines or departments on a floor so that material moves short distances between them. This code solves the continuous version with blocks of unequal size: each block can go anywhere on the floor and can be rotated, but blocks must not overlap. The code places the blocks only. It does not decide where a facility should be built or which customers it serves, which is what a location allocation problem would do.

The problem

The floor is a rectangle of width W=100W = 100 and height H=80H = 80. Block ii has a width wiw_i, a height hih_i and a gap δi\delta_i that must stay free around it. Material leaves block ii at its output gate and enters block jj at its input gate. The amount of flow from ii to jj is aija_{ij}, given as an 8 by 8 matrix in CreateModel.m.

For each block, the decision variables are:

  • the position of its center, (xi,yi)(x_i, y_i),
  • its rotation, one of 0, 90, 180 or 270 degrees.

The distance dijd_{ij} is the rectilinear (Manhattan) distance from the output gate of block ii to the input gate of block jj, after the rotation. Material handling usually moves along aisles, so this distance is a common choice.

The cost function

ParseSolution.m computes the cost of a layout as the sum of three terms:

z=∑i∑jaij dij  +  ϕ⋅Abox−AblocksAbox  +  α vz = \sum_{i}\sum_{j} a_{ij} \, d_{ij} \; + \; \phi \cdot \frac{A_{\text{box}} - A_{\text{blocks}}}{A_{\text{box}}} \; + \; \alpha \, v
  • The first term is the material handling cost: flow times distance, summed over all pairs.
  • The second term is the unused area. AboxA_{\text{box}} is the area of the smallest rectangle that holds all blocks, and AblocksA_{\text{blocks}} is the total area of the blocks. The weight is ϕ=50000\phi = 50000. This term makes the layout compact.
  • The third term is the overlap penalty. For each pair of blocks, the code measures how much they overlap in xx and in yy, including the gap, and vv is the mean overlap over all pairs. The weight is α=1012\alpha = 10^{12}, which strongly penalizes overlap. A layout with v=0v = 0 is feasible, and the program marks it with “(Feasible)”.

How PSO handles the layout

Each particle holds three vectors with one value per block, all in [0,1][0, 1]:

  • xhat and yhat are scaled to the range of positions where the block fits on the floor, with its gap.
  • rhat is split into four equal parts, and each part gives one of the four rotations.

The swarm moves all three vectors with the usual PSO velocity update. Two extra steps help the search:

  • Mutation. After each move, Mutate.m shifts the xx value of one random block and the yy value of another random block (they may be the same block) by a small random amount. The change is kept if it is not worse, and also with probability 0.2 when it is worse.
  • Local search. In each iteration, ImproveSolution.m visits the blocks of the global best layout in random order. For each block it tries staying in place and eight moves (up, down, left, right and the four diagonals), each with all four rotations, and keeps the best result.

Files in the download

  • pso.m: the PSO algorithm.
  • CreateModel.m: defines the blocks and their gates.
  • CreateRandomSolution.m, ParseSolution.m and MyCost.m: create a candidate layout, decode it and compute its cost.
  • Mutate.m and ImproveSolution.m: modify a solution and improve it by moving machines.
  • PlotSolution.m: draws the layout.
  • license.txt: license terms.

How to run

Open the folder in MATLAB and run pso.m. There is no separate main.m.

The program prints the best cost in every iteration. PlotSolution.m draws the floor with each block as a numbered colored rectangle, the input gates as open circles, the output gates as filled circles and the bounding rectangle as a red dash-dot line. At the end, a second figure shows the best cost against the iteration.

To design your own layout, change the block sizes, gaps, gate positions, the flow matrix a and the floor size in CreateModel.m. The gate positions rin and rout are numbers in [0,1][0, 1] that run once around the edge of the block. The code calls unifrnd, so it probably needs the Statistics and Machine Learning Toolbox.

Parameters in the code

Parameter Meaning Value
MaxIt Number of iterations 500
nPop Swarm size 50
w Inertia weight 1.0
wdamp Inertia weight damping ratio 0.99
c1 Personal learning coefficient 0.7
c2 Global learning coefficient 1.5
phi Weight of the unused area (in CreateModel.m) 50000
alpha Weight of the overlap penalty (in ParseSolution.m) 101210^{12}

Check the result

Check the decoded geometry directly: each rotated block and its required gap must fit within the floor, and no pair may overlap. A large finite penalty is not a substitute for checking those constraints. Inspect material-flow cost, compactness, and overlap separately when comparing layouts. Keep units consistent across dimensions, gate positions, and flow weights, and compare several runs before selecting a practical layout.

Applications

Facility layout design is used in:

  • Factory and workshop planning, to cut material handling cost.
  • Hospital layout, where patients and staff move between departments.
  • Warehouse design.
  • Placing components on a chip or a circuit board.

Downloads

How to cite

If you use this code or tutorial in your work, articles or publications, please cite it.

Plain text
Mostapha Kalami Heris, Facility Layout Design using PSO in MATLAB (YPAP109), Yarpiz, 2015. https://yarpiz.com/layout-design-ypap109
BibTeX
@misc{yarpiz-ypap109,
  author = {{Mostapha Kalami Heris}},
  title = {{Facility Layout Design using PSO in MATLAB}},
  howpublished = {Yarpiz},
  year = {2015},
  note = {Code YPAP109},
  url = {https://yarpiz.com/layout-design-ypap109}
}

Comments

Sign in or create a free account to join the discussion. No password needed.