Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2851


Ignore:
Timestamp:
02/22/10 04:15:53 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on algorithms
Location:
trunk/sources
Files:
9 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/ParameterizedNamedItemView.cs

    r2845 r2851  
    5353      if (Content == null) {
    5454        parameterCollectionView.Content = null;
     55        parameterCollectionView.Enabled = false;
    5556      } else {
    5657        parameterCollectionView.Content = Content.Parameters;
     58        parameterCollectionView.Enabled = true;
    5759      }
    5860    }
  • trunk/sources/HeuristicLab.Core/3.3/Engine.cs

    r2834 r2851  
    116116    protected bool Canceled {
    117117      get { return canceled; }
     118      private set {
     119        if (canceled != value) {
     120          canceled = value;
     121          OnCanceledChanged();
     122        }
     123      }
    118124    }
    119125    /// <summary>
     
    154160
    155161    public void Prepare(IOperation initialOperation) {
    156       canceled = false;
     162      Canceled = false;
    157163      running = false;
    158164      globalScope.Clear();
     
    177183    public void Start() {
    178184      running = true;
    179       canceled = false;
     185      Canceled = false;
    180186      ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null);
    181187    }
     
    185191    public void Step() {
    186192      running = true;
    187       canceled = false;
     193      Canceled = false;
    188194      ThreadPool.QueueUserWorkItem(new WaitCallback(RunStep), null);
    189195    }
    190196    /// <inheritdoc/>
    191197    /// <remarks>Sets the protected flag <c>myCanceled</c> to <c>true</c>.</remarks>
    192     public virtual void Stop() {
    193       canceled = true;
     198    public void Stop() {
     199      Canceled = true;
    194200    }
    195201
     
    282288        Stopped(this, EventArgs.Empty);
    283289    }
     290    protected virtual void OnCanceledChanged() { }
    284291    /// <summary>
    285292    /// Occurs when an exception occured during the execution.
  • trunk/sources/HeuristicLab.Core/3.3/NamedItem.cs

    r2830 r2851  
    3131  public abstract class NamedItem : Item, INamedItem {
    3232    [Storable]
    33     private string name;
     33    protected string name;
    3434    /// <inheritdoc/>
    3535    /// <remarks>Calls <see cref="OnNameChanging"/> and also <see cref="OnNameChanged"/>
     
    5454    }
    5555    [Storable]
    56     private string description;
     56    protected string description;
    5757    public string Description {
    5858      get { return description; }
  • trunk/sources/HeuristicLab.Core/3.3/ParameterizedNamedItem.cs

    r2845 r2851  
    4848    }
    4949
    50     protected ParameterizedNamedItem() {
    51       Name = ItemName;
    52       Description = ItemDescription;
     50    protected ParameterizedNamedItem()
     51      : base() {
     52      name = ItemName;
     53      description = ItemDescription;
    5354      Parameters = new ParameterCollection();
    5455      readOnlyParameters = null;
     
    5657    protected ParameterizedNamedItem(string name)
    5758      : base(name) {
    58       Description = ItemDescription;
     59      description = ItemDescription;
    5960      Parameters = new ParameterCollection();
    6061      readOnlyParameters = null;
     
    6263    protected ParameterizedNamedItem(string name, ParameterCollection parameters)
    6364      : base(name) {
    64       Description = ItemDescription;
     65      description = ItemDescription;
    6566      Parameters = parameters;
    6667      readOnlyParameters = null;
  • trunk/sources/HeuristicLab.Operators.Views/3.3/OperatorView.cs

    r2845 r2851  
    7777      } else {
    7878        breakpointCheckBox.Checked = Content.Breakpoint;
     79        breakpointCheckBox.Enabled = true;
    7980      }
    8081    }
  • trunk/sources/HeuristicLab.Operators/3.3/CombinedOperator.cs

    r2834 r2851  
    3131  public sealed class CombinedOperator : AlgorithmOperator, IParameterizedItem {
    3232    public new ParameterCollection Parameters {
    33       get {
    34         return base.Parameters;
    35       }
     33      get { return base.Parameters; }
    3634    }
    3735    IObservableKeyedCollection<string, IParameter> IParameterizedItem.Parameters {
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r2834 r2851  
    5252  <ItemGroup>
    5353    <None Include="HeuristicLabOptimizationViewsPlugin.cs.frame" />
     54    <Compile Include="AlgorithmView.cs">
     55      <SubType>UserControl</SubType>
     56    </Compile>
     57    <Compile Include="AlgorithmView.Designer.cs">
     58      <DependentUpon>AlgorithmView.cs</DependentUpon>
     59    </Compile>
     60    <Compile Include="UserDefinedAlgorithmView.cs">
     61      <SubType>UserControl</SubType>
     62    </Compile>
     63    <Compile Include="UserDefinedAlgorithmView.Designer.cs">
     64      <DependentUpon>UserDefinedAlgorithmView.cs</DependentUpon>
     65    </Compile>
     66    <Compile Include="EngineAlgorithmView.cs">
     67      <SubType>UserControl</SubType>
     68    </Compile>
     69    <Compile Include="EngineAlgorithmView.Designer.cs">
     70      <DependentUpon>EngineAlgorithmView.cs</DependentUpon>
     71    </Compile>
    5472    <Compile Include="HeuristicLabOptimizationViewsPlugin.cs" />
    5573    <Compile Include="ProblemView.cs">
     
    6987      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
    7088      <Name>HeuristicLab.Collections-3.3</Name>
     89    </ProjectReference>
     90    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.2\HeuristicLab.Common.Resources-3.2.csproj">
     91      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
     92      <Name>HeuristicLab.Common.Resources-3.2</Name>
     93    </ProjectReference>
     94    <ProjectReference Include="..\..\HeuristicLab.Common\3.2\HeuristicLab.Common-3.2.csproj">
     95      <Project>{1FC004FC-59AF-4249-B1B6-FF25873A20E4}</Project>
     96      <Name>HeuristicLab.Common-3.2</Name>
    7197    </ProjectReference>
    7298    <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">
     
    89115      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    90116      <Name>HeuristicLab.Optimization-3.3</Name>
     117    </ProjectReference>
     118    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
     119      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
     120      <Name>HeuristicLab.Persistence-3.3</Name>
    91121    </ProjectReference>
    92122    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLabOptimizationViewsPlugin.cs.frame

    r2834 r2851  
    2929  [PluginFile("HeuristicLab.Optimization.Views-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Collections", "3.3")]
     31  [PluginDependency("HeuristicLab.Common", "3.2")]
     32  [PluginDependency("HeuristicLab.Common.Resources", "3.2")]
    3133  [PluginDependency("HeuristicLab.Core", "3.3")]
    3234  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
     
    3436  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.2")]
    3537  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     38  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    3639  public class HeuristicLabOptimizationViewsPlugin : PluginBase {
    3740  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ProblemView.Designer.cs

    r2834 r2851  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
    4847      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    4948      this.SuspendLayout();
     
    6160      this.descriptionTextBox.Size = new System.Drawing.Size(418, 87);
    6261      //
    63       // parameterCollectionView
    64       //
    65       this.parameterCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    66                   | System.Windows.Forms.AnchorStyles.Left)
    67                   | System.Windows.Forms.AnchorStyles.Right)));
    68       this.parameterCollectionView.Caption = "ParameterCollection";
    69       this.parameterCollectionView.Content = null;
    70       this.parameterCollectionView.Location = new System.Drawing.Point(0, 119);
    71       this.parameterCollectionView.Name = "parameterCollectionView";
    72       this.parameterCollectionView.Size = new System.Drawing.Size(490, 234);
    73       this.parameterCollectionView.TabIndex = 4;
    74       //
    7562      // ProblemView
    7663      //
    7764      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    7865      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    79       this.Controls.Add(this.parameterCollectionView);
    8066      this.Name = "ProblemView";
    8167      this.Size = new System.Drawing.Size(490, 353);
    82       this.Controls.SetChildIndex(this.parameterCollectionView, 0);
    83       this.Controls.SetChildIndex(this.nameLabel, 0);
    84       this.Controls.SetChildIndex(this.descriptionLabel, 0);
    85       this.Controls.SetChildIndex(this.nameTextBox, 0);
    86       this.Controls.SetChildIndex(this.descriptionTextBox, 0);
    8768      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    8869      this.ResumeLayout(false);
     
    9374    #endregion
    9475
    95     protected HeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView;
    9676
    9777  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ProblemView.cs

    r2834 r2851  
    2929  [Content(typeof(Problem), true)]
    3030  [Content(typeof(IProblem), false)]
    31   public partial class ProblemView : NamedItemView {
     31  public partial class ProblemView : ParameterizedNamedItemView {
    3232    public new IProblem Content {
    3333      get { return (IProblem)base.Content; }
     
    5252    protected override void OnContentChanged() {
    5353      base.OnContentChanged();
    54       if (Content == null)
    55         parameterCollectionView.Content = null;
    56       else
    57         parameterCollectionView.Content = ((IProblem)Content).Parameters;
    5854    }
    5955  }
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r2845 r2851  
    5151  <ItemGroup>
    5252    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
     53    <Compile Include="Algorithm.cs" />
     54    <Compile Include="UserDefinedAlgorithm.cs" />
     55    <Compile Include="EngineAlgorithm.cs" />
    5356    <Compile Include="IAlgorithm.cs" />
    5457    <Compile Include="HeuristicLabOptimizationPlugin.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/IAlgorithm.cs

    r2845 r2851  
    3838    void Stop();
    3939
     40    event EventHandler ProblemChanged;
    4041    event EventHandler ExecutionTimeChanged;
    4142    event EventHandler Prepared;
     
    4344    event EventHandler Stopped;
    4445    event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    45 
    4646  }
    4747}
  • trunk/sources/HeuristicLab.Optimization/3.3/Problem.cs

    r2845 r2851  
    2222using System.Drawing;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425
    2526namespace HeuristicLab.Optimization {
    2627  /// <summary>
    27   /// The base class for all problems.
     28  /// A base class for problems.
    2829  /// </summary>
    29   [Item("Problem", "Base class for problems.")]
     30  [Item("Problem", "A base class for problems.")]
     31  [EmptyStorableClass]
    3032  public abstract class Problem : ParameterizedNamedItem, IProblem {
    3133    public override Image ItemImage {
  • trunk/sources/HeuristicLab.SGA/3.3/HeuristicLab.SGA-3.3.csproj

    r2830 r2851  
    8383  <ItemGroup>
    8484    <None Include="HeuristicLabSGAPlugin.cs.frame" />
     85    <Compile Include="SGA.cs" />
    8586    <Compile Include="SGAOperator.cs" />
    8687    <Compile Include="HeuristicLabSGAPlugin.cs" />
     
    108109      <Name>HeuristicLab.Operators-3.3</Name>
    109110    </ProjectReference>
     111    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
     112      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
     113      <Name>HeuristicLab.Optimization-3.3</Name>
     114    </ProjectReference>
    110115    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
    111116      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
     
    119124      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    120125      <Name>HeuristicLab.PluginInfrastructure</Name>
     126    </ProjectReference>
     127    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
     128      <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
     129      <Name>HeuristicLab.Random-3.3</Name>
    121130    </ProjectReference>
    122131    <ProjectReference Include="..\..\HeuristicLab.Selection\3.3\HeuristicLab.Selection-3.3.csproj">
  • trunk/sources/HeuristicLab.SGA/3.3/HeuristicLabSGAPlugin.cs.frame

    r2830 r2851  
    3333  [PluginDependency("HeuristicLab.Evolutionary", "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")]
     38  [PluginDependency("HeuristicLab.Random", "3.3")]
    3739  [PluginDependency("HeuristicLab.Selection", "3.3")]
    3840  public class HeuristicLabSGAPlugin : PluginBase {
  • trunk/sources/HeuristicLab.SGA/3.3/SGA.cs

    r2526 r2851  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2623using HeuristicLab.Core;
     24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Collections;
     26using HeuristicLab.Parameters;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Operators;
     29using HeuristicLab.Optimization;
    2830using HeuristicLab.Evolutionary;
    29 using HeuristicLab.SequentialEngine;
    30 using HeuristicLab.Operators;
    31 using HeuristicLab.Random;
    32 using HeuristicLab.Logging;
    33 using HeuristicLab.Selection;
    34 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3531
    3632namespace HeuristicLab.SGA {
    3733  /// <summary>
    38   /// Class for the heuristic optimization technique "simple genetic algorithm".
     34  /// A standard genetic algorithm.
    3935  /// </summary>
    40   public class SGA : ItemBase {
    41     #region Create Operators
    42     /// <summary>
    43     /// Creates operators for the current instance.
    44     /// </summary>
    45     /// <param name="engine">The engine where to add the operators.</param>
    46     public static void Create(IEngine engine) {
    47       engine.OperatorGraph.Clear();
    48 
    49       CombinedOperator co = CreateSGA();
    50       co.Name = "SGA";
    51       engine.OperatorGraph.AddOperator(co);
    52       engine.OperatorGraph.InitialOperator = co;
    53 
    54       engine.Reset();
    55     }
    56     private static CombinedOperator CreateSGA() {
    57       CombinedOperator op = new CombinedOperator();
    58       SequentialProcessor sp = new SequentialProcessor();
    59       op.OperatorGraph.AddOperator(sp);
    60       op.OperatorGraph.InitialOperator = sp;
    61 
    62       CombinedOperator co1 = CreateVariableInjection();
    63       co1.Name = "Variable Injection";
    64       op.OperatorGraph.AddOperator(co1);
    65       sp.AddSubOperator(co1);
    66 
    67       // place holder for ProblemInjector
    68       EmptyOperator eo1 = new EmptyOperator();
    69       eo1.Name = "ProblemInjector";
    70       op.OperatorGraph.AddOperator(eo1);
    71       co1.AddSubOperator(eo1);
    72 
    73       CombinedOperator co2 = CreatePopulationInitialization();
    74       co2.Name = "Population Initialization";
    75       op.OperatorGraph.AddOperator(co2);
    76       sp.AddSubOperator(co2);
    77 
    78       // place holder for SolutionGenerator
    79       EmptyOperator eo2 = new EmptyOperator();
    80       eo2.Name = "SolutionGenerator";
    81       op.OperatorGraph.AddOperator(eo2);
    82       co2.AddSubOperator(eo2);
    83 
    84       // place holder for Evaluator
    85       EmptyOperator eo3 = new EmptyOperator();
    86       eo3.Name = "Evaluator";
    87       op.OperatorGraph.AddOperator(eo3);
    88       co2.AddSubOperator(eo3);
    89 
    90       CombinedOperator co3 = CreateSGAMain();
    91       co3.Name = "SGA Main";
    92       op.OperatorGraph.AddOperator(co3);
    93       sp.AddSubOperator(co3);
    94 
    95       // place holder for Selector
    96       EmptyOperator eo4 = new EmptyOperator();
    97       eo4.Name = "Selector";
    98       op.OperatorGraph.AddOperator(eo4);
    99       co3.AddSubOperator(eo4);
    100 
    101       // place holder for Crossover
    102       EmptyOperator eo5 = new EmptyOperator();
    103       eo5.Name = "Crossover";
    104       op.OperatorGraph.AddOperator(eo5);
    105       co3.AddSubOperator(eo5);
    106 
    107       // place holder for Mutator
    108       EmptyOperator eo6 = new EmptyOperator();
    109       eo6.Name = "Mutator";
    110       op.OperatorGraph.AddOperator(eo6);
    111       co3.AddSubOperator(eo6);
    112 
    113       // place holder for Evaluator
    114       co3.AddSubOperator(eo3);
    115 
    116       return op;
    117     }
    118     private static CombinedOperator CreateVariableInjection() {
    119       CombinedOperator op = new CombinedOperator();
    120       SequentialProcessor sp = new SequentialProcessor();
    121       op.OperatorGraph.AddOperator(sp);
    122       op.OperatorGraph.InitialOperator = sp;
    123 
    124       RandomInjector ri = new RandomInjector();
    125       op.OperatorGraph.AddOperator(ri);
    126       sp.AddSubOperator(ri);
    127 
    128       OperatorExtractor oe = new OperatorExtractor();
    129       oe.Name = "ProblemInjector";
    130       oe.GetVariableInfo("Operator").ActualName = "ProblemInjector";
    131       op.OperatorGraph.AddOperator(oe);
    132       sp.AddSubOperator(oe);
    133 
    134       VariableInjector vi = new VariableInjector();
    135       vi.AddVariable(new Variable("PopulationSize", new IntData(100)));
    136       vi.AddVariable(new Variable("EvaluatedSolutions", new IntData()));
    137       vi.AddVariable(new Variable("Parents", new IntData(200)));
    138       vi.AddVariable(new Variable("MutationRate", new DoubleData(0.05)));
    139       vi.AddVariable(new Variable("Elites", new IntData(1)));
    140       vi.AddVariable(new Variable("Generations", new IntData()));
    141       vi.AddVariable(new Variable("MaximumGenerations", new IntData(1000)));
    142       op.OperatorGraph.AddOperator(vi);
    143       sp.AddSubOperator(vi);
    144 
    145       return op;
    146     }
    147     private static CombinedOperator CreatePopulationInitialization() {
    148       CombinedOperator op = new CombinedOperator();
    149       SequentialProcessor sp1 = new SequentialProcessor();
    150       op.OperatorGraph.AddOperator(sp1);
    151       op.OperatorGraph.InitialOperator = sp1;
    152 
    153       SubScopesCreater ssc = new SubScopesCreater();
    154       ssc.GetVariableInfo("SubScopes").ActualName = "PopulationSize";
    155       op.OperatorGraph.AddOperator(ssc);
    156       sp1.AddSubOperator(ssc);
    157 
    158       UniformSequentialSubScopesProcessor ussp = new UniformSequentialSubScopesProcessor();
    159       op.OperatorGraph.AddOperator(ussp);
    160       sp1.AddSubOperator(ussp);
    161 
    162       SequentialProcessor sp2 = new SequentialProcessor();
    163       op.OperatorGraph.AddOperator(sp2);
    164       ussp.AddSubOperator(sp2);
    165 
    166       OperatorExtractor oe1 = new OperatorExtractor();
    167       oe1.Name = "SolutionGenerator";
    168       oe1.GetVariableInfo("Operator").ActualName = "SolutionGenerator";
    169       op.OperatorGraph.AddOperator(oe1);
    170       sp2.AddSubOperator(oe1);
    171 
    172       OperatorExtractor oe2 = new OperatorExtractor();
    173       oe2.Name = "Evaluator";
    174       oe2.GetVariableInfo("Operator").ActualName = "Evaluator";
    175       op.OperatorGraph.AddOperator(oe2);
    176       sp2.AddSubOperator(oe2);
    177 
    178       Counter c = new Counter();
    179       c.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
    180       op.OperatorGraph.AddOperator(c);
    181       sp2.AddSubOperator(c);
    182 
    183       Sorter s = new Sorter();
    184       s.GetVariableInfo("Descending").ActualName = "Maximization";
    185       s.GetVariableInfo("Value").ActualName = "Quality";
    186       op.OperatorGraph.AddOperator(s);
    187       sp1.AddSubOperator(s);
    188 
    189       return op;
    190     }
    191     private static CombinedOperator CreateSGAMain() {
    192       CombinedOperator op = new CombinedOperator();
    193       SequentialProcessor sp = new SequentialProcessor();
    194       op.OperatorGraph.AddOperator(sp);
    195       op.OperatorGraph.InitialOperator = sp;
    196 
    197       OperatorExtractor oe = new OperatorExtractor();
    198       oe.Name = "Selector";
    199       oe.GetVariableInfo("Operator").ActualName = "Selector";
    200       op.OperatorGraph.AddOperator(oe);
    201       sp.AddSubOperator(oe);
    202 
    203       SequentialSubScopesProcessor ssp = new SequentialSubScopesProcessor();
    204       op.OperatorGraph.AddOperator(ssp);
    205       sp.AddSubOperator(ssp);
    206 
    207       EmptyOperator eo = new EmptyOperator();
    208       op.OperatorGraph.AddOperator(eo);
    209       ssp.AddSubOperator(eo);
    210 
    211       CombinedOperator co1 = CreateCreateChildren();
    212       co1.Name = "Create Children";
    213       op.OperatorGraph.AddOperator(co1);
    214       ssp.AddSubOperator(co1);
    215 
    216       CombinedOperator co2 = CreateReplacement();
    217       co2.Name = "Replacement";
    218       op.OperatorGraph.AddOperator(co2);
    219       sp.AddSubOperator(co2);
    220 
    221       QualityLogger ql = new QualityLogger();
    222       op.OperatorGraph.AddOperator(ql);
    223       sp.AddSubOperator(ql);
    224 
    225       BestAverageWorstQualityCalculator bawqc = new BestAverageWorstQualityCalculator();
    226       op.OperatorGraph.AddOperator(bawqc);
    227       sp.AddSubOperator(bawqc);
    228 
    229       DataCollector dc = new DataCollector();
    230       ItemList<StringData> names = dc.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
    231       names.Add(new StringData("BestQuality"));
    232       names.Add(new StringData("AverageQuality"));
    233       names.Add(new StringData("WorstQuality"));
    234       op.OperatorGraph.AddOperator(dc);
    235       sp.AddSubOperator(dc);
    236 
    237       LinechartInjector lci = new LinechartInjector();
    238       lci.GetVariableInfo("Linechart").ActualName = "Quality Linechart";
    239       lci.GetVariable("NumberOfLines").GetValue<IntData>().Data = 3;
    240       op.OperatorGraph.AddOperator(lci);
    241       sp.AddSubOperator(lci);
    242 
    243       Counter c = new Counter();
    244       c.GetVariableInfo("Value").ActualName = "Generations";
    245       op.OperatorGraph.AddOperator(c);
    246       sp.AddSubOperator(c);
    247 
    248       LessThanComparator ltc = new LessThanComparator();
    249       ltc.GetVariableInfo("LeftSide").ActualName = "Generations";
    250       ltc.GetVariableInfo("RightSide").ActualName = "MaximumGenerations";
    251       ltc.GetVariableInfo("Result").ActualName = "GenerationsCondition";
    252       op.OperatorGraph.AddOperator(ltc);
    253       sp.AddSubOperator(ltc);
    254 
    255       ConditionalBranch cb = new ConditionalBranch();
    256       cb.GetVariableInfo("Condition").ActualName = "GenerationsCondition";
    257       op.OperatorGraph.AddOperator(cb);
    258       sp.AddSubOperator(cb);
    259 
    260       cb.AddSubOperator(sp);
    261 
    262       return op;
    263     }
    264     private static CombinedOperator CreateCreateChildren() {
    265       CombinedOperator op = new CombinedOperator();
    266       SequentialProcessor sp1 = new SequentialProcessor();
    267       op.OperatorGraph.AddOperator(sp1);
    268       op.OperatorGraph.InitialOperator = sp1;
    269 
    270       ChildrenInitializer ci = new ChildrenInitializer();
    271       op.OperatorGraph.AddOperator(ci);
    272       sp1.AddSubOperator(ci);
    273 
    274       UniformSequentialSubScopesProcessor ussp = new UniformSequentialSubScopesProcessor();
    275       op.OperatorGraph.AddOperator(ussp);
    276       sp1.AddSubOperator(ussp);
    277 
    278       SequentialProcessor sp2 = new SequentialProcessor();
    279       op.OperatorGraph.AddOperator(sp2);
    280       ussp.AddSubOperator(sp2);
    281 
    282       OperatorExtractor oe1 = new OperatorExtractor();
    283       oe1.Name = "Crossover";
    284       oe1.GetVariableInfo("Operator").ActualName = "Crossover";
    285       op.OperatorGraph.AddOperator(oe1);
    286       sp2.AddSubOperator(oe1);
    287 
    288       StochasticBranch hb = new StochasticBranch();
    289       hb.GetVariableInfo("Probability").ActualName = "MutationRate";
    290       op.OperatorGraph.AddOperator(hb);
    291       sp2.AddSubOperator(hb);
    292 
    293       OperatorExtractor oe2 = new OperatorExtractor();
    294       oe2.Name = "Mutator";
    295       oe2.GetVariableInfo("Operator").ActualName = "Mutator";
    296       op.OperatorGraph.AddOperator(oe2);
    297       hb.AddSubOperator(oe2);
    298 
    299       OperatorExtractor oe3 = new OperatorExtractor();
    300       oe3.Name = "Evaluator";
    301       oe3.GetVariableInfo("Operator").ActualName = "Evaluator";
    302       op.OperatorGraph.AddOperator(oe3);
    303       sp2.AddSubOperator(oe3);
    304 
    305       SubScopesRemover sr = new SubScopesRemover();
    306       sr.GetVariableInfo("SubScopeIndex").Local = true;
    307       op.OperatorGraph.AddOperator(sr);
    308       sp2.AddSubOperator(sr);
    309 
    310       Counter c = new Counter();
    311       c.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
    312       op.OperatorGraph.AddOperator(c);
    313       sp2.AddSubOperator(c);
    314 
    315       Sorter s = new Sorter();
    316       s.GetVariableInfo("Descending").ActualName = "Maximization";
    317       s.GetVariableInfo("Value").ActualName = "Quality";
    318       op.OperatorGraph.AddOperator(s);
    319       sp1.AddSubOperator(s);
    320 
    321       return op;
    322     }
    323     private static CombinedOperator CreateReplacement() {
    324       CombinedOperator op = new CombinedOperator();
    325       SequentialProcessor sp1 = new SequentialProcessor();
    326       op.OperatorGraph.AddOperator(sp1);
    327       op.OperatorGraph.InitialOperator = sp1;
    328 
    329       SequentialSubScopesProcessor ssp = new SequentialSubScopesProcessor();
    330       op.OperatorGraph.AddOperator(ssp);
    331       sp1.AddSubOperator(ssp);
    332 
    333       SequentialProcessor sp2 = new SequentialProcessor();
    334       op.OperatorGraph.AddOperator(sp2);
    335       ssp.AddSubOperator(sp2);
    336 
    337       LeftSelector ls = new LeftSelector();
    338       ls.GetVariableInfo("Selected").ActualName = "Elites";
    339       op.OperatorGraph.AddOperator(ls);
    340       sp2.AddSubOperator(ls);
    341 
    342       RightReducer rr = new RightReducer();
    343       op.OperatorGraph.AddOperator(rr);
    344       sp2.AddSubOperator(rr);
    345 
    346       SequentialProcessor sp3 = new SequentialProcessor();
    347       op.OperatorGraph.AddOperator(sp3);
    348       ssp.AddSubOperator(sp3);
    349 
    350       RightSelector rs = new RightSelector();
    351       rs.GetVariableInfo("Selected").ActualName = "Elites";
    352       op.OperatorGraph.AddOperator(rs);
    353       sp3.AddSubOperator(rs);
    354 
    355       LeftReducer lr = new LeftReducer();
    356       op.OperatorGraph.AddOperator(lr);
    357       sp3.AddSubOperator(lr);
    358 
    359       MergingReducer mr = new MergingReducer();
    360       op.OperatorGraph.AddOperator(mr);
    361       sp1.AddSubOperator(mr);
    362 
    363       Sorter s = new Sorter();
    364       s.GetVariableInfo("Descending").ActualName = "Maximization";
    365       s.GetVariableInfo("Value").ActualName = "Quality";
    366       op.OperatorGraph.AddOperator(s);
    367       sp1.AddSubOperator(s);
    368 
    369       return op;
    370     }
    371     #endregion
    372 
    373     #region Properties
    374 
    375     [Storable]
    376     private IEngine myEngine;
    377     /// <summary>
    378     /// Gets the engine of the current instance.
    379     /// </summary>
    380     public IEngine Engine {
    381       get { return myEngine; }
     36  [Item("SGA", "A standard genetic algorithm.")]
     37  [Creatable("Algorithms")]
     38  [EmptyStorableClass]
     39  public sealed class SGA : EngineAlgorithm {
     40    public new IScope GlobalScope {
     41      get { return base.GlobalScope; }
    38242    }
    38343
    384     [Storable]
    385     private BoolData mySetSeedRandomly;
    386     /// <summary>
    387     /// Gets or sets the flag whether to set the seed randomly or not.
    388     /// </summary>
    389     public bool SetSeedRandomly {
    390       get { return mySetSeedRandomly.Data; }
    391       set { mySetSeedRandomly.Data = value; }
    392     }
     44    public SGA()
     45      : 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."));
     48      Parameters.Add(new ValueParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0)));
     49      Parameters.Add(new ValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true)));
     50      Parameters.Add(new ValueParameter<IntData>("PopulationSize", "The size of the population of solutions.", new IntData(100)));
     51      Parameters.Add(new OperatorParameter("CrossoverOperator", "The operator used to cross solutions."));
     52      Parameters.Add(new ValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05)));
     53      Parameters.Add(new OperatorParameter("MutationOperator", "The operator used to mutate solutions."));
     54//      Parameters.Add(new ValueLookupParameter<IOperator>("SolutionEvaluator", "The operator used to evaluate solutions."));
     55      Parameters.Add(new ValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1)));
     56      Parameters.Add(new ValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000)));
    39357
    394     [Storable]
    395     private IntData mySeed;
    396     /// <summary>
    397     /// Gets or sets the value of the seed of the current instance.
    398     /// </summary>
    399     public int Seed {
    400       get { return mySeed.Data; }
    401       set { mySeed.Data = value; }
    402     }
     58      RandomCreator randomCreator = new RandomCreator();
     59      PopulationCreator populationCreator = new PopulationCreator();
     60      SGAOperator sgaOperator = new SGAOperator();
    40361
    404     [Storable]
    405     private IntData myParents;
     62      randomCreator.RandomParameter.ActualName = "Random";
     63      randomCreator.SeedParameter.ActualName = "Seed";
     64      randomCreator.SeedParameter.Value = null;
     65      randomCreator.SetSeedRandomlyParameter.ActualName = "SetSeedRandomly";
     66      randomCreator.SetSeedRandomlyParameter.Value = null;
     67      randomCreator.Successor = populationCreator;
    40668
    407     [Storable]
    408     private IntData myPopulationSize;   
    409     /// <summary>
    410     /// Gets or sets the population size of the current instance.
    411     /// </summary>
    412     /// <remarks>The number of parents is set to two times the population size.</remarks>
    413     public int PopulationSize {
    414       get { return myPopulationSize.Data; }
    415       set {
    416         myPopulationSize.Data = value;
    417         myParents.Data = value * 2;
    418       }
    419     }
     69      populationCreator.PopulationSizeParameter.ActualName = "PopulationSize";
     70      populationCreator.PopulationSizeParameter.Value = null;
     71      populationCreator.SolutionCreatorParameter.ActualName = "SolutionCreator";
     72      populationCreator.SolutionEvaluatorParameter.ActualName = "SolutionEvaluator";
     73      populationCreator.Successor = sgaOperator;
    42074
    421     [Storable]
    422     private IntData myMaximumGenerations;
    423     /// <summary>
    424     /// Gets or sets the number of maximum generations.
    425     /// </summary>
    426     public int MaximumGenerations {
    427       get { return myMaximumGenerations.Data; }
    428       set { myMaximumGenerations.Data = value; }
    429     }
     75      sgaOperator.CrossoverOperatorParameter.ActualName = "CrossoverOperator";
     76      sgaOperator.ElitesParameter.ActualName = "Elites";
     77      sgaOperator.MaximizationParameter.ActualName = "Maximization";
     78      sgaOperator.MaximumGenerationsParameter.ActualName = "MaximumGenerations";
     79      sgaOperator.MutationOperatorParameter.ActualName = "MutationOperator";
     80      sgaOperator.MutationProbabilityParameter.ActualName = "MutationProbability";
     81      sgaOperator.QualityParameter.ActualName = "Quality";
     82      sgaOperator.RandomParameter.ActualName = "Random";
     83      sgaOperator.SolutionEvaluatorParameter.ActualName = "SolutionEvaluator";
    43084
    431     [Storable]
    432     private DoubleData myMutationRate;
    433     /// <summary>
    434     /// Gets or sets the mutation rate of the current instance.
    435     /// </summary>
    436     public double MutationRate {
    437       get { return myMutationRate.Data; }
    438       set { myMutationRate.Data = value; }
    439     }
    440 
    441     [Storable]
    442     private IntData myElites;
    443     /// <summary>
    444     /// Gets or sets the elites of the current instance.
    445     /// </summary>
    446     public int Elites {
    447       get { return myElites.Data; }
    448       set { myElites.Data = value; }
    449     }
    450 
    451     [Storable]
    452     private CombinedOperator mySGA;
    453 
    454     [Storable]
    455     private IOperator myVariableInjection;
    456 
    457     /// <summary>
    458     /// Gets or sets the problem injector of the current instance.
    459     /// </summary>
    460     public IOperator ProblemInjector {
    461       get { return myVariableInjection.SubOperators[0]; }
    462       set {
    463         value.Name = "ProblemInjector";
    464         mySGA.OperatorGraph.RemoveOperator(ProblemInjector);
    465         mySGA.OperatorGraph.AddOperator(value);
    466         myVariableInjection.AddSubOperator(value, 0);
    467       }
    468     }
    469 
    470     [Storable]
    471     private IOperator myPopulationInitialization;
    472     /// <summary>
    473     /// Gets or sets the solution generator of the current instance.
    474     /// </summary>
    475     public IOperator SolutionGenerator {
    476       get { return myPopulationInitialization.SubOperators[0]; }
    477       set {
    478         value.Name = "SolutionGenerator";
    479         mySGA.OperatorGraph.RemoveOperator(SolutionGenerator);
    480         mySGA.OperatorGraph.AddOperator(value);
    481         myPopulationInitialization.AddSubOperator(value, 0);
    482       }
    483     }
    484 
    485     /// <summary>
    486     /// Gets or sets the evaluator of the current instance.
    487     /// </summary>
    488     public IOperator Evaluator {
    489       get { return myPopulationInitialization.SubOperators[1]; }
    490       set {
    491         value.Name = "Evaluator";
    492         mySGA.OperatorGraph.RemoveOperator(Evaluator);
    493         mySGA.OperatorGraph.AddOperator(value);
    494         myPopulationInitialization.AddSubOperator(value, 1);
    495         mySGAMain.AddSubOperator(value, 3);
    496       }
    497     }
    498 
    499     [Storable]
    500     private IOperator mySGAMain;
    501 
    502     /// <summary>
    503     /// Gets or sets the selection operator of the current instance.
    504     /// </summary>
    505     public IOperator Selector {
    506       get { return mySGAMain.SubOperators[0]; }
    507       set {
    508         value.Name = "Selector";
    509         mySGA.OperatorGraph.RemoveOperator(Selector);
    510         mySGA.OperatorGraph.AddOperator(value);
    511         mySGAMain.AddSubOperator(value, 0);
    512       }
    513     }
    514 
    515     /// <summary>
    516     /// Gets or sets the crossover operator of the current instance.
    517     /// </summary>
    518     public IOperator Crossover {
    519       get { return mySGAMain.SubOperators[1]; }
    520       set {
    521         value.Name = "Crossover";
    522         mySGA.OperatorGraph.RemoveOperator(Crossover);
    523         mySGA.OperatorGraph.AddOperator(value);
    524         mySGAMain.AddSubOperator(value, 1);
    525       }
    526     }
    527 
    528     /// <summary>
    529     /// Gets or sets the mutation operator of the current instance.
    530     /// </summary>
    531     public IOperator Mutator {
    532       get { return mySGAMain.SubOperators[2]; }
    533       set {
    534         value.Name = "Mutator";
    535         mySGA.OperatorGraph.RemoveOperator(Mutator);
    536         mySGA.OperatorGraph.AddOperator(value);
    537         mySGAMain.AddSubOperator(value, 2);
    538       }
    539     }
    540     #endregion
    541 
    542     /// <summary>
    543     /// Initializes a new instance of <see cref="SGA"/>.
    544     /// </summary>
    545     public SGA() {
    546       myEngine = new SequentialEngine.SequentialEngine();
    547       Create(myEngine);
    548       SetReferences();
    549     }
    550 
    551     /// <summary>
    552     /// Clones the current instance (deep clone).
    553     /// </summary>
    554     /// <remarks>Deep clone through <see cref="cloner.Clone"/> method of helper class
    555     /// <see cref="Auxiliary"/>.</remarks>
    556     /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    557     /// <returns>The cloned object as <see cref="SGA"/>.</returns>
    558     public override IItem Clone(ICloner cloner) {
    559       SGA clone = new SGA();
    560       cloner.RegisterClonedObject(this, clone);
    561       clone.myEngine = (IEngine)cloner.Clone(Engine);
    562       return clone;
    563     }
    564    
    565     private void SetReferences() {
    566       // SGA
    567       CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
    568       mySGA = co1;
    569       // SequentialProcessor in SGA
    570       SequentialProcessor sp1 = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
    571       // Variable Injection
    572       CombinedOperator co2 = (CombinedOperator)sp1.SubOperators[0];
    573       myVariableInjection = co2;
    574       // SequentialProcessor in Variable Injection
    575       SequentialProcessor sp2 = (SequentialProcessor)co2.OperatorGraph.InitialOperator;
    576       // RandomInjector
    577       RandomInjector ri = (RandomInjector)sp2.SubOperators[0];
    578       mySetSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>();
    579       mySeed = ri.GetVariable("Seed").GetValue<IntData>();
    580       // VariableInjector
    581       VariableInjector vi = (VariableInjector)sp2.SubOperators[2];
    582       myPopulationSize = vi.GetVariable("PopulationSize").GetValue<IntData>();
    583       myParents = vi.GetVariable("Parents").GetValue<IntData>();
    584       myMaximumGenerations = vi.GetVariable("MaximumGenerations").GetValue<IntData>();
    585       myMutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>();
    586       myElites = vi.GetVariable("Elites").GetValue<IntData>();
    587       // Population Initialization
    588       CombinedOperator co3 = (CombinedOperator)sp1.SubOperators[1];
    589       myPopulationInitialization = co3;
    590       // SGA Main
    591       CombinedOperator co4 = (CombinedOperator)sp1.SubOperators[2];
    592       mySGAMain = co4;
     85      OperatorGraph.InitialOperator = randomCreator;
    59386    }
    59487  }
  • trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs

    r2834 r2851  
    3636
    3737    /// <summary>
    38     /// Aborts the engine execution.
    39     /// </summary>
    40     /// <remarks>Calls <see cref="EngineBase.Abort"/> of base class <see cref="EngineBase"/> and
    41     /// <see cref="IOperator.Abort"/> of the current <see cref="IOperator"/>.</remarks>
    42     public override void Stop() {
    43       base.Stop();
    44       if (currentOperator != null)
    45         currentOperator.Abort();
    46     }
    47 
    48     /// <summary>
    4938    /// Deals with the next operation, if it is an <see cref="AtomicOperation"/> it is executed,
    5039    /// if it is a <see cref="CompositeOperation"/> its single operations are pushed on the execution stack.
     
    7968      }
    8069    }
     70
     71    protected override void OnCanceledChanged() {
     72      if (Canceled && (currentOperator != null))
     73        currentOperator.Abort();
     74    }
    8175  }
    8276}
Note: See TracChangeset for help on using the changeset viewer.