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


C# IScope.ToList方法代码示例

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


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

示例1: Apply

    public override IOperation Apply() {
      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
      ResultCollection results = ResultsParameter.ActualValue;
      bool max = MaximizationParameter.ActualValue.Value;
      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;

      if (results.ContainsKey(BestSolutionResultName) && !typeof(IScope).IsAssignableFrom(results[BestSolutionResultName].DataType)) {
        throw new InvalidOperationException(string.Format("Could not add best solution result, because there is already a result with the name \"{0}\" present in the result collection.", BestSolutionResultName));
      }

      int i = -1;
      if (!max)
        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;

      IEnumerable<IScope> scopes = new IScope[] { ExecutionContext.Scope };
      for (int j = 0; j < QualityParameter.Depth; j++)
        scopes = scopes.SelectMany(x => x.SubScopes);
      IScope currentBestScope = scopes.ToList()[i];

      if (bestKnownQuality == null ||
          max && qualities[i].Value > bestKnownQuality.Value
          || !max && qualities[i].Value < bestKnownQuality.Value) {
        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
      }

      if (!results.ContainsKey(BestSolutionResultName)) {
        var cloner = new Cloner();
        //avoid cloning of subscopes and the results collection that the solution is put in
        cloner.RegisterClonedObject(results, new ResultCollection());
        cloner.RegisterClonedObject(currentBestScope.SubScopes, new ScopeList());
        var solution = cloner.Clone(currentBestScope);

        results.Add(new Result(BestSolutionResultName, solution));
      } else {
        var bestSolution = (IScope)results[BestSolutionResultName].Value;
        string qualityName = QualityParameter.TranslatedName;
        if (bestSolution.Variables.ContainsKey(qualityName)) {
          double bestQuality = ((DoubleValue)bestSolution.Variables[qualityName].Value).Value;
          if (max && qualities[i].Value > bestQuality
              || !max && qualities[i].Value < bestQuality) {
            var cloner = new Cloner();
            //avoid cloning of subscopes and the results collection that the solution is put in
            cloner.RegisterClonedObject(results, new ResultCollection());
            cloner.RegisterClonedObject(currentBestScope.SubScopes, new ScopeList());
            var solution = cloner.Clone(currentBestScope);

            results[BestSolutionResultName].Value = solution;
          }
        }
      }
      return base.Apply();
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:53,代码来源:BestScopeSolutionAnalyzer.cs


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