Skip to content

Latest commit

 

History

History
73 lines (62 loc) · 6.66 KB

README.md

File metadata and controls

73 lines (62 loc) · 6.66 KB

QAP-instance-Genetic-algorithm

Solving a QAP instance using genetic algorithms

What is QAP?

The quadratic assignment problem (QAP) is one of the fundamental combinatorial optimization problems in the branch of optimization or operations research in mathematics, from the category of the facilities location problems first introduced by Koopmans and Beckmann.

The problem models the following real-life problem:

There are a set of n facilities and a set of n locations. For each pair of locations, a distance is specified and for each pair of facilities a weight or flow is specified (e.g., the amount of supplies transported between the two facilities). The problem is to assign all facilities to different locations with the goal of minimizing the sum of the distances multiplied by the corresponding flows. Intuitively, the cost function encourages facilities with high flows between each other to be placed close together.

The instance of the QAP problem with 25 facilities and locations is given by the following data.

Distance matrix:

0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8
1 0 1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 4 5 6 5 4 5 6 7
2 1 0 1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 4 5 6 5 4 5 6
3 2 1 0 1 4 3 2 1 2 5 4 3 2 3 6 5 4 3 4 7 6 5 4 5
4 3 2 1 0 5 4 3 2 1 6 5 4 3 2 7 6 5 4 3 8 7 6 5 4
1 2 3 4 5 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7
2 1 2 3 4 1 0 1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 4 5 6
3 2 1 2 3 2 1 0 1 2 3 2 1 2 3 4 3 2 3 4 5 4 3 4 5
4 3 2 1 2 3 2 1 0 1 4 3 2 1 2 5 4 3 2 3 6 5 4 3 4
5 4 3 2 1 4 3 2 1 0 5 4 3 2 1 6 5 4 3 2 7 6 5 4 3
2 3 4 5 6 1 2 3 4 5 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6
3 2 3 4 5 2 1 2 3 4 1 0 1 2 3 2 1 2 3 4 3 2 3 4 5
4 3 2 3 4 3 2 1 2 3 2 1 0 1 2 3 2 1 2 3 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