Changeset 13345


Ignore:
Timestamp:
11/23/15 18:38:37 (4 years ago)
Author:
mkommend
Message:

#2521: refactored programmable problem

Location:
branches/ProblemRefactoring
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj

    r12470 r13345  
    9393    <Compile Include="ProblemDefinitionScriptView.Designer.cs">
    9494      <DependentUpon>ProblemDefinitionScriptView.cs</DependentUpon>
    95     </Compile>
    96     <Compile Include="MultiObjectiveProgrammableProblemView.cs">
    97       <SubType>UserControl</SubType>
    98     </Compile>
    99     <Compile Include="MultiObjectiveProgrammableProblemView.Designer.cs">
    100       <DependentUpon>MultiObjectiveProgrammableProblemView.cs</DependentUpon>
    10195    </Compile>
    10296    <Compile Include="SingleObjectiveProgrammableProblemView.cs">
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/ProblemDefinitionScriptView.cs

    r12012 r13345  
    2323using System.Drawing;
    2424using HeuristicLab.MainForm;
     25using HeuristicLab.Optimization;
    2526using HeuristicLab.Scripting.Views;
    2627
     
    5253      try {
    5354        base.Compile();
    54       } catch (ProblemDefinitionScriptException e) {
     55      }
     56      catch (ProblemDefinitionScriptException e) {
    5557        PluginInfrastructure.ErrorHandling.ShowErrorDialog(e);
    5658        return false;
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable.Views/3.3/SingleObjectiveProgrammableProblemView.cs

    r12012 r13345  
    2828namespace HeuristicLab.Problems.Programmable.Views {
    2929  [View("Single-Objective Scriptable Problem View")]
    30   [Content(typeof(SingleObjectiveProgrammableProblem), true)]
     30  [Content(typeof(IProgrammableProblem), true)]
    3131  public partial class SingleObjectiveProgrammableProblemView : ItemView {
    3232    protected ViewHost ScriptView;
    3333
    34     public new SingleObjectiveProgrammableProblem Content {
    35       get { return (SingleObjectiveProgrammableProblem)base.Content; }
     34    public new IProgrammableProblem Content {
     35      get { return (IProgrammableProblem)base.Content; }
    3636      set { base.Content = value; }
    3737    }
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs

    r12012 r13345  
    2424
    2525namespace HeuristicLab.Problems.Programmable {
    26   public abstract class CompiledProblemDefinition : IProblemDefinition {
    27     private IEncoding encoding;
    28     public IEncoding Encoding {
     26  public abstract class CompiledProblemDefinition<TEncoding, TSolution> : IProblemDefinition<TEncoding, TSolution>
     27    where TEncoding : class, IEncoding<TSolution>
     28    where TSolution : class, ISolution {
     29    private TEncoding encoding;
     30    public TEncoding Encoding {
    2931      get { return encoding; }
    30       protected set {
     32      internal set {
    3133        if (value == null) throw new ArgumentNullException("The encoding must not be null.");
    3234        encoding = value;
     
    3840
    3941    protected CompiledProblemDefinition() { }
    40     protected CompiledProblemDefinition(IEncoding encoding)
     42    protected CompiledProblemDefinition(TEncoding encoding)
    4143      : base() {
    4244      Encoding = encoding;
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj

    r12724 r13345  
    8686  </ItemGroup>
    8787  <ItemGroup>
    88     <Compile Include="MultiObjectiveProgrammableProblem.cs" />
     88    <Compile Include="CompiledProblemDefinition.cs">
     89      <SubType>Code</SubType>
     90    </Compile>
     91    <Compile Include="Interfaces\IProgrammableProblem.cs" />
     92    <Compile Include="ProblemDefinitionScript.cs">
     93      <SubType>Code</SubType>
     94    </Compile>
    8995    <Compile Include="ProblemDefinitionScriptException.cs" />
    90     <Compile Include="Templates\CompiledMultiObjectiveProblemDefinition.cs" />
    91     <Compile Include="Templates\CompiledSingleObjectiveProblemDefinition.cs" />
     96    <Compile Include="SingleObjectiveProgrammableProblems.cs" />
     97    <Content Include="Templates\CompiledSingleObjectiveProblemDefinition.cs" />
    9298    <Compile Include="Templates\ScriptTemplates.Designer.cs">
    9399      <AutoGen>True</AutoGen>
     
    95101      <DependentUpon>ScriptTemplates.resx</DependentUpon>
    96102    </Compile>
    97     <Compile Include="CompiledProblemDefinition.cs" />
    98     <Compile Include="ProblemDefinitionScript.cs" />
    99103    <Compile Include="SingleObjectiveProgrammableProblem.cs" />
    100     <Compile Include="MultiObjectiveProblemDefinitionScript.cs" />
    101104    <Compile Include="SingleObjectiveProblemDefinitionScript.cs" />
    102105    <EmbeddedResource Include="Templates\ScriptTemplates.resx">
     
    145148      <Name>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</Name>
    146149    </ProjectReference>
    147     <ProjectReference Include="..\..\HeuristicLab.Encodings.IntegerVectorEncoding\3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj">
    148       <Project>{ddfb14dd-2a85-493c-a52d-e69729bbaeb0}</Project>
    149       <Name>HeuristicLab.Encodings.IntegerVectorEncoding-3.3</Name>
    150     </ProjectReference>
    151     <ProjectReference Include="..\..\HeuristicLab.Encodings.LinearLinkageEncoding\3.3\HeuristicLab.Encodings.LinearLinkageEncoding-3.3.csproj">
    152       <Project>{be698769-975a-429e-828c-72bb2b6182c8}</Project>
    153       <Name>HeuristicLab.Encodings.LinearLinkageEncoding-3.3</Name>
    154       <Private>False</Private>
    155     </ProjectReference>
    156     <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj">
    157       <Project>{dbecb8b0-b166-4133-baf1-ed67c3fd7fca}</Project>
    158       <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name>
    159     </ProjectReference>
    160     <ProjectReference Include="..\..\HeuristicLab.Encodings.RealVectorEncoding\3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj">
    161       <Project>{bb6d334a-4bb6-4674-9883-31a6ebb32cab}</Project>
    162       <Name>HeuristicLab.Encodings.RealVectorEncoding-3.3</Name>
    163     </ProjectReference>
    164     <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
    165       <Project>{06d4a186-9319-48a0-bade-a2058d462eea}</Project>
    166       <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>
    167       <Private>False</Private>
    168     </ProjectReference>
    169150    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
    170151      <Project>{23da7ff4-d5b8-41b6-aa96-f0561d24f3ee}</Project>
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs

    r13218 r13345  
    3030
    3131namespace HeuristicLab.Problems.Programmable {
    32   [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3332  [StorableClass]
    34   public abstract class ProblemDefinitionScript : Script, IProblemDefinition {
    35     protected bool SuppressEvents { get; set; }
    36 
     33  public abstract class ProblemDefinitionScript : Script {
    3734    [Storable]
    3835    private VariableStore variableStore;
     
    4138    }
    4239
    43     [Storable]
    44     private bool codeChanged;
    45 
    4640    [StorableConstructor]
    4741    protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     
    4943      : base(original, cloner) {
    5044      variableStore = cloner.Clone(original.variableStore);
    51       codeChanged = original.codeChanged;
    5245    }
    5346    protected ProblemDefinitionScript()
     
    5952      variableStore = new VariableStore();
    6053    }
     54  }
    6155
    62     IEncoding IProblemDefinition.Encoding {
    63       get { return CompiledProblemDefinition.Encoding; }
     56  [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
     57  [StorableClass]
     58  public abstract class ProblemDefinitionScript<TEncoding, TSolution> : ProblemDefinitionScript, IProblemDefinition<TEncoding, TSolution>
     59    where TEncoding : class, IEncoding<TSolution>
     60    where TSolution : class, ISolution {
     61
     62    [Storable]
     63    private bool codeChanged;
     64
     65    [Storable]
     66    private TEncoding encoding;
     67    internal TEncoding Encoding {
     68      get { return encoding; }
     69      set { encoding = value; }
     70    }
     71
     72    TEncoding IProblemDefinition<TEncoding, TSolution>.Encoding {
     73      get { return Encoding; }
     74    }
     75
     76    internal void Initialize() {
     77      CompiledProblemDefinition.Initialize();
     78    }
     79
     80    [StorableConstructor]
     81    protected ProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     82    protected ProblemDefinitionScript(ProblemDefinitionScript<TEncoding, TSolution> original, Cloner cloner)
     83      : base(original, cloner) {
     84      codeChanged = original.codeChanged;
     85    }
     86    protected ProblemDefinitionScript()
     87      : base() {
     88    }
     89    protected ProblemDefinitionScript(string code)
     90      : base(code) {
    6491    }
    6592
    6693    private readonly object compileLock = new object();
    67     private volatile IProblemDefinition compiledProblemDefinition;
    68     protected IProblemDefinition CompiledProblemDefinition {
     94    private volatile CompiledProblemDefinition<TEncoding, TSolution> compiledProblemDefinition;
     95    protected CompiledProblemDefinition<TEncoding, TSolution> CompiledProblemDefinition {
    6996      get {
    7097        // double checked locking pattern
     
    88115      var assembly = base.Compile();
    89116      var types = assembly.GetTypes();
    90       if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
     117      if (!types.Any(x => typeof(CompiledProblemDefinition<TEncoding, TSolution>).IsAssignableFrom(x)))
    91118        throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition.");
    92       if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
     119      if (types.Count(x => typeof(CompiledProblemDefinition<TEncoding, TSolution>).IsAssignableFrom(x)) > 1)
    93120        throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed.");
    94121
    95       CompiledProblemDefinition inst;
     122      CompiledProblemDefinition<TEncoding, TSolution> inst;
    96123      try {
    97         inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
    98       } catch (Exception e) {
     124        inst = (CompiledProblemDefinition<TEncoding, TSolution>)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition<TEncoding, TSolution>).IsAssignableFrom(x)));
     125      }
     126      catch (Exception e) {
    99127        compiledProblemDefinition = null;
    100128        throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
     
    103131      try {
    104132        inst.vars = new Variables(VariableStore);
    105         inst.Initialize();
    106       } catch (Exception e) {
     133        inst.Encoding = encoding;
     134      }
     135      catch (Exception e) {
    107136        compiledProblemDefinition = null;
    108137        throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
     
    112141        compiledProblemDefinition = inst;
    113142        if (fireChanged) OnProblemDefinitionChanged();
    114       } catch (Exception e) {
     143      }
     144      catch (Exception e) {
    115145        compiledProblemDefinition = null;
    116146        throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e);
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs

    r13218 r13345  
    2929  [Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3030  [StorableClass]
    31   public sealed class SingleObjectiveProblemDefinitionScript : ProblemDefinitionScript, ISingleObjectiveProblemDefinition, IStorableContent {
     31  public class SingleObjectiveProblemDefinitionScript<TEncoding, TSolution> : ProblemDefinitionScript<TEncoding, TSolution>, ISingleObjectiveProblemDefinition<TEncoding, TSolution>, IStorableContent
     32    where TEncoding : class, IEncoding<TSolution>
     33    where TSolution : class, ISolution {
    3234    public string Filename { get; set; }
    3335
    34     private new ISingleObjectiveProblemDefinition CompiledProblemDefinition {
    35       get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; }
     36    protected new ISingleObjectiveProblemDefinition<TEncoding, TSolution> CompiledProblemDefinition {
     37      get { return (ISingleObjectiveProblemDefinition<TEncoding, TSolution>)base.CompiledProblemDefinition; }
    3638    }
    3739
    3840    [StorableConstructor]
    39     private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
    40     private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
    41     public SingleObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledSingleObjectiveProblemDefinition) { }
     41    protected SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     42    protected SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript<TEncoding, TSolution> original, Cloner cloner) : base(original, cloner) { }
     43    public SingleObjectiveProblemDefinitionScript(string codeTemplate) : base(codeTemplate) { }
     44    public SingleObjectiveProblemDefinitionScript() { }
    4245
    4346    public override IDeepCloneable Clone(Cloner cloner) {
    44       return new SingleObjectiveProblemDefinitionScript(this, cloner);
     47      return new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>(this, cloner);
    4548    }
    4649
    47     bool ISingleObjectiveProblemDefinition.Maximization {
     50    bool ISingleObjectiveProblemDefinition<TEncoding, TSolution>.Maximization {
    4851      get { return CompiledProblemDefinition.Maximization; }
    4952    }
    5053
    51     double ISingleObjectiveProblemDefinition.Evaluate(Individual individual, IRandom random) {
     54    double ISingleObjectiveProblemDefinition<TEncoding, TSolution>.Evaluate(TSolution individual, IRandom random) {
    5255      return CompiledProblemDefinition.Evaluate(individual, random);
    5356    }
    5457
    55     void ISingleObjectiveProblemDefinition.Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     58    void ISingleObjectiveProblemDefinition<TEncoding, TSolution>.Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    5659      CompiledProblemDefinition.Analyze(individuals, qualities, results, random);
    5760    }
    58     IEnumerable<Individual> ISingleObjectiveProblemDefinition.GetNeighbors(Individual individual, IRandom random) {
     61    IEnumerable<TSolution> ISingleObjectiveProblemDefinition<TEncoding, TSolution>.GetNeighbors(TSolution individual, IRandom random) {
    5962      return CompiledProblemDefinition.GetNeighbors(individual, random);
    6063    }
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r13336 r13345  
    3333namespace HeuristicLab.Problems.Programmable {
    3434  [Item("Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed with a script.")]
    35   [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
    3635  [StorableClass]
    37   public sealed class SingleObjectiveProgrammableProblem : SingleObjectiveProblem<IEncoding>, IProgrammableItem {
     36  public class SingleObjectiveProgrammableProblem<TEncoding, TSolution> : SingleObjectiveProblem<TEncoding, TSolution>, IProgrammableItem, IProgrammableProblem
     37    where TEncoding : class, IEncoding<TSolution>
     38    where TSolution : class, ISolution {
    3839    public static new Image StaticItemImage {
    3940      get { return VSImageLibrary.Script; }
    4041    }
    4142
    42     private FixedValueParameter<SingleObjectiveProblemDefinitionScript> SingleObjectiveProblemScriptParameter {
    43       get { return (FixedValueParameter<SingleObjectiveProblemDefinitionScript>)Parameters["ProblemScript"]; }
     43    private FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>> SingleObjectiveProblemScriptParameter {
     44      get { return (FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>>)Parameters["ProblemScript"]; }
    4445    }
    4546
    46     public SingleObjectiveProblemDefinitionScript ProblemScript {
     47    public SingleObjectiveProblemDefinitionScript<TEncoding, TSolution> ProblemScript {
    4748      get { return SingleObjectiveProblemScriptParameter.Value; }
    4849    }
    4950
    50     public ISingleObjectiveProblemDefinition ProblemDefinition {
     51    public ISingleObjectiveProblemDefinition<TEncoding, TSolution> ProblemDefinition {
    5152      get { return SingleObjectiveProblemScriptParameter.Value; }
    5253    }
    5354
    54     private SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
     55    protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem<TEncoding, TSolution> original, Cloner cloner)
    5556      : base(original, cloner) {
    5657      RegisterEvents();
    5758    }
    58     public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem(this, cloner); }
     59    public override IDeepCloneable Clone(Cloner cloner) { return new SingleObjectiveProgrammableProblem<TEncoding, TSolution>(this, cloner); }
    5960
    6061    [StorableConstructor]
    61     private SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
    62     public SingleObjectiveProgrammableProblem()
     62    protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
     63    public SingleObjectiveProgrammableProblem(string codeTemplate)
    6364      : base() {
    64       Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
     65      Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>(codeTemplate) { Name = Name, Encoding = Encoding }));
    6566      Operators.Add(new BestScopeSolutionAnalyzer());
    6667      RegisterEvents();
     
    7980      Parameters.Remove("Maximization");
    8081      Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
     82      ProblemScript.Initialize();
    8183
    82       Encoding = ProblemDefinition.Encoding;
    8384      OnOperatorsChanged();
    8485      OnReset();
     
    8687
    8788    public override bool Maximization {
    88       get { return Parameters.ContainsKey("ProblemScript") ? ProblemDefinition.Maximization : false; }
     89      get { return Parameters.ContainsKey("ProblemScript") && ProblemDefinition.Maximization; }
    8990    }
    9091
    91     public override double Evaluate(Individual individual, IRandom random) {
     92    public override double Evaluate(TSolution individual, IRandom random) {
    9293      return ProblemDefinition.Evaluate(individual, random);
    9394    }
    9495
    95     public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     96    public override void Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    9697      ProblemDefinition.Analyze(individuals, qualities, results, random);
    9798    }
    98     public override IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     99    public override IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random) {
    99100      return ProblemDefinition.GetNeighbors(individual, random);
    100101    }
     102
     103    #region IProgrammableProblem Members
     104    Scripting.Script IProgrammableProblem.ProblemScript {
     105      get { return ProblemScript; }
     106    }
     107    #endregion
    101108  }
    102109}
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition.cs

    r12731 r13345  
    55using HeuristicLab.Core;
    66using HeuristicLab.Data;
    7 using HeuristicLab.Encodings.BinaryVectorEncoding;
    8 using HeuristicLab.Encodings.IntegerVectorEncoding;
    9 using HeuristicLab.Encodings.RealVectorEncoding;
    10 using HeuristicLab.Encodings.PermutationEncoding;
    11 using HeuristicLab.Encodings.LinearLinkageEncoding;
    12 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     7using {0}
    138using HeuristicLab.Optimization;
    149using HeuristicLab.Problems.Programmable;
    1510
    1611namespace HeuristicLab.Problems.Programmable {
    17   public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
     12  public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition<{1}, {2}>, ISingleObjectiveProblemDefinition<{1}, {2}> {
    1813    public bool Maximization { get { return false; } }
    1914
    2015    public override void Initialize() {
    2116      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    22       // Define the solution encoding which can also consist of multiple vectors, examples below
    23       //Encoding = new BinaryVectorEncoding("b", length: 5);
    24       //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 2);
    25       //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0);
    26       //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
    27       //Encoding = new LinearLinkageEncoding("l", length: 5);
    28       //Encoding = new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12);
    29       // The encoding can also be a combination
    30       //Encoding = new MultiEncoding()
    31       //.Add(new BinaryVectorEncoding("b", length: 5))
    32       //.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4))
    33       //.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0))
    34       //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
    35       //.Add(new LinearLinkageEncoding("l", length: 5))
    36       //.Add(new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12))
    37       ;
     17      // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property
    3818      // Add additional initialization code e.g. private variables that you need for evaluating
    3919    }
    4020
    41     public double Evaluate(Individual individual, IRandom random) {
     21    public double Evaluate({2} individual, IRandom random) {
    4222      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    4323      var quality = 0.0;
    44       //quality = individual.RealVector("r").Sum(x => x * x);
    4524      return quality;
    4625    }
    4726
    48     public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     27    public void Analyze({2}[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    4928      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    5029      // Write or update results given the range of vectors and resulting qualities
     
    5534
    5635      //if (!results.ContainsKey("Best Solution")) {
    57       //  results.Add(new Result("Best Solution", typeof(RealVector)));
     36      //  results.Add(new Result("Best Solution", typeof({20)));
    5837      //}
    59       //results["Best Solution"].Value = (IItem)best.RealVector("r").Clone();
     38      //results["Best Solution"].Value = (IItem)best.Clone();
    6039    }
    6140
    62     public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     41    public IEnumerable<{2}> GetNeighbors({2} individual, IRandom random) {
    6342      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    6443      // Create new vectors, based on the given one that represent small changes
     
    6746        // Algorithm will draw only a finite amount of samples
    6847        // Change to a for-loop to return a concrete amount of neighbors
    69         var neighbor = individual.Copy();
    70         // For instance, perform a single bit-flip in a binary parameter
    71         //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
    72         //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
     48        var neighbor = ({2})individual.Clone();
     49        // modify the solution specified as neighbor
    7350        yield return neighbor;
    7451      }
Note: See TracChangeset for help on using the changeset viewer.