Changeset 17939


Ignore:
Timestamp:
04/14/21 09:55:41 (4 months ago)
Author:
mkommend
Message:

#3115: Simplified source code for checking compatibility of solutions by using Hashset and IsSubset method in PDP controls.

Location:
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/FactorPartialDependencePlot.cs

    r17180 r17939  
    222222        if (updateOnFinish)
    223223          Update();
    224       } catch (OperationCanceledException) { 
     224      } catch (OperationCanceledException) {
    225225      } catch (AggregateException ae) {
    226226        if (!ae.InnerExceptions.Any(e => e is OperationCanceledException))
     
    434434      var refSolution = solutions.First();
    435435      var refSolVars = refSolution.ProblemData.Dataset.VariableNames;
     436      var refFactorVars = refSolution.ProblemData.Dataset.StringVariables;
     437      var distinctVals = refFactorVars.ToDictionary(fv => fv, fv => refSolution.ProblemData.Dataset.GetStringValues(fv).Distinct().ToArray());
     438
    436439      foreach (var solution in solutions.Skip(1)) {
    437         var variables1 = solution.ProblemData.Dataset.VariableNames;
    438         if (!variables1.All(refSolVars.Contains))
     440        var variables1 = new HashSet<string>(solution.ProblemData.Dataset.VariableNames);
     441        if (!variables1.IsSubsetOf(refSolVars))
    439442          return false;
    440443
    441         foreach (var factorVar in variables1.Where(solution.ProblemData.Dataset.VariableHasType<string>)) {
    442           var distinctVals = refSolution.ProblemData.Dataset.GetStringValues(factorVar).Distinct();
    443           if (solution.ProblemData.Dataset.GetStringValues(factorVar).Any(val => !distinctVals.Contains(val))) return false;
     444        foreach (var factorVar in solution.ProblemData.Dataset.StringVariables) {
     445          var refValues = distinctVals[factorVar];
     446          var values = new HashSet<string>(solution.ProblemData.Dataset.GetStringValues(factorVar));
     447
     448          if (!values.IsSubsetOf(refValues))
     449            return false;
    444450        }
    445451      }
  • trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/PartialDependencePlot.cs

    r17920 r17939  
    568568      var refSolution = solutions.First();
    569569      var refSolVars = refSolution.ProblemData.Dataset.VariableNames;
    570       var refFactorVars = refSolVars.Where(refSolution.ProblemData.Dataset.VariableHasType<string>);
     570      var refFactorVars = refSolution.ProblemData.Dataset.StringVariables;
    571571      var distinctVals = refFactorVars.ToDictionary(fv => fv, fv => refSolution.ProblemData.Dataset.GetStringValues(fv).Distinct().ToArray());
     572
    572573      foreach (var solution in solutions.Skip(1)) {
    573         var variables1 = solution.ProblemData.Dataset.VariableNames;
    574         if (!variables1.All(refSolVars.Contains))
     574        var variables1 = new HashSet<string>(solution.ProblemData.Dataset.VariableNames);
     575        if (!variables1.IsSubsetOf(refSolVars))
    575576          return false;
    576577
    577         foreach (var factorVar in variables1.Where(solution.ProblemData.Dataset.VariableHasType<string>)) {
     578        foreach (var factorVar in solution.ProblemData.Dataset.StringVariables) {
    578579          var refValues = distinctVals[factorVar];
    579           if (solution.ProblemData.Dataset.GetStringValues(factorVar).Distinct().Any(val => !refValues.Contains(val))) return false;
     580          var values = new HashSet<string>(solution.ProblemData.Dataset.GetStringValues(factorVar));
     581
     582          if (!values.IsSubsetOf(refValues))
     583            return false;
    580584        }
    581585      }
Note: See TracChangeset for help on using the changeset viewer.