Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/15 21:07:22 (9 years ago)
Author:
mkommend
Message:

#2521: Refactored single-objective programmable problem.

Location:
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3
Files:
7 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs

    r13345 r13348  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Threading;
     25using HeuristicLab.Core;
    2326using HeuristicLab.Optimization;
    2427
     
    4548    }
    4649  }
     50
     51  public abstract class CompiledSingleObjectiveProblemDefinition<TEncoding, TSolution> : CompiledProblemDefinition<TEncoding, TSolution>, ISingleObjectiveProblemDefinition<TEncoding, TSolution>
     52    where TEncoding : class, IEncoding<TSolution>
     53    where TSolution : class, ISolution {
     54
     55    protected CompiledSingleObjectiveProblemDefinition() : base() { }
     56
     57    protected CompiledSingleObjectiveProblemDefinition(TEncoding encoding)
     58      : base(encoding) { }
     59
     60    #region ISingleObjectiveProblemDefinition<TEncoding,TSolution> Members
     61    public abstract bool Maximization { get; }
     62    public abstract double Evaluate(TSolution individual, IRandom random);
     63    public abstract void Analyze(TSolution[] individuals, double[] qualities, ResultCollection results, IRandom random);
     64    public abstract IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random);
     65    #endregion
     66  }
     67
     68  public abstract class CompiledMultiObjectiveProblemDefinition<TEncoding, TSolution> : CompiledProblemDefinition<TEncoding, TSolution>, IMultiObjectiveProblemDefinition<TEncoding, TSolution>
     69    where TEncoding : class, IEncoding<TSolution>
     70    where TSolution : class, ISolution {
     71
     72    protected CompiledMultiObjectiveProblemDefinition() : base() { }
     73
     74    protected CompiledMultiObjectiveProblemDefinition(TEncoding encoding)
     75      : base(encoding) { }
     76
     77    #region ISingleObjectiveProblemDefinition<TEncoding,TSolution> Members
     78    public abstract bool[] Maximization { get; }
     79    public abstract double[] Evaluate(TSolution individual, IRandom random);
     80    public abstract void Analyze(TSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random);
     81    public abstract IEnumerable<TSolution> GetNeighbors(TSolution individual, IRandom random);
     82    #endregion
     83  }
    4784}
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj

    r13345 r13348  
    9595    <Compile Include="ProblemDefinitionScriptException.cs" />
    9696    <Compile Include="SingleObjectiveProgrammableProblems.cs" />
    97     <Content Include="Templates\CompiledSingleObjectiveProblemDefinition.cs" />
     97    <Content Include="Templates\CompiledSingleObjectiveProblemDefinition_Template.cs" />
    9898    <Compile Include="Templates\ScriptTemplates.Designer.cs">
    9999      <AutoGen>True</AutoGen>
     
    104104    <Compile Include="SingleObjectiveProblemDefinitionScript.cs" />
    105105    <EmbeddedResource Include="Templates\ScriptTemplates.resx">
    106       <Generator>ResXFileCodeGenerator</Generator>
     106      <Generator>PublicResXFileCodeGenerator</Generator>
    107107      <LastGenOutput>ScriptTemplates.Designer.cs</LastGenOutput>
     108      <SubType>Designer</SubType>
    108109    </EmbeddedResource>
    109110    <None Include="HeuristicLab.snk" />
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs

    r13345 r13348  
    8282    protected ProblemDefinitionScript(ProblemDefinitionScript<TEncoding, TSolution> original, Cloner cloner)
    8383      : base(original, cloner) {
     84      encoding = cloner.Clone(original.encoding);
    8485      codeChanged = original.codeChanged;
    8586    }
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r13345 r13348  
    3737    where TEncoding : class, IEncoding<TSolution>
    3838    where TSolution : class, ISolution {
     39    protected static readonly string ENCODING_NAMESPACE = "ENCODING_NAMESPACE";
     40    protected static readonly string ENCODING_CLASS = "ENCODING_CLASS";
     41    protected static readonly string SOLUTION_CLASS = "SOLUTION_CLASS";
     42
    3943    public static new Image StaticItemImage {
    4044      get { return VSImageLibrary.Script; }
     
    6165    [StorableConstructor]
    6266    protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
    63     public SingleObjectiveProgrammableProblem(string codeTemplate)
     67    public SingleObjectiveProgrammableProblem()
    6468      : base() {
    65       Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>(codeTemplate) { Name = Name, Encoding = Encoding }));
     69      Parameters.Add(new FixedValueParameter<SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>>("ProblemScript", "Defines the problem.", new SingleObjectiveProblemDefinitionScript<TEncoding, TSolution>() { Name = Name, Encoding = Encoding }));
    6670      Operators.Add(new BestScopeSolutionAnalyzer());
    6771      RegisterEvents();
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblems.cs

    r13345 r13348  
    3636    private SingleObjectiveBinaryVectorProgrammableProblem(bool deserializing) : base(deserializing) { }
    3737    private SingleObjectiveBinaryVectorProgrammableProblem(SingleObjectiveBinaryVectorProgrammableProblem original, Cloner cloner) : base(original, cloner) { }
     38
    3839    public SingleObjectiveBinaryVectorProgrammableProblem()
    39       : base(string.Format(ScriptTemplates.CompiledSingleObjectiveProblemDefinition, "HeuristicLab.Encodings.BinaryVectorEncoding", "BinaryVectorEncoding", "BinaryVector")) { }
     40      : base() {
     41      var codeTemplate = ScriptTemplates.CompiledSingleObjectiveProblemDefinition_Template;
     42      codeTemplate = codeTemplate.Replace(ENCODING_NAMESPACE, "HeuristicLab.Encodings.BinaryVectorEncoding");
     43      codeTemplate = codeTemplate.Replace(ENCODING_CLASS, "BinaryVectorEncoding");
     44      codeTemplate = codeTemplate.Replace(SOLUTION_CLASS, "BinaryVector");
     45      ProblemScript.Code = codeTemplate;
     46    }
     47
    4048
    4149    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition_Template.cs

    r13347 r13348  
    55using HeuristicLab.Core;
    66using HeuristicLab.Data;
    7 using {0}
     7using ENCODING_NAMESPACE;
    88using HeuristicLab.Optimization;
    99using HeuristicLab.Problems.Programmable;
    1010
    1111namespace HeuristicLab.Problems.Programmable {
    12   public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition<{1}, {2}>, ISingleObjectiveProblemDefinition<{1}, {2}> {
    13     public bool Maximization { get { return false; } }
     12  public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition<ENCODING_CLASS, SOLUTION_CLASS> {
     13    public override bool Maximization { get { return false; } }
    1414
    1515    public override void Initialize() {
     
    1919    }
    2020
    21     public double Evaluate({2} individual, IRandom random) {
     21    public override double Evaluate(SOLUTION_CLASS solution, IRandom random) {
    2222      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    2323      var quality = 0.0;
     
    2525    }
    2626
    27     public void Analyze({2}[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     27    public override void Analyze(SOLUTION_CLASS[] solution, double[] qualities, ResultCollection results, IRandom random) {
    2828      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    2929      // Write or update results given the range of vectors and resulting qualities
     
    3434
    3535      //if (!results.ContainsKey("Best Solution")) {
    36       //  results.Add(new Result("Best Solution", typeof({20)));
     36      //  results.Add(new Result("Best Solution", typeof(SOLUTION_CLASS)));
    3737      //}
    3838      //results["Best Solution"].Value = (IItem)best.Clone();
    3939    }
    4040
    41     public IEnumerable<{2}> GetNeighbors({2} individual, IRandom random) {
     41    public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS individual, IRandom random) {
    4242      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    4343      // Create new vectors, based on the given one that represent small changes
     
    4646        // Algorithm will draw only a finite amount of samples
    4747        // Change to a for-loop to return a concrete amount of neighbors
    48         var neighbor = ({2})individual.Clone();
     48        var neighbor = (SOLUTION_CLASS)individual.Clone();
    4949        // modify the solution specified as neighbor
    5050        yield return neighbor;
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/ScriptTemplates.Designer.cs

    r11949 r13348  
    22// <auto-generated>
    33//     This code was generated by a tool.
    4 //     Runtime Version:4.0.30319.18444
     4//     Runtime Version:4.0.30319.34209
    55//
    66//     Changes to this file may cause incorrect behavior and will be lost if
     
    1010
    1111namespace HeuristicLab.Problems.Programmable {
    12     using System;
    13    
    14    
     12  using System;
     13
     14
     15  /// <summary>
     16  ///   A strongly-typed resource class, for looking up localized strings, etc.
     17  /// </summary>
     18  // This class was auto-generated by the StronglyTypedResourceBuilder
     19  // class via a tool like ResGen or Visual Studio.
     20  // To add or remove a member, edit your .ResX file then rerun ResGen
     21  // with the /str option, or rebuild your VS project.
     22  [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
     23  [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     24  [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
     25  public class ScriptTemplates {
     26
     27    private static global::System.Resources.ResourceManager resourceMan;
     28
     29    private static global::System.Globalization.CultureInfo resourceCulture;
     30
     31    [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
     32    internal ScriptTemplates() {
     33    }
     34
    1535    /// <summary>
    16     ///   A strongly-typed resource class, for looking up localized strings, etc.
     36    ///   Returns the cached ResourceManager instance used by this class.
    1737    /// </summary>
    18     // This class was auto-generated by the StronglyTypedResourceBuilder
    19     // class via a tool like ResGen or Visual Studio.
    20     // To add or remove a member, edit your .ResX file then rerun ResGen
    21     // with the /str option, or rebuild your VS project.
    22     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    23     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    24     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    25     internal class ScriptTemplates {
    26        
    27         private static global::System.Resources.ResourceManager resourceMan;
    28        
    29         private static global::System.Globalization.CultureInfo resourceCulture;
    30        
    31         [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    32         internal ScriptTemplates() {
     38    [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
     39    public static global::System.Resources.ResourceManager ResourceManager {
     40      get {
     41        if (object.ReferenceEquals(resourceMan, null)) {
     42          global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HeuristicLab.Problems.Programmable.Templates.ScriptTemplates", typeof(ScriptTemplates).Assembly);
     43          resourceMan = temp;
    3344        }
    34        
    35         /// <summary>
    36         ///   Returns the cached ResourceManager instance used by this class.
    37         /// </summary>
    38         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    39         internal static global::System.Resources.ResourceManager ResourceManager {
    40             get {
    41                 if (object.ReferenceEquals(resourceMan, null)) {
    42                     global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HeuristicLab.Problems.Programmable.Templates.ScriptTemplates", typeof(ScriptTemplates).Assembly);
    43                     resourceMan = temp;
    44                 }
    45                 return resourceMan;
    46             }
    47         }
    48        
    49         /// <summary>
    50         ///   Overrides the current thread's CurrentUICulture property for all
    51         ///   resource lookups using this strongly typed resource class.
    52         /// </summary>
    53         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    54         internal static global::System.Globalization.CultureInfo Culture {
    55             get {
    56                 return resourceCulture;
    57             }
    58             set {
    59                 resourceCulture = value;
    60             }
    61         }
    62        
    63         /// <summary>
    64         ///   Looks up a localized string similar to using System;
    65         ///using System.Linq;
    66         ///using System.Collections.Generic;
    67         ///using HeuristicLab.Common;
    68         ///using HeuristicLab.Core;
    69         ///using HeuristicLab.Data;
    70         ///using HeuristicLab.Encodings.PermutationEncoding;
    71         ///using HeuristicLab.Optimization;
    72         ///using HeuristicLab.Problems.Programmable;
    73         ///
    74         ///namespace HeuristicLab.Problems.Programmable {
    75         ///  public class CompiledMultiObjectiveProblemDefinition : CompiledProblemDefinition, IMultiObjectiveProblemDefinition {
    76         ///    public bool[] Maximization { get { return new[] { false, fal [rest of string was truncated]&quot;;.
    77         /// </summary>
    78         internal static string CompiledMultiObjectiveProblemDefinition {
    79             get {
    80                 return ResourceManager.GetString("CompiledMultiObjectiveProblemDefinition", resourceCulture);
    81             }
    82         }
    83        
    84         /// <summary>
    85         ///   Looks up a localized string similar to using System;
    86         ///using System.Linq;
    87         ///using System.Collections.Generic;
    88         ///using HeuristicLab.Common;
    89         ///using HeuristicLab.Core;
    90         ///using HeuristicLab.Data;
    91         ///using HeuristicLab.Encodings.PermutationEncoding;
    92         ///using HeuristicLab.Optimization;
    93         ///using HeuristicLab.Problems.Programmable;
    94         ///
    95         ///namespace HeuristicLab.Problems.Programmable {
    96         ///  public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
    97         ///    public bool Maximization { get { return false; } }
    98         ///
    99         ///     [rest of string was truncated]&quot;;.
    100         /// </summary>
    101         internal static string CompiledSingleObjectiveProblemDefinition {
    102             get {
    103                 return ResourceManager.GetString("CompiledSingleObjectiveProblemDefinition", resourceCulture);
    104             }
    105         }
     45        return resourceMan;
     46      }
    10647    }
     48
     49    /// <summary>
     50    ///   Overrides the current thread's CurrentUICulture property for all
     51    ///   resource lookups using this strongly typed resource class.
     52    /// </summary>
     53    [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
     54    public static global::System.Globalization.CultureInfo Culture {
     55      get {
     56        return resourceCulture;
     57      }
     58      set {
     59        resourceCulture = value;
     60      }
     61    }
     62
     63    /// <summary>
     64    ///   Looks up a localized string similar to using System;
     65    ///using System.Linq;
     66    ///using System.Collections.Generic;
     67    ///using HeuristicLab.Common;
     68    ///using HeuristicLab.Core;
     69    ///using HeuristicLab.Data;
     70    ///using HeuristicLab.Encodings.BinaryVectorEncoding;
     71    ///using HeuristicLab.Encodings.IntegerVectorEncoding;
     72    ///using HeuristicLab.Encodings.RealVectorEncoding;
     73    ///using HeuristicLab.Encodings.PermutationEncoding;
     74    ///using HeuristicLab.Encodings.LinearLinkageEncoding;
     75    ///using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     76    ///using HeuristicLab.Optimization;
     77    ///using H [rest of string was truncated]&quot;;.
     78    /// </summary>
     79    public static string CompiledMultiObjectiveProblemDefinition_Template {
     80      get {
     81        return ResourceManager.GetString("CompiledMultiObjectiveProblemDefinition_Template", resourceCulture);
     82      }
     83    }
     84
     85    /// <summary>
     86    ///   Looks up a localized string similar to using System;
     87    ///using System.Linq;
     88    ///using System.Collections.Generic;
     89    ///using HeuristicLab.Common;
     90    ///using HeuristicLab.Core;
     91    ///using HeuristicLab.Data;
     92    ///using ENCODING_NAMESPACE;
     93    ///using HeuristicLab.Optimization;
     94    ///using HeuristicLab.Problems.Programmable;
     95    ///
     96    ///namespace HeuristicLab.Problems.Programmable {
     97    ///  public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition&lt;ENCODING_CLASS, SOLUTION_CLASS&gt; {
     98    ///    public override bool Maximization { get { return false; } }
     99    ///
     100    ///    pub [rest of string was truncated]&quot;;.
     101    /// </summary>
     102    public static string CompiledSingleObjectiveProblemDefinition_Template {
     103      get {
     104        return ResourceManager.GetString("CompiledSingleObjectiveProblemDefinition_Template", resourceCulture);
     105      }
     106    }
     107  }
    107108}
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/ScriptTemplates.resx

    r11753 r13348  
    119119  </resheader>
    120120  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    121   <data name="CompiledMultiObjectiveProblemDefinition" type="System.Resources.ResXFileRef, System.Windows.Forms">
    122     <value>CompiledMultiObjectiveProblemDefinition.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
     121  <data name="CompiledMultiObjectiveProblemDefinition_Template" type="System.Resources.ResXFileRef, System.Windows.Forms">
     122    <value>CompiledMultiObjectiveProblemDefinition_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
    123123  </data>
    124   <data name="CompiledSingleObjectiveProblemDefinition" type="System.Resources.ResXFileRef, System.Windows.Forms">
    125     <value>CompiledSingleObjectiveProblemDefinition.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
     124  <data name="CompiledSingleObjectiveProblemDefinition_Template" type="System.Resources.ResXFileRef, System.Windows.Forms">
     125    <value>CompiledSingleObjectiveProblemDefinition_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
    126126  </data>
    127127</root>
Note: See TracChangeset for help on using the changeset viewer.