本文整理汇总了C#中ISolution.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# ISolution.Clone方法的具体用法?C# ISolution.Clone怎么用?C# ISolution.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISolution
的用法示例。
在下文中一共展示了ISolution.Clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNeighbors
public IEnumerable<ISolution> GetNeighbors(ISolution solution)
{
for (int i = 1; i < solution.Count; i++)
for (int j = i + 1; j <= solution.Count; j++)
{
ISolution item = solution.Clone();
var t = item.Items[i];
item.Items[i] = item.Items[j];
item.Items[j] = t;
yield return item;
}
}
示例2: Combine
public ISolution Combine(ISolution solutionFirst, ISolution solutionSecond)
{
Random rnd = new Random();
ISolution result = solutionFirst.Clone();
int k = rnd.Next(solutionFirst.Count) + 1;
for (int i = 1; i <= k; i++)
result.Items[i] = solutionFirst.Items[i];
for (int i = 1; i <= solutionSecond.Count; i++)
if (!result.Items.Contains(solutionSecond.Items[i]))
{
result.Items[k] = solutionSecond.Items[i];
k++;
}
return result;
}
示例3: GetBestNeighbor
public ISolution GetBestNeighbor(ISolution solution)
{
ISolution result = null;
for (int i = 1; i < solution.Count; i++)
for (int j = i + 1; j <= solution.Count; j++)
{
ISolution item = solution.Clone();
var t = item.Items[i];
item.Items[i] = item.Items[j];
item.Items[j] = t;
if (result == null || result.Cost > item.Cost) result = item;
}
if (result == null)
result = solution;
return result;
}