- Timestamp:
- 01/08/15 15:52:05 (10 years ago)
- Location:
- branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 11 added
- 7 deleted
- 16 edited
- 1 copied
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/BinaryEncoding.cs
r11598 r11739 71 71 RegisterParameterEvents(); 72 72 } 73 74 public BinaryEncoding() : this("BinaryVector", 10) { } 75 public BinaryEncoding(int length) : this("BinaryVector", length) { } 73 76 public BinaryEncoding(string name, int length) 74 77 : base(name) { -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/IntegerEncoding.cs
r11598 r11739 94 94 public override IDeepCloneable Clone(Cloner cloner) { return new IntegerEncoding(this, cloner); } 95 95 96 public IntegerEncoding(string name, int length, int min, int max, int? step = null) 96 97 public IntegerEncoding() : this("IntegerVector", 10) { } 98 public IntegerEncoding(int length) : this("integerVector", length) { } 99 public IntegerEncoding(string name, int length, int min = int.MinValue, int max = int.MaxValue, int? step = null) 97 100 : base(name) { 98 101 if (min >= max) throw new ArgumentException("min must be less than max", "min"); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/PermutationEncoding.cs
r11598 r11739 95 95 } 96 96 97 98 public PermutationEncoding() : this("Permutation", 10, PermutationTypes.Absolute) { } 99 public PermutationEncoding(int length) : this("Permuration", length, PermutationTypes.Absolute) { } 97 100 public PermutationEncoding(string name, int length, PermutationTypes type) 98 101 : base(name) { -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/RealEncoding.cs
r11598 r11739 93 93 } 94 94 95 public RealEncoding(string name, int length, double min, double max) 95 public RealEncoding() : this("RealVector", 10) { } 96 public RealEncoding(int length) : this("RealVector", length) { } 97 public RealEncoding(string name, int length, double min = double.MinValue, double max = double.MaxValue) 96 98 : base(name) { 97 99 if (min >= max) throw new ArgumentException("min must be less than max", "min"); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r11655 r11739 140 140 <Compile Include="Interfaces\IEncoding.cs" /> 141 141 <Compile Include="Interfaces\IMultiEncodingOperator.cs" /> 142 <Compile Include="Interfaces\ISingleObjectiveMoveOperator.cs" /> 142 <Compile Include="Interfaces\internal\INeighborBasedOperator.cs" /> 143 <Compile Include="Interfaces\internal\IMultiObjectiveAnalysisOperator.cs" /> 144 <Compile Include="Interfaces\internal\ISingleObjectiveAnalysisOperator.cs" /> 145 <Compile Include="Interfaces\internal\IMultiObjectiveEvaluationOperator.cs" /> 146 <Compile Include="Interfaces\internal\ISingleObjectiveEvaluationOperator.cs" /> 143 147 <Compile Include="Interfaces\IMultiObjectiveProblemDefinition.cs" /> 144 <Compile Include="Interfaces\IMultiObjectiveProgrammableProblemAnalyzer.cs" /> 145 <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemAnalyzer.cs" /> 146 <Compile Include="Interfaces\IMultiObjectiveProgrammableProblemEvaluator.cs" /> 147 <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemEvaluator.cs" /> 148 <Compile Include="Interfaces\IEncodingOperator.cs" /> 149 <Compile Include="New\ProgrammableProblem.cs" /> 148 150 <Compile Include="Operators\MultiEncodingManipulator.cs" /> 149 151 <Compile Include="Operators\MultiEncodingCrossover.cs" /> … … 160 162 <Compile Include="Interfaces\ISingleObjectiveProblemDefinition.cs" /> 161 163 <Compile Include="Operators\SingleObjectiveImprover.cs" /> 162 <Compile Include=" ProblemDefinition.cs" />163 <Compile Include=" ProblemScriptBase.cs" />164 <Compile Include=" ProblemScript.cs" />165 <Compile Include=" MultiObjectiveProblemDefinition.cs" />166 <Compile Include=" SingleObjectiveProblemDefinition.cs" />167 <Compile Include=" MultiObjectiveProblemScript.cs" />168 <Compile Include=" SingleObjectiveProblemScript.cs" />169 <Compile Include=" MultiObjectiveProgrammableProblem.cs" />170 <Compile Include=" SingleObjectiveProgrammableProblem.cs" />164 <Compile Include="New\Scripts\CompiledProblemDefinition.cs" /> 165 <Compile Include="New\Scripts\ProblemDefinitionScript.cs" /> 166 <Compile Include="New\OneMaxNew.cs" /> 167 <Compile Include="New\SingleObjectiveProgrammableProblem.cs" /> 168 <Compile Include="New\SingleObjectiveScriptableProblem.cs" /> 169 <Compile Include="New\Scripts\MultiObjectiveProblemDefinitionScript.cs" /> 170 <Compile Include="New\Scripts\SingleObjectiveProblemDefinitionScript.cs" /> 171 <Compile Include="OLD_MultiObjectiveProgrammableProblem.cs" /> 172 <Compile Include="OLD_SingleObjectiveProgrammableProblem.cs" /> 171 173 <None Include="HeuristicLab.snk" /> 172 174 <None Include="Plugin.cs.frame" /> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IEncodingOperator.cs
r11738 r11739 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Optimization;24 23 25 24 namespace HeuristicLab.Problems.Programmable { 26 public interface ISingleObjectiveProgrammableProblemEvaluator : ISingleObjectiveEvaluator { 27 ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { get; } 25 public interface IEncodingOperator : IOperator { 28 26 ILookupParameter<IEncoding> EncodingParameter { get; } 29 27 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IMultiObjectiveProblemDefinition.cs
r11484 r11739 26 26 public interface IMultiObjectiveProblemDefinition : IProblemDefinition { 27 27 bool[] Maximization { get; } 28 double[] Evaluate(I Random random, Individual individual);28 double[] Evaluate(Individual individual, IRandom random); 29 29 void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results); 30 30 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProblemDefinition.cs
r11550 r11739 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using HeuristicLab.Core; … … 27 26 public interface IProblemDefinition : INamedItem { 28 27 IEncoding Encoding { get; } 29 IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual); 30 31 event EventHandler ProblemDefinitionChanged; 28 IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random); 32 29 } 33 30 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProblemDefinition.cs
r11484 r11739 25 25 namespace HeuristicLab.Problems.Programmable { 26 26 public interface ISingleObjectiveProblemDefinition : IProblemDefinition { 27 bool IsMaximizationProblem{ get; }28 double Evaluate(I Random random, Individual individual);27 bool Maximization { get; } 28 double Evaluate(Individual individual, IRandom random); 29 29 void Analyze(Individual[] individuals, double[] qualities, ResultCollection results); 30 30 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/CompiledProblemDefinition.cs
r11738 r11739 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 27 25 28 namespace HeuristicLab.Problems.Programmable { 26 public abstract class ProblemScriptBase : ProblemDefinition { 27 protected ProblemScriptBase() 28 : base(new MultiEncoding()) { } 29 public abstract class CompiledProblemDefinition : NamedItem, IProblemDefinition { 30 [Storable(Name = "Encoding")] 31 private IEncoding encoding; 32 public IEncoding Encoding { 33 get { return encoding; } 34 protected set { 35 if (value == null) throw new ArgumentNullException("The encoding must not be null."); 36 if (encoding == value) return; 37 encoding = value; 38 } 39 } 29 40 30 41 public dynamic vars { get; set; } 31 42 public abstract void Initialize(); 32 43 44 [StorableConstructor] 45 protected CompiledProblemDefinition(bool deserializing) : base(deserializing) { } 46 protected CompiledProblemDefinition(CompiledProblemDefinition original, Cloner cloner) 47 : base(original, cloner) { 48 this.encoding = cloner.Clone(original.encoding); 49 } 33 50 public override IDeepCloneable Clone(Cloner cloner) { 34 51 throw new InvalidOperationException("ProblemScript instances cannot be cloned."); 35 52 } 53 54 protected CompiledProblemDefinition(IEncoding encoding) : this(encoding, "ProblemDefinition") { } 55 protected CompiledProblemDefinition(IEncoding encoding, string name) : this(encoding, name, string.Empty) { } 56 protected CompiledProblemDefinition(IEncoding encoding, string name, string description) 57 : base(name, description) { 58 Encoding = encoding; 59 //TODO call initialize and set refactor ctors 60 } 61 62 public abstract IEnumerable<Individual> GetNeighbors(Individual vector, IRandom random); 36 63 } 37 64 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/MultiObjectiveProblemDefinitionScript.cs
r11738 r11739 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; … … 30 28 [Item("Multi-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 31 29 [StorableClass] 32 public class MultiObjectiveProblem Script : ProblemScript, IMultiObjectiveProblemDefinition, IStorableContent {30 public class MultiObjectiveProblemDefinitionScript : ProblemDefinitionScript, IMultiObjectiveProblemDefinition, IStorableContent { 33 31 public string Filename { get; set; } 34 32 … … 45 43 using HeuristicLab.Problems.Programmable; 46 44 47 public class CustomProblemDefinition : ProblemScriptBase, IMultiObjectiveProblemDefinition {45 public class CustomProblemDefinition : CompiledProblemDefinition, IMultiObjectiveProblemDefinition { 48 46 public bool[] Maximization { get { return new [] { false, false }; } } 49 47 … … 98 96 99 97 [StorableConstructor] 100 protected MultiObjectiveProblem Script(bool deserializing) : base(deserializing) { }101 protected MultiObjectiveProblem Script(MultiObjectiveProblemScript original, Cloner cloner)98 protected MultiObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { } 99 protected MultiObjectiveProblemDefinitionScript(MultiObjectiveProblemDefinitionScript original, Cloner cloner) 102 100 : base(original, cloner) { } 103 101 104 public MultiObjectiveProblem Script() {102 public MultiObjectiveProblemDefinitionScript() { 105 103 Code = CodeTemplate; 106 104 } 107 105 108 106 public override IDeepCloneable Clone(Cloner cloner) { 109 return new MultiObjectiveProblem Script(this, cloner);107 return new MultiObjectiveProblemDefinitionScript(this, cloner); 110 108 } 111 109 112 public new IMultiObjectiveProblemDefinition Instance { 113 get { return (IMultiObjectiveProblemDefinition)base.Instance; } 114 protected set { base.Instance = value; } 115 } 116 117 protected override void OnInstanceChanged() { 118 OnProblemDefinitionChanged(); 119 base.OnInstanceChanged(); 110 public new IMultiObjectiveProblemDefinition CompiledProblemDefinition { 111 get { return (IMultiObjectiveProblemDefinition)base.CompiledProblemDefinition; } 120 112 } 121 113 122 114 bool[] IMultiObjectiveProblemDefinition.Maximization { 123 get { return Instance != null ? Instance.Maximization : new bool[0]; }115 get { return CompiledProblemDefinition != null ? CompiledProblemDefinition.Maximization : new bool[0]; } 124 116 } 125 117 126 IEncoding IProblemDefinition.Encoding { 127 get { return Instance != null ? Instance.Encoding : null; } 128 } 129 130 double[] IMultiObjectiveProblemDefinition.Evaluate(IRandom random, Individual individual) { 131 return Instance.Evaluate(random, individual); 118 double[] IMultiObjectiveProblemDefinition.Evaluate(Individual individual, IRandom random) { 119 return CompiledProblemDefinition.Evaluate(individual, random); 132 120 } 133 121 134 122 void IMultiObjectiveProblemDefinition.Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 135 Instance.Analyze(individuals, qualities, results); 136 } 137 138 IEnumerable<Individual> IProblemDefinition.GetNeighbors(IRandom random, Individual individual) { 139 return Instance.GetNeighbors(random, individual); 140 } 141 142 public event EventHandler ProblemDefinitionChanged; 143 private void OnProblemDefinitionChanged() { 144 var handler = ProblemDefinitionChanged; 145 if (handler != null) handler(this, EventArgs.Empty); 123 CompiledProblemDefinition.Analyze(individuals, qualities, results); 146 124 } 147 125 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/ProblemDefinitionScript.cs
r11738 r11739 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Reflection; … … 31 32 [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 32 33 [StorableClass] 33 public abstract class Problem Script : Script{34 public abstract class ProblemDefinitionScript : Script, IProblemDefinition { 34 35 protected bool SuppressEvents { get; set; } 35 36 … … 41 42 42 43 [StorableConstructor] 43 protected Problem Script(bool deserializing) : base(deserializing) { }44 protected Problem Script(ProblemScript original, Cloner cloner)44 protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { } 45 protected ProblemDefinitionScript(ProblemDefinitionScript original, Cloner cloner) 45 46 : base(original, cloner) { 46 47 variableStore = cloner.Clone(original.variableStore); 47 48 } 48 protected Problem Script(){49 protected ProblemDefinitionScript() :base(){ 49 50 variableStore = new VariableStore(); 50 51 } 51 52 52 private volatile IProblemDefinition instance; 53 private object locker = new object(); 54 public IProblemDefinition Instance { 53 IEncoding IProblemDefinition.Encoding { 54 get { return CompiledProblemDefinition != null ? CompiledProblemDefinition.Encoding : null; } 55 } 56 IEnumerable<Individual> IProblemDefinition.GetNeighbors(Individual individual, IRandom random) { 57 return CompiledProblemDefinition.GetNeighbors(individual, random); 58 } 59 60 private readonly object locker = new object(); 61 private volatile IProblemDefinition compiledProblemDefinition; 62 protected IProblemDefinition CompiledProblemDefinition { 55 63 get { 56 SuppressEvents = true; 57 try { 58 var oldInstance = instance; 59 var compilationNecessary = false; 60 if (instance == null) { 61 lock (locker) { 62 if (instance == null) { 63 compilationNecessary = true; 64 Compile(); 65 } 64 lock (locker) { 65 if (compiledProblemDefinition == null) { 66 Compile(); 66 67 } 67 68 } 68 if (compilationNecessary && (oldInstance != null || instance != null)) 69 OnInstanceChanged(); 70 return instance; 71 } finally { 72 SuppressEvents = false; 73 } 69 return compiledProblemDefinition; 74 70 } 75 pr otectedset {76 instance= value;77 if (!SuppressEvents) OnInstanceChanged();71 private set { 72 compiledProblemDefinition = value; 73 OnProblemDefinitionChanged(); 78 74 } 79 75 } … … 83 79 var types = assembly.GetTypes(); 84 80 try { 85 var inst = ( ProblemScriptBase)Activator.CreateInstance(types.First(x => typeof(ProblemScriptBase).IsAssignableFrom(x)));81 var inst = (CompiledProblemDefinition)Activator.CreateInstance(types.First(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))); 86 82 inst.vars = new Variables(VariableStore); 87 83 inst.Initialize(); 88 Instance = inst; 89 } catch { 90 Instance = null; 84 CompiledProblemDefinition = inst; 85 } 86 catch { 87 compiledProblemDefinition = null; 91 88 } 92 89 return assembly; … … 95 92 protected override void OnCodeChanged() { 96 93 base.OnCodeChanged(); 97 instance= null;94 compiledProblemDefinition = null; 98 95 } 99 96 100 public event EventHandler InstanceChanged;101 protected virtual void On InstanceChanged() {102 var handler = InstanceChanged;97 public event EventHandler ProblemDefinitionChanged; 98 protected virtual void OnProblemDefinitionChanged() { 99 var handler = ProblemDefinitionChanged; 103 100 if (handler != null) handler(this, EventArgs.Empty); 104 101 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/SingleObjectiveProblemDefinitionScript.cs
r11738 r11739 30 30 [Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 31 31 [StorableClass] 32 public sealed class SingleObjectiveProblem Script : ProblemScript, ISingleObjectiveProblemDefinition, IStorableContent {32 public sealed class SingleObjectiveProblemDefinitionScript : ProblemDefinitionScript, ISingleObjectiveProblemDefinition, IStorableContent { 33 33 public string Filename { get; set; } 34 34 … … 45 45 using HeuristicLab.Problems.Programmable; 46 46 47 public class CustomProblemDefinition : ProblemScriptBase, ISingleObjectiveProblemDefinition {47 public class CustomProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition { 48 48 public bool IsMaximizationProblem { get { return false; } } 49 49 … … 98 98 99 99 [StorableConstructor] 100 private SingleObjectiveProblem Script(bool deserializing) : base(deserializing) { }101 private SingleObjectiveProblem Script(SingleObjectiveProblemScript original, Cloner cloner) : base(original, cloner) { }102 public SingleObjectiveProblem Script(){100 private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { } 101 private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { } 102 public SingleObjectiveProblemDefinitionScript() :base(){ 103 103 Code = CodeTemplate; 104 104 } 105 105 106 106 public override IDeepCloneable Clone(Cloner cloner) { 107 return new SingleObjectiveProblem Script(this, cloner);107 return new SingleObjectiveProblemDefinitionScript(this, cloner); 108 108 } 109 109 110 public new ISingleObjectiveProblemDefinition Instance { 111 get { return (ISingleObjectiveProblemDefinition)base.Instance; } 112 private set { base.Instance = value; } 110 public new ISingleObjectiveProblemDefinition CompiledProblemDefinition { 111 get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; } 113 112 } 114 113 115 protected override void OnInstanceChanged() { 116 OnProblemDefinitionChanged(); 117 base.OnInstanceChanged(); 114 bool ISingleObjectiveProblemDefinition.Maximization { 115 get { return CompiledProblemDefinition != null && CompiledProblemDefinition.Maximization; } 118 116 } 119 117 120 bool ISingleObjectiveProblemDefinition.IsMaximizationProblem { 121 get { return Instance != null && Instance.IsMaximizationProblem; } 122 } 123 124 IEncoding IProblemDefinition.Encoding { 125 get { return Instance != null ? Instance.Encoding : null; } 126 } 127 128 double ISingleObjectiveProblemDefinition.Evaluate(IRandom random, Individual individual) { 129 return Instance.Evaluate(random, individual); 118 double ISingleObjectiveProblemDefinition.Evaluate(Individual individual, IRandom random) { 119 return CompiledProblemDefinition.Evaluate(individual, random); 130 120 } 131 121 132 122 void ISingleObjectiveProblemDefinition.Analyze(Individual[] individuals, double[] qualities, ResultCollection results) { 133 Instance.Analyze(individuals, qualities, results); 134 } 135 136 IEnumerable<Individual> IProblemDefinition.GetNeighbors(IRandom random, Individual individual) { 137 return Instance.GetNeighbors(random, individual); 138 } 139 140 public event EventHandler ProblemDefinitionChanged; 141 private void OnProblemDefinitionChanged() { 142 var handler = ProblemDefinitionChanged; 143 if (handler != null) handler(this, EventArgs.Empty); 123 CompiledProblemDefinition.Analyze(individuals, qualities, results); 144 124 } 145 125 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/SingleObjectiveProgrammableProblem.cs
r11736 r11739 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Drawing;25 22 using System.Linq; 26 23 using HeuristicLab.Analysis; 27 24 using HeuristicLab.Common; 28 25 using HeuristicLab.Core; 29 using HeuristicLab.Encodings.RealVectorEncoding;30 26 using HeuristicLab.Optimization; 31 using HeuristicLab.Parameters;32 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 28 34 29 namespace HeuristicLab.Problems.Programmable { 35 [Item("Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed.")]36 [Creatable("Problems")]37 30 [StorableClass] 38 public class SingleObjectiveProgrammableProblem : SingleObjectiveHeuristicOptimizationProblem<ISingleObjectiveProgrammableProblemEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent { 39 public string Filename { get; set; } 40 41 public static new Image StaticItemImage { 42 get { return Common.Resources.VSImageLibrary.Script; } 43 } 44 45 public new ParameterCollection Parameters { 46 get { return base.Parameters; } 47 } 48 IKeyedItemCollection<string, IParameter> IParameterizedItem.Parameters { 49 get { return Parameters; } 50 } 51 52 public IValueParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { 53 get { return (IValueParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; } 54 } 55 56 protected IValueParameter<IEncoding> EncodingParameter { 57 get { return (IValueParameter<IEncoding>)Parameters["Encoding"]; } 58 } 59 60 public ISingleObjectiveProblemDefinition ProblemDefinition { 61 get { return ProblemDefinitionParameter.Value; } 62 set { ProblemDefinitionParameter.Value = value; } 63 } 64 65 66 public override IEnumerable<IParameterizedItem> ExecutionContextItems { 67 get { return base.ExecutionContextItems.Concat(new[] { ProblemDefinition.Encoding }); } 68 } 69 protected override IEnumerable<IItem> GetOperators() { 70 return base.GetOperators().Concat(ProblemDefinition.Encoding.Operators); 71 } 72 31 public abstract class SingleObjectiveProgrammableProblem<TEncoding> : ProgrammableProblem<TEncoding, SingleObjectiveEvaluator>, ISingleObjectiveProblemDefinition 32 where TEncoding : class, IEncoding { 73 33 [StorableConstructor] 74 34 protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { } 75 35 76 protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)36 protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem<TEncoding> original, Cloner cloner) 77 37 : base(original, cloner) { 78 RegisterEventHandlers();38 ParameterizeOperators(); 79 39 } 80 public SingleObjectiveProgrammableProblem()81 : base(new SingleObjectiveEvaluator(), new MultiEncodingCreator()) {82 Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemScript() { Name = Name }));83 Parameters.Add(new ValueParameter<IEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any."));84 40 41 protected SingleObjectiveProgrammableProblem() 42 : base() { 85 43 86 44 Operators.Add(new BestScopeSolutionAnalyzer()); 45 Operators.Add(new SingleObjectiveEvaluator()); 87 46 Operators.Add(new SingleObjectiveAnalyzer()); 88 Operators.Add(Evaluator);89 47 90 RegisterEventHandlers(); 91 } 92 93 public override IDeepCloneable Clone(Cloner cloner) { 94 return new SingleObjectiveProgrammableProblem(this, cloner); 48 ParameterizeOperators(); 95 49 } 96 50 97 51 [StorableHook(HookType.AfterDeserialization)] 98 // ReSharper disable UnusedMember.Local99 52 private void AfterDeserialization() { 100 RegisterEventHandlers(); 101 } 102 // ReSharper restore UnusedMember.Local 103 104 private void RegisterEventHandlers() { 105 ProblemDefinitionParameter.ValueChanged += ProblemDefinitionParameterOnValueChanged; 106 RegisterProblemDefinitionEventHandlers(); 53 ParameterizeOperators(); 107 54 } 108 55 109 private void ProblemDefinitionParameterOnValueChanged(object sender, EventArgs eventArgs) { 110 RegisterProblemDefinitionEventHandlers(); 111 Parameterize(); 112 } 56 public abstract bool Maximization { get; } 57 public abstract double Evaluate(Individual individual, IRandom random); 58 public virtual void Analyze(Individual[] individuals, double[] qualities, ResultCollection results) { } 113 59 114 private void RegisterProblemDefinitionEventHandlers() {115 ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;116 ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionNameChanged;117 }118 119 private void ProblemDefinitionNameChanged(object sender, EventArgs eventArgs) {120 if (sender != ProblemDefinitionParameter.Value) return;121 Name = ProblemDefinitionParameter.Value.Name;122 }123 124 protected override void OnNameChanged() {125 base.OnNameChanged();126 ProblemDefinitionParameter.Value.Name = Name;127 }128 60 129 61 protected override void OnEvaluatorChanged() { 130 62 base.OnEvaluatorChanged(); 131 Parameterize ();63 ParameterizeOperators(); 132 64 } 133 65 134 protected virtual void ProblemDefinitionChanged(object sender, EventArgs eventArgs) { 135 Parameterize(); 66 protected override void ParameterizeOperators() { 67 base.ParameterizeOperators(); 68 foreach (var op in Operators.OfType<ISingleObjectiveEvaluationOperator>()) 69 op.EvaluateFunc = Evaluate; 70 foreach (var op in Operators.OfType<ISingleObjectiveAnalysisOperator>()) 71 op.AnalyzeAction = Analyze; 136 72 } 137 73 138 protected virtual void Parameterize() {139 var definition = ProblemDefinitionParameter.Value;140 if (definition == null) return;141 142 IEncoding encoding = definition.Encoding;143 SolutionCreator = encoding.SolutionCreator;144 145 EncodingParameter.Value = encoding;146 Maximization.Value = definition.IsMaximizationProblem;147 148 Evaluator.EncodingParameter.ActualName = EncodingParameter.Name;149 Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;150 foreach (var evalOp in Operators.OfType<ISingleObjectiveProgrammableProblemEvaluator>()) {151 evalOp.EncodingParameter.ActualName = EncodingParameter.Name;152 evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;153 }154 foreach (var analyzeOp in Operators.OfType<ISingleObjectiveProgrammableProblemAnalyzer>()) {155 analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name;156 analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;157 analyzeOp.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;158 }159 160 ConfigureSingleEncodingOperators();161 UpdateImprovementOperators();162 UpdateMoveOperators();163 }164 165 166 protected virtual void ConfigureSingleEncodingOperators() {167 foreach (var su in GetOperators().OfType<IRealVectorSwarmUpdater>()) {168 su.MaximizationParameter.ActualName = MaximizationParameter.Name;169 }170 }171 172 protected virtual void UpdateImprovementOperators() {173 if (!Operators.Any(x => x is SingleObjectiveImprover))174 Operators.Add(new SingleObjectiveImprover());175 foreach (var improver in Operators.OfType<SingleObjectiveImprover>()) {176 improver.EncodingParameter.ActualName = EncodingParameter.Name;177 improver.MaximizationParameter.ActualName = MaximizationParameter.Name;178 improver.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;179 improver.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;180 }181 }182 protected virtual void UpdateMoveOperators() {183 if (!Operators.Any(x => x is SingleObjectiveMoveGenerator))184 Operators.Add(new SingleObjectiveMoveGenerator());185 if (!Operators.Any(x => x is SingleObjectiveMoveEvaluator))186 Operators.Add(new SingleObjectiveMoveEvaluator());187 if (!Operators.Any(x => x is SingleObjectiveMoveMaker))188 Operators.Add(new SingleObjectiveMoveMaker());189 190 foreach (var generator in Operators.OfType<SingleObjectiveMoveGenerator>()) {191 generator.EncodingParameter.ActualName = EncodingParameter.Name;192 generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;193 }194 foreach (var evaluator in Operators.OfType<SingleObjectiveMoveEvaluator>()) {195 evaluator.EncodingParameter.ActualName = EncodingParameter.Name;196 evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;197 evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;198 }199 foreach (var maker in Operators.OfType<SingleObjectiveMoveMaker>()) {200 maker.EncodingParameter.ActualName = EncodingParameter.Name;201 maker.MoveQualityParameter.ActualName = Operators.OfType<SingleObjectiveMoveEvaluator>().First().MoveQualityParameter.ActualName;202 maker.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;203 }204 }205 74 } 206 75 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/OLD_MultiObjectiveProgrammableProblem.cs
r11738 r11739 35 35 [Creatable("Problems")] 36 36 [StorableClass] 37 public class MultiObjectiveProgrammableProblem : MultiObjectiveHeuristicOptimizationProblem<IMultiObjectiveProgrammableProblemEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {37 public class OLD_MultiObjectiveProgrammableProblem : MultiObjectiveHeuristicOptimizationProblem<MultiObjectiveEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent { 38 38 public string Filename { get; set; } 39 39 … … 66 66 67 67 [StorableConstructor] 68 protected MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }69 protected MultiObjectiveProgrammableProblem(MultiObjectiveProgrammableProblem original, Cloner cloner)68 protected OLD_MultiObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { } 69 protected OLD_MultiObjectiveProgrammableProblem(OLD_MultiObjectiveProgrammableProblem original, Cloner cloner) 70 70 : base(original, cloner) { 71 71 DynamicEncodingParameters = original.DynamicEncodingParameters.Select(cloner.Clone).ToList(); 72 72 RegisterEventHandlers(); 73 73 } 74 public MultiObjectiveProgrammableProblem()74 public OLD_MultiObjectiveProgrammableProblem() 75 75 : base(new MultiObjectiveEvaluator(), new MultiEncodingCreator()) { 76 Parameters.Add(new ValueParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new MultiObjectiveProblem Script() { Name = Name }));76 Parameters.Add(new ValueParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name })); 77 77 Parameters.Add(new ValueParameter<IEncoding>("Encoding", "Describes which parameters exist, what they're called, what type they are and their bounds if any.")); 78 78 … … 86 86 87 87 public override IDeepCloneable Clone(Cloner cloner) { 88 return new MultiObjectiveProgrammableProblem(this, cloner);88 return new OLD_MultiObjectiveProgrammableProblem(this, cloner); 89 89 } 90 90 … … 107 107 108 108 private void RegisterHostInstanceChanges() { 109 ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;109 //ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged; 110 110 ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionHostOnNameChanged; 111 111 } … … 139 139 140 140 Evaluator.EncodingParameter.ActualName = EncodingParameter.Name; 141 Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;142 foreach (var evalOp in Operators.OfType<IMultiObjectiveProgrammableProblemEvaluator>()) {143 evalOp.EncodingParameter.ActualName = EncodingParameter.Name;144 evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;145 }146 foreach (var analyzeOp in Operators.OfType<IMultiObjectiveProgrammableProblemAnalyzer>()) {147 analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name;148 analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;149 analyzeOp.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName;150 }141 //Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 142 //foreach (var evalOp in Operators.OfType<IMultiObjectiveProgrammableProblemEvaluator>()) { 143 // evalOp.EncodingParameter.ActualName = EncodingParameter.Name; 144 // evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 145 //} 146 //foreach (var analyzeOp in Operators.OfType<IMultiObjectiveProgrammableProblemAnalyzer>()) { 147 // analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name; 148 // analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 149 // analyzeOp.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName; 150 //} 151 151 152 152 SolutionCreator = encoding.SolutionCreator; -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/OLD_SingleObjectiveProgrammableProblem.cs
r11738 r11739 36 36 [Creatable("Problems")] 37 37 [StorableClass] 38 public class SingleObjectiveProgrammableProblem : SingleObjectiveHeuristicOptimizationProblem<ISingleObjectiveProgrammableProblemEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {38 public class OLD_SingleObjectiveProgrammableProblem : SingleObjectiveHeuristicOptimizationProblem<ISingleObjectiveEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent { 39 39 public string Filename { get; set; } 40 40 41 41 public static new Image StaticItemImage { 42 42 get { return Common.Resources.VSImageLibrary.Script; } 43 }44 45 public new ParameterCollection Parameters {46 get { return base.Parameters; }47 }48 IKeyedItemCollection<string, IParameter> IParameterizedItem.Parameters {49 get { return Parameters; }50 43 } 51 44 … … 72 65 73 66 [StorableConstructor] 74 protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }67 protected OLD_SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { } 75 68 76 protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)69 protected OLD_SingleObjectiveProgrammableProblem(OLD_SingleObjectiveProgrammableProblem original, Cloner cloner) 77 70 : base(original, cloner) { 78 71 RegisterEventHandlers(); 79 72 } 80 public SingleObjectiveProgrammableProblem()73 public OLD_SingleObjectiveProgrammableProblem() 81 74 : base(new SingleObjectiveEvaluator(), new MultiEncodingCreator()) { 82 Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblem Script() { Name = Name }));75 Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name })); 83 76 Parameters.Add(new ValueParameter<IEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any.")); 84 77 … … 92 85 93 86 public override IDeepCloneable Clone(Cloner cloner) { 94 return new SingleObjectiveProgrammableProblem(this, cloner);87 return new OLD_SingleObjectiveProgrammableProblem(this, cloner); 95 88 } 96 89 … … 113 106 114 107 private void RegisterProblemDefinitionEventHandlers() { 115 ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;108 //ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged; 116 109 ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionNameChanged; 117 110 } … … 144 137 145 138 EncodingParameter.Value = encoding; 146 Maximization.Value = definition. IsMaximizationProblem;139 Maximization.Value = definition.Maximization; 147 140 148 Evaluator.EncodingParameter.ActualName = EncodingParameter.Name;149 Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;150 foreach (var evalOp in Operators.OfType<ISingleObjectiveProgrammableProblemEvaluator>()) {151 evalOp.EncodingParameter.ActualName = EncodingParameter.Name;152 evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;153 }154 foreach (var analyzeOp in Operators.OfType<ISingleObjectiveProgrammableProblemAnalyzer>()) {155 analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name;156 analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;157 analyzeOp.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;158 }141 //Evaluator.EncodingParameter.ActualName = EncodingParameter.Name; 142 //Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 143 //foreach (var evalOp in Operators.OfType<ISingleObjectiveProgrammableProblemEvaluator>()) { 144 // evalOp.EncodingParameter.ActualName = EncodingParameter.Name; 145 // evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 146 //} 147 //foreach (var analyzeOp in Operators.OfType<ISingleObjectiveProgrammableProblemAnalyzer>()) { 148 // analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name; 149 // analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 150 // analyzeOp.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 151 //} 159 152 160 153 ConfigureSingleEncodingOperators(); … … 173 166 if (!Operators.Any(x => x is SingleObjectiveImprover)) 174 167 Operators.Add(new SingleObjectiveImprover()); 175 foreach (var improver in Operators.OfType<SingleObjectiveImprover>()) {176 improver.EncodingParameter.ActualName = EncodingParameter.Name;177 improver.MaximizationParameter.ActualName = MaximizationParameter.Name;178 improver.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;179 improver.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;180 }168 //foreach (var improver in Operators.OfType<SingleObjectiveImprover>()) { 169 // improver.EncodingParameter.ActualName = EncodingParameter.Name; 170 // improver.MaximizationParameter.ActualName = MaximizationParameter.Name; 171 // improver.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 172 // improver.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 173 //} 181 174 } 182 175 protected virtual void UpdateMoveOperators() { … … 190 183 foreach (var generator in Operators.OfType<SingleObjectiveMoveGenerator>()) { 191 184 generator.EncodingParameter.ActualName = EncodingParameter.Name; 192 generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;185 //generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 193 186 } 194 187 foreach (var evaluator in Operators.OfType<SingleObjectiveMoveEvaluator>()) { 195 188 evaluator.EncodingParameter.ActualName = EncodingParameter.Name; 196 189 evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 197 evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;190 //evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name; 198 191 } 199 192 foreach (var maker in Operators.OfType<SingleObjectiveMoveMaker>()) { -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiObjectiveAnalyzer.cs
r11619 r11739 13 13 [Item("Multi-objective Analyzer", "Calls the Analyze method of the problem definition.")] 14 14 [StorableClass] 15 public class MultiObjectiveAnalyzer : SingleSuccessorOperator, IMultiObjective ProgrammableProblemAnalyzer {15 public class MultiObjectiveAnalyzer : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator { 16 16 public bool EnabledByDefault { get { return true; } } 17 18 public ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter {19 get { return (ILookupParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }20 }21 17 22 18 public ILookupParameter<IEncoding> EncodingParameter { … … 32 28 } 33 29 30 public Action<Individual[], double[][], ResultCollection> AnalyzeAction { get; set; } 31 34 32 [StorableConstructor] 35 33 protected MultiObjectiveAnalyzer(bool deserializing) : base(deserializing) { } … … 37 35 public MultiObjectiveAnalyzer() { 38 36 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 39 Parameters.Add(new LookupParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));40 37 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 41 38 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); … … 48 45 49 46 public override IOperation Apply() { 50 var definition = ProblemDefinitionParameter.ActualValue;51 if (definition == null) throw new InvalidOperationException("Problem definition is null.");52 47 var encoding = EncodingParameter.ActualValue; 53 48 var results = ResultsParameter.ActualValue; … … 58 53 59 54 var individuals = scopes.Select(encoding.GetIndividual).ToArray(); 60 definition.Analyze(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results);55 AnalyzeAction(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results); 61 56 return base.Apply(); 62 57 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiObjectiveEvaluator.cs
r11619 r11739 32 32 [Item("Multi-objective Evaluator", "Calls the Evaluate method of the problem definition and writes the return value into the scope.")] 33 33 [StorableClass] 34 public class MultiObjectiveEvaluator : SingleSuccessorOperator, IMul tiObjectiveProgrammableProblemEvaluator, IStochasticOperator {34 public class MultiObjectiveEvaluator : SingleSuccessorOperator, IMulitObjectiveEvaluationOperator, IStochasticOperator { 35 35 36 36 public ILookupParameter<IRandom> RandomParameter { 37 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 38 }39 40 public ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter {41 get { return (ILookupParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }42 38 } 43 39 … … 50 46 } 51 47 48 public Func<Individual, IRandom, double[]> EvaluateFunc { get; set; } 49 52 50 [StorableConstructor] 53 51 protected MultiObjectiveEvaluator(bool deserializing) : base(deserializing) { } … … 55 53 public MultiObjectiveEvaluator() { 56 54 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 57 Parameters.Add(new LookupParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));58 55 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 59 56 Parameters.Add(new LookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); … … 66 63 public override IOperation Apply() { 67 64 var random = RandomParameter.ActualValue; 68 var definition = ProblemDefinitionParameter.ActualValue;69 if (definition == null) throw new InvalidOperationException("Problem definition is null.");70 65 var encoding = EncodingParameter.ActualValue; 71 66 var individual = encoding.GetIndividual(ExecutionContext.Scope); 72 QualitiesParameter.ActualValue = new DoubleArray( definition.Evaluate(random, individual));67 QualitiesParameter.ActualValue = new DoubleArray(EvaluateFunc(individual, random)); 73 68 return base.Apply(); 74 69 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveAnalyzer.cs
r11619 r11739 13 13 [Item("Single-objective Analyzer", "Calls the script's Analyze method to be able to write into the results collection.")] 14 14 [StorableClass] 15 public class SingleObjectiveAnalyzer : SingleSuccessorOperator, ISingleObjectiveProgrammableProblemAnalyzer {15 public sealed class SingleObjectiveAnalyzer : SingleSuccessorOperator, ISingleObjectiveAnalysisOperator, IAnalyzer { 16 16 public bool EnabledByDefault { get { return true; } } 17 18 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {19 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }20 }21 17 22 18 public ILookupParameter<IEncoding> EncodingParameter { … … 32 28 } 33 29 30 public Action<Individual[], double[], ResultCollection> AnalyzeAction { get; set; } 31 34 32 [StorableConstructor] 35 pr otectedSingleObjectiveAnalyzer(bool deserializing) : base(deserializing) { }36 pr otectedSingleObjectiveAnalyzer(SingleObjectiveAnalyzer original, Cloner cloner) : base(original, cloner) { }33 private SingleObjectiveAnalyzer(bool deserializing) : base(deserializing) { } 34 private SingleObjectiveAnalyzer(SingleObjectiveAnalyzer original, Cloner cloner) : base(original, cloner) { } 37 35 public SingleObjectiveAnalyzer() { 38 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));39 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));40 36 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 41 37 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); … … 48 44 49 45 public override IOperation Apply() { 50 var definition = ProblemDefinitionParameter.ActualValue;51 if (definition == null) throw new InvalidOperationException("Problem definition is null");52 46 var encoding = EncodingParameter.ActualValue; 53 47 var results = ResultsParameter.ActualValue; … … 58 52 59 53 var individuals = scopes.Select(encoding.GetIndividual).ToArray(); 60 definition.Analyze(individuals, QualityParameter.ActualValue.Select(x => x.Value).ToArray(), results);54 AnalyzeAction(individuals, QualityParameter.ActualValue.Select(x => x.Value).ToArray(), results); 61 55 return base.Apply(); 62 56 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveEvaluator.cs
r11619 r11739 32 32 [Item("Single-objective Evaluator", "Calls the script's Evaluate method to get the quality value of the parameter vector.")] 33 33 [StorableClass] 34 public class SingleObjectiveEvaluator : SingleSuccessorOperator, ISingleObjectiveProgrammableProblemEvaluator, IStochasticOperator {34 public sealed class SingleObjectiveEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator, IStochasticOperator { 35 35 36 36 public ILookupParameter<IRandom> RandomParameter { 37 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 38 }39 40 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {41 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }42 38 } 43 39 … … 50 46 } 51 47 48 public Func<Individual, IRandom, double> EvaluateFunc { get; set; } 49 52 50 [StorableConstructor] 53 pr otectedSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }54 pr otectedSingleObjectiveEvaluator(SingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }51 private SingleObjectiveEvaluator(bool deserializing) : base(deserializing) { } 52 private SingleObjectiveEvaluator(SingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { } 55 53 public SingleObjectiveEvaluator() { 56 54 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 57 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));58 55 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 59 56 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); 60 57 } 61 58 62 public override IDeepCloneable Clone(Cloner cloner) { 63 return new SingleObjectiveEvaluator(this, cloner); 64 } 59 public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveEvaluator(this, cloner); } 65 60 66 61 public override IOperation Apply() { 67 62 var random = RandomParameter.ActualValue; 68 var definition = ProblemDefinitionParameter.ActualValue;69 if (definition == null) throw new InvalidOperationException("Problem definition is null.");70 63 var encoding = EncodingParameter.ActualValue; 71 64 var individual = encoding.GetIndividual(ExecutionContext.Scope); 72 QualityParameter.ActualValue = new DoubleValue( definition.Evaluate(random, individual));65 QualityParameter.ActualValue = new DoubleValue(EvaluateFunc(individual, random)); 73 66 return base.Apply(); 74 67 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveImprover.cs
r11619 r11739 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 23 using System.Collections.Generic; 2 24 using System.Linq; 3 25 using HeuristicLab.Common; … … 12 34 [Item("Single-objective Improver", "Improves a solution by calling GetNeighbors and Evaluate of the corresponding problem definition.")] 13 35 [StorableClass] 14 public sealed class SingleObjectiveImprover : SingleSuccessorOperator, ISingleObjectiveImprovementOperator, IStochasticOperator { 15 public IValueLookupParameter<IItem> SolutionParameter { 16 get { return new ValueLookupParameter<IItem>("notused"); } 17 } 18 36 public sealed class SingleObjectiveImprover : SingleSuccessorOperator, INeighborBasedOperator, ISingleObjectiveEvaluationOperator, IStochasticOperator { 19 37 public ILookupParameter<IRandom> RandomParameter { 20 38 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 21 }22 23 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {24 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }25 39 } 26 40 … … 49 63 } 50 64 65 public Func<Individual, IRandom, double> EvaluateFunc { get; set; } 66 public Func<Individual, IRandom, IEnumerable<Individual>> GetNeighborsFunc { get; set; } 67 51 68 [StorableConstructor] 52 69 private SingleObjectiveImprover(bool deserializing) : base(deserializing) { } … … 54 71 public SingleObjectiveImprover() { 55 72 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 56 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));57 73 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 58 74 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); … … 69 85 public override IOperation Apply() { 70 86 var random = RandomParameter.ActualValue; 71 var definition = ProblemDefinitionParameter.ActualValue;72 if (definition == null) throw new InvalidOperationException("Problem definition is null.");73 87 var encoding = EncodingParameter.ActualValue; 74 88 var maximize = MaximizationParameter.ActualValue.Value; … … 76 90 var sampleSize = SampleSizeParameter.ActualValue.Value; 77 91 var individual = encoding.GetIndividual(ExecutionContext.Scope); 78 var quality = QualityParameter.ActualValue == null ? definition.Evaluate(random, individual) : QualityParameter.ActualValue.Value;92 var quality = QualityParameter.ActualValue == null ? EvaluateFunc(individual, random) : QualityParameter.ActualValue.Value; 79 93 80 94 var count = 0; … … 82 96 Individual best = null; 83 97 var bestQuality = quality; 84 foreach (var neighbor in definition.GetNeighbors(random, individual).Take(sampleSize)) {85 var q = definition.Evaluate(random, neighbor);98 foreach (var neighbor in GetNeighborsFunc(individual, random).Take(sampleSize)) { 99 var q = EvaluateFunc(neighbor, random); 86 100 count++; 87 101 if (maximize && bestQuality > q || !maximize && bestQuality < q) continue; … … 95 109 96 110 LocalEvaluatedSolutionsParameter.ActualValue = new IntValue(count); 111 QualityParameter.ActualValue = new DoubleValue(quality); 97 112 individual.Copy(ExecutionContext.Scope); 98 113 return base.Apply(); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveEvaluator.cs
r11619 r11739 32 32 [Item("Single-objective MoveEvaluator", "Evaluates a parameter vector that results from a move.")] 33 33 [StorableClass] 34 public class SingleObjectiveMoveEvaluator : InstrumentedOperator, ISingleObjectiveMoveOperator, ISingleObjectiveMoveEvaluator, IStochasticOperator {34 public class SingleObjectiveMoveEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator, ISingleObjectiveMoveEvaluator, IStochasticOperator { 35 35 36 36 public ILookupParameter<IRandom> RandomParameter { 37 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 38 }39 40 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {41 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }42 38 } 43 39 … … 54 50 } 55 51 52 public Func<Individual, IRandom, double> EvaluateFunc { get; set; } 53 56 54 [StorableConstructor] 57 55 protected SingleObjectiveMoveEvaluator(bool deserializing) : base(deserializing) { } … … 59 57 public SingleObjectiveMoveEvaluator() { 60 58 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 61 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));62 59 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 63 60 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector.")); … … 69 66 } 70 67 71 public override IOperation InstrumentedApply() {68 public override IOperation Apply() { 72 69 var random = RandomParameter.ActualValue; 73 var definition = ProblemDefinitionParameter.ActualValue;74 if (definition == null) throw new InvalidOperationException("Problem definition is null.");75 70 var encoding = EncodingParameter.ActualValue; 76 71 var individual = encoding.GetIndividual(ExecutionContext.Scope); 77 MoveQualityParameter.ActualValue = new DoubleValue( definition.Evaluate(random, individual));78 return base. InstrumentedApply();72 MoveQualityParameter.ActualValue = new DoubleValue(EvaluateFunc(individual, random)); 73 return base.Apply(); 79 74 } 80 75 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveGenerator.cs
r11619 r11739 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Globalization; 24 25 using System.Linq; … … 34 35 [Item("Single-objective MoveGenerator", "Calls the GetNeighbors method of the problem definition to obtain the moves.")] 35 36 [StorableClass] 36 public class SingleObjectiveMoveGenerator : InstrumentedOperator, ISingleObjectiveMoveOperator, IMultiMoveGenerator, IStochasticOperator { 37 37 public class SingleObjectiveMoveGenerator : SingleSuccessorOperator, INeighborBasedOperator, IMultiMoveGenerator, IStochasticOperator { 38 38 public ILookupParameter<IRandom> RandomParameter { 39 39 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 44 44 } 45 45 46 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {47 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }48 }49 50 46 public ILookupParameter<IEncoding> EncodingParameter { 51 47 get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; } 52 48 } 49 50 public Func<Individual, IRandom, IEnumerable<Individual>> GetNeighborsFunc { get; set; } 53 51 54 52 [StorableConstructor] … … 59 57 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 60 58 Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to sample.")); 61 Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));62 59 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 63 60 } … … 67 64 } 68 65 69 public override IOperation InstrumentedApply() {66 public override IOperation Apply() { 70 67 var random = RandomParameter.ActualValue; 71 var definition = ProblemDefinitionParameter.ActualValue;72 if (definition == null) throw new InvalidOperationException("Problem definition is null.");73 68 var sampleSize = SampleSizeParameter.ActualValue.Value; 74 69 var encoding = EncodingParameter.ActualValue; 75 70 var individual = encoding.GetIndividual(ExecutionContext.Scope); 76 var nbhood = definition.GetNeighbors(random, individual).Take(sampleSize).ToList();71 var nbhood = GetNeighborsFunc(individual, random).Take(sampleSize).ToList(); 77 72 78 73 var moveScopes = new Scope[nbhood.Count]; … … 83 78 ExecutionContext.Scope.SubScopes.AddRange(moveScopes); 84 79 85 return base. InstrumentedApply();80 return base.Apply(); 86 81 } 87 82 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveMaker.cs
r11619 r11739 32 32 [Item("Single-objective MoveMaker", "Applies a move.")] 33 33 [StorableClass] 34 public class SingleObjectiveMoveMaker : InstrumentedOperator, I SingleObjectiveMoveOperator, IMoveMaker {34 public class SingleObjectiveMoveMaker : InstrumentedOperator, IMoveMaker { 35 35 public ILookupParameter<IEncoding> EncodingParameter { 36 36 get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; }
Note: See TracChangeset
for help on using the changeset viewer.