I want to use Minimize
where the variables to minimize are indices pointing into an array.
Here a MWE that hopefully shows what my problem is.
vars = u@# & /@ Range[3];
cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1,
3 - 1}],
1 <= # <= 3 & /@ vars };
vec1 = {1, 2, 3}; vec2 = {1, 2, 3};
Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]),
cons}, vars, Integers]
The error I get:
Part::pkspec1: The expression u[1] cannot be used as a part specification. >>