9.4 Permuting a collection of values
When we permute a collection of values, we’ll generate all the possible orders for the values in the collection. There are n! permutations of n items. We can use a sequence of permutations as a kind of brute-force solution to a variety of optimization problems.
Typical combinatorial optimization problems are the Traveling Salesman problem, the Minimum Spanning Tree problem, and the Knapsack problem. These problems are famous because they involve potentially vast numbers of permutations. Approximate solutions are necessary to avoid exhaustive enumeration of all permutations. The use of the itertools.permutations()
function is only handy for exploring very small problems.
One popular example of these combinatorial optimization problems is the assignment problem. We have n agents and n tasks, but the cost of each agent performing a given task is not equal. Imagine that some agents have trouble with some details, while other agents excel at these...