Changeset 11739


Ignore:
Timestamp:
01/08/15 15:52:05 (5 years ago)
Author:
mkommend
Message:

#2174: Worked on operators and programmable problem base classes and scripts.

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  
    7171      RegisterParameterEvents();
    7272    }
     73
     74    public BinaryEncoding() : this("BinaryVector", 10) { }
     75    public BinaryEncoding(int length) : this("BinaryVector", length) { }
    7376    public BinaryEncoding(string name, int length)
    7477      : base(name) {
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/IntegerEncoding.cs

    r11598 r11739  
    9494    public override IDeepCloneable Clone(Cloner cloner) { return new IntegerEncoding(this, cloner); }
    9595
    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)
    97100      : base(name) {
    98101      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  
    9595    }
    9696
     97
     98    public PermutationEncoding() : this("Permutation", 10, PermutationTypes.Absolute) { }
     99    public PermutationEncoding(int length) : this("Permuration", length, PermutationTypes.Absolute) { }
    97100    public PermutationEncoding(string name, int length, PermutationTypes type)
    98101      : base(name) {
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/RealEncoding.cs

    r11598 r11739  
    9393    }
    9494
    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)
    9698      : base(name) {
    9799      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  
    140140    <Compile Include="Interfaces\IEncoding.cs" />
    141141    <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" />
    143147    <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" />
    148150    <Compile Include="Operators\MultiEncodingManipulator.cs" />
    149151    <Compile Include="Operators\MultiEncodingCrossover.cs" />
     
    160162    <Compile Include="Interfaces\ISingleObjectiveProblemDefinition.cs" />
    161163    <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" />
    171173    <None Include="HeuristicLab.snk" />
    172174    <None Include="Plugin.cs.frame" />
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IEncodingOperator.cs

    r11738 r11739  
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.Optimization;
    2423
    2524namespace HeuristicLab.Problems.Programmable {
    26   public interface ISingleObjectiveProgrammableProblemEvaluator : ISingleObjectiveEvaluator {
    27     ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter { get; }
     25  public interface IEncodingOperator : IOperator {
    2826    ILookupParameter<IEncoding> EncodingParameter { get; }
    2927  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IMultiObjectiveProblemDefinition.cs

    r11484 r11739  
    2626  public interface IMultiObjectiveProblemDefinition : IProblemDefinition {
    2727    bool[] Maximization { get; }
    28     double[] Evaluate(IRandom random, Individual individual);
     28    double[] Evaluate(Individual individual, IRandom random);
    2929    void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results);
    3030  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProblemDefinition.cs

    r11550 r11739  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Core;
     
    2726  public interface IProblemDefinition : INamedItem {
    2827    IEncoding Encoding { get; }
    29     IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual);
    30 
    31     event EventHandler ProblemDefinitionChanged;
     28    IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random);
    3229  }
    3330}
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProblemDefinition.cs

    r11484 r11739  
    2525namespace HeuristicLab.Problems.Programmable {
    2626  public interface ISingleObjectiveProblemDefinition : IProblemDefinition {
    27     bool IsMaximizationProblem { get; }
    28     double Evaluate(IRandom random, Individual individual);
     27    bool Maximization { get; }
     28    double Evaluate(Individual individual, IRandom random);
    2929    void Analyze(Individual[] individuals, double[] qualities, ResultCollection results);
    3030  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/CompiledProblemDefinition.cs

    r11738 r11739  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Common;
     25using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2427
    2528namespace 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    }
    2940
    3041    public dynamic vars { get; set; }
    3142    public abstract void Initialize();
    3243
     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    }
    3350    public override IDeepCloneable Clone(Cloner cloner) {
    3451      throw new InvalidOperationException("ProblemScript instances cannot be cloned.");
    3552    }
     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);
    3663  }
    3764}
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/MultiObjectiveProblemDefinitionScript.cs

    r11738 r11739  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
     
    3028  [Item("Multi-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3129  [StorableClass]
    32   public class MultiObjectiveProblemScript : ProblemScript, IMultiObjectiveProblemDefinition, IStorableContent {
     30  public class MultiObjectiveProblemDefinitionScript : ProblemDefinitionScript, IMultiObjectiveProblemDefinition, IStorableContent {
    3331    public string Filename { get; set; }
    3432
     
    4543using HeuristicLab.Problems.Programmable;
    4644
    47 public class CustomProblemDefinition : ProblemScriptBase, IMultiObjectiveProblemDefinition {
     45public class CustomProblemDefinition : CompiledProblemDefinition, IMultiObjectiveProblemDefinition {
    4846  public bool[] Maximization { get { return new [] { false, false }; } }
    4947
     
    9896
    9997    [StorableConstructor]
    100     protected MultiObjectiveProblemScript(bool deserializing) : base(deserializing) { }
    101     protected MultiObjectiveProblemScript(MultiObjectiveProblemScript original, Cloner cloner)
     98    protected MultiObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     99    protected MultiObjectiveProblemDefinitionScript(MultiObjectiveProblemDefinitionScript original, Cloner cloner)
    102100      : base(original, cloner) { }
    103101
    104     public MultiObjectiveProblemScript() {
     102    public MultiObjectiveProblemDefinitionScript() {
    105103      Code = CodeTemplate;
    106104    }
    107105
    108106    public override IDeepCloneable Clone(Cloner cloner) {
    109       return new MultiObjectiveProblemScript(this, cloner);
     107      return new MultiObjectiveProblemDefinitionScript(this, cloner);
    110108    }
    111109
    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; }
    120112    }
    121113
    122114    bool[] IMultiObjectiveProblemDefinition.Maximization {
    123       get { return Instance != null ? Instance.Maximization : new bool[0]; }
     115      get { return CompiledProblemDefinition != null ? CompiledProblemDefinition.Maximization : new bool[0]; }
    124116    }
    125117
    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);
    132120    }
    133121
    134122    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);
    146124    }
    147125  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/ProblemDefinitionScript.cs

    r11738 r11739  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Reflection;
     
    3132  [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3233  [StorableClass]
    33   public abstract class ProblemScript : Script {
     34  public abstract class ProblemDefinitionScript : Script, IProblemDefinition {
    3435    protected bool SuppressEvents { get; set; }
    3536
     
    4142
    4243    [StorableConstructor]
    43     protected ProblemScript(bool deserializing) : base(deserializing) { }
    44     protected ProblemScript(ProblemScript original, Cloner cloner)
     44    protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     45    protected ProblemDefinitionScript(ProblemDefinitionScript original, Cloner cloner)
    4546      : base(original, cloner) {
    4647      variableStore = cloner.Clone(original.variableStore);
    4748    }
    48     protected ProblemScript() {
     49    protected ProblemDefinitionScript() :base(){
    4950      variableStore = new VariableStore();
    5051    }
    5152
    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 {
    5563      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();
    6667            }
    6768          }
    68           if (compilationNecessary && (oldInstance != null || instance != null))
    69             OnInstanceChanged();
    70           return instance;
    71         } finally {
    72           SuppressEvents = false;
    73         }
     69        return compiledProblemDefinition;
    7470      }
    75       protected set {
    76         instance = value;
    77         if (!SuppressEvents) OnInstanceChanged();
     71      private set {
     72        compiledProblemDefinition = value;
     73        OnProblemDefinitionChanged();
    7874      }
    7975    }
     
    8379      var types = assembly.GetTypes();
    8480      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)));
    8682        inst.vars = new Variables(VariableStore);
    8783        inst.Initialize();
    88         Instance = inst;
    89       } catch {
    90         Instance = null;
     84        CompiledProblemDefinition = inst;
     85      }
     86      catch {
     87        compiledProblemDefinition = null;
    9188      }
    9289      return assembly;
     
    9592    protected override void OnCodeChanged() {
    9693      base.OnCodeChanged();
    97       instance = null;
     94      compiledProblemDefinition = null;
    9895    }
    9996
    100     public event EventHandler InstanceChanged;
    101     protected virtual void OnInstanceChanged() {
    102       var handler = InstanceChanged;
     97    public event EventHandler ProblemDefinitionChanged;
     98    protected virtual void OnProblemDefinitionChanged() {
     99      var handler = ProblemDefinitionChanged;
    103100      if (handler != null) handler(this, EventArgs.Empty);
    104101    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/SingleObjectiveProblemDefinitionScript.cs

    r11738 r11739  
    3030  [Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3131  [StorableClass]
    32   public sealed class SingleObjectiveProblemScript : ProblemScript, ISingleObjectiveProblemDefinition, IStorableContent {
     32  public sealed class SingleObjectiveProblemDefinitionScript : ProblemDefinitionScript, ISingleObjectiveProblemDefinition, IStorableContent {
    3333    public string Filename { get; set; }
    3434
     
    4545using HeuristicLab.Problems.Programmable;
    4646
    47 public class CustomProblemDefinition : ProblemScriptBase, ISingleObjectiveProblemDefinition {
     47public class CustomProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
    4848  public bool IsMaximizationProblem { get { return false; } }
    4949
     
    9898
    9999    [StorableConstructor]
    100     private SingleObjectiveProblemScript(bool deserializing) : base(deserializing) { }
    101     private SingleObjectiveProblemScript(SingleObjectiveProblemScript original, Cloner cloner) : base(original, cloner) { }
    102     public SingleObjectiveProblemScript() {
     100    private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     101    private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
     102    public SingleObjectiveProblemDefinitionScript() :base(){
    103103      Code = CodeTemplate;
    104104    }
    105105
    106106    public override IDeepCloneable Clone(Cloner cloner) {
    107       return new SingleObjectiveProblemScript(this, cloner);
     107      return new SingleObjectiveProblemDefinitionScript(this, cloner);
    108108    }
    109109
    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; }
    113112    }
    114113
    115     protected override void OnInstanceChanged() {
    116       OnProblemDefinitionChanged();
    117       base.OnInstanceChanged();
     114    bool ISingleObjectiveProblemDefinition.Maximization {
     115      get { return CompiledProblemDefinition != null && CompiledProblemDefinition.Maximization; }
    118116    }
    119117
    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);
    130120    }
    131121
    132122    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);
    144124    }
    145125  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/SingleObjectiveProgrammableProblem.cs

    r11736 r11739  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Drawing;
    2522using System.Linq;
    2623using HeuristicLab.Analysis;
    2724using HeuristicLab.Common;
    2825using HeuristicLab.Core;
    29 using HeuristicLab.Encodings.RealVectorEncoding;
    3026using HeuristicLab.Optimization;
    31 using HeuristicLab.Parameters;
    3227using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3328
    3429namespace HeuristicLab.Problems.Programmable {
    35   [Item("Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed.")]
    36   [Creatable("Problems")]
    3730  [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 {
    7333    [StorableConstructor]
    7434    protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
    7535
    76     protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
     36    protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem<TEncoding> original, Cloner cloner)
    7737      : base(original, cloner) {
    78       RegisterEventHandlers();
     38      ParameterizeOperators();
    7939    }
    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."));
    8440
     41    protected SingleObjectiveProgrammableProblem()
     42      : base() {
    8543
    8644      Operators.Add(new BestScopeSolutionAnalyzer());
     45      Operators.Add(new SingleObjectiveEvaluator());
    8746      Operators.Add(new SingleObjectiveAnalyzer());
    88       Operators.Add(Evaluator);
    8947
    90       RegisterEventHandlers();
    91     }
    92 
    93     public override IDeepCloneable Clone(Cloner cloner) {
    94       return new SingleObjectiveProgrammableProblem(this, cloner);
     48      ParameterizeOperators();
    9549    }
    9650
    9751    [StorableHook(HookType.AfterDeserialization)]
    98     // ReSharper disable UnusedMember.Local
    9952    private void AfterDeserialization() {
    100       RegisterEventHandlers();
    101     }
    102     // ReSharper restore UnusedMember.Local
    103 
    104     private void RegisterEventHandlers() {
    105       ProblemDefinitionParameter.ValueChanged += ProblemDefinitionParameterOnValueChanged;
    106       RegisterProblemDefinitionEventHandlers();
     53      ParameterizeOperators();
    10754    }
    10855
    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) { }
    11359
    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     }
    12860
    12961    protected override void OnEvaluatorChanged() {
    13062      base.OnEvaluatorChanged();
    131       Parameterize();
     63      ParameterizeOperators();
    13264    }
    13365
    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;
    13672    }
    13773
    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     }
    20574  }
    20675}
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/OLD_MultiObjectiveProgrammableProblem.cs

    r11738 r11739  
    3535  [Creatable("Problems")]
    3636  [StorableClass]
    37   public class MultiObjectiveProgrammableProblem : MultiObjectiveHeuristicOptimizationProblem<IMultiObjectiveProgrammableProblemEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {
     37  public class OLD_MultiObjectiveProgrammableProblem : MultiObjectiveHeuristicOptimizationProblem<MultiObjectiveEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {
    3838    public string Filename { get; set; }
    3939
     
    6666
    6767    [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)
    7070      : base(original, cloner) {
    7171      DynamicEncodingParameters = original.DynamicEncodingParameters.Select(cloner.Clone).ToList();
    7272      RegisterEventHandlers();
    7373    }
    74     public MultiObjectiveProgrammableProblem()
     74    public OLD_MultiObjectiveProgrammableProblem()
    7575      : base(new MultiObjectiveEvaluator(), new MultiEncodingCreator()) {
    76       Parameters.Add(new ValueParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new MultiObjectiveProblemScript() { Name = Name }));
     76      Parameters.Add(new ValueParameter<IMultiObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new MultiObjectiveProblemDefinitionScript() { Name = Name }));
    7777      Parameters.Add(new ValueParameter<IEncoding>("Encoding", "Describes which parameters exist, what they're called, what type they are and their bounds if any."));
    7878
     
    8686
    8787    public override IDeepCloneable Clone(Cloner cloner) {
    88       return new MultiObjectiveProgrammableProblem(this, cloner);
     88      return new OLD_MultiObjectiveProgrammableProblem(this, cloner);
    8989    }
    9090
     
    107107
    108108    private void RegisterHostInstanceChanges() {
    109       ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;
     109      //ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;
    110110      ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionHostOnNameChanged;
    111111    }
     
    139139
    140140      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      //}
    151151
    152152      SolutionCreator = encoding.SolutionCreator;
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/OLD_SingleObjectiveProgrammableProblem.cs

    r11738 r11739  
    3636  [Creatable("Problems")]
    3737  [StorableClass]
    38   public class SingleObjectiveProgrammableProblem : SingleObjectiveHeuristicOptimizationProblem<ISingleObjectiveProgrammableProblemEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {
     38  public class OLD_SingleObjectiveProgrammableProblem : SingleObjectiveHeuristicOptimizationProblem<ISingleObjectiveEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {
    3939    public string Filename { get; set; }
    4040
    4141    public static new Image StaticItemImage {
    4242      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; }
    5043    }
    5144
     
    7265
    7366    [StorableConstructor]
    74     protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
     67    protected OLD_SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
    7568
    76     protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
     69    protected OLD_SingleObjectiveProgrammableProblem(OLD_SingleObjectiveProgrammableProblem original, Cloner cloner)
    7770      : base(original, cloner) {
    7871      RegisterEventHandlers();
    7972    }
    80     public SingleObjectiveProgrammableProblem()
     73    public OLD_SingleObjectiveProgrammableProblem()
    8174      : base(new SingleObjectiveEvaluator(), new MultiEncodingCreator()) {
    82       Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemScript() { Name = Name }));
     75      Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
    8376      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."));
    8477
     
    9285
    9386    public override IDeepCloneable Clone(Cloner cloner) {
    94       return new SingleObjectiveProgrammableProblem(this, cloner);
     87      return new OLD_SingleObjectiveProgrammableProblem(this, cloner);
    9588    }
    9689
     
    113106
    114107    private void RegisterProblemDefinitionEventHandlers() {
    115       ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;
     108      //ProblemDefinitionParameter.Value.ProblemDefinitionChanged += ProblemDefinitionChanged;
    116109      ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionNameChanged;
    117110    }
     
    144137
    145138      EncodingParameter.Value = encoding;
    146       Maximization.Value = definition.IsMaximizationProblem;
     139      Maximization.Value = definition.Maximization;
    147140
    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      //}
    159152
    160153      ConfigureSingleEncodingOperators();
     
    173166      if (!Operators.Any(x => x is SingleObjectiveImprover))
    174167        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      //}
    181174    }
    182175    protected virtual void UpdateMoveOperators() {
     
    190183      foreach (var generator in Operators.OfType<SingleObjectiveMoveGenerator>()) {
    191184        generator.EncodingParameter.ActualName = EncodingParameter.Name;
    192         generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
     185        //generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
    193186      }
    194187      foreach (var evaluator in Operators.OfType<SingleObjectiveMoveEvaluator>()) {
    195188        evaluator.EncodingParameter.ActualName = EncodingParameter.Name;
    196189        evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    197         evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
     190        //evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
    198191      }
    199192      foreach (var maker in Operators.OfType<SingleObjectiveMoveMaker>()) {
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiObjectiveAnalyzer.cs

    r11619 r11739  
    1313  [Item("Multi-objective Analyzer", "Calls the Analyze method of the problem definition.")]
    1414  [StorableClass]
    15   public class MultiObjectiveAnalyzer : SingleSuccessorOperator, IMultiObjectiveProgrammableProblemAnalyzer {
     15  public class MultiObjectiveAnalyzer : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator {
    1616    public bool EnabledByDefault { get { return true; } }
    17 
    18     public ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter {
    19       get { return (ILookupParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    20     }
    2117
    2218    public ILookupParameter<IEncoding> EncodingParameter {
     
    3228    }
    3329
     30    public Action<Individual[], double[][], ResultCollection> AnalyzeAction { get; set; }
     31
    3432    [StorableConstructor]
    3533    protected MultiObjectiveAnalyzer(bool deserializing) : base(deserializing) { }
     
    3735    public MultiObjectiveAnalyzer() {
    3836      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."));
    4037      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    4138      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
     
    4845
    4946    public override IOperation Apply() {
    50       var definition = ProblemDefinitionParameter.ActualValue;
    51       if (definition == null) throw new InvalidOperationException("Problem definition is null.");
    5247      var encoding = EncodingParameter.ActualValue;
    5348      var results = ResultsParameter.ActualValue;
     
    5853
    5954      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);
    6156      return base.Apply();
    6257    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiObjectiveEvaluator.cs

    r11619 r11739  
    3232  [Item("Multi-objective Evaluator", "Calls the Evaluate method of the problem definition and writes the return value into the scope.")]
    3333  [StorableClass]
    34   public class MultiObjectiveEvaluator : SingleSuccessorOperator, IMultiObjectiveProgrammableProblemEvaluator, IStochasticOperator {
     34  public class MultiObjectiveEvaluator : SingleSuccessorOperator, IMulitObjectiveEvaluationOperator, IStochasticOperator {
    3535
    3636    public ILookupParameter<IRandom> RandomParameter {
    3737      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    38     }
    39 
    40     public ILookupParameter<IMultiObjectiveProblemDefinition> ProblemDefinitionParameter {
    41       get { return (ILookupParameter<IMultiObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    4238    }
    4339
     
    5046    }
    5147
     48    public Func<Individual, IRandom, double[]> EvaluateFunc { get; set; }
     49
    5250    [StorableConstructor]
    5351    protected MultiObjectiveEvaluator(bool deserializing) : base(deserializing) { }
     
    5553    public MultiObjectiveEvaluator() {
    5654      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."));
    5855      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    5956      Parameters.Add(new LookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
     
    6663    public override IOperation Apply() {
    6764      var random = RandomParameter.ActualValue;
    68       var definition = ProblemDefinitionParameter.ActualValue;
    69       if (definition == null) throw new InvalidOperationException("Problem definition is null.");
    7065      var encoding = EncodingParameter.ActualValue;
    7166      var individual = encoding.GetIndividual(ExecutionContext.Scope);
    72       QualitiesParameter.ActualValue = new DoubleArray(definition.Evaluate(random, individual));
     67      QualitiesParameter.ActualValue = new DoubleArray(EvaluateFunc(individual, random));
    7368      return base.Apply();
    7469    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveAnalyzer.cs

    r11619 r11739  
    1313  [Item("Single-objective Analyzer", "Calls the script's Analyze method to be able to write into the results collection.")]
    1414  [StorableClass]
    15   public class SingleObjectiveAnalyzer : SingleSuccessorOperator, ISingleObjectiveProgrammableProblemAnalyzer {
     15  public sealed class SingleObjectiveAnalyzer : SingleSuccessorOperator, ISingleObjectiveAnalysisOperator, IAnalyzer {
    1616    public bool EnabledByDefault { get { return true; } }
    17 
    18     public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {
    19       get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    20     }
    2117
    2218    public ILookupParameter<IEncoding> EncodingParameter {
     
    3228    }
    3329
     30    public Action<Individual[], double[], ResultCollection> AnalyzeAction { get; set; }
     31
    3432    [StorableConstructor]
    35     protected SingleObjectiveAnalyzer(bool deserializing) : base(deserializing) { }
    36     protected SingleObjectiveAnalyzer(SingleObjectiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
     33    private SingleObjectiveAnalyzer(bool deserializing) : base(deserializing) { }
     34    private SingleObjectiveAnalyzer(SingleObjectiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
    3735    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."));
    4036      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    4137      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
     
    4844
    4945    public override IOperation Apply() {
    50       var definition = ProblemDefinitionParameter.ActualValue;
    51       if (definition == null) throw new InvalidOperationException("Problem definition is null");
    5246      var encoding = EncodingParameter.ActualValue;
    5347      var results = ResultsParameter.ActualValue;
     
    5852
    5953      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);
    6155      return base.Apply();
    6256    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveEvaluator.cs

    r11619 r11739  
    3232  [Item("Single-objective Evaluator", "Calls the script's Evaluate method to get the quality value of the parameter vector.")]
    3333  [StorableClass]
    34   public class SingleObjectiveEvaluator : SingleSuccessorOperator, ISingleObjectiveProgrammableProblemEvaluator, IStochasticOperator {
     34  public sealed class SingleObjectiveEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator, IStochasticOperator {
    3535
    3636    public ILookupParameter<IRandom> RandomParameter {
    3737      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    38     }
    39 
    40     public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {
    41       get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    4238    }
    4339
     
    5046    }
    5147
     48    public Func<Individual, IRandom, double> EvaluateFunc { get; set; }
     49
    5250    [StorableConstructor]
    53     protected SingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
    54     protected SingleObjectiveEvaluator(SingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
     51    private SingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
     52    private SingleObjectiveEvaluator(SingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
    5553    public SingleObjectiveEvaluator() {
    5654      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."));
    5855      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    5956      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
    6057    }
    6158
    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); }
    6560
    6661    public override IOperation Apply() {
    6762      var random = RandomParameter.ActualValue;
    68       var definition = ProblemDefinitionParameter.ActualValue;
    69       if (definition == null) throw new InvalidOperationException("Problem definition is null.");
    7063      var encoding = EncodingParameter.ActualValue;
    7164      var individual = encoding.GetIndividual(ExecutionContext.Scope);
    72       QualityParameter.ActualValue = new DoubleValue(definition.Evaluate(random, individual));
     65      QualityParameter.ActualValue = new DoubleValue(EvaluateFunc(individual, random));
    7366      return base.Apply();
    7467    }
  • 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
     22using System;
     23using System.Collections.Generic;
    224using System.Linq;
    325using HeuristicLab.Common;
     
    1234  [Item("Single-objective Improver", "Improves a solution by calling GetNeighbors and Evaluate of the corresponding problem definition.")]
    1335  [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 {
    1937    public ILookupParameter<IRandom> RandomParameter {
    2038      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    21     }
    22 
    23     public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {
    24       get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    2539    }
    2640
     
    4963    }
    5064
     65    public Func<Individual, IRandom, double> EvaluateFunc { get; set; }
     66    public Func<Individual, IRandom, IEnumerable<Individual>> GetNeighborsFunc { get; set; }
     67
    5168    [StorableConstructor]
    5269    private SingleObjectiveImprover(bool deserializing) : base(deserializing) { }
     
    5471    public SingleObjectiveImprover() {
    5572      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."));
    5773      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    5874      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
     
    6985    public override IOperation Apply() {
    7086      var random = RandomParameter.ActualValue;
    71       var definition = ProblemDefinitionParameter.ActualValue;
    72       if (definition == null) throw new InvalidOperationException("Problem definition is null.");
    7387      var encoding = EncodingParameter.ActualValue;
    7488      var maximize = MaximizationParameter.ActualValue.Value;
     
    7690      var sampleSize = SampleSizeParameter.ActualValue.Value;
    7791      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;
    7993
    8094      var count = 0;
     
    8296        Individual best = null;
    8397        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);
    86100          count++;
    87101          if (maximize && bestQuality > q || !maximize && bestQuality < q) continue;
     
    95109
    96110      LocalEvaluatedSolutionsParameter.ActualValue = new IntValue(count);
     111      QualityParameter.ActualValue = new DoubleValue(quality);
    97112      individual.Copy(ExecutionContext.Scope);
    98113      return base.Apply();
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveEvaluator.cs

    r11619 r11739  
    3232  [Item("Single-objective MoveEvaluator", "Evaluates a parameter vector that results from a move.")]
    3333  [StorableClass]
    34   public class SingleObjectiveMoveEvaluator : InstrumentedOperator, ISingleObjectiveMoveOperator, ISingleObjectiveMoveEvaluator, IStochasticOperator {
     34  public class SingleObjectiveMoveEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluationOperator, ISingleObjectiveMoveEvaluator, IStochasticOperator {
    3535
    3636    public ILookupParameter<IRandom> RandomParameter {
    3737      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    38     }
    39 
    40     public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {
    41       get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    4238    }
    4339
     
    5450    }
    5551
     52    public Func<Individual, IRandom, double> EvaluateFunc { get; set; }
     53
    5654    [StorableConstructor]
    5755    protected SingleObjectiveMoveEvaluator(bool deserializing) : base(deserializing) { }
     
    5957    public SingleObjectiveMoveEvaluator() {
    6058      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."));
    6259      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    6360      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the parameter vector."));
     
    6966    }
    7067
    71     public override IOperation InstrumentedApply() {
     68    public override IOperation Apply() {
    7269      var random = RandomParameter.ActualValue;
    73       var definition = ProblemDefinitionParameter.ActualValue;
    74       if (definition == null) throw new InvalidOperationException("Problem definition is null.");
    7570      var encoding = EncodingParameter.ActualValue;
    7671      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();
    7974    }
    8075  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveGenerator.cs

    r11619 r11739  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Globalization;
    2425using System.Linq;
     
    3435  [Item("Single-objective MoveGenerator", "Calls the GetNeighbors method of the problem definition to obtain the moves.")]
    3536  [StorableClass]
    36   public class SingleObjectiveMoveGenerator : InstrumentedOperator, ISingleObjectiveMoveOperator, IMultiMoveGenerator, IStochasticOperator {
    37 
     37  public class SingleObjectiveMoveGenerator : SingleSuccessorOperator, INeighborBasedOperator, IMultiMoveGenerator, IStochasticOperator {
    3838    public ILookupParameter<IRandom> RandomParameter {
    3939      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     
    4444    }
    4545
    46     public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {
    47       get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    48     }
    49 
    5046    public ILookupParameter<IEncoding> EncodingParameter {
    5147      get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; }
    5248    }
     49
     50    public Func<Individual, IRandom, IEnumerable<Individual>> GetNeighborsFunc { get; set; }
    5351
    5452    [StorableConstructor]
     
    5957      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    6058      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."));
    6259      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    6360    }
     
    6764    }
    6865
    69     public override IOperation InstrumentedApply() {
     66    public override IOperation Apply() {
    7067      var random = RandomParameter.ActualValue;
    71       var definition = ProblemDefinitionParameter.ActualValue;
    72       if (definition == null) throw new InvalidOperationException("Problem definition is null.");
    7368      var sampleSize = SampleSizeParameter.ActualValue.Value;
    7469      var encoding = EncodingParameter.ActualValue;
    7570      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();
    7772
    7873      var moveScopes = new Scope[nbhood.Count];
     
    8378      ExecutionContext.Scope.SubScopes.AddRange(moveScopes);
    8479
    85       return base.InstrumentedApply();
     80      return base.Apply();
    8681    }
    8782  }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveMaker.cs

    r11619 r11739  
    3232  [Item("Single-objective MoveMaker", "Applies a move.")]
    3333  [StorableClass]
    34   public class SingleObjectiveMoveMaker : InstrumentedOperator, ISingleObjectiveMoveOperator, IMoveMaker {
     34  public class SingleObjectiveMoveMaker : InstrumentedOperator, IMoveMaker {
    3535    public ILookupParameter<IEncoding> EncodingParameter {
    3636      get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; }
Note: See TracChangeset for help on using the changeset viewer.