Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2852


Ignore:
Timestamp:
02/23/10 06:50:50 (15 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on algorithms
Location:
trunk/sources
Files:
18 added
3 deleted
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r2836 r2852  
    5858    {72104A0B-90E7-42F3-9ABE-9BBBADD4B943} = {72104A0B-90E7-42F3-9ABE-9BBBADD4B943}
    5959    {25087811-F74C-4128-BC86-8324271DA13E} = {25087811-F74C-4128-BC86-8324271DA13E}
     60    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2} = {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}
    6061    {E226881D-315F-423D-B419-A766FE0D8685} = {E226881D-315F-423D-B419-A766FE0D8685}
     62    {14AB8D24-25BC-400C-A846-4627AA945192} = {14AB8D24-25BC-400C-A846-4627AA945192}
    6163    {C36BD924-A541-4A00-AFA8-41701378DDC5} = {C36BD924-A541-4A00-AFA8-41701378DDC5}
    6264    {1849A92E-DCFC-4E05-BB0A-D7B7A3DAFCFB} = {1849A92E-DCFC-4E05-BB0A-D7B7A3DAFCFB}
     
    7173    {56F9106A-079F-4C61-92F6-86A84C2D84B7} = {56F9106A-079F-4C61-92F6-86A84C2D84B7}
    7274    {DC3D7072-7999-4719-B65D-3997744D5DC1} = {DC3D7072-7999-4719-B65D-3997744D5DC1}
     75    {F42F3576-7233-4B28-90F7-36AE15F30F92} = {F42F3576-7233-4B28-90F7-36AE15F30F92}
    7376    {57F38579-409D-4DD8-AB19-3F2C4A665126} = {57F38579-409D-4DD8-AB19-3F2C4A665126}
    7477    {BF7D9494-A586-457B-8DF9-ED599F9E6A71} = {BF7D9494-A586-457B-8DF9-ED599F9E6A71}
     
    7780    {958B43BC-CC5C-4FA2-8628-2B3B01D890B6} = {958B43BC-CC5C-4FA2-8628-2B3B01D890B6}
    7881    {AB687BBE-1BFE-476B-906D-44237135431D} = {AB687BBE-1BFE-476B-906D-44237135431D}
     82    {4C3305C4-E440-4EAD-B218-68D77AE51543} = {4C3305C4-E440-4EAD-B218-68D77AE51543}
    7983    {DF2E61C4-A76D-4315-9D0B-53A077B1AC2C} = {DF2E61C4-A76D-4315-9D0B-53A077B1AC2C}
     84    {4D59BEC9-A69E-4686-B8C9-0E6C073B093E} = {4D59BEC9-A69E-4686-B8C9-0E6C073B093E}
    8085    {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B} = {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}
    8186    {EE2034D9-6E27-48A1-B855-42D45F69A4FC} = {EE2034D9-6E27-48A1-B855-42D45F69A4FC}
    8287    {1B3063DB-D71C-4A6A-A359-883E8F53A140} = {1B3063DB-D71C-4A6A-A359-883E8F53A140}
     88    {35A42EE0-A896-4D7A-A99F-8ED9E925F320} = {35A42EE0-A896-4D7A-A99F-8ED9E925F320}
    8389    {AE5B1CE5-9862-4D6F-A700-D72CD9AEA295} = {AE5B1CE5-9862-4D6F-A700-D72CD9AEA295}
    8490    {A9E282EA-180F-4233-B809-AEDF0787545C} = {A9E282EA-180F-4233-B809-AEDF0787545C}
     
    157163EndProject
    158164Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Permutation-3.3.Tests", "HeuristicLab.Permutation\3.3\Tests\HeuristicLab.Permutation-3.3.Tests.csproj", "{4D59BEC9-A69E-4686-B8C9-0E6C073B093E}"
     165EndProject
     166Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.SGA.Views-3.3", "HeuristicLab.SGA.Views\3.3\HeuristicLab.SGA.Views-3.3.csproj", "{35A42EE0-A896-4D7A-A99F-8ED9E925F320}"
    159167EndProject
    160168Global
     
    705713    {4D59BEC9-A69E-4686-B8C9-0E6C073B093E}.Release|x64.ActiveCfg = Release|Any CPU
    706714    {4D59BEC9-A69E-4686-B8C9-0E6C073B093E}.Release|x86.ActiveCfg = Release|Any CPU
     715    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     716    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Debug|Any CPU.Build.0 = Debug|Any CPU
     717    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Debug|x64.ActiveCfg = Debug|Any CPU
     718    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Debug|x86.ActiveCfg = Debug|Any CPU
     719    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Release|Any CPU.ActiveCfg = Release|Any CPU
     720    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Release|Any CPU.Build.0 = Release|Any CPU
     721    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Release|x64.ActiveCfg = Release|Any CPU
     722    {35A42EE0-A896-4D7A-A99F-8ED9E925F320}.Release|x86.ActiveCfg = Release|Any CPU
    707723  EndGlobalSection
    708724  GlobalSection(SolutionProperties) = preSolution
  • trunk/sources/HeuristicLab 3.3/Files.txt

    r2834 r2852  
    3838HeuristicLab.SequentialEngine\3.3:HeuristicLab.SequentialEngine-3.3.dll
    3939HeuristicLab.SGA\3.3:HeuristicLab.SGA-3.3.dll
     40HeuristicLab.SGA.Views\3.3:HeuristicLab.SGA.Views-3.3.dll
    4041HeuristicLab.TestFunctions\3.3:HeuristicLab.TestFunctions-3.3.dll
    4142HeuristicLab.ThreadParallelEngine\3.3:HeuristicLab.ThreadParallelEngine-3.3.dll
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IDeepCloneable.cs

    r2790 r2852  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523
    2624namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IItem.cs

    r2790 r2852  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.ComponentModel;
    25 using System.Text;
    2622using System.Drawing;
    2723
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/ILookupParameter.cs

    r2796 r2852  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2623
    2724namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/INamedItem.cs

    r2790 r2852  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2623using HeuristicLab.Common;
    2724
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IRandom.cs

    r2790 r2852  
    1919 */
    2020#endregion
    21 
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Core;
    2621
    2722namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IScope.cs

    r2790 r2852  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using HeuristicLab.Collections;
    28 
    2922namespace HeuristicLab.Core {
    3023  /// <summary>
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IValueLookupParameter.cs

    r2796 r2852  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    26 
    2722namespace HeuristicLab.Core {
    2823  public interface IValueLookupParameter : IValueParameter, ILookupParameter { }
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IValueParameter.cs

    r2796 r2852  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2623
    2724namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IVariable.cs

    r2790 r2852  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using HeuristicLab.Common;
    2823
    2924namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Core/3.3/ItemCollection.cs

    r2833 r2852  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Drawing;
    2325using System.Linq;
    24 using System.Collections;
    25 using System.Collections.Generic;
    26 using System.Collections.ObjectModel;
    27 using System.Text;
    28 using System.Drawing;
     26using HeuristicLab.Collections;
     27using HeuristicLab.Common.Resources;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 using HeuristicLab.Common.Resources;
    31 using HeuristicLab.Collections;
    32 
    3329
    3430namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r2851 r2852  
    2727using HeuristicLab.Persistence.Default.Xml;
    2828
    29 namespace HeuristicLab.Optimization.Views { 
     29namespace HeuristicLab.Optimization.Views {
    3030  /// <summary>
    3131  /// The base class for visual representations of items.
     
    167167        problemTypeSelectorDialog = new TypeSelectorDialog();
    168168        problemTypeSelectorDialog.Caption = "Select Problem";
    169         problemTypeSelectorDialog.TypeSelector.Configure(typeof(IProblem), false, false);
     169        problemTypeSelectorDialog.TypeSelector.Configure(Content.ProblemType, false, false);
    170170      }
    171171      if (problemTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
     
    184184        }
    185185        if (problem == null)
    186           MessageBox.Show(this, "Selected file does not contain a problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
     186          MessageBox.Show(this, "The selected file does not contain a problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
     187        else if (!Content.ProblemType.IsInstanceOfType(problem))
     188          MessageBox.Show(this, "The selected file contains a problem type which is not supported by this algorithm.", "Invalid Problem Type", MessageBoxButtons.OK, MessageBoxIcon.Error);
    187189        else
    188190          Content.Problem = problem;
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/EngineAlgorithmView.cs

    r2851 r2852  
    2626using HeuristicLab.MainForm;
    2727
    28 namespace HeuristicLab.Optimization.Views { 
     28namespace HeuristicLab.Optimization.Views {
    2929  /// <summary>
    3030  /// The base class for visual representations of items.
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ProblemView.cs

    r2851 r2852  
    2323using HeuristicLab.MainForm;
    2424
    25 namespace HeuristicLab.Optimization.Views { 
     25namespace HeuristicLab.Optimization.Views {
    2626  /// <summary>
    2727  /// The base class for visual representations of items.
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.cs

    r2851 r2852  
    2727using HeuristicLab.Persistence.Default.Xml;
    2828
    29 namespace HeuristicLab.Optimization.Views { 
     29namespace HeuristicLab.Optimization.Views {
    3030  /// <summary>
    3131  /// The base class for visual representations of items.
     
    9494        }
    9595        if (operatorGraph == null)
    96           MessageBox.Show(this, "Selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
     96          MessageBox.Show(this, "The selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
    9797        else
    9898          Content.OperatorGraph = operatorGraph;
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs

    r2851 r2852  
    3636    }
    3737
     38    public virtual Type ProblemType {
     39      get { return typeof(IProblem); }
     40    }
     41
    3842    private IProblem problem;
    3943    [Storable]
     
    4246      set {
    4347        if (problem != value) {
    44           if (problem != null) problem.Changed -= new ChangedEventHandler(Problem_Changed);
     48          if ((value != null) && !ProblemType.IsInstanceOfType(value)) throw new ArgumentException("Invalid problem type.");
     49          if (problem != null) DeregisterProblemEvents();
    4550          problem = value;
    46           if (problem != null) problem.Changed += new ChangedEventHandler(Problem_Changed);
     51          if (problem != null) RegisterProblemEvents();
    4752          OnProblemChanged();
    4853        }
     
    135140        ExceptionOccurred(this, new EventArgs<Exception>(exception));
    136141    }
     142    protected virtual void DeregisterProblemEvents() {
     143      problem.SolutionCreatorChanged -= new EventHandler(Problem_SolutionCreatorChanged);
     144      problem.EvaluatorChanged -= new EventHandler(Problem_EvaluatorChanged);
     145      problem.Changed -= new ChangedEventHandler(Problem_Changed);
     146    }
     147    protected virtual void RegisterProblemEvents() {
     148      problem.SolutionCreatorChanged += new EventHandler(Problem_SolutionCreatorChanged);
     149      problem.EvaluatorChanged += new EventHandler(Problem_EvaluatorChanged);
     150      problem.Changed += new ChangedEventHandler(Problem_Changed);
     151    }
     152
     153    protected virtual void Problem_SolutionCreatorChanged(object sender, EventArgs e) { }
     154    protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { }
    137155    private void Problem_Changed(object sender, ChangedEventArgs e) {
    138156      OnChanged(e);
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r2851 r2852  
    5252    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
    5353    <Compile Include="Algorithm.cs" />
     54    <Compile Include="ISolutionCreator.cs" />
     55    <Compile Include="SingleObjectiveProblem.cs" />
     56    <Compile Include="ISingleObjectiveProblem.cs" />
     57    <Compile Include="IEvaluator.cs" />
     58    <Compile Include="ISingleObjectiveEvaluator.cs" />
     59    <Compile Include="SingleObjectiveEvaluator.cs" />
    5460    <Compile Include="UserDefinedAlgorithm.cs" />
    5561    <Compile Include="EngineAlgorithm.cs" />
     
    8187      <Name>HeuristicLab.Core-3.3</Name>
    8288    </ProjectReference>
     89    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     90      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     91      <Name>HeuristicLab.Data-3.3</Name>
     92    </ProjectReference>
     93    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
     94      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
     95      <Name>HeuristicLab.Operators-3.3</Name>
     96    </ProjectReference>
     97    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     98      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
     99      <Name>HeuristicLab.Parameters-3.3</Name>
     100    </ProjectReference>
    83101    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
    84102      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLabOptimizationPlugin.cs.frame

    r2845 r2852  
    3232  [PluginDependency("HeuristicLab.Common.Resources", "3.2")]
    3333  [PluginDependency("HeuristicLab.Core", "3.3")]
     34  [PluginDependency("HeuristicLab.Data", "3.3")]
     35  [PluginDependency("HeuristicLab.Operators", "3.3")]
     36  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3437  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    3538  public class HeuristicLabOptimizationPlugin : PluginBase {
  • trunk/sources/HeuristicLab.Optimization/3.3/IAlgorithm.cs

    r2851 r2852  
    2929  /// </summary>
    3030  public interface IAlgorithm : IParameterizedNamedItem {
     31    Type ProblemType { get; }
    3132    IProblem Problem { get; set; }
    3233    TimeSpan ExecutionTime { get; }
  • trunk/sources/HeuristicLab.Optimization/3.3/IProblem.cs

    r2845 r2852  
    2121
    2222using HeuristicLab.Core;
     23using System;
    2324
    2425namespace HeuristicLab.Optimization {
    2526  /// <summary>
    26   /// Interface to represent a problem.
     27  /// Interface to represent an optimization problem.
    2728  /// </summary>
    28   public interface IProblem : IParameterizedNamedItem { }
     29  public interface IProblem : IParameterizedNamedItem {
     30    ISolutionCreator SolutionCreator { get; set; }
     31    IEvaluator Evaluator { get; set; }
     32
     33    event EventHandler SolutionCreatorChanged;
     34    event EventHandler EvaluatorChanged;
     35  }
    2936}
  • trunk/sources/HeuristicLab.Optimization/3.3/Problem.cs

    r2851 r2852  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Parameters;
     26using System;
    2527
    2628namespace HeuristicLab.Optimization {
    2729  /// <summary>
    28   /// A base class for problems.
     30  /// A base class for optimization problems.
    2931  /// </summary>
    30   [Item("Problem", "A base class for problems.")]
     32  [Item("Problem", "A base class for optimization problems.")]
    3133  [EmptyStorableClass]
    3234  public abstract class Problem : ParameterizedNamedItem, IProblem {
     
    3537    }
    3638
    37     protected Problem() : base() { }
    38     protected Problem(string name) : base(name) { }
    39     protected Problem(string name, ParameterCollection parameters) : base(name, parameters) { }
    40     protected Problem(string name, string description) : base(name, description) { }
    41     protected Problem(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { }
     39    private IValueParameter<ISolutionCreator> SolutionCreatorParameter {
     40      get { return (IValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
     41    }
     42    private IValueParameter<IEvaluator> EvaluatorParameter {
     43      get { return (IValueParameter<IEvaluator>)Parameters["Evaluator"]; }
     44    }
     45    public ISolutionCreator SolutionCreator {
     46      get { return SolutionCreatorParameter.Value; }
     47      set { SolutionCreatorParameter.Value = value; }
     48    }
     49    public IEvaluator Evaluator {
     50      get { return EvaluatorParameter.Value; }
     51      set { EvaluatorParameter.Value = value; }
     52    }
     53
     54    protected Problem()
     55      : base() {
     56      AddParameters();
     57    }
     58    protected Problem(string name)
     59      : base(name) {
     60      AddParameters();
     61    }
     62    protected Problem(string name, ParameterCollection parameters)
     63      : base(name, parameters) {
     64      AddParameters();
     65    }
     66    protected Problem(string name, string description)
     67      : base(name, description) {
     68      AddParameters();
     69    }
     70    protected Problem(string name, string description, ParameterCollection parameters)
     71      : base(name, description, parameters) {
     72      AddParameters();
     73    }
     74
     75    private void AddParameters() {
     76      ValueParameter<ISolutionCreator> solutionCreatorParameter = new ValueParameter<ISolutionCreator>("SolutionCreator", "The operator which should be used to create new solutions.");
     77      solutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
     78      Parameters.Add(solutionCreatorParameter);
     79
     80      ValueParameter<IEvaluator> evaluatorParameter = new ValueParameter<IEvaluator>("Evaluator", "The operator which should be used to evaluate solutions.");
     81      evaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
     82      Parameters.Add(evaluatorParameter);
     83    }
     84
     85    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     86      OnSolutionCreatorChanged();
     87    }
     88    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
     89      OnEvaluatorChanged();
     90    }
     91
     92    public event EventHandler SolutionCreatorChanged;
     93    protected virtual void OnSolutionCreatorChanged() {
     94      if (SolutionCreatorChanged != null)
     95        SolutionCreatorChanged(this, EventArgs.Empty);
     96    }
     97    public event EventHandler EvaluatorChanged;
     98    protected virtual void OnEvaluatorChanged() {
     99      if (EvaluatorChanged != null)
     100        EvaluatorChanged(this, EventArgs.Empty);
     101    }
    42102  }
    43103}
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj

    r2818 r2852  
    6969  <ItemGroup>
    7070    <None Include="HeuristicLabParametersViewsPlugin.cs.frame" />
     71    <Compile Include="ConstrainedValueParameterView.cs">
     72      <SubType>UserControl</SubType>
     73    </Compile>
     74    <Compile Include="ConstrainedValueParameterView.Designer.cs">
     75      <DependentUpon>ConstrainedValueParameterView.cs</DependentUpon>
     76    </Compile>
    7177    <Compile Include="ValueLookupParameterView.cs">
    7278      <SubType>UserControl</SubType>
     
    101107  </ItemGroup>
    102108  <ItemGroup>
     109    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
     110      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     111      <Name>HeuristicLab.Collections-3.3</Name>
     112    </ProjectReference>
    103113    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.2\HeuristicLab.Common.Resources-3.2.csproj">
    104114      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/HeuristicLabParametersViewsPlugin.cs.frame

    r2818 r2852  
    2828  [Plugin("HeuristicLab.Parameters.Views", "3.3.0.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Parameters.Views-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3031  [PluginDependency("HeuristicLab.Common", "3.2")]
    3132  [PluginDependency("HeuristicLab.Common.Resources", "3.2")]
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r2803 r2852  
    6767  <ItemGroup>
    6868    <None Include="HeuristicLabParametersPlugin.cs.frame" />
     69    <Compile Include="ConstrainedValueParameter.cs" />
    6970    <Compile Include="LookupParameter.cs" />
    7071    <Compile Include="SubScopesLookupParameter.cs" />
  • trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs

    r2834 r2852  
    108108      return scope != null ? scope.Variables[actualName] : null;
    109109    }
    110     //private IValueParameter GetProblemParameter(string name) {
    111     //  IValueParameter param = null;
    112     //  if (ExecutionContext.Problem.Parameters.ContainsKey(name)) {
    113     //    param = ExecutionContext.Problem.Parameters[name] as IValueParameter;
    114     //    if (param == null)
    115     //      throw new InvalidOperationException(
    116     //        string.Format("Parameter look-up chain broken. Parameter \"{0}\" is not an \"{1}\".",
    117     //                      name,
    118     //                      typeof(IValueParameter).GetPrettyName())
    119     //      );
    120     //  }
    121     //  return param;
    122     //}
    123110    protected override IItem GetActualValue() {
    124111      string name;
     
    130117      IVariable var = LookupVariable(name);
    131118      if (var != null) {
    132         T value = var.Value as T;
    133         if (value == null)
     119        if (!(var.Value is T))
    134120          throw new InvalidOperationException(
    135121            string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
     
    137123                          typeof(T).GetPrettyName())
    138124          );
    139         return value;
     125        return var.Value;
    140126      }
    141 
    142       // try to get value from problem
    143       //IValueParameter problemParam = GetProblemParameter(name);
    144       //if (problemParam != null) return problemParam.Value;
    145 
    146127      return null;
    147128    }
    148129    protected override void SetActualValue(IItem value) {
    149       T val = value as T;
    150       if (val == null)
     130      if (!(value is T))
    151131        throw new InvalidOperationException(
    152132          string.Format("Type mismatch. Value is not a \"{0}\".",
     
    157137      IValueParameter param = GetParameter(out name);
    158138      if (param != null) {
    159         param.Value = val;
     139        param.Value = value;
    160140        return;
    161141      }
     
    164144      IVariable var = LookupVariable(name);
    165145      if (var != null) {
    166         var.Value = val;
     146        var.Value = value;
    167147        return;
    168148      }
    169 
    170       // try to set value in problem
    171       //IValueParameter problemParam = GetProblemParameter(name);
    172       //if (problemParam != null) {
    173       //  problemParam.Value = val;
    174       //  return;
    175       //}
    176149
    177150      // create new variable
  • trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs

    r2818 r2852  
    4545        if (var != null) {
    4646          value = var.Value as T;
    47           if (value == null)
     47          if ((var.Value != null) && (value == null))
    4848            throw new InvalidOperationException(
    4949              string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs

    r2818 r2852  
    4848      set {
    4949        T val = value as T;
    50         if (val == null)
     50        if ((value != null) && (val == null))
    5151          throw new InvalidOperationException(
    5252            string.Format("Type mismatch. Value is not a \"{0}\".",
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueParameter.cs

    r2818 r2852  
    4848      set {
    4949        T val = value as T;
    50         if (val == null)
     50        if ((value != null) && (val == null))
    5151          throw new InvalidOperationException(
    5252            string.Format("Type mismatch. Value is not a \"{0}\".",
  • trunk/sources/HeuristicLab.Permutation/3.3/HeuristicLab.Permutation-3.3.csproj

    r2829 r2852  
    121121      <Name>HeuristicLab.Operators-3.3</Name>
    122122    </ProjectReference>
     123    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
     124      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
     125      <Name>HeuristicLab.Optimization-3.3</Name>
     126    </ProjectReference>
    123127    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
    124128      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
  • trunk/sources/HeuristicLab.Permutation/3.3/HeuristicLabPermutationPlugin.cs.frame

    r2794 r2852  
    3333  [PluginDependency("HeuristicLab.Data", "3.3")]
    3434  [PluginDependency("HeuristicLab.Operators", "3.3")]
     35  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3536  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3637  [PluginDependency("HeuristicLab.Persistence", "3.3")]
  • trunk/sources/HeuristicLab.Permutation/3.3/RandomPermutationCreator.cs

    r2834 r2852  
    2323using HeuristicLab.Data;
    2424using HeuristicLab.Operators;
     25using HeuristicLab.Optimization;
    2526using HeuristicLab.Parameters;
    2627using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3334  [EmptyStorableClass]
    3435  [Creatable("Test")]
    35   public sealed class RandomPermutationCreator : SingleSuccessorOperator {
    36     public LookupParameter<IRandom> RandomParameter {
     36  public sealed class RandomPermutationCreator : SingleSuccessorOperator, ISolutionCreator {
     37    public ILookupParameter<IRandom> RandomParameter {
    3738      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    3839    }
  • trunk/sources/HeuristicLab.Routing.TSP/3.3/TSP.cs

    r2834 r2852  
    3131  [Creatable("Problems")]
    3232  [EmptyStorableClass]
    33   public sealed class TSP : Problem {
     33  public sealed class TSP : SingleObjectiveProblem {
    3434    private ValueParameter<DoubleMatrixData> CoordinatesParameter {
    3535      get { return (ValueParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
    36     }
    37     private OperatorParameter SolutionCreatorParameter {
    38       get { return (OperatorParameter)Parameters["SolutionCreator"]; }
    39     }
    40     private OperatorParameter SolutionEvaluatorParameter {
    41       get { return (OperatorParameter)Parameters["SolutionEvaluator"]; }
    4236    }
    4337
     
    4640      set { CoordinatesParameter.Value = value; }
    4741    }
    48     public IOperator SolutionCreator {
    49       get { return SolutionCreatorParameter.Value; }
    50       set { SolutionCreatorParameter.Value = value; }
    51     }
    52     public IOperator SolutionEvaluator {
    53       get { return SolutionEvaluatorParameter.Value; }
    54       set { SolutionEvaluatorParameter.Value = value; }
    55     }
    5642
    5743    public TSP()
    5844      : base() {
    59       Parameters.Add(new ValueParameter<BoolData>("Maximization", "Set to false as the TSP is a minimization problem.", new BoolData(false)));
     45      Maximization = new BoolData(false);
    6046      Parameters.Add(new ValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0)));
    6147      Parameters.Add(new ValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
    62       Parameters.Add(new OperatorParameter("SolutionCreator", "The operator which should be used to create new solutions."));
    63       Parameters.Add(new OperatorParameter("SolutionEvaluator", "The operator which should be used to evaluate solutions."));
     48      RandomPermutationCreator creator = new RandomPermutationCreator();
     49      creator.LengthParameter.Value = new IntData(0);
     50      SolutionCreator = creator;
     51      Evaluator = new TSPRoundedEuclideanPathEvaluator();
    6452    }
    6553
     
    7361      SolutionCreator = creator;
    7462      TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator();
    75       SolutionEvaluator = evaluator;
     63      Evaluator = evaluator;
    7664    }
    7765  }
  • trunk/sources/HeuristicLab.Routing.TSP/3.3/TSPPathEvaluator.cs

    r2834 r2852  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
    24 using HeuristicLab.Operators;
     24using HeuristicLab.Optimization;
    2525using HeuristicLab.Parameters;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3232  [Item("TSPPathEvaluator", "A base class for operators which evaluate TSP solutions given in path representation.")]
    3333  [EmptyStorableClass]
    34   public abstract class TSPPathEvaluator : SingleSuccessorOperator {
     34  public abstract class TSPPathEvaluator : SingleObjectiveEvaluator {
    3535    public LookupParameter<DoubleMatrixData> CoordinatesParameter {
    3636      get { return (LookupParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
     
    3939      get { return (LookupParameter<Permutation.Permutation>)Parameters["Permutation"]; }
    4040    }
    41     public LookupParameter<DoubleData> QualityParameter {
    42       get { return (LookupParameter<DoubleData>)Parameters["Quality"]; }
    43     }
    4441
    4542    protected TSPPathEvaluator()
     
    4744      Parameters.Add(new LookupParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities."));
    4845      Parameters.Add(new LookupParameter<Permutation.Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated."));
    49       Parameters.Add(new LookupParameter<DoubleData>("Quality", "The evaluated quality of the given TSP solution."));
    5046    }
    5147
  • trunk/sources/HeuristicLab.SGA/3.3/SGA.cs

    r2851 r2852  
    2020#endregion
    2121
    22 using System;
    2322using HeuristicLab.Core;
    24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    25 using HeuristicLab.Collections;
    26 using HeuristicLab.Parameters;
    2723using HeuristicLab.Data;
     24using HeuristicLab.Evolutionary;
    2825using HeuristicLab.Operators;
    2926using HeuristicLab.Optimization;
    30 using HeuristicLab.Evolutionary;
     27using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using System;
    3130
    3231namespace HeuristicLab.SGA {
     
    3635  [Item("SGA", "A standard genetic algorithm.")]
    3736  [Creatable("Algorithms")]
    38   [EmptyStorableClass]
    3937  public sealed class SGA : EngineAlgorithm {
     38    [Storable]
     39    private PopulationCreator populationCreator;
     40    [Storable]
     41    private SGAOperator sgaOperator;
     42
     43    public override Type ProblemType {
     44      get { return typeof(ISingleObjectiveProblem); }
     45    }
     46    public new ISingleObjectiveProblem Problem {
     47      get { return (ISingleObjectiveProblem)base.Problem; }
     48      set { base.Problem = value; }
     49    }
     50
    4051    public new IScope GlobalScope {
    4152      get { return base.GlobalScope; }
     
    4455    public SGA()
    4556      : base() {
    46 //      Parameters.Add(new ValueLookupParameter<BoolData>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    47 //      Parameters.Add(new SubScopesLookupParameter<DoubleData>("Quality", "The value which represents the quality of a solution."));
    4857      Parameters.Add(new ValueParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0)));
    4958      Parameters.Add(new ValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true)));
     
    5261      Parameters.Add(new ValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05)));
    5362      Parameters.Add(new OperatorParameter("MutationOperator", "The operator used to mutate solutions."));
    54 //      Parameters.Add(new ValueLookupParameter<IOperator>("SolutionEvaluator", "The operator used to evaluate solutions."));
    5563      Parameters.Add(new ValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1)));
    5664      Parameters.Add(new ValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000)));
    5765
    5866      RandomCreator randomCreator = new RandomCreator();
    59       PopulationCreator populationCreator = new PopulationCreator();
    60       SGAOperator sgaOperator = new SGAOperator();
     67      populationCreator = new PopulationCreator();
     68      sgaOperator = new SGAOperator();
    6169
    6270      randomCreator.RandomParameter.ActualName = "Random";
     
    6977      populationCreator.PopulationSizeParameter.ActualName = "PopulationSize";
    7078      populationCreator.PopulationSizeParameter.Value = null;
    71       populationCreator.SolutionCreatorParameter.ActualName = "SolutionCreator";
    72       populationCreator.SolutionEvaluatorParameter.ActualName = "SolutionEvaluator";
    7379      populationCreator.Successor = sgaOperator;
    7480
    7581      sgaOperator.CrossoverOperatorParameter.ActualName = "CrossoverOperator";
    7682      sgaOperator.ElitesParameter.ActualName = "Elites";
    77       sgaOperator.MaximizationParameter.ActualName = "Maximization";
    7883      sgaOperator.MaximumGenerationsParameter.ActualName = "MaximumGenerations";
    7984      sgaOperator.MutationOperatorParameter.ActualName = "MutationOperator";
    8085      sgaOperator.MutationProbabilityParameter.ActualName = "MutationProbability";
    81       sgaOperator.QualityParameter.ActualName = "Quality";
    8286      sgaOperator.RandomParameter.ActualName = "Random";
    83       sgaOperator.SolutionEvaluatorParameter.ActualName = "SolutionEvaluator";
    8487
    8588      OperatorGraph.InitialOperator = randomCreator;
    8689    }
     90
     91    public override IDeepCloneable Clone(Cloner cloner) {
     92      SGA clone = (SGA)base.Clone(cloner);
     93      clone.populationCreator = (PopulationCreator)cloner.Clone(populationCreator);
     94      clone.sgaOperator = (SGAOperator)cloner.Clone(sgaOperator);
     95      return clone;
     96    }
     97
     98    protected override void DeregisterProblemEvents() {
     99      Problem.MaximizationChanged -= new EventHandler(Problem_MaximizationChanged);
     100      base.DeregisterProblemEvents();
     101    }
     102    protected override void RegisterProblemEvents() {
     103      base.RegisterProblemEvents();
     104      Problem.MaximizationChanged += new EventHandler(Problem_MaximizationChanged);
     105    }
     106
     107    protected override void OnProblemChanged() {
     108      Problem.SolutionCreator.RandomParameter.ActualName = "Random";
     109      populationCreator.SolutionCreatorParameter.Value = Problem.SolutionCreator;
     110      populationCreator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
     111      sgaOperator.MaximizationParameter.Value = Problem.Maximization;
     112      sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.Name;
     113      sgaOperator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
     114      base.OnProblemChanged();
     115    }
     116    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
     117      Problem.SolutionCreator.RandomParameter.ActualName = "Random";
     118      populationCreator.SolutionCreatorParameter.Value = Problem.SolutionCreator;
     119      base.Problem_SolutionCreatorChanged(sender, e);
     120    }
     121    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
     122      populationCreator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
     123      sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.Name;
     124      sgaOperator.SolutionEvaluatorParameter.Value = Problem.Evaluator;
     125      base.Problem_EvaluatorChanged(sender, e);
     126    }
     127    private void Problem_MaximizationChanged(object sender, EventArgs e) {
     128      sgaOperator.MaximizationParameter.Value = Problem.Maximization;
     129    }
    87130  }
    88131}
Note: See TracChangeset for help on using the changeset viewer.