This project implements the Computerized Relative Allocation of Facilities Technique (CRAFT) algorithm for facility layout planning. The implementation includes visualization of material flow between departments and automated optimization of the layout.
- Input of total rectangular or square area
- Input of departments and their respective areas
- Random generation of material flow between departments
- Initial layout creation based on department areas
- Layout optimization using the CRAFT algorithm
- Visualization of the final layout with material flow paths
- Export of the final layout as an image
- Python 3.6+
- NumPy
- Matplotlib
-
Clone this repository or download the files
-
Set up a virtual environment (recommended to avoid system Python conflicts):
# Navigate to the project directory
cd path/to/project
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activate
- Install the required packages:
# Make sure your virtual environment is activated
python3 -m pip install -r requirements.txt
-
Clone this repository or download the files
-
Install the required packages:
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
python guide.py
python craft_example.py
python craft_algorithm.py
Make sure your virtual environment is activated if you're using one.
Run the main script:
# For macOS
python3 craft_algorithm.py
# For Windows/Linux
python craft_algorithm.py
Or use the interactive guide:
# For macOS
python3 guide.py
# For Windows/Linux
python guide.py
The program will guide you through the following steps:
- Input the total area dimensions (rectangular or square)
- Input the number of departments and their areas
- The program will automatically generate random material flow quantities between departments
- The initial layout will be created
- The CRAFT algorithm will optimize the layout
- The final layout with material flow will be visualized and saved as an image
=== CRAFT Algorithm Implementation ===
Is the total area square or rectangular? (s/r): r
Enter the width of the rectangular area: 20
Enter the height of the rectangular area: 15
Total area: 300.0 square units
Enter the number of departments: 5
Enter name for department 1: Assembly
Enter area for department Assembly: 80
Enter name for department 2: Machining
Enter area for department Machining: 60
Enter name for department 3: Painting
Enter area for department Painting: 50
Enter name for department 4: Packaging
Enter area for department Packaging: 45
Enter name for department 5: Storage
Enter area for department Storage: 40
Generated Flow Matrix (Material Quantities between Departments):
0 5 8 3 7
9 0 4 6 2
6 3 0 8 5
4 2 9 0 3
8 7 4 6 0
Initial layout created. Placed area: 275.0 of 300.0
Optimizing layout using CRAFT algorithm...
Iteration 1: Swapped departments Assembly and Machining
New cost: 451.23
Iteration 2: Swapped departments Packaging and Storage
New cost: 431.56
...
Optimization completed after 8 iterations
Final cost: 384.79
-
Initial Layout Creation: Departments are placed in the layout based on their areas, starting with the largest departments first.
-
Cost Calculation: The total transportation cost is calculated based on the rectilinear distance between department centers and the flow matrix.
-
Iterative Improvement: The algorithm iteratively swaps pairs of departments and keeps the swap if it improves the total cost.
-
Termination: The process stops when no further improvements can be made or the maximum number of iterations is reached.
-
Visualization: The final layout is visualized with color-coded departments and material flow paths between them.
The final layout is displayed in a matplotlib visualization and saved as 'craft_layout.png' in the current directory. The visualization includes:
- Color-coded departments with their names and areas
- Red lines representing material flow between departments (thicker lines indicate higher flow)
- Flow values displayed on the material flow lines
- Total transportation cost of the final layout
If you encounter "command not found" errors for python
or pip
:
- Use
python3
andpip3
instead on macOS - Make sure Python is properly installed and added to your PATH
If you get "externally-managed-environment" errors:
- Always use a virtual environment as described in the installation section
This project is open source and available under the MIT License.