Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/20 17:31:31 (4 years ago)
Author:
abeham
Message:

#2521: Worked on ResultParameter for Problem and Algorithms

  • Add ResultParameter to TSP, BinaryVectorProblem, and HillClimber
  • Refactor ResultParameter to allow presetting the ResultCollection instead of having to discover it (e.g. for use in BasicAlgorithms)
  • Unify Results property among EngineAlgorithm and BasicAlgorithm
    • There is now only a single instance which is storable
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r17513 r17517  
    9595    }
    9696
    97     public abstract ResultCollection Results { get; }
     97    [Storable]
     98    private readonly ResultCollection results = new ResultCollection();
     99    public ResultCollection Results {
     100      get { return results; }
     101    }
    98102
    99103    [Storable]
     
    185189      storeAlgorithmInEachRun = original.storeAlgorithmInEachRun;
    186190      runsCounter = original.runsCounter;
     191      results = cloner.Clone(original.Results);
    187192      runs = cloner.Clone(original.runs);
    188193      Initialize();
     
    197202      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    198203        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
     204      results.Clear();
    199205    }
    200206    public void Prepare(bool clearRuns) {
     
    286292    public event EventHandler Started;
    287293    protected virtual void OnStarted() {
     294      foreach (var param in Parameters.Concat(Problem.Parameters).OfType<IResultParameter>())
     295        param.ResultCollection = results;
    288296      ExecutionState = ExecutionState.Started;
    289297      EventHandler handler = Started;
     
    292300    public event EventHandler Paused;
    293301    protected virtual void OnPaused() {
     302      foreach (var param in Parameters.Concat(Problem.Parameters).OfType<IResultParameter>())
     303        param.ResultCollection = null;
    294304      ExecutionState = ExecutionState.Paused;
    295305      EventHandler handler = Paused;
     
    311321        }
    312322      } finally {
     323        foreach (var param in Parameters.Concat(Problem.Parameters).OfType<IResultParameter>())
     324          param.ResultCollection = null;
    313325        ExecutionState = ExecutionState.Stopped;
    314326        EventHandler handler = Stopped;
Note: See TracChangeset for help on using the changeset viewer.