Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/20 17:31:31 (5 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
Location:
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms
Files:
3 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;
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs

    r17226 r17517  
    2222using System;
    2323using System.Threading;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Optimization {
     
    4242    [Storable]
    4343    private bool initialized;
    44     [Storable]
    45     private readonly ResultCollection results;
    46     public override ResultCollection Results {
    47       get { return results; }
    48     }
    4944
    5045    private CancellationTokenSource cancellationTokenSource;
     
    5853    protected BasicAlgorithm(BasicAlgorithm original, Cloner cloner)
    5954      : base(original, cloner) {
    60       results = cloner.Clone(original.Results);
    6155      initialized = original.initialized;
    6256    }
    6357    protected BasicAlgorithm()
    6458      : base() {
    65       results = new ResultCollection();
    6659    }
    6760
     
    6962      if (Problem == null) return;
    7063      base.Prepare();
    71       results.Clear();
    7264      initialized = false;
    7365      OnPrepared();
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs

    r17513 r17517  
    7676    }
    7777
    78     public override ResultCollection Results {
    79       get {
    80         return (ResultCollection)globalScope.Variables["Results"].Value;
    81       }
    82     }
    83 
    8478    protected EngineAlgorithm()
    8579      : base() {
    8680      globalScope = new Scope("Global Scope");
    87       globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     81      globalScope.Variables.Add(new Variable("Results", Results));
    8882      operatorGraph = new OperatorGraph();
    8983      Initialize();
     
    9286      : base(name) {
    9387      globalScope = new Scope("Global Scope");
    94       globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     88      globalScope.Variables.Add(new Variable("Results", Results));
    9589      operatorGraph = new OperatorGraph();
    9690      Initialize();
     
    9993      : base(name, parameters) {
    10094      globalScope = new Scope("Global Scope");
    101       globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     95      globalScope.Variables.Add(new Variable("Results", Results));
    10296      operatorGraph = new OperatorGraph();
    10397      Initialize();
     
    106100      : base(name, description) {
    107101      globalScope = new Scope("Global Scope");
    108       globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     102      globalScope.Variables.Add(new Variable("Results", Results));
    109103      operatorGraph = new OperatorGraph();
    110104      Initialize();
     
    113107      : base(name, description, parameters) {
    114108      globalScope = new Scope("Global Scope");
    115       globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     109      globalScope.Variables.Add(new Variable("Results", Results));
    116110      operatorGraph = new OperatorGraph();
    117111      Initialize();
     
    160154      base.Prepare();
    161155      globalScope.Clear();
    162       globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
     156      globalScope.Variables.Add(new Variable("Results", Results));
    163157
    164158      if ((engine != null) && (operatorGraph.InitialOperator != null)) {
Note: See TracChangeset for help on using the changeset viewer.