Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6677


Ignore:
Timestamp:
08/23/11 10:30:14 (13 years ago)
Author:
epitzer
Message:

Enable modifications of order and number of runs in RunCollectionModificationEvaluator and implement RunCollectionSorter (#1622)

Location:
trunk/sources/HeuristicLab.Optimization/3.3
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r6673 r6677  
    111111  </ItemGroup>
    112112  <ItemGroup>
     113    <Compile Include="RunCollectionSorter.cs" />
    113114    <Compile Include="RunCollectionValueRemover.cs" />
    114115    <Compile Include="IRunCollectionModifier.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionModificationEvaluator.cs

    r6667 r6677  
    5050    public void Evaluate() {
    5151      RunCollection.UpdateOfRunsInProgress = true;
    52       var runs = RunCollection.Where(r => r.Visible).ToList();
     52      var runs = RunCollection.Select((r, i) => new {Run = r, r.Visible, Index = i}).ToList();
     53      var visibleRuns = runs.Where(r => r.Visible).Select(r => r.Run).ToList();
     54      int n = visibleRuns.Count;
     55      if (n == 0)
     56        return;
    5357      foreach (var modifier in Modifiers.CheckedItems)
    54         modifier.Value.Modify(runs);
    55       RunCollection.UpdateOfRunsInProgress = false;
    56       if (runs.Count > 0) { // force update
    57         var run = (IRun) runs[0].Clone();
     58        modifier.Value.Modify(visibleRuns);
     59      if (n != visibleRuns.Count ||
     60          runs.Where(r => r.Visible).Zip(visibleRuns, (r1, r2) => r1.Run != r2).Any()) {
     61        var runIt = runs.GetEnumerator();
     62        var visibleRunIt = visibleRuns.GetEnumerator();
     63        var newRuns = new List<IRun>();
     64        while (runIt.MoveNext()) {
     65          if (!runIt.Current.Visible)
     66            newRuns.Add(runIt.Current.Run);
     67          else if (visibleRunIt.MoveNext())
     68            newRuns.Add(visibleRunIt.Current);
     69        }
     70        while (visibleRunIt.MoveNext())
     71          newRuns.Add(visibleRunIt.Current);
     72        RunCollection.Clear();
     73        RunCollection.AddRange(newRuns);
     74      } else if (runs.Count > 0) { // force update
     75        var run = (IRun) runs[0].Run.Clone();
    5876        RunCollection.Add(run);
    5977        RunCollection.Remove(run);
    6078      }
     79      RunCollection.UpdateOfRunsInProgress = false;
    6180    }
    6281  }
Note: See TracChangeset for help on using the changeset viewer.