我有三套积分。我需要每组最多一个点的所有组合。
从上图中结果应该是:
我正在使用
中的方法Combinations
Accord.Math
在所有集合的所有点上,之后我删除包含来自同一集合的更多点的组合。 我不想计算组合,而是计算从Set1到Set3的所有可能路径(也为Set2传递),因为组合花费了太多时间来处理大量的点。 如何更改我的代码?
var result1 = new Dictionary<int, List<List<ClusterInPath>>>();
foreach (KeyValuePair<int, List<ClusterInPath>> currentClustersInImage in allClustersInVertebra)
{
var allPaths = currentClustersInImage.Value.ToArray().Combinations().Select(el => el.ToList()).ToList();
var filterPaths = new List<List<ClusterInPath>>();
foreach (List<ClusterInPath> path in allPaths)
{
if(PathContainsMoreClustersOnSameImage(path)) continue;
filterPaths.Add(path);
}
result1.Add(currentClustersInVertebra.Key, filterPaths);
}
ClusterInPath类定义如下:
public class ClusterInPath
{
public ClusterInPath(int imageIndex, int clusterIndex)
{
ImageIndex = imageIndex;
ClusterIndex = clusterIndex;
}
public int ImageIndex { get; set; }
public int ClusterIndex { get; set; }
}
提前致谢
答案 0 :(得分:0)
在每个集合中添加虚构(零,空等)元素并获得集合的笛卡尔积。在输出期间忽略或删除这些元素。