本文整理汇总了C#中IScope.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# IScope.SelectMany方法的具体用法?C# IScope.SelectMany怎么用?C# IScope.SelectMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScope
的用法示例。
在下文中一共展示了IScope.SelectMany方法的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();
}