Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/16/15 17:04:35 (8 years ago)
Author:
abeham
Message:

#2457, #2431: updated from trunk, worked on okb connection for downloading knowledge base

Location:
branches/PerformanceComparison
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison

    • Property svn:ignore
      •  

        old new  
        22*.suo
        33*.user
         4.git
         5.gitignore
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs

    r12860 r13475  
    2121
    2222using System;
     23using System.Collections;
    2324using System.ComponentModel;
     25using System.IO;
     26using System.Linq;
    2427using System.Windows.Forms;
     28using HeuristicLab.Clients.OKB.Administration;
     29using HeuristicLab.Clients.OKB.Query;
    2530using HeuristicLab.Common;
     31using HeuristicLab.Common.Resources;
     32using HeuristicLab.Core;
    2633using HeuristicLab.Core.Views;
    2734using HeuristicLab.MainForm;
    2835using HeuristicLab.Optimization;
     36using HeuristicLab.Persistence.Default.Xml;
    2937using HeuristicLab.PluginInfrastructure;
    3038
     
    4351    public ExpertSystemView() {
    4452      InitializeComponent();
     53      refreshMapButton.Text = string.Empty;
     54      refreshMapButton.Image = VSImageLibrary.Refresh;
    4555    }
    4656
     
    8393          runsView.Content = null;
    8494          algorithmInstancesViewHost.Content = null;
     95          problemInstancesView.Content = null;
    8596        } else {
    8697          maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString();
     
    8899          runsView.Content = Content.Runs;
    89100          algorithmInstancesViewHost.Content = Content.AlgorithmInstances;
     101          problemInstancesView.Content = Content.ProblemInstances;
    90102        }
    91103      } finally { SuppressEvents = false; }
     
    103115      runsView.Enabled = Content != null;
    104116      algorithmInstancesViewHost.Enabled = Content != null;
     117      refreshMapButton.Enabled = Content != null;
     118      okbDownloadButton.Enabled = Content != null && Content.Problem != null && !ReadOnly && !Locked;
    105119    }
    106120
     
    131145      try {
    132146        switch (e.PropertyName) {
     147          case "AlgorithmInstances": algorithmInstancesViewHost.Content = Content.AlgorithmInstances; break;
    133148          case "MaximumEvaluations": maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString(); break;
    134149          case "Problem": problemViewHost.Content = Content.Problem; break;
     150          case "ProblemInstances": problemInstancesView.Content = Content.ProblemInstances; break;
    135151        }
    136152      } finally { SuppressEvents = false; }
     153      SetEnabledStateOfControls();
    137154    }
    138155
     
    233250    }
    234251    #endregion
     252
     253    private bool validDragOperation;
     254    private void instancesDropPanel_DragEnter(object sender, DragEventArgs e) {
     255      validDragOperation = false;
     256      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun)) {
     257        validDragOperation = true;
     258      } else if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {
     259        validDragOperation = true;
     260        var items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     261        foreach (object item in items)
     262          validDragOperation = validDragOperation && (item is IRun);
     263      }
     264    }
     265    private void instancesDropPanel_DragOver(object sender, DragEventArgs e) {
     266      e.Effect = DragDropEffects.None;
     267      if (!validDragOperation) return;
     268      if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
     269      else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
     270      else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     271      else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     272      else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
     273    }
     274    private void instancesDropPanel_DragDrop(object sender, DragEventArgs e) {
     275      if (e.Effect == DragDropEffects.None) return;
     276      if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun) {
     277        var item = (IRun)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     278        Content.ProblemInstances.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item);
     279      } else if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) {
     280        var items = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<IRun>();
     281        if (e.Effect.HasFlag(DragDropEffects.Copy)) {
     282          var cloner = new Cloner();
     283          items = items.Select(x => cloner.Clone(x));
     284        }
     285        Content.ProblemInstances.AddRange(items);
     286      }
     287    }
    235288    #endregion
     289
     290    private void refreshMapButton_Click(object sender, EventArgs e) {
     291      Content.UpdateInstanceMap();
     292    }
     293
     294    private void okbDownloadButton_Click(object sender, EventArgs e) {
     295      var queryClient = QueryClient.Instance;
     296      queryClient.Refresh();
     297
     298      var problemTypeFilter = (StringComparisonAvailableValuesFilter)queryClient.Filters.Single(x => x.Label == "Problem Data Type Name");
     299      problemTypeFilter.Value = Content.Problem.GetType().Name;
     300
     301      var runIds = queryClient.GetRunIds(problemTypeFilter).ToList();
     302      var count = queryClient.GetNumberOfRuns(problemTypeFilter);
     303      if (count > 0) {
     304        var list = new ItemList<IAlgorithm>();
     305        var adminClient = AdministrationClient.Instance;
     306        adminClient.Refresh();
     307        var runs = queryClient.GetRuns(runIds, true).ToList();
     308        foreach (var rGroup in runs.GroupBy(x => x.Algorithm.Id)) {
     309          var data = AdministrationClient.GetAlgorithmData(rGroup.Key);
     310          if (data != null) {
     311            using (var stream = new MemoryStream(data)) {
     312              try {
     313                var alg = (IAlgorithm)XmlParser.Deserialize<IContent>(stream);
     314                alg.Runs.AddRange(rGroup.Select(x => queryClient.ConvertToOptimizationRun(x)));
     315                list.Add(alg);
     316              } catch (Exception) { }
     317              stream.Close();
     318            }
     319          }
     320        }
     321        Content.AlgorithmInstances = list;
     322      }
     323    }
    236324  }
    237325}
Note: See TracChangeset for help on using the changeset viewer.