1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Hive.JobBase;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
10 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
11 | using HeuristicLab.Hive.Experiment.Properties;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Hive.Experiment.Jobs {
|
---|
14 | [StorableClass]
|
---|
15 | public class ExperimentJob : OptimizerJob {
|
---|
16 | [Storable]
|
---|
17 | private ExecutionState executionState = ExecutionState.Stopped;
|
---|
18 |
|
---|
19 | public ExperimentJob() {
|
---|
20 | this.ComputeInParallel = true;
|
---|
21 | }
|
---|
22 |
|
---|
23 | public ExperimentJob(IOptimizer optimizer) : base(optimizer) {
|
---|
24 | this.ComputeInParallel = true;
|
---|
25 | }
|
---|
26 |
|
---|
27 | public override ExecutionState ExecutionState {
|
---|
28 | get {
|
---|
29 | return ComputeInParallel ? executionState : base.ExecutionState;
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | public override void Start() {
|
---|
34 | if (ComputeInParallel) {
|
---|
35 | executionState = Core.ExecutionState.Started;
|
---|
36 | foreach (IJob child in this.ChildJobs) {
|
---|
37 | OnNewChildJob(child);
|
---|
38 | }
|
---|
39 | executionState = Core.ExecutionState.Paused;
|
---|
40 | OnWaitForChildJobs();
|
---|
41 | } else {
|
---|
42 | base.Start();
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public override void Resume(IEnumerable<IJob> childJobs) {
|
---|
47 | executionState = Core.ExecutionState.Started;
|
---|
48 | this.childJobs = new List<IJob>(childJobs);
|
---|
49 | UpdateRuns();
|
---|
50 | executionState = Core.ExecutionState.Stopped;
|
---|
51 | OnJobStopped();
|
---|
52 | }
|
---|
53 |
|
---|
54 | private void UpdateRuns() {
|
---|
55 | foreach (OptimizerJob optimizerJob in childJobs.Cast<OptimizerJob>()) {
|
---|
56 | this.optimizer.Runs.AddRange(optimizerJob.Optimizer.Runs);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | public void AddChildJob(IJob job) {
|
---|
61 | this.childJobs.Add(job);
|
---|
62 | }
|
---|
63 |
|
---|
64 | public override bool IsParallelizable {
|
---|
65 | get { return true; }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|