Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/MultiTrajectory/PreassignedSolutionCreator.cs @ 11247

Last change on this file since 11247 was 7128, checked in by epitzer, 13 years ago

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

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 HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Analysis.FitnessLandscape.MultiTrajectory {
10
11  [StorableClass]
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(bool deserializing) : base(deserializing) { }
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.