Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/MultiTrajectory/PreassignedSolutionCreator.cs @ 17460

Last change on this file since 17460 was 16995, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

File size: 2.8 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Operators;
5using HeuristicLab.Optimization;
6using HeuristicLab.Parameters;
7using HEAL.Attic;
8
9namespace HeuristicLab.Analysis.FitnessLandscape.MultiTrajectory {
10
11  [StorableType("1F8136F9-FBED-40F7-ACA3-E3D05F623A28")]
12  public abstract class PreassignedSolutionCreator : SingleSuccessorOperator, ISolutionCreator {
13
14    #region Parameters
15    public ValueParameter<IScope> SolutionCollectionParameter {
16      get { return (ValueParameter<IScope>)Parameters["SolutionCollection"]; }
17    }
18    public ValueParameter<IntValue> CurrentSolutionIndexParameter {
19      get { return (ValueParameter<IntValue>)Parameters["CurrentSolutionIndex"]; }
20    }
21    public ValueParameter<ISolutionCreator> OriginalSolutionCreatorParameter {
22      get { return (ValueParameter<ISolutionCreator>)Parameters["OriginalSolutionCreator"]; }
23    }
24    #endregion
25
26    #region Parameter Values
27    public IScope SolutionCollection {
28      get { return SolutionCollectionParameter.Value; }
29      set { SolutionCollectionParameter.Value = value; }
30    }
31    public int CurrentSolutionIndex {
32      get { return CurrentSolutionIndexParameter.Value.Value; }
33      set { CurrentSolutionIndexParameter.Value = new IntValue(value); }
34    }
35    public ISolutionCreator OriginalSolutionCreator {
36      get { return OriginalSolutionCreatorParameter.Value; }
37      set { OriginalSolutionCreatorParameter.Value = value; }
38    }
39    #endregion
40
41    [StorableConstructor]
42    protected PreassignedSolutionCreator(StorableConstructorFlag _) : base(_) { }
43
44    protected PreassignedSolutionCreator(PreassignedSolutionCreator original, Cloner cloner)
45      : base(original, cloner) {
46    }
47
48    public PreassignedSolutionCreator() {
49      Parameters.Add(new ValueParameter<IScope>("SolutionCollection", "Scope with subscopes that contains the list of solutions."));
50      Parameters.Add(new ValueParameter<IntValue>("CurrentSolutionIndex", "Index of currently created solution."));
51      Parameters.Add(new ValueParameter<ISolutionCreator>("OriginalSolutionCreator", "Original solution creator used for a certain problem."));
52    }
53
54    public abstract void Create(IScope scope);
55
56    public sealed override IOperation Apply() {
57      if (CurrentSolutionIndex < 0 && OriginalSolutionCreator != null) {
58        OperationCollection collection = new OperationCollection();
59        collection.Add(ExecutionContext.CreateOperation(OriginalSolutionCreator));
60        collection.Add(base.Apply());
61        return collection;
62      } else {
63        Create(SolutionCollection.SubScopes[CurrentSolutionIndex]);
64        CurrentSolutionIndex = (CurrentSolutionIndex+1) % SolutionCollection.SubScopes.Count;
65        return base.Apply();
66      }
67    }
68
69  }
70}
Note: See TracBrowser for help on using the repository browser.