Hello Henrik Schachner,
Thank you, it is a creative idea but it need further processing and although it work for large amount of points on my system (Windows 10), it still slower than FindMinimumCostFlow, and sometimes it does not give right answer for my problem.
Regards -- Haobo Xia
(*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]]