Thank you,
It does work, but if it is guaranteed to be optimal, it has to enumerate n! cases.
So it is slower than FindMinimumCostFlow. Thanks anyway.
(*My Function*)
ca[n_] := ca[n] = ConstantArray[0, {n, n}]
PointsMatch[s1_, s2_] :=
If[s1 == s2, {IdentityMatrix[#], 0},
Extract[FindMinimumCostFlow[
ArrayFlatten[{{0, 1., 0, 0}, {0, 0,
DistanceMatrix[s1, s2,
DistanceFunction -> EuclideanDistance], 0}, {0, ca[#],
0, -1.}, {0, 0, 0, 0}}], 1, 2*# + 2,
"OptimumFlowData"][{"FlowMatrix", "CostValue"}], {{1,
Range[2, 1 + #], Range[# + 2, 2*# + 1]}, {2}}]] &@Length[s1]
aPts = RandomReal[{-10, 10}, {8, 3}];
bPts = RandomReal[{-10, 10}, {8, 3}];
pts = Join[aPts, bPts];
(*By MaximizeOverPermutations*)
AbsoluteTiming[
MaximizeOverPermutations[-Plus @@
MapThread[EuclideanDistance, {aPts, bPts[[#]]}] &, 8]]
(*By FindShortestTour*)
AbsoluteTiming[{length, order} =
FindShortestTour[pts,
DistanceFunction -> (If[sameListQ[#1, #2], Infinity,
EuclideanDistance[#1, #2]] &)];
MinimalBy[{Plus @@ (EuclideanDistance@(Sequence @@
pts[[#]]) & /@ #), #} & /@ (Partition[#, 2] & /@ {Rest[
order], order}), First]]
(*By FindMinimumCostFlow*)
AbsoluteTiming[MatrixForm /@ PointsMatch[aPts, bPts]]
