当前位置: 首页>>代码示例>>C#>>正文


C# IItem.Any方法代码示例

本文整理汇总了C#中IItem.Any方法的典型用法代码示例。如果您正苦于以下问题:C# IItem.Any方法的具体用法?C# IItem.Any怎么用?C# IItem.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IItem的用法示例。


在下文中一共展示了IItem.Any方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

    public static ItemArray<IItem> Apply(IItem initiator, IItem[] guides, DistanceMatrix distances, PercentValue n) {
      if (!(initiator is Permutation) || guides.Any(x => !(x is Permutation)))
        throw new ArgumentException("Cannot relink path because some of the provided solutions have the wrong type.");
      if (n.Value <= 0.0)
        throw new ArgumentException("RelinkingAccuracy must be greater than 0.");

      Permutation v1 = initiator.Clone() as Permutation;
      Permutation[] targets = new Permutation[guides.Length];
      Array.Copy(guides, targets, guides.Length);

      if (targets.Any(x => x.Length != v1.Length))
        throw new ArgumentException("At least one solution is of different length.");

      IList<Permutation> solutions = new List<Permutation>();
      for (int i = 0; i < v1.Length; i++) {
        int currCityIndex = i;
        int bestCityIndex = (i + 1) % v1.Length;
        double currDistance = distances[v1[currCityIndex], v1[bestCityIndex]];
        // check each guiding solution
        targets.ToList().ForEach(solution => {
          // locate current city
          var node = solution.Select((x, index) => new { Id = x, Index = index }).Single(x => x.Id == v1[currCityIndex]);
          int pred = solution[(node.Index - 1 + solution.Length) % solution.Length];
          int succ = solution[(node.Index + 1) % solution.Length];
          // get distances to neighbors
          var results = new[] { pred, succ }.Select(x => new { Id = x, Distance = distances[x, node.Id] });
          var bestCity = results.Where(x => x.Distance < currDistance).OrderBy(x => x.Distance).FirstOrDefault();
          if (bestCity != null) {
            bestCityIndex = v1.Select((x, index) => new { Id = x, Index = index }).Single(x => x.Id == bestCity.Id).Index;
            currDistance = bestCity.Distance;
          }
        });
        Invert(v1, currCityIndex + 1, bestCityIndex);
        solutions.Add(v1.Clone() as Permutation);
      }

      IList<IItem> selection = new List<IItem>();
      if (solutions.Count > 0) {
        int noSol = (int)(solutions.Count * n.Value);
        if (noSol <= 0) noSol++;
        double stepSize = (double)solutions.Count / (double)noSol;
        for (int i = 0; i < noSol; i++)
          selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
      }

      return new ItemArray<IItem>(selection);
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:47,代码来源:TSPMultipleGuidesPathRelinker.cs


注:本文中的IItem.Any方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。