Skip to content

sakshishahani/craft-algorithm

 
 

Repository files navigation

CRAFT Algorithm Implementation

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.

Features

  • 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

Requirements

  • Python 3.6+
  • NumPy
  • Matplotlib

Installation

For macOS Users

  1. Clone this repository or download the files

  2. 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
  1. Install the required packages:
# Make sure your virtual environment is activated
python3 -m pip install -r requirements.txt

For Windows/Linux Users

  1. Clone this repository or download the files

  2. 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

Usage

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:

  1. Input the total area dimensions (rectangular or square)
  2. Input the number of departments and their areas
  3. The program will automatically generate random material flow quantities between departments
  4. The initial layout will be created
  5. The CRAFT algorithm will optimize the layout
  6. The final layout with material flow will be visualized and saved as an image

Example Session

=== 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

How the CRAFT Algorithm Works

  1. Initial Layout Creation: Departments are placed in the layout based on their areas, starting with the largest departments first.

  2. Cost Calculation: The total transportation cost is calculated based on the rectilinear distance between department centers and the flow matrix.

  3. Iterative Improvement: The algorithm iteratively swaps pairs of departments and keeps the swap if it improves the total cost.

  4. Termination: The process stops when no further improvements can be made or the maximum number of iterations is reached.

  5. Visualization: The final layout is visualized with color-coded departments and material flow paths between them.

Output

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

Troubleshooting

If you encounter "command not found" errors for python or pip:

  • Use python3 and pip3 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

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.7%
  • C 1.3%
  • Cython 0.4%
  • C++ 0.3%
  • Fortran 0.1%
  • JavaScript 0.1%
  • Other 0.1%