Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/19/16 08:49:23 (8 years ago)
Author:
abeham
Message:

#2457: Added characteristic calculator for qap and adapted expert system view

File:
1 edited

Legend:

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

    r13485 r13551  
    3030using HeuristicLab.MainForm;
    3131using HeuristicLab.Optimization;
    32 using HeuristicLab.PluginInfrastructure;
     32using HeuristicLab.Optimization.Views;
    3333
    3434namespace HeuristicLab.OptimizationExpertSystem.Views {
     
    4747    public ExpertSystemView() {
    4848      InitializeComponent();
     49      // brings progress panel to front (it is not visible by default, but obstructs other elements in designer)
     50      this.Controls.SetChildIndex(this.progressPanel, 0);
     51      algorithmStartButton.Text = string.Empty;
     52      algorithmStartButton.Image = VSImageLibrary.Play;
    4953      refreshMapButton.Text = string.Empty;
    5054      refreshMapButton.Image = VSImageLibrary.Refresh;
     
    6064
    6165    protected override void DeregisterContentEvents() {
    62       Content.PropertyChanged -= Content_PropertyChanged;
     66      Content.PropertyChanged -= ContentOnPropertyChanged;
    6367      Content.SuggestedInstances.CollectionReset -= SuggestedInstancesOnChanged;
    6468      Content.SuggestedInstances.ItemsAdded -= SuggestedInstancesOnChanged;
     
    6670      Content.SuggestedInstances.ItemsRemoved -= SuggestedInstancesOnChanged;
    6771      Content.SuggestedInstances.ItemsReplaced -= SuggestedInstancesOnChanged;
     72      if (Content.Problem != null) Content.Problem.ProblemChanged -= ContentOnProblemChanged;
    6873      base.DeregisterContentEvents();
    6974    }
    7075    protected override void RegisterContentEvents() {
    7176      base.RegisterContentEvents();
    72       Content.PropertyChanged += Content_PropertyChanged;
     77      Content.PropertyChanged += ContentOnPropertyChanged;
    7378      Content.SuggestedInstances.CollectionReset += SuggestedInstancesOnChanged;
    7479      Content.SuggestedInstances.ItemsAdded += SuggestedInstancesOnChanged;
     
    7681      Content.SuggestedInstances.ItemsRemoved += SuggestedInstancesOnChanged;
    7782      Content.SuggestedInstances.ItemsReplaced += SuggestedInstancesOnChanged;
     83      if (Content.Problem != null) Content.Problem.ProblemChanged += ContentOnProblemChanged;
    7884    }
    7985
     
    8995          algorithmViewHost.Content = null;
    9096          runsView.Content = null;
    91           algorithmInstancesViewHost.Content = null;
     97          kbViewHost.Content = null;
    9298          problemInstancesView.Content = null;
    9399        } else {
     
    95101          problemViewHost.Content = Content.Problem;
    96102          runsView.Content = Content.Runs;
    97           algorithmInstancesViewHost.Content = Content.AlgorithmInstances;
     103          kbViewHost.ViewType = typeof(RunCollectionRLDView);
     104          kbViewHost.Content = Content.KnowledgeBase;
    98105          problemInstancesView.Content = Content.ProblemInstances;
    99106        }
     
    105112      base.SetEnabledStateOfControls();
    106113      maxEvaluationsTextBox.Enabled = Content != null && !ReadOnly && !Locked;
    107       newProblemButton.Enabled = Content != null && !ReadOnly && !Locked;
    108       openProblemButton.Enabled = Content != null && !ReadOnly && !Locked;
    109       problemViewHost.Enabled = Content != null && !ReadOnly && !Locked;
    110       suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked;
     114      problemViewHost.Enabled = Content != null && !ReadOnly && !Locked && !okbDownloadInProgress;
     115      suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked && !okbDownloadInProgress;
     116      algorithmStartButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
    111117      algorithmViewHost.Enabled = Content != null && !ReadOnly && !Locked;
    112118      runsView.Enabled = Content != null;
    113       algorithmInstancesViewHost.Enabled = Content != null && !okbDownloadInProgress;
     119      kbViewHost.Enabled = Content != null && !okbDownloadInProgress;
     120      problemInstancesView.Enabled = Content != null && !okbDownloadInProgress;
    114121      refreshMapButton.Enabled = Content != null;
    115       okbDownloadButton.Enabled = Content != null && Content.Problem != null && !ReadOnly && !Locked && !okbDownloadInProgress;
     122      okbDownloadButton.Enabled = Content != null && Content.Problem != null && Content.Problem.ProblemId >= 0 && !ReadOnly && !Locked && !okbDownloadInProgress;
    116123    }
    117124
     
    134141    #region Event Handlers
    135142    #region Content events
    136     private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     143    private void ContentOnProblemChanged(object sender, EventArgs eventArgs) {
     144      UpdateSuggestedInstancesCombobox();
     145      SetEnabledStateOfControls();
     146    }
     147
     148    private void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs e) {
    137149      if (InvokeRequired) {
    138         Invoke((Action<object, PropertyChangedEventArgs>)Content_PropertyChanged, sender, e);
     150        Invoke((Action<object, PropertyChangedEventArgs>)ContentOnPropertyChanged, sender, e);
    139151        return;
    140152      }
     
    142154      try {
    143155        switch (e.PropertyName) {
    144           case "AlgorithmInstances": algorithmInstancesViewHost.Content = Content.AlgorithmInstances; break;
     156          case "KnowledgeBase": kbViewHost.Content = Content.KnowledgeBase; break;
    145157          case "MaximumEvaluations": maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString(); break;
    146           case "Problem": problemViewHost.Content = Content.Problem; break;
     158          case "Problem":
     159            problemViewHost.Content = Content.Problem;
     160            Content.Problem.ProblemChanged += ContentOnProblemChanged;
     161            break;
    147162          case "ProblemInstances": problemInstancesView.Content = Content.ProblemInstances; break;
    148163        }
     
    172187        errorProvider.SetError(maxEvaluationsTextBox, null);
    173188      }
    174     }
    175 
    176     private void newProblemButton_Click(object sender, EventArgs e) {
    177       if (problemTypeSelectorDialog == null) {
    178         problemTypeSelectorDialog = new TypeSelectorDialog { Caption = "Select Problem" };
    179         problemTypeSelectorDialog.TypeSelector.Caption = "Available Problems";
    180         problemTypeSelectorDialog.TypeSelector.Configure(typeof(ISingleObjectiveHeuristicOptimizationProblem)
    181           , showNotInstantiableTypes: false, showGenericTypes: false);
    182       }
    183       if (problemTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    184         try {
    185           Content.Problem = (ISingleObjectiveHeuristicOptimizationProblem)problemTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    186         } catch (Exception ex) {
    187           ErrorHandling.ShowErrorDialog(this, ex);
    188         }
    189       }
    190     }
    191 
    192     private void openProblemButton_Click(object sender, EventArgs e) {
    193       openFileDialog.Title = "Open Problem";
    194       if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    195         newProblemButton.Enabled = openProblemButton.Enabled = false;
    196         problemViewHost.Enabled = false;
    197 
    198         ContentManager.LoadAsync(openFileDialog.FileName, delegate(IStorableContent content, Exception error) {
    199           try {
    200             if (error != null) throw error;
    201             var problem = content as ISingleObjectiveHeuristicOptimizationProblem;
    202             if (problem == null) {
    203               var algorithm = content as IAlgorithm;
    204               if (algorithm == null || !(algorithm.Problem is ISingleObjectiveHeuristicOptimizationProblem))
    205                 MessageBox.Show(this, "The selected file is not a problem, nor an algorithm with a problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
    206               else Content.Problem = (ISingleObjectiveHeuristicOptimizationProblem)algorithm.Problem;
    207             } else
    208               Content.Problem = problem;
    209           } catch (Exception ex) {
    210             ErrorHandling.ShowErrorDialog(this, ex);
    211           } finally {
    212             Invoke(new Action(delegate() {
    213               problemViewHost.Enabled = true;
    214               newProblemButton.Enabled = openProblemButton.Enabled = true;
    215             }));
    216           }
    217         });
    218       }
    219     }
    220 
    221     private void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    222       e.Effect = DragDropEffects.None;
    223       var prob = e.Data.GetData(Constants.DragDropDataFormat) as ISingleObjectiveHeuristicOptimizationProblem;
    224       if (!ReadOnly && prob != null) {
    225         if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    226         else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    227         else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
    228         else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
    229         else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    230       }
    231     }
    232 
    233     private void problemTabPage_DragDrop(object sender, DragEventArgs e) {
    234       if (e.Effect != DragDropEffects.None) {
    235         var prob = e.Data.GetData(Constants.DragDropDataFormat) as ISingleObjectiveHeuristicOptimizationProblem;
    236         if (e.Effect.HasFlag(DragDropEffects.Copy)) prob = (ISingleObjectiveHeuristicOptimizationProblem)prob.Clone();
    237         Content.Problem = prob;
    238       }
    239     }
    240 
    241     private void suggestedInstancesComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    242       if (SuppressEvents) return;
    243       if (InvokeRequired) { Invoke((Action<object, EventArgs>)suggestedInstancesComboBox_SelectedIndexChanged, sender, e); return; }
    244       if (suggestedInstancesComboBox.SelectedIndex >= 0)
    245         algorithmViewHost.Content = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
    246       else algorithmViewHost.Content = null;
    247189    }
    248190    #endregion
     
    290232
    291233    private void okbDownloadButton_Click(object sender, EventArgs e) {
     234      if (Content.Problem.ProblemId < 0) {
     235        MessageBox.Show("Please select a problem instance first.");
     236        return;
     237      }
    292238      var progress = new Progress();
    293239      progress.ProgressStateChanged += OkbDownloadProgressOnStateChanged;
     
    307253      }
    308254    }
     255
     256    private void algorithmStartButton_Click(object sender, EventArgs e) {
     257      var selectedInstance = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
     258      var clone = (IAlgorithm)selectedInstance.Clone();
     259      clone.Prepare(true);
     260      clone.Start();
     261      algorithmViewHost.Content = clone.Results;
     262    }
    309263  }
    310264}
Note: See TracChangeset for help on using the changeset viewer.