【发布时间】:2018-05-30 15:55:50
【问题描述】:
我有三组积分。我需要所有组合每组最多有一个点。
从上图中的结果应该是:
- p1、p3、p6
- p1、p3、p7
- p1、p4、p6
- p1、p4、p7
- p1、p5、p6
- p1、p5、p7
- p2、p3、p6
- p2、p3、p7
- p2、p4、p6
- p2、p4、p7
- p2、p5、p6
- p2、p5、p7
- p1,p3
- p1, p4
- p1,p5
- ...
- ...
- p4,p6
- ...
- p1
- p2
- ...
我在
中使用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; }
}
提前致谢
【问题讨论】:
标签: c# performance combinations accord.net