Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12128


Ignore:
Timestamp:
03/04/15 16:30:38 (10 years ago)
Author:
abeham
Message:

#1985: mkommend improved MakeSnapshot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/TimeLimitRunOptimizer/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs

    r9153 r12128  
    376376      string time = Math.Round(ExecutionTime.TotalSeconds, 1).ToString("0.0");
    377377      string runName = "Snapshot " + time + "s " + algorithm.Name;
    378       Run run;
    379       if (StoreAlgorithmInEachSnapshot) {
    380         var temporarilySetStoreFlag = !Algorithm.StoreAlgorithmInEachRun;
    381         if (temporarilySetStoreFlag) Algorithm.StoreAlgorithmInEachRun = true;
    382         run = new Run(runName, Algorithm);
    383         if (temporarilySetStoreFlag) Algorithm.StoreAlgorithmInEachRun = false;
    384       } else {
    385         // duplicate code of Run.Initialize - necessary, because Algorithm property doesn't have a setter
    386         run = new Run() { Name = runName };
    387         var parameters = new Dictionary<string, IItem>();
    388         var results = new Dictionary<string, IItem>();
    389         algorithm.CollectParameterValues(parameters);
    390         algorithm.CollectResultValues(results);
    391         var cloner = new Cloner();
    392         foreach (var kvp in parameters.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value))
    393           run.Parameters.Add(kvp);
    394         foreach (var kvp in results.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value))
    395           run.Results.Add(kvp);
    396       }
     378      var changed = false;
     379      if (StoreAlgorithmInEachSnapshot && !Algorithm.StoreAlgorithmInEachRun) {
     380        Algorithm.StoreAlgorithmInEachRun = true;
     381        changed = true;
     382      } else if (!StoreAlgorithmInEachSnapshot && Algorithm.StoreAlgorithmInEachRun) {
     383        Algorithm.StoreAlgorithmInEachRun = false;
     384        changed = true;
     385      }
     386      var run = new Run(runName, Algorithm);
     387      if (changed)
     388        Algorithm.StoreAlgorithmInEachRun = !Algorithm.StoreAlgorithmInEachRun;
     389
    397390      snapshots.Add(run);
    398391    }
Note: See TracChangeset for help on using the changeset viewer.