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 |
|
---|
9 | namespace 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 | }
|
---|