Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13183


Ignore:
Timestamp:
11/16/15 18:55:07 (9 years ago)
Author:
pfleck
Message:

#1674

  • Added a SupportScript for the MultiObjectiveExternalEvaluationProblem.
  • Extracted code from the SingleObjectiveOptimizationSupportScript into the OptimizationSupportScript to reuse code for the MultiObjectiveOptimizationSupportScript.
Location:
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4
Files:
1 added
5 edited
3 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/HeuristicLab.Problems.ExternalEvaluation-3.4.csproj

    r13180 r13183  
    135135    <Compile Include="Drivers\EvaluationTCPChannel.cs" />
    136136    <Compile Include="Interfaces\IExternalEvaluationProblem.cs" />
     137    <Compile Include="Interfaces\IMultiObjectiveOptimizationSupport.cs" />
    137138    <Compile Include="MultiObjectiveExternalEvaluationProblem.cs" />
    138139    <Compile Include="ExternalEvaluationProblem.cs" />
     
    143144    <Compile Include="Plugin.cs" />
    144145    <Compile Include="Programmable\CompiledOptimizationSupport.cs" />
     146    <Compile Include="Programmable\CompiledMultiObjectiveOptimizationSupport.cs" />
    145147    <Compile Include="Programmable\CompiledSingleObjectiveOptimizationSupport.cs" />
     148    <Compile Include="Programmable\MultiObjectiveOptimizationSupportScript.cs" />
     149    <Compile Include="Programmable\OptimizationSupportScript.cs" />
    146150    <Compile Include="Programmable\SingleObjectiveOptimizationSupportScript.cs" />
    147     <Compile Include="Programmable\SingleObjectiveOptimizationSupportScriptException.cs" />
     151    <Compile Include="Programmable\OptimizationSupportScriptException.cs" />
    148152    <Compile Include="Programmable\Templates.Designer.cs">
    149153      <AutoGen>True</AutoGen>
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/IMultiObjectiveOptimizationSupport.cs

    r13166 r13183  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Core;
    2423using HeuristicLab.Optimization;
    2524
    2625namespace HeuristicLab.Problems.ExternalEvaluation {
    27   public interface ISingleObjectiveOptimizationSupport {
    28     void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random);
    29     IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random);
     26  public interface IMultiObjectiveOptimizationSupport {
     27    void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random);
    3028  }
    3129}
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs

    r13180 r13183  
    5353      get { return (IValueParameter<SolutionMessageBuilder>)Parameters["MessageBuilder"]; }
    5454    }
    55     //public IFixedValueParameter<MultiObjectiveOptimizationSupportScript> SupportScriptParameter {
    56     //  get { return (IFixedValueParameter<MultiObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; }
    57     //}
     55    public IFixedValueParameter<MultiObjectiveOptimizationSupportScript> SupportScriptParameter {
     56      get { return (IFixedValueParameter<MultiObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; }
     57    }
    5858    #endregion
    5959
     
    6868      get { return MessageBuilderParameter.Value; }
    6969    }
    70     //public MultiObjectiveOptimizationSupportScript OptimizationSupportScript {
    71     //  get { return SupportScriptParameter.Value; }
    72     //}
    73     //private IMultiObjectiveOptimizationSupport OptimizationSupport {
    74     //  get { return SupportScriptParameter.Value; }
    75     //}
     70    public MultiObjectiveOptimizationSupportScript OptimizationSupportScript {
     71      get { return SupportScriptParameter.Value; }
     72    }
     73    private IMultiObjectiveOptimizationSupport OptimizationSupport {
     74      get { return SupportScriptParameter.Value; }
     75    }
    7676    #endregion
    7777
     
    8989      Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() }));
    9090      Parameters.Add(new ValueParameter<SolutionMessageBuilder>("MessageBuilder", "The message builder that converts from HeuristicLab objects to SolutionMessage representation.", new SolutionMessageBuilder()) { Hidden = true });
    91       //Parameters.Add(new FixedValueParameter<MultiObjectiveOptimizationSupportScript>("SupportScript", "A script that can analyze the results of the optimization.", new MultiObjectiveOptimizationSupportScript()));
     91      Parameters.Add(new FixedValueParameter<MultiObjectiveOptimizationSupportScript>("SupportScript", "A script that can analyze the results of the optimization.", new MultiObjectiveOptimizationSupportScript()));
    9292
    9393      //Operators.Add(new BestScopeSolutionAnalyzer()); pareto front
     
    114114
    115115    public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    116       //OptimizationSupport.Analyze(individuals, qualities, results, random);
     116      OptimizationSupport.Analyze(individuals, qualities, results, random);
    117117    }
    118118
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledMultiObjectiveOptimizationSupport.cs

    r13166 r13183  
    88
    99namespace HeuristicLab.Problems.ExternalEvaluation {
    10   public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport {
     10  public class CompiledMultiObjectiveOptimizationSupport : CompiledOptimizationSupport, IMultiObjectiveOptimizationSupport {
    1111
    12     public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     12    public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    1313      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    1414      // Write or update results given the range of vectors and resulting qualities
     
    2020    }
    2121
    22     public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
    23       // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    24       // Create new vectors, based on the given one that represent small changes
    25       // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
    26       while (true) {
    27         // Algorithm will draw only a finite amount of samples
    28         // Change to a for-loop to return a concrete amount of neighbors
    29         var neighbor = individual.Copy();
    30         // For instance, perform a single bit-flip in a binary parameter
    31         //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
    32         //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
    33         yield return neighbor;
    34       }
    35     }
    36 
    3722    // Implement further classes and methods
    3823  }
    3924}
    40 
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs

    r13166 r13183  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Reflection;
    2622using HeuristicLab.Common;
    2723using HeuristicLab.Core;
     
    2925using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3026using HeuristicLab.Problems.ExternalEvaluation.Programmable;
    31 using HeuristicLab.Scripting;
    3227
    3328namespace HeuristicLab.Problems.ExternalEvaluation {
    3429  [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3530  [StorableClass]
    36   public sealed class SingleObjectiveOptimizationSupportScript : Script, ISingleObjectiveOptimizationSupport {
    37 
    38     [Storable]
    39     private VariableStore variableStore;
    40     public VariableStore VariableStore {
    41       get { return variableStore; }
    42     }
     31  public sealed class MultiObjectiveOptimizationSupportScript : OptimizationSupportScript<IMultiObjectiveOptimizationSupport>, IMultiObjectiveOptimizationSupport {
    4332
    4433    protected override string CodeTemplate {
    45       get { return Templates.CompiledSingleObjectiveOptimizationSupport; }
     34      get { return Templates.CompiledMultiObjectiveOptimizationSupport; }
    4635    }
    4736
    4837    [StorableConstructor]
    49     private SingleObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { }
    50     private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner)
    51       : base(original, cloner) {
    52       variableStore = cloner.Clone(original.variableStore);
    53     }
    54     public SingleObjectiveOptimizationSupportScript()
    55       : base() {
    56       variableStore = new VariableStore();
     38    private MultiObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { }
     39    private MultiObjectiveOptimizationSupportScript(MultiObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { }
     40    public MultiObjectiveOptimizationSupportScript() : base() { }
     41
     42    public override IDeepCloneable Clone(Cloner cloner) {
     43      return new MultiObjectiveOptimizationSupportScript(this, cloner);
    5744    }
    5845
    59     public override IDeepCloneable Clone(Cloner cloner) {
    60       return new SingleObjectiveOptimizationSupportScript(this, cloner);
    61     }
    62 
    63     private readonly object compileLock = new object();
    64     private volatile ISingleObjectiveOptimizationSupport compiledInstance;
    65     private ISingleObjectiveOptimizationSupport CompiledInstance {
    66       get {
    67         if (compiledInstance == null) {
    68           lock (compileLock) {
    69             if (compiledInstance == null) {
    70               Compile();
    71             }
    72           }
    73         }
    74         return compiledInstance;
    75       }
    76       set { compiledInstance = value; }
    77     }
    78 
    79     public override Assembly Compile() {
    80       var assembly = base.Compile();
    81       var types = assembly.GetTypes();
    82       if (!types.Any(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)))
    83         throw new SingleObjectiveOptimizationSupportException("The compiled code doesn't contain an optimization support." + Environment.NewLine + "The support class must be a subclass of CompiledOptimizationSupport.");
    84       if (types.Count(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)) > 1)
    85         throw new SingleObjectiveOptimizationSupportException("The compiled code contains multiple support classes." + Environment.NewLine + "Only one subclass of CompiledOptimizationSupport is allowed.");
    86 
    87       CompiledOptimizationSupport inst;
    88       try {
    89         inst = (CompiledOptimizationSupport)Activator.CreateInstance(types.Single(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)));
    90         inst.vars = new Variables(VariableStore);
    91       } catch (Exception e) {
    92         compiledInstance = null;
    93         throw new SingleObjectiveOptimizationSupportException("Instantiating the optimization support class failed." + Environment.NewLine + "Check your default constructor.", e);
    94       }
    95 
    96       var soInst = inst as ISingleObjectiveOptimizationSupport;
    97       if (soInst == null)
    98         throw new SingleObjectiveOptimizationSupportException("The optimization support class does not implement ISingleObjectiveOptimizationSupport." + Environment.NewLine + "Please implement that interface in the subclass of CompiledOptimizationSupport.");
    99 
    100       CompiledInstance = soInst;
    101 
    102       return assembly;
    103     }
    104 
    105     protected override void OnCodeChanged() {
    106       base.OnCodeChanged();
    107       compiledInstance = null;
    108     }
    109 
    110     void ISingleObjectiveOptimizationSupport.Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     46    void IMultiObjectiveOptimizationSupport.Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    11147      CompiledInstance.Analyze(individuals, qualities, results, random);
    112     }
    113 
    114     IEnumerable<Individual> ISingleObjectiveOptimizationSupport.GetNeighbors(Individual individual, IRandom random) {
    115       return CompiledInstance.GetNeighbors(individual, random);
    11648    }
    11749  }
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScriptException.cs

    r13166 r13183  
    2525namespace HeuristicLab.Problems.ExternalEvaluation {
    2626  [Serializable]
    27   public class SingleObjectiveOptimizationSupportException : Exception {
    28     public SingleObjectiveOptimizationSupportException() { }
    29     public SingleObjectiveOptimizationSupportException(string message) : base(message) { }
    30     public SingleObjectiveOptimizationSupportException(string message, Exception inner) : base(message, inner) { }
     27  public class OptimizationSupportException : Exception {
     28    public OptimizationSupportException() { }
     29    public OptimizationSupportException(string message) : base(message) { }
     30    public OptimizationSupportException(string message, Exception inner) : base(message, inner) { }
    3131
    32     protected SingleObjectiveOptimizationSupportException(SerializationInfo info, StreamingContext context)
     32    protected OptimizationSupportException(SerializationInfo info, StreamingContext context)
    3333      : base(info, context) { }
    3434  }
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs

    r12012 r13183  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Reflection;
    2623using HeuristicLab.Common;
    2724using HeuristicLab.Core;
     
    2926using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3027using HeuristicLab.Problems.ExternalEvaluation.Programmable;
    31 using HeuristicLab.Scripting;
    3228
    3329namespace HeuristicLab.Problems.ExternalEvaluation {
    3430  [Item("ProblemDefinitionScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3531  [StorableClass]
    36   public sealed class SingleObjectiveOptimizationSupportScript : Script, ISingleObjectiveOptimizationSupport {
    37 
    38     [Storable]
    39     private VariableStore variableStore;
    40     public VariableStore VariableStore {
    41       get { return variableStore; }
    42     }
     32  public sealed class SingleObjectiveOptimizationSupportScript : OptimizationSupportScript<ISingleObjectiveOptimizationSupport>, ISingleObjectiveOptimizationSupport {
    4333
    4434    protected override string CodeTemplate {
     
    4838    [StorableConstructor]
    4939    private SingleObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { }
    50     private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner)
    51       : base(original, cloner) {
    52       variableStore = cloner.Clone(original.variableStore);
    53     }
    54     public SingleObjectiveOptimizationSupportScript()
    55       : base() {
    56       variableStore = new VariableStore();
    57     }
     40    private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { }
     41    public SingleObjectiveOptimizationSupportScript() : base() { }
    5842
    5943    public override IDeepCloneable Clone(Cloner cloner) {
    6044      return new SingleObjectiveOptimizationSupportScript(this, cloner);
    61     }
    62 
    63     private readonly object compileLock = new object();
    64     private volatile ISingleObjectiveOptimizationSupport compiledInstance;
    65     private ISingleObjectiveOptimizationSupport CompiledInstance {
    66       get {
    67         if (compiledInstance == null) {
    68           lock (compileLock) {
    69             if (compiledInstance == null) {
    70               Compile();
    71             }
    72           }
    73         }
    74         return compiledInstance;
    75       }
    76       set { compiledInstance = value; }
    77     }
    78 
    79     public override Assembly Compile() {
    80       var assembly = base.Compile();
    81       var types = assembly.GetTypes();
    82       if (!types.Any(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)))
    83         throw new SingleObjectiveOptimizationSupportException("The compiled code doesn't contain an optimization support." + Environment.NewLine + "The support class must be a subclass of CompiledOptimizationSupport.");
    84       if (types.Count(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)) > 1)
    85         throw new SingleObjectiveOptimizationSupportException("The compiled code contains multiple support classes." + Environment.NewLine + "Only one subclass of CompiledOptimizationSupport is allowed.");
    86 
    87       CompiledOptimizationSupport inst;
    88       try {
    89         inst = (CompiledOptimizationSupport)Activator.CreateInstance(types.Single(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)));
    90         inst.vars = new Variables(VariableStore);
    91       } catch (Exception e) {
    92         compiledInstance = null;
    93         throw new SingleObjectiveOptimizationSupportException("Instantiating the optimization support class failed." + Environment.NewLine + "Check your default constructor.", e);
    94       }
    95 
    96       var soInst = inst as ISingleObjectiveOptimizationSupport;
    97       if (soInst == null)
    98         throw new SingleObjectiveOptimizationSupportException("The optimization support class does not implement ISingleObjectiveOptimizationSupport." + Environment.NewLine + "Please implement that interface in the subclass of CompiledOptimizationSupport.");
    99 
    100       CompiledInstance = soInst;
    101 
    102       return assembly;
    103     }
    104 
    105     protected override void OnCodeChanged() {
    106       base.OnCodeChanged();
    107       compiledInstance = null;
    10845    }
    10946
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/Templates.Designer.cs

    r11893 r13183  
    22// <auto-generated>
    33//     This code was generated by a tool.
    4 //     Runtime Version:4.0.30319.34209
     4//     Runtime Version:4.0.30319.42000
    55//
    66//     Changes to this file may cause incorrect behavior and will be lost if
     
    6868        ///using HeuristicLab.Core;
    6969        ///using HeuristicLab.Data;
    70         ///using HeuristicLab.Encodings.PermutationEncoding;
    7170        ///using HeuristicLab.Optimization;
    72         ///using HeuristicLab.Problems.Programmable;
    7371        ///
    74         ///namespace HeuristicLab.Problems.Programmable {
    75         ///  public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
    76         ///    public bool Maximization { get { return false; } }
     72        ///namespace HeuristicLab.Problems.ExternalEvaluation {
     73        ///  public class CompiledMultiObjectiveOptimizationSupport : CompiledOptimizationSupport, IMultiObjectiveOptimizationSupport {
    7774        ///
    78         ///     [rest of string was truncated]&quot;;.
     75        ///    public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
     76        ///      // Use vars.yourVaria [rest of string was truncated]&quot;;.
     77        /// </summary>
     78        internal static string CompiledMultiObjectiveOptimizationSupport {
     79            get {
     80                return ResourceManager.GetString("CompiledMultiObjectiveOptimizationSupport", 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.Optimization;
     92        ///
     93        ///namespace HeuristicLab.Problems.ExternalEvaluation {
     94        ///  public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport {
     95        ///
     96        ///    public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     97        ///      // Use vars.yourVaria [rest of string was truncated]&quot;;.
    7998        /// </summary>
    8099        internal static string CompiledSingleObjectiveOptimizationSupport {
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/Templates.resx

    r11893 r13183  
    119119  </resheader>
    120120  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
     121  <data name="CompiledMultiObjectiveOptimizationSupport" type="System.Resources.ResXFileRef, System.Windows.Forms">
     122    <value>compiledmultiobjectiveoptimizationsupport.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
     123  </data>
    121124  <data name="CompiledSingleObjectiveOptimizationSupport" type="System.Resources.ResXFileRef, System.Windows.Forms">
    122125    <value>CompiledSingleObjectiveOptimizationSupport.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
Note: See TracChangeset for help on using the changeset viewer.