Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12860 for branches


Ignore:
Timestamp:
08/13/15 16:05:08 (9 years ago)
Author:
abeham
Message:

#2457: worked on expert system

Location:
branches/PerformanceComparison
Files:
2 edited
3 moved

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.Designer.cs

    r12847 r12860  
    2121
    2222namespace HeuristicLab.OptimizationExpertSystem.Views {
    23   partial class ExpertSystemOptimizerView {
     23  partial class ExpertSystemView {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    4848      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
    4949      this.okbTabPage = new System.Windows.Forms.TabPage();
    50       this.okbRunCollectionView = new HeuristicLab.Optimization.Views.RunCollectionView();
    5150      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
     51      this.algorithmInstancesViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5252      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5353      this.tabControl.SuspendLayout();
     
    5858      this.SuspendLayout();
    5959      //
    60       // startButton
    61       //
    62       this.startButton.Location = new System.Drawing.Point(0, 440);
    63       this.startButton.TabIndex = 18;
    64       this.toolTip.SetToolTip(this.startButton, "Start/Resume Optimizer");
    65       //
    66       // executionTimeTextBox
    67       //
    68       this.executionTimeTextBox.Location = new System.Drawing.Point(412, 444);
    69       this.executionTimeTextBox.TabIndex = 23;
    70       //
    71       // executionTimeLabel
    72       //
    73       this.executionTimeLabel.Location = new System.Drawing.Point(323, 447);
    74       this.executionTimeLabel.TabIndex = 22;
    75       //
    76       // pauseButton
    77       //
    78       this.pauseButton.Location = new System.Drawing.Point(30, 440);
    79       this.pauseButton.TabIndex = 19;
    80       this.toolTip.SetToolTip(this.pauseButton, "Pause Optimizer");
    81       //
    82       // stopButton
    83       //
    84       this.stopButton.Location = new System.Drawing.Point(60, 440);
    85       this.stopButton.TabIndex = 20;
    86       this.toolTip.SetToolTip(this.stopButton, "Stop Optimizer");
    87       //
    88       // resetButton
    89       //
    90       this.resetButton.Location = new System.Drawing.Point(90, 440);
    91       this.resetButton.TabIndex = 21;
    92       this.toolTip.SetToolTip(this.resetButton, "Reset Optimizer");
    93       //
    9460      // nameTextBox
    9561      //
     
    135101      this.tabControl.Name = "tabControl";
    136102      this.tabControl.SelectedIndex = 0;
    137       this.tabControl.Size = new System.Drawing.Size(546, 382);
     103      this.tabControl.Size = new System.Drawing.Size(546, 361);
    138104      this.tabControl.TabIndex = 17;
    139105      //
     
    147113      this.problemTabPage.Name = "problemTabPage";
    148114      this.problemTabPage.Padding = new System.Windows.Forms.Padding(3);
    149       this.problemTabPage.Size = new System.Drawing.Size(538, 356);
     115      this.problemTabPage.Size = new System.Drawing.Size(538, 335);
    150116      this.problemTabPage.TabIndex = 1;
    151117      this.problemTabPage.Text = "Problem";
     
    166132      this.problemViewHost.Name = "problemViewHost";
    167133      this.problemViewHost.ReadOnly = false;
    168       this.problemViewHost.Size = new System.Drawing.Size(526, 314);
     134      this.problemViewHost.Size = new System.Drawing.Size(526, 293);
    169135      this.problemViewHost.TabIndex = 2;
    170136      this.problemViewHost.ViewsLabelVisible = true;
     
    201167      this.algorithmTabPage.Name = "algorithmTabPage";
    202168      this.algorithmTabPage.Padding = new System.Windows.Forms.Padding(3);
    203       this.algorithmTabPage.Size = new System.Drawing.Size(538, 356);
     169      this.algorithmTabPage.Size = new System.Drawing.Size(538, 335);
    204170      this.algorithmTabPage.TabIndex = 4;
    205171      this.algorithmTabPage.Text = "Algorithm";
     
    217183      this.algorithmViewHost.Name = "algorithmViewHost";
    218184      this.algorithmViewHost.ReadOnly = false;
    219       this.algorithmViewHost.Size = new System.Drawing.Size(526, 314);
     185      this.algorithmViewHost.Size = new System.Drawing.Size(526, 293);
    220186      this.algorithmViewHost.TabIndex = 2;
    221187      this.algorithmViewHost.ViewsLabelVisible = true;
     
    249215      this.runsTabPage.Name = "runsTabPage";
    250216      this.runsTabPage.Padding = new System.Windows.Forms.Padding(3);
    251       this.runsTabPage.Size = new System.Drawing.Size(538, 356);
     217      this.runsTabPage.Size = new System.Drawing.Size(538, 335);
    252218      this.runsTabPage.TabIndex = 3;
    253219      this.runsTabPage.Text = "Runs";
     
    262228      this.runsView.Name = "runsView";
    263229      this.runsView.ReadOnly = false;
    264       this.runsView.Size = new System.Drawing.Size(532, 350);
     230      this.runsView.Size = new System.Drawing.Size(532, 329);
    265231      this.runsView.TabIndex = 1;
    266232      //
    267233      // okbTabPage
    268234      //
    269       this.okbTabPage.Controls.Add(this.okbRunCollectionView);
     235      this.okbTabPage.Controls.Add(this.algorithmInstancesViewHost);
    270236      this.okbTabPage.Location = new System.Drawing.Point(4, 22);
    271237      this.okbTabPage.Name = "okbTabPage";
    272238      this.okbTabPage.Padding = new System.Windows.Forms.Padding(3);
    273       this.okbTabPage.Size = new System.Drawing.Size(538, 356);
     239      this.okbTabPage.Size = new System.Drawing.Size(538, 335);
    274240      this.okbTabPage.TabIndex = 5;
    275241      this.okbTabPage.Text = "Knowledge Base";
    276242      this.okbTabPage.UseVisualStyleBackColor = true;
    277       //
    278       // okbRunCollectionView
    279       //
    280       this.okbRunCollectionView.Caption = "RunCollection View";
    281       this.okbRunCollectionView.Content = null;
    282       this.okbRunCollectionView.Dock = System.Windows.Forms.DockStyle.Fill;
    283       this.okbRunCollectionView.Location = new System.Drawing.Point(3, 3);
    284       this.okbRunCollectionView.Name = "okbRunCollectionView";
    285       this.okbRunCollectionView.ReadOnly = false;
    286       this.okbRunCollectionView.Size = new System.Drawing.Size(532, 350);
    287       this.okbRunCollectionView.TabIndex = 0;
    288243      //
    289244      // openFileDialog
     
    293248      this.openFileDialog.Filter = "HeuristicLab Files|*.hl|All Files|*.*";
    294249      this.openFileDialog.Title = "Open Optimizer";
     250      //
     251      // algorithmInstancesViewHost
     252      //
     253      this.algorithmInstancesViewHost.Caption = "View";
     254      this.algorithmInstancesViewHost.Content = null;
     255      this.algorithmInstancesViewHost.Dock = System.Windows.Forms.DockStyle.Fill;
     256      this.algorithmInstancesViewHost.Enabled = false;
     257      this.algorithmInstancesViewHost.Location = new System.Drawing.Point(3, 3);
     258      this.algorithmInstancesViewHost.Name = "algorithmInstancesViewHost";
     259      this.algorithmInstancesViewHost.ReadOnly = false;
     260      this.algorithmInstancesViewHost.Size = new System.Drawing.Size(532, 329);
     261      this.algorithmInstancesViewHost.TabIndex = 0;
     262      this.algorithmInstancesViewHost.ViewsLabelVisible = true;
     263      this.algorithmInstancesViewHost.ViewType = null;
    295264      //
    296265      // ExpertSystemOptimizerView
     
    301270      this.Controls.Add(this.maxEvaluationsTextBox);
    302271      this.Name = "ExpertSystemOptimizerView";
    303       this.Size = new System.Drawing.Size(549, 464);
     272      this.Size = new System.Drawing.Size(549, 413);
    304273      this.Controls.SetChildIndex(this.maxEvaluationsTextBox, 0);
    305274      this.Controls.SetChildIndex(this.evaluationsLimitabel, 0);
     
    308277      this.Controls.SetChildIndex(this.nameTextBox, 0);
    309278      this.Controls.SetChildIndex(this.infoLabel, 0);
    310       this.Controls.SetChildIndex(this.resetButton, 0);
    311       this.Controls.SetChildIndex(this.stopButton, 0);
    312       this.Controls.SetChildIndex(this.pauseButton, 0);
    313       this.Controls.SetChildIndex(this.executionTimeLabel, 0);
    314       this.Controls.SetChildIndex(this.executionTimeTextBox, 0);
    315       this.Controls.SetChildIndex(this.startButton, 0);
    316279      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    317280      this.tabControl.ResumeLayout(false);
     
    343306    private System.Windows.Forms.ComboBox suggestedInstancesComboBox;
    344307    private System.Windows.Forms.TabPage okbTabPage;
    345     private Optimization.Views.RunCollectionView okbRunCollectionView;
     308    private MainForm.WindowsForms.ViewHost algorithmInstancesViewHost;
    346309  }
    347310}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs

    r12847 r12860  
    2222using System;
    2323using System.ComponentModel;
    24 using System.Globalization;
    25 using System.Linq;
    2624using System.Windows.Forms;
    27 using HeuristicLab.Analysis;
    2825using HeuristicLab.Common;
    29 using HeuristicLab.Core;
    3026using HeuristicLab.Core.Views;
    3127using HeuristicLab.MainForm;
    3228using HeuristicLab.Optimization;
    33 using HeuristicLab.Optimization.Views;
    3429using HeuristicLab.PluginInfrastructure;
    3530
    3631namespace HeuristicLab.OptimizationExpertSystem.Views {
    3732  [View("Expert-system Optimizer View")]
    38   [Content(typeof(ExpertSystemOptimizer), IsDefaultView = true)]
    39   public partial class ExpertSystemOptimizerView : IOptimizerView {
     33  [Content(typeof(ExpertSystem), IsDefaultView = true)]
     34  public partial class ExpertSystemView : NamedItemView {
    4035    protected TypeSelectorDialog problemTypeSelectorDialog;
    4136    protected virtual bool SuppressEvents { get; set; }
    4237
    43     public new ExpertSystemOptimizer Content {
    44       get { return (ExpertSystemOptimizer)base.Content; }
     38    public new ExpertSystem Content {
     39      get { return (ExpertSystem)base.Content; }
    4540      set { base.Content = value; }
    4641    }
    4742
    48     public ExpertSystemOptimizerView() {
     43    public ExpertSystemView() {
    4944      InitializeComponent();
    5045    }
     
    8782          algorithmViewHost.Content = null;
    8883          runsView.Content = null;
    89           okbRunCollectionView.Content = null;
     84          algorithmInstancesViewHost.Content = null;
    9085        } else {
    9186          maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString();
    9287          problemViewHost.Content = Content.Problem;
    9388          runsView.Content = Content.Runs;
    94           okbRunCollectionView.Content = Content.KnowledgeBase;
     89          algorithmInstancesViewHost.Content = Content.AlgorithmInstances;
    9590        }
    96         UpdateSuggestedInstancesCombobox();
    9791      } finally { SuppressEvents = false; }
     92      UpdateSuggestedInstancesCombobox();
    9893    }
    9994
     
    107102      algorithmViewHost.Enabled = Content != null && !ReadOnly && !Locked;
    108103      runsView.Enabled = Content != null;
    109       okbRunCollectionView.Enabled = Content != null;
    110     }
    111 
    112     protected override void OnClosed(FormClosedEventArgs e) {
    113       if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) {
    114         //The content must be stopped if no other view showing the content is available
    115         var optimizers = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v != this).Select(v => v.Content).OfType<IOptimizer>();
    116         if (!optimizers.Contains(Content)) {
    117           var nestedOptimizers = optimizers.SelectMany(opt => opt.NestedOptimizers);
    118           if (!nestedOptimizers.Contains(Content)) Content.Stop();
    119         }
    120       }
    121       base.OnClosed(e);
     104      algorithmInstancesViewHost.Enabled = Content != null;
    122105    }
    123106
    124107    private void UpdateSuggestedInstancesCombobox() {
    125       SuspendRepaint();
    126       try {
    127         var prevSelection = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
    128         var prevNewIndex = -1;
    129         suggestedInstancesComboBox.Items.Clear();
    130         if (Content == null) return;
    131 
    132         for (var i = 0; i < Content.SuggestedInstances.Count; i++) {
    133           suggestedInstancesComboBox.Items.Add(Content.SuggestedInstances[i]);
    134           if (prevSelection == null || Content.SuggestedInstances[i].Name == prevSelection.Name)
    135             prevNewIndex = prevSelection == null ? 0 : i;
    136         }
    137         if (prevNewIndex >= 0) {
    138           suggestedInstancesComboBox.SelectedIndex = prevNewIndex;
    139         }
    140       } finally { ResumeRepaint(true); }
     108      var prevSelection = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
     109      var prevNewIndex = -1;
     110      suggestedInstancesComboBox.Items.Clear();
     111      if (Content == null) return;
     112
     113      for (var i = 0; i < Content.SuggestedInstances.Count; i++) {
     114        suggestedInstancesComboBox.Items.Add(Content.SuggestedInstances[i]);
     115        if (prevSelection == null || Content.SuggestedInstances[i].Name == prevSelection.Name)
     116          prevNewIndex = prevSelection == null ? 0 : i;
     117      }
     118      if (prevNewIndex >= 0) {
     119        suggestedInstancesComboBox.SelectedIndex = prevNewIndex;
     120      }
    141121    }
    142122
     
    152132        switch (e.PropertyName) {
    153133          case "MaximumEvaluations": maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString(); break;
    154           case "Runs": runsView.Content = Content.Runs; break;
    155           case "KnowledgeBase": okbRunCollectionView.Content = Content.KnowledgeBase; break;
    156134          case "Problem": problemViewHost.Content = Content.Problem; break;
    157135        }
     
    160138
    161139    private void SuggestedInstancesOnChanged(object sender, EventArgs e) {
    162       SuppressEvents = true;
    163       try {
    164         UpdateSuggestedInstancesCombobox();
    165       } finally { SuppressEvents = false; }
     140      UpdateSuggestedInstancesCombobox();
    166141    }
    167142    #endregion
     
    189164        problemTypeSelectorDialog = new TypeSelectorDialog { Caption = "Select Problem" };
    190165        problemTypeSelectorDialog.TypeSelector.Caption = "Available Problems";
    191         problemTypeSelectorDialog.TypeSelector.Configure(typeof(IProblem)
     166        problemTypeSelectorDialog.TypeSelector.Configure(typeof(ISingleObjectiveHeuristicOptimizationProblem)
    192167          , showNotInstantiableTypes: false, showGenericTypes: false);
    193168      }
    194169      if (problemTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    195170        try {
    196           Content.Problem = (IProblem)problemTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     171          Content.Problem = (ISingleObjectiveHeuristicOptimizationProblem)problemTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    197172        } catch (Exception ex) {
    198173          ErrorHandling.ShowErrorDialog(this, ex);
     
    210185          try {
    211186            if (error != null) throw error;
    212             var problem = content as IProblem;
     187            var problem = content as ISingleObjectiveHeuristicOptimizationProblem;
    213188            if (problem == null) {
    214189              var algorithm = content as IAlgorithm;
    215               if (algorithm == null || algorithm.Problem == null)
     190              if (algorithm == null || !(algorithm.Problem is ISingleObjectiveHeuristicOptimizationProblem))
    216191                MessageBox.Show(this, "The selected file is not a problem, nor an algorithm with a problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
    217               else Content.Problem = algorithm.Problem;
     192              else Content.Problem = (ISingleObjectiveHeuristicOptimizationProblem)algorithm.Problem;
    218193            } else
    219194              Content.Problem = problem;
     
    232207    private void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    233208      e.Effect = DragDropEffects.None;
    234       var prob = e.Data.GetData(Constants.DragDropDataFormat) as IProblem;
     209      var prob = e.Data.GetData(Constants.DragDropDataFormat) as ISingleObjectiveHeuristicOptimizationProblem;
    235210      if (!ReadOnly && prob != null) {
    236211        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
     
    244219    private void problemTabPage_DragDrop(object sender, DragEventArgs e) {
    245220      if (e.Effect != DragDropEffects.None) {
    246         var prob = e.Data.GetData(Constants.DragDropDataFormat) as IProblem;
    247         if (e.Effect.HasFlag(DragDropEffects.Copy)) prob = (IProblem)prob.Clone();
     221        var prob = e.Data.GetData(Constants.DragDropDataFormat) as ISingleObjectiveHeuristicOptimizationProblem;
     222        if (e.Effect.HasFlag(DragDropEffects.Copy)) prob = (ISingleObjectiveHeuristicOptimizationProblem)prob.Clone();
    248223        Content.Problem = prob;
    249224      }
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/HeuristicLab.OptimizationExpertSystem.Views-3.3.csproj

    r12847 r12860  
    134134  </ItemGroup>
    135135  <ItemGroup>
    136     <Compile Include="ExpertSystemOptimizerView.cs">
     136    <Compile Include="ExpertSystemView.cs">
    137137      <SubType>UserControl</SubType>
    138138    </Compile>
    139     <Compile Include="ExpertSystemOptimizerView.Designer.cs">
    140       <DependentUpon>ExpertSystemOptimizerView.cs</DependentUpon>
     139    <Compile Include="ExpertSystemView.Designer.cs">
     140      <DependentUpon>ExpertSystemView.cs</DependentUpon>
    141141    </Compile>
    142142    <Compile Include="Plugin.cs" />
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ExpertSystem.cs

    r12847 r12860  
    2424using System.Collections.Generic;
    2525using System.Drawing;
    26 
     26using System.Linq;
     27using HeuristicLab.Analysis;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Optimization;
     
    3031using HeuristicLab.Common;
    3132using HeuristicLab.Common.Resources;
     33using HeuristicLab.Data;
    3234
    3335namespace HeuristicLab.OptimizationExpertSystem {
    34   [Item("Expert-System Optimizer", "Currently in experimental phase, an expert system that makes algorithm suggestions based on fitness landscape analysis features and an optimization knowledge base.")]
     36  [Item("Expert-System", "Currently in experimental phase, an expert system that makes algorithm suggestions based on fitness landscape analysis features and an optimization knowledge base.")]
    3537  [StorableClass]
    36   [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 118)]
    37   public sealed class ExpertSystemOptimizer : ParameterizedNamedItem, IOptimizer, IStorableContent, INotifyPropertyChanged {
     38  [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 119)]
     39  public sealed class ExpertSystem : NamedItem, IStorableContent, INotifyPropertyChanged {
    3840
    3941    public string Filename { get; set; }
     
    5153        maximumEvaluations = value;
    5254        OnPropertyChanged("MaximumEvaluations");
     55        UpdateSuggestions();
    5356      }
    5457    }
     
    5861    public RunCollection Runs {
    5962      get { return runs; }
    60       private set {
    61         if (value == null) throw new ArgumentNullException("value");
    62         if (runs == value) return;
    63         runs = value;
    64         OnPropertyChanged("Runs");
    65       }
    6663    }
    6764
    6865    [Storable]
    69     private ExecutionState executionState;
    70     public ExecutionState ExecutionState {
    71       get { return executionState; }
    72       private set {
    73         if (executionState != value) {
    74           executionState = value;
    75           OnPropertyChanged("ExecutionState");
    76           OnExecutionStateChanged();
    77           OnItemImageChanged();
    78         }
    79       }
     66    private ItemList<IAlgorithm> algorithmInstances;
     67    public ItemList<IAlgorithm> AlgorithmInstances {
     68      get { return algorithmInstances; }
    8069    }
    8170
    8271    [Storable]
    83     private TimeSpan executionTime;
    84     public TimeSpan ExecutionTime {
    85       get { return executionTime; }
    86       private set {
    87         if (executionTime == value) return;
    88         executionTime = value;
    89         OnPropertyChanged("ExecutionTime");
    90         OnExecutionTimeChanged();
    91       }
    92     }
    93 
    94     [Storable]
    95     private RunCollection knowledgeBase;
    96     public RunCollection KnowledgeBase {
    97       get { return knowledgeBase; }
    98       private set {
    99         if (value == null) throw new ArgumentNullException("value");
    100         if (knowledgeBase == value) return;
    101         knowledgeBase = value;
    102         OnPropertyChanged("KnowledgeBase");
    103       }
    104     }
    105 
    106     [Storable]
    107     private IProblem problem;
    108     public IProblem Problem {
     72    private ISingleObjectiveHeuristicOptimizationProblem problem;
     73    public ISingleObjectiveHeuristicOptimizationProblem Problem {
    10974      get { return problem; }
    11075      set {
     
    11277        problem = value;
    11378        OnPropertyChanged("Problem");
     79        UpdateSuggestions();
    11480      }
    11581    }
     
    12288    }
    12389
    124     public IEnumerable<IOptimizer> NestedOptimizers {
    125       get { return SuggestedInstances; }
     90    private bool Maximization {
     91      get { return Problem != null && ((IValueParameter<BoolValue>)Problem.MaximizationParameter).Value.Value; }
    12692    }
    12793
    12894    [StorableConstructor]
    129     private ExpertSystemOptimizer(bool deserializing) : base(deserializing) { }
    130     private ExpertSystemOptimizer(ExpertSystemOptimizer original, Cloner cloner)
     95    private ExpertSystem(bool deserializing) : base(deserializing) { }
     96    private ExpertSystem(ExpertSystem original, Cloner cloner)
    13197      : base(original, cloner) {
    13298      runs = cloner.Clone(original.runs);
    133       executionState = original.executionState;
    134       executionTime = original.executionTime;
    135       knowledgeBase = cloner.Clone(original.knowledgeBase);
     99      algorithmInstances = cloner.Clone(original.algorithmInstances);
    136100      problem = cloner.Clone(original.problem);
    137101      suggestedInstances = cloner.Clone(original.suggestedInstances);
    138102      readOnlySuggestedInstances = suggestedInstances.AsReadOnly();
     103      RegisterEventHandlers();
    139104    }
    140     public ExpertSystemOptimizer() {
    141       Runs = new RunCollection();
    142       KnowledgeBase = new RunCollection();
     105    public ExpertSystem() {
     106      Name = ItemName;
     107      Description = ItemDescription;
     108      runs = new RunCollection();
     109      algorithmInstances = new ItemList<IAlgorithm>();
    143110      suggestedInstances = new ItemList<IAlgorithm>();
    144111      readOnlySuggestedInstances = suggestedInstances.AsReadOnly();
    145       ExecutionState = ExecutionState.Stopped;
    146       ExecutionTime = TimeSpan.Zero;
     112      RegisterEventHandlers();
    147113    }
    148114
    149115    public override IDeepCloneable Clone(Cloner cloner) {
    150       return new ExpertSystemOptimizer(this, cloner);
     116      return new ExpertSystem(this, cloner);
    151117    }
    152118
     
    154120    private void AfterDeserialization() {
    155121      readOnlySuggestedInstances = suggestedInstances.AsReadOnly();
     122      RegisterEventHandlers();
    156123    }
    157124
    158     public void Prepare() {
    159       Prepare(false);
     125    private void RegisterEventHandlers() {
     126      runs.CollectionReset += InformationChanged;
     127      runs.ItemsAdded += InformationChanged;
     128      runs.ItemsRemoved += InformationChanged;
     129      runs.Reset += InformationChanged;
     130      runs.UpdateOfRunsInProgressChanged += InformationChanged;
     131      algorithmInstances.CollectionReset += InformationChanged;
     132      algorithmInstances.ItemsAdded += InformationChanged;
     133      algorithmInstances.ItemsRemoved += InformationChanged;
    160134    }
    161135
    162     public void Prepare(bool clearRuns) {
    163       if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    164         throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    165       if (clearRuns) Runs.Clear();
    166       ExecutionTime = TimeSpan.Zero;
    167       ExecutionState = ExecutionState.Prepared;
    168       OnPrepared();
     136    private void InformationChanged(object sender, EventArgs e) {
     137      var runCollection = sender as RunCollection;
     138      if (runCollection != null && runCollection.UpdateOfRunsInProgress) return;
     139      UpdateSuggestions();
    169140    }
    170141
    171     public void Start() {
    172       if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    173         throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
    174       ExecutionState = ExecutionState.Started;
    175       OnStarted();
    176     }
     142    private void UpdateSuggestions() {
     143      if (Problem == null) return;
     144      var instances = new SortedList<double, IAlgorithm>();
     145      foreach (var instance in algorithmInstances) {
     146        var relevantRuns = instance.Runs.Where(x => ((StringValue)x.Parameters["Problem Type"]).Value == Problem.GetType().Name);
     147        var avgQuality = 0.0;
     148        var counter = 0;
     149        foreach (var run in relevantRuns) {
     150          var performanceGraph = ((IndexedDataTable<double>)run.Results["QualityPerEvaluations"]);
     151          try {
     152            avgQuality += performanceGraph.Rows.First().Values.TakeWhile(x => x.Item1 < MaximumEvaluations).Last().Item2;
     153            counter++;
     154          } catch { continue; }
     155        }
     156        avgQuality /= counter;
     157        instances.Add(avgQuality, instance);
     158      }
    177159
    178     public void Pause() {
    179       if (ExecutionState != ExecutionState.Started)
    180         throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
    181       ExecutionState = ExecutionState.Paused;
    182       OnPaused();
    183     }
    184 
    185 
    186     public void Stop() {
    187       if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
    188         throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
    189       ExecutionState = ExecutionState.Stopped;
    190       OnStopped();
    191     }
    192 
    193     public event EventHandler Prepared;
    194     private void OnPrepared() {
    195       var handler = Prepared;
    196       if (handler != null) handler(this, EventArgs.Empty);
    197     }
    198 
    199     public event EventHandler Started;
    200     private void OnStarted() {
    201       var handler = Started;
    202       if (handler != null) handler(this, EventArgs.Empty);
    203     }
    204 
    205     public event EventHandler Paused;
    206     private void OnPaused() {
    207       var handler = Paused;
    208       if (handler != null) handler(this, EventArgs.Empty);
    209     }
    210 
    211     public event EventHandler Stopped;
    212     private void OnStopped() {
    213       var handler = Stopped;
    214       if (handler != null) handler(this, EventArgs.Empty);
    215     }
    216 
    217     public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    218     private void OnExceptionOccurred(Exception e) {
    219       var handler = ExceptionOccurred;
    220       if (handler != null) handler(this, new EventArgs<Exception>(e));
    221     }
    222 
    223     public event EventHandler ExecutionStateChanged;
    224     private void OnExecutionStateChanged() {
    225       var handler = ExecutionStateChanged;
    226       if (handler != null) handler(this, EventArgs.Empty);
    227     }
    228 
    229     public event EventHandler ExecutionTimeChanged;
    230     private void OnExecutionTimeChanged() {
    231       var handler = ExecutionTimeChanged;
    232       if (handler != null) handler(this, EventArgs.Empty);
     160      suggestedInstances.Clear();
     161      var instanceLadder = instances.Select(x => x.Value);
     162      suggestedInstances.AddRange(Maximization ? instanceLadder.Reverse() : instanceLadder);
    233163    }
    234164
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/HeuristicLab.OptimizationExpertSystem-3.3.csproj

    r12842 r12860  
    112112  </ItemGroup>
    113113  <ItemGroup>
    114     <Compile Include="ExpertSystemOptimizer.cs" />
     114    <Compile Include="ExpertSystem.cs" />
    115115    <Compile Include="Plugin.cs" />
    116116    <None Include="Properties\AssemblyInfo.cs.frame" />
Note: See TracChangeset for help on using the changeset viewer.