Quadratic Assignment Problem Solution
Thanks to LocalSolver’s non-linear operators, the model is really straightforward (no linearization required). It is not even necessary to introduce a quadratic number of decision variables . Indeed what we are considering is a permuation of all facilities, what can be modeled directly in LocalSolver with a single list variable. The only constraint is for the list to contain all the facilities. As for the objective, it is the sum, for each pair of locations (l1,l2), of the product between the distance between l1 and l2 and the flow between the factory on l1 and the factory on l2. It will be written with “at” operators that can retrieve a member of an array indexed by an expression (see this page for more information about the “at” operator).
With such a compact model, instances with thousands of points can be tackled with no resource issues.
You will find below this model for each language. You can also have a look at a performance comparison of LocalSolver against MIP solvers on this Quadratic Assignment Problem.
localsolver qap.lsp inFileName=instances/esc32a.dat [lsTimeLimit=] [solFileName=]
- Execution (Windows)
python qap.py instances\esc32a.dat
- Execution (Linux)
python qap.py instances/esc32a.dat
- Compilation / Execution (Windows)
cl /EHsc qap.cpp -I%LS_HOME%\include /link %LS_HOME%\bin\localsolver.dll.lib
- Compilation / Execution (Linux)
g++ qap.cpp -I/opt/localsolver_XXX/include -llocalsolver -lpthread -o qap
- Compilation/Execution (Windows)
copy %LS_HOME%\bin\*net.dll .
csc Qap.cs /reference:localsolvernet.dll
- Compilation / Execution (Windows)
javac Qap.java -cp %LS_HOME%\bin\localsolver.jar
java -cp %LS_HOME%\bin\localsolver.jar;. Qap instances\esc32a.dat
- Compilation/Execution (Linux)
javac Qap.java -cp /opt/localsolver_XXX/bin/localsolver.jar
java -cp /opt/localsolver_XXX/bin/localsolver.jar:. Qap instances/esc32a.dat
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.
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 factories with high flows between each other to be placed close together.
The problem statement resembles that of the assignment problem, except that the cost function is expressed in terms of quadratic inequalities, hence the name.
Formal mathematical definition
The formal definition of the quadratic assignment problem is as follows:
- Given two sets, P ("facilities") and L ("locations"), of equal size, together with a weight functionw : P × P → R and a distance function d : L × L → R. Find the bijectionf : P → L ("assignment") such that the cost function:
- is minimized.
Usually weight and distance functions are viewed as square real-valued matrices, so that the cost function is written down as:
In matrix notation:
- where are the permutation matrices, "W" is the weight matrix and "D" is the distance matrix.
The problem is NP-hard, so there is no known algorithm for solving this problem in polynomial time, and even small instances may require long computation time. It was also proven that the problem does not have an approximation algorithm running in polynomial time for any (constant) factor, unless P = NP. The travelling salesman problem may be seen as a special case of QAP if one assumes that the flows connect all facilities only along a single ring, all flows have the same non-zero (constant) value. Many other problems of standard combinatorial optimization problems may be written in this form.
In addition to the original plant location formulation, QAP is a mathematical model for the problem of placement of interconnected electronic components onto a printed circuit board or on a microchip, which is part of the place and route stage of computer aided design in the electronics industry.