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