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

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 and height . Block has a width , a height and a gap that must stay free around it. Material leaves block at its output gate and enters block at its input gate. The amount of flow from to is , given as an 8 by 8 matrix in CreateModel.m.
For each block, the decision variables are:
- the position of its center, ,
- its rotation, one of 0, 90, 180 or 270 degrees.
The distance is the rectilinear (Manhattan) distance from the output gate of block to the input gate of block , 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:
- The first term is the material handling cost: flow times distance, summed over all pairs.
- The second term is the unused area. is the area of the smallest rectangle that holds all blocks, and is the total area of the blocks. The weight is . 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 and in , including the gap, and is the mean overlap over all pairs. The weight is , which strongly penalizes overlap. A layout with 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 :
xhatandyhatare scaled to the range of positions where the block fits on the floor, with its gap.rhatis 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.mshifts the value of one random block and the 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.mvisits 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.mandMyCost.m: create a candidate layout, decode it and compute its cost.Mutate.mandImproveSolution.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 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) |
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.
Related posts
- Particle Swarm Optimization in MATLAB
- Quadratic Assignment Problem using GA, PSO and FA, the discrete version of layout design, where units go to fixed sites.
- p-Hub Location Allocation Problem in MATLAB, a location allocation problem.
Downloads
How to cite
If you use this code or tutorial in your work, articles or publications, please cite it.
Mostapha Kalami Heris, Facility Layout Design using PSO in MATLAB (YPAP109), Yarpiz, 2015. https://yarpiz.com/layout-design-ypap109@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}
}Published Updated
Comments