Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/07/10 05:22:33 (14 years ago)
Author:
swagner
Message:

Continued work on algorithm batch processing (#947).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs

    r3275 r3280  
    6464    }
    6565
     66    [Storable]
    6667    private IProblem problem;
    67     [Storable]
    68     private IProblem ProblemPersistence {
    69       get { return problem; }
    70       set {
    71         if (problem != null) DeregisterProblemEvents();
    72         problem = value;
    73         if (problem != null) RegisterProblemEvents();
    74       }
    75     }
    7668    public IProblem Problem {
    7769      get { return problem; }
     
    9183
    9284    [Storable]
     85    protected int runsCounter;
     86
     87    [Storable]
    9388    private RunCollection runs;
    9489    public RunCollection Runs {
     
    10095      executionState = ExecutionState.Stopped;
    10196      executionTime = TimeSpan.Zero;
     97      runsCounter = 0;
    10298      runs = new RunCollection();
    10399    }
     
    106102      executionState = ExecutionState.Stopped;
    107103      executionTime = TimeSpan.Zero;
     104      runsCounter = 0;
    108105      runs = new RunCollection();
    109106    }
     
    112109      executionState = ExecutionState.Stopped;
    113110      executionTime = TimeSpan.Zero;
     111      runsCounter = 0;
    114112      runs = new RunCollection();
    115113    }
     
    118116      executionState = ExecutionState.Stopped;
    119117      executionTime = TimeSpan.Zero;
     118      runsCounter = 0;
    120119      runs = new RunCollection();
    121120    }
     
    124123      executionState = ExecutionState.Stopped;
    125124      executionTime = TimeSpan.Zero;
    126       runs = new RunCollection();
     125      runsCounter = 0;
     126      runs = new RunCollection();
     127    }
     128    internal Algorithm(Algorithm algorithm, Cloner cloner)
     129      : base(algorithm.Name, algorithm.Description, (ParameterCollection)cloner.Clone(algorithm.Parameters)) {
     130      executionState = algorithm.executionState;
     131      executionTime = algorithm.executionTime;
     132      problem = (IProblem)cloner.Clone(algorithm.problem);
     133      runsCounter = algorithm.runsCounter;
     134      runs = (RunCollection)cloner.Clone(algorithm.runs);
     135      Initialize();
     136    }
     137    [StorableConstructor]
     138    protected Algorithm(bool deserializing) : base(deserializing) { }
     139
     140    [StorableHook(HookType.AfterDeserialization)]
     141    private void Initialize() {
     142      if (problem != null) RegisterProblemEvents();
    127143    }
    128144
    129145    public override IDeepCloneable Clone(Cloner cloner) {
     146      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    130147      Algorithm clone = (Algorithm)base.Clone(cloner);
    131148      clone.executionState = executionState;
    132149      clone.executionTime = executionTime;
    133       clone.Problem = (IProblem)cloner.Clone(problem);
     150      clone.problem = (IProblem)cloner.Clone(problem);
     151      clone.runsCounter = runsCounter;
    134152      clone.runs = (RunCollection)cloner.Clone(runs);
     153      clone.Initialize();
    135154      return clone;
    136155    }
     
    143162      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    144163        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    145       if (clearRuns) runs.Clear();
     164      if (clearRuns) {
     165        runsCounter = 0;
     166        runs.Clear();
     167      }
    146168      Prepare();
    147169    }
     
    165187    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    166188      foreach (IResult result in Results)
    167         values.Add(result.Name, result.Value != null ? (IItem)result.Value.Clone() : null);
     189        values.Add(result.Name, result.Value);
    168190    }
    169191
     
    205227    public event EventHandler Stopped;
    206228    protected virtual void OnStopped() {
    207       Run run = new Run("Run (" + ExecutionTime.ToString() + ")");
    208       CollectParameterValues(run.Parameters);
    209       CollectResultValues(run.Results);
    210       runs.Add(run);
    211229      ExecutionState = ExecutionState.Stopped;
     230      runsCounter++;
     231      runs.Add(new Run(string.Format("{0} Run {1} ({2})", Name, runsCounter, ExecutionTime), this));
    212232      EventHandler handler = Stopped;
    213233      if (handler != null) handler(this, EventArgs.Empty);
Note: See TracChangeset for help on using the changeset viewer.