- Timestamp:
- 11/03/15 17:09:44 (8 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/ReseedingController.cs
r13110 r13111 20 20 #endregion 21 21 22 using System.Drawing;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Data; 26 25 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization.Operators;28 26 using HeuristicLab.Parameters; 29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 28 31 29 namespace HeuristicLab.Algorithms.ALPS { 32 [Item(" LayerReseeder", "An operator that encapsulates the reseeding of the lowest layer in ALPS.")]30 [Item("ReseedingController", "An operator that controls if reseeding is needed.")] 33 31 [StorableClass] 34 public sealed class LayerReseeder : SingleSuccessorOperator, IOperatorGraphOperator { 35 public static new Image StaticItemImage { 36 get { return HeuristicLab.Common.Resources.VSImageLibrary.Module; } 37 } 38 public override Image ItemImage { 39 get { 40 if (Breakpoint) return HeuristicLab.Common.Resources.VSImageLibrary.BreakpointActive; 41 else return base.ItemImage; 42 } 43 } 44 32 public sealed class ReseedingController : SingleSuccessorOperator { 45 33 private ILookupParameter<IntValue> GenerationsParameter { 46 34 get { return (ILookupParameter<IntValue>)Parameters["Generations"]; } … … 49 37 get { return (ILookupParameter<IntValue>)Parameters["AgeGap"]; } 50 38 } 39 public OperatorParameter FirstLayerOperatorParameter { 40 get { return (OperatorParameter)Parameters["FirstLayerOperator"]; } 41 } 51 42 52 [Storable] 53 private OperatorGraph operatorGraph; 54 public OperatorGraph OperatorGraph { 55 get { return operatorGraph; } 43 public IOperator FirstLayerOperator { 44 get { return FirstLayerOperatorParameter.Value; } 45 set { FirstLayerOperatorParameter.Value = value; } 56 46 } 57 47 58 48 [StorableConstructor] 59 private LayerReseeder(bool deserializing)49 private ReseedingController(bool deserializing) 60 50 : base(deserializing) { } 61 51 62 private LayerReseeder(LayerReseeder original, Cloner cloner)52 private ReseedingController(ReseedingController original, Cloner cloner) 63 53 : base(original, cloner) { 64 operatorGraph = cloner.Clone(original.operatorGraph);65 54 } 66 55 public override IDeepCloneable Clone(Cloner cloner) { 67 return new LayerReseeder(this, cloner);56 return new ReseedingController(this, cloner); 68 57 } 69 58 70 public LayerReseeder()59 public ReseedingController() 71 60 : base() { 72 61 Parameters.Add(new LookupParameter<IntValue>("Generations")); 73 62 Parameters.Add(new LookupParameter<IntValue>("AgeGap")); 74 75 operatorGraph = new OperatorGraph(); 76 77 var removeIndividuals = new SubScopesRemover(); 78 var createIndividuals = new SolutionsCreator(); 79 var initializeAgeProsessor = new UniformSubScopesProcessor(); 80 var initializeAge = new VariableCreator() { Name = "Initialize Age" }; 81 var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; 82 83 OperatorGraph.InitialOperator = removeIndividuals; 84 85 removeIndividuals.Successor = createIndividuals; 86 87 createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize"; 88 createIndividuals.Successor = initializeAgeProsessor; 89 90 initializeAgeProsessor.Operator = initializeAge; 91 initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding; 92 93 initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0))); 94 initializeAge.Successor = null; 95 96 incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions"; 97 incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true); 98 incrEvaluatedSolutionsAfterReseeding.Successor = null; 63 Parameters.Add(new OperatorParameter("FirstLayerOperator")); 99 64 } 100 65 … … 106 71 if (generations % ageGap == 0) { 107 72 var layerZeroScope = ExecutionContext.Scope.SubScopes[0]; 108 if ( operatorGraph.InitialOperator != null)109 next.Insert(0, ExecutionContext.CreateChildOperation( operatorGraph.InitialOperator, layerZeroScope));73 if (FirstLayerOperator != null) 74 next.Insert(0, ExecutionContext.CreateChildOperation(FirstLayerOperator, layerZeroScope)); 110 75 } 111 76 return next;
Note: See TracChangeset
for help on using the changeset viewer.