本文整理汇总了C#中ItemArray.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ItemArray.Select方法的具体用法?C# ItemArray.Select怎么用?C# ItemArray.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemArray
的用法示例。
在下文中一共展示了ItemArray.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
var len = parents[0].Length;
var child = new LinearLinkage(len);
var childGroup = new List<HashSet<int>>();
var currentParent = random.Next(parents.Length);
var groups = parents.Select(x => x.GetGroups().Select(y => new HashSet<int>(y)).ToList()).ToList();
bool remaining;
do {
var maxGroup = groups[currentParent].Select((v, i) => Tuple.Create(i, v))
.MaxItems(x => x.Item2.Count)
.SampleRandom(random).Item1;
var group = groups[currentParent][maxGroup];
groups[currentParent].RemoveAt(maxGroup);
childGroup.Add(group);
remaining = false;
for (var p = 0; p < groups.Count; p++) {
for (var j = 0; j < groups[p].Count; j++) {
foreach (var elem in group) groups[p][j].Remove(elem);
if (!remaining && groups[p][j].Count > 0) remaining = true;
}
}
currentParent = (currentParent + 1) % parents.Length;
} while (remaining);
child.SetGroups(childGroup);
return child;
}
示例2: Apply
public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
var len = parents[0].Length;
var child = new LinearLinkage(len);
var remaining = new SortedSet<int>(Enumerable.Range(0, len));
do {
var groups = parents.Select(x => x.GetGroupForward(remaining.Min).Where(y => remaining.Contains(y)).ToList()).ToList();
var max = groups.Select((v, idx) => Tuple.Create(idx, v.Count)).MaxItems(x => x.Item2).SampleRandom(random).Item1;
var i = groups[max][0];
for (var k = 1; k < groups[max].Count; k++) {
child[i] = groups[max][k];
remaining.Remove(i);
i = child[i];
}
child[i] = i;
remaining.Remove(i);
} while (remaining.Count > 0);
return child;
}