An interesting model class are the permutation problems (PERM). Many of them can be formulated in linear (MIP) or non-linear discrete models too, but are inefficient in solving so. In simple permutation problem we are looking for a permuation out of all permutations that minimizes an expression. A typical example is the TSP problem (see also model tsp): The cities to be visited are numbered from 1 to n. Then any permutation of these numbers can be interpreted as “round trip” – visiting all cities in the order of the sequence of these numbers. The goal is now to find a particular permutation that minimizes the total distance. (In the Casebook I, several formulations of the TSP problem are given, for example.) In practice such problems are often solved using (meta)-heuristics. There are many problems that fall into this class: quadratic assignment (QAP), flowshop scheduling, linear ordering problem (LOP), etc. As an example, the traveling salsman problem (TSP) is an used here.
Problem
Given a complete graph G = (V,E,c), with a set of nodes i,j ∈ V = {1,…,n} and edge list E = V ×V and an edge length c_{i,j} for each edge (i,j) ∈ E, find a Hamilton cycle of the graph, that is, a “round trip” in the graph that visits all nodes exactly once with minimal length (the sum of its edge lengths).
In a complete graph it is easy to get a Hamilton cycle: Every permutation of the nodes determines a Hamilton cycle. The difficulty arises when we ask for the shortest cycle. At the present time, we do not known a better method (in the worst case) to get the shortest one, then to enumerate all Hamilton cycles and pick the shortest, that means to check all (n - 1)! permutations and check each time its length. For a small graph with n = 30, we already have the gigantic number of permutations of 29! = 8.84 ⋅ 10^{30}, far to big to be enumerated even by supercomputers in reasonable time. Nevertheless clever methods and mathematical models have been invented that can solve larger problems most of the time.
Modeling Steps
A mathematical formulation can be derived directly from the definition: Out of all permutation, find the one that minimizes the cycle.
Let Π be the set of all permutations, and let π be a single permutation (π ∈ Π). For example, π = [1, 2, 3,…,n] is a single permutation. Let π_{i} be the i-th element in π.
Then the distance of a roundtrip of the permutation π = [π_{1},π_{2},…,π_{n},π_{1}] can be formulated as :
or
(j is the next element of i in the permutation π, and the next to the last is the first element in π). That is:
In other words: Let π be a permutation π_{1}π_{2}π_{3}…π_{n-1}π_{n}. Then c_{πi,πj} with 1 ≤ i,j ≤ n is the cost from the node π_{i} to node π_{j}. The summation, therefore, expresses the costs of a round trip: c_{π1,π2}+c_{π2,π3}+…+c_{πn-1,πn}+c_{πn,π1}. Each possible round trip can be generated by a permutation. Minimizing this sum over all permutations means to look for the shortest round trip. Hence, the traveling salesman problem can be formulated as following:
Note the syntax characteristic for this kind of models is, that (integer) variable are used as indexes: π_{i} is a variable. For example, π_{2} = 7 means that 7 is at the second position (from left to right) in the permutation. And c_{πi,πj} is the distance value of c_{h,k} where h = π_{i} and k = π_{j}. This notation extension allows the modeler to formulated the problem directly in the modeling language LPL:
model tsp "A Simple Permutation Model";
set i,j "the node set";
parameter c{i,j} "distance matrix";
alldiff variable z{i} [1..#i] "a permutation";
minimize obj: sum{i} c[z[if(i=1,#i,i-1)],z[i]];
end
Further Comments
The LPL code is an one-to-one formulation of the model above. The variable definition alldiff defines a permutation of numbers starting with 1. The minimization function is also close to the mathematical notation: in LPL, the construct with if is used instead of the modulo operation. One could also use the modulo operation to specify the objective function as follows:
minimize obj: sum{i} c[z[i],z[i%#i+1]];
This is a very compact formulation, but how is the problem solved? A model in LPL consisting of only a permutation variable and an objective function is identified by LPL as a special model type, called here as Simple Permutation Problem (PERM). These problems are sent to an special solver integrated in LPL which is based on an Tabu-Search metaheuristic method. A much more powerful solver is the commercial LocalSolver.
Solution
A random instance with 30 locations (nodes) is generated in the data model. So, n = 30 coordinates are generated for the nodes in a rectangle and calculate the distances as Euclidean distances:
model data;
parameter n:=[30] "problem size";
parameter X{i}; Y{i}; m:=Trunc(Sqrt(n));;
i:=1..n;
X{i}:=(i%m+1)*2+Trunc(Rnd(0,2));
Y{i}:=(i/m+1)*2+Trunc(Rnd(0,2));
c{i,j}:= Sqrt((X[j]-X[i])^2+(Y[j]-Y[i])^2);
end
With the problem size n = 30, the Tabu-Search method normally finds the optimal solution in a few seconds, which is 51.8052 in this case (see Figure 5).