Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/21/16 11:15:23 (8 years ago)
Author:
abeham
Message:

#2457:

  • added two types of problem instance mappings: PCA and MDS
File:
1 edited

Legend:

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

    r13551 r13561  
    2121
    2222using System;
    23 using System.Collections;
    2423using System.ComponentModel;
    2524using System.Linq;
     25using System.Text.RegularExpressions;
    2626using System.Windows.Forms;
    27 using HeuristicLab.Common;
     27using System.Windows.Forms.DataVisualization.Charting;
    2828using HeuristicLab.Common.Resources;
    2929using HeuristicLab.Core.Views;
     
    172172
    173173    #region Control events
    174     private void maxEvaluationsTextBox_Validating(object sender, CancelEventArgs e) {
     174    private void MaxEvaluationsTextBoxOnValidating(object sender, CancelEventArgs e) {
    175175      if (SuppressEvents) return;
    176176      if (InvokeRequired) {
    177         Invoke((Action<object, CancelEventArgs>)maxEvaluationsTextBox_Validating, sender, e);
     177        Invoke((Action<object, CancelEventArgs>)MaxEvaluationsTextBoxOnValidating, sender, e);
    178178        return;
    179179      }
     
    189189    }
    190190    #endregion
    191 
    192     private bool validDragOperation;
    193     private void instancesDropPanel_DragEnter(object sender, DragEventArgs e) {
    194       validDragOperation = false;
    195       if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun)) {
    196         validDragOperation = true;
    197       } else if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {
    198         validDragOperation = true;
    199         var items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    200         foreach (object item in items)
    201           validDragOperation = validDragOperation && (item is IRun);
    202       }
    203     }
    204     private void instancesDropPanel_DragOver(object sender, DragEventArgs e) {
    205       e.Effect = DragDropEffects.None;
    206       if (!validDragOperation) return;
    207       if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    208       else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    209       else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
    210       else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
    211       else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    212     }
    213     private void instancesDropPanel_DragDrop(object sender, DragEventArgs e) {
    214       if (e.Effect == DragDropEffects.None) return;
    215       if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun) {
    216         var item = (IRun)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    217         Content.ProblemInstances.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item);
    218       } else if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) {
    219         var items = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<IRun>();
    220         if (e.Effect.HasFlag(DragDropEffects.Copy)) {
    221           var cloner = new Cloner();
    222           items = items.Select(x => cloner.Clone(x));
    223         }
    224         Content.ProblemInstances.AddRange(items);
    225       }
    226     }
    227191    #endregion
    228192
    229     private void refreshMapButton_Click(object sender, EventArgs e) {
    230       Content.UpdateInstanceMap();
    231     }
    232 
    233     private void okbDownloadButton_Click(object sender, EventArgs e) {
     193    private void RefreshMapButtonOnClick(object sender, EventArgs e) {
     194      Content.UpdateInstanceProjection();
     195      UpdateProjectionComboBox();
     196    }
     197
     198    private void UpdateProjectionComboBox() {
     199      projectionComboBox.Items.Clear();
     200      var projStrings = Content.ProblemInstances
     201        .SelectMany(x => x.Results.Where(y => Regex.IsMatch(y.Key, "^Projection[.].*[.][XY]$")))
     202        .Select(x => Regex.Match(x.Key, "Projection[.](?<g>.*)[.][XY]").Groups["g"].Value)
     203        .Distinct();
     204      foreach (var str in projStrings) {
     205        projectionComboBox.Items.Add(str);
     206      }
     207    }
     208
     209    private void OkbDownloadButtonOnClick(object sender, EventArgs e) {
    234210      if (Content.Problem.ProblemId < 0) {
    235211        MessageBox.Show("Please select a problem instance first.");
     
    254230    }
    255231
    256     private void algorithmStartButton_Click(object sender, EventArgs e) {
     232    private void AlgorithmStartButtonOnClick(object sender, EventArgs e) {
    257233      var selectedInstance = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
    258234      var clone = (IAlgorithm)selectedInstance.Clone();
     
    261237      algorithmViewHost.Content = clone.Results;
    262238    }
     239
     240    private void ProjectionComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
     241      if (projectionComboBox.SelectedIndex < 0) return;
     242      var projection = (string)projectionComboBox.SelectedItem;
     243      var instancesSeries = instanceMapChart.Series["InstancesSeries"];
     244      var currentInstanceSeries = instanceMapChart.Series["CurrentInstanceSeries"];
     245
     246      instancesSeries.Points.Clear();
     247      currentInstanceSeries.Points.Clear();
     248
     249      foreach (var run in Content.ProblemInstances) {
     250        var xKey = "Projection." + projection + ".X";
     251        var yKey = "Projection." + projection + ".Y";
     252        if (!run.Results.ContainsKey(xKey) || !run.Results.ContainsKey(yKey)
     253          || !(run.Results[xKey] is Data.DoubleValue) || !(run.Results[yKey] is Data.DoubleValue)) continue;
     254        var x = ((Data.DoubleValue)run.Results[xKey]).Value;
     255        var y = ((Data.DoubleValue)run.Results[yKey]).Value;
     256        var dataPoint = new DataPoint(x, y) {
     257          Label = run.Name
     258        };
     259        instancesSeries.Points.Add(dataPoint);
     260      }
     261
     262      var curPoint = Content.ProjectCurrentInstance(projection);
     263      if (curPoint != null) {
     264        var dp = new DataPoint(curPoint.Item1, curPoint.Item2) {
     265          Label = Content.Problem.Problem.Name
     266        };
     267        currentInstanceSeries.Points.Add(dp);
     268      }
     269    }
    263270  }
    264271}
Note: See TracChangeset for help on using the changeset viewer.