Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13751


Ignore:
Timestamp:
04/11/16 17:34:50 (9 years ago)
Author:
abeham
Message:

#2457: worked on problem instance mapping

Location:
branches/PerformanceComparison
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/KnowledgeCenter.cs

    r13750 r13751  
    5353    }
    5454
    55     private IntValue maximumEvaluations;
     55    private readonly IntValue maximumEvaluations;
    5656    public IntValue MaximumEvaluations {
    5757      get { return maximumEvaluations; }
    5858    }
    5959
    60     private RunCollection instanceRuns;
     60    private readonly RunCollection instanceRuns;
    6161    public RunCollection InstanceRuns {
    6262      get { return instanceRuns; }
    6363    }
    6464
    65     private RunCollection seededRuns;
     65    private readonly RunCollection seededRuns;
    6666    public RunCollection SeededRuns {
    6767      get { return seededRuns; }
    6868    }
    6969
    70     private RunCollection knowledgeBase;
     70    private readonly RunCollection knowledgeBase;
    7171    public RunCollection KnowledgeBase {
    7272      get { return knowledgeBase; }
    7373    }
    7474
    75     private SingleObjectiveOKBProblem problem;
     75    private readonly SingleObjectiveOKBProblem problem;
    7676    public SingleObjectiveOKBProblem Problem {
    7777      get { return problem; }
    7878    }
    7979
    80     private ItemList<IAlgorithm> suggestedInstances;
    81     private ReadOnlyItemList<IAlgorithm> readOnlySuggestedInstances;
     80    private readonly ItemList<IAlgorithm> suggestedInstances;
     81    private readonly ReadOnlyItemList<IAlgorithm> readOnlySuggestedInstances;
    8282    public ReadOnlyItemList<IAlgorithm> SuggestedInstances {
    8383      get { return readOnlySuggestedInstances; }
    8484    }
    8585
    86     private RunCollection problemInstances;
     86    private readonly RunCollection problemInstances;
    8787    public RunCollection ProblemInstances {
    8888      get { return problemInstances; }
    8989    }
    9090
    91     private CheckedItemList<IScope> solutionSeedingPool;
     91    private readonly CheckedItemList<StringValue> problemCharacteristics;
     92    public CheckedItemList<StringValue> ProblemCharacteristics {
     93      get { return problemCharacteristics; }
     94    }
     95
     96    private readonly CheckedItemList<IScope> solutionSeedingPool;
    9297    public CheckedItemList<IScope> SolutionSeedingPool {
    9398      get { return solutionSeedingPool; }
    9499    }
    95100
    96     private EnumValue<SeedingStrategyTypes> seedingStrategy;
     101    private readonly EnumValue<SeedingStrategyTypes> seedingStrategy;
    97102    public EnumValue<SeedingStrategyTypes> SeedingStrategy {
    98103      get { return seedingStrategy; }
     
    101106    private BidirectionalLookup<long, IRun> algorithmId2RunMapping;
    102107    private BidirectionalDictionary<long, IAlgorithm> algorithmId2AlgorithmInstanceMapping;
    103 
    104     private Run currentInstance;
    105 
     108    private BidirectionalDictionary<long, IRun> problemId2ProblemInstanceMapping;
     109   
    106110    private bool Maximization {
    107111      get { return Problem != null && Problem.ProblemId >= 0 && ((IValueParameter<BoolValue>)Problem.MaximizationParameter).Value.Value; }
     
    116120      readOnlySuggestedInstances = suggestedInstances.AsReadOnly();
    117121      problemInstances = new RunCollection();
     122      problemCharacteristics = new CheckedItemList<StringValue>();
    118123      problem = new SingleObjectiveOKBProblem();
    119124      algorithmId2RunMapping = new BidirectionalLookup<long, IRun>();
    120125      algorithmId2AlgorithmInstanceMapping = new BidirectionalDictionary<long, IAlgorithm>();
     126      problemId2ProblemInstanceMapping = new BidirectionalDictionary<long, IRun>();
    121127      solutionSeedingPool = new CheckedItemList<IScope>();
    122128      seedingStrategy = new EnumValue<SeedingStrategyTypes>(SeedingStrategyTypes.NoSeeding);
     
    162168    }
    163169
    164     private void UpdateInstanceProjection() {
    165       currentInstance = null;
    166       var filter = new HashSet<string>();
    167 
    168       if (Problem.ProblemId != -1) {
    169         currentInstance = new Run { Name = Problem.Name };
    170         Problem.Problem.CollectParameterValues(currentInstance.Parameters);
    171         foreach (var c in RunCreationClient.Instance.GetCharacteristicValues(Problem.ProblemId)) {
    172           var key = "Characteristic." + c.Name;
    173           currentInstance.Results.Add(key, RunCreationClient.Instance.ConvertToItem(c));
    174           filter.Add(key);
    175         }
    176       }
    177       // TODO: There is a problem with missing values that has to be solved
    178       // The common set of characteristics among all problems may be too small to be useful
    179       // It has to be decided somehow which problem instances to include in order to obtain the set of features that is expressive and available
    180       var allCharacteristics = ProblemInstances.Select(x => new HashSet<string>(x.Results.Where(y => y.Key.StartsWith("Characteristic.", StringComparison.Ordinal)).Select(y => y.Key))).ToList();
    181       if (allCharacteristics.Count == 0) return;
    182 
    183       var commonCharacteristics = filter.Count > 0 ? filter : allCharacteristics[0];
    184       for (var i = 0; i < allCharacteristics.Count; i++)
    185         commonCharacteristics.IntersectWith(allCharacteristics[i]);
    186 
    187       if (commonCharacteristics.Count == 0) return;
    188 
    189       var instances = new Dictionary<string, double[]>();
    190       foreach (var i in ProblemInstances)
    191         instances[i.Name] = i.Results.Where(x => commonCharacteristics.Contains(x.Key)).OrderBy(x => x.Key).Select(x => (double)((dynamic)x.Value).Value).ToArray();
    192       if (currentInstance != null)
    193         instances[currentInstance.Name] = currentInstance.Results.Where(x => commonCharacteristics.Contains(x.Key)).OrderBy(x => x.Key).Select(x => (double)((dynamic)x.Value).Value).ToArray();
     170    public bool IsCurrentInstance(IRun run) {
     171      if (!problemId2ProblemInstanceMapping.ContainsSecond(run)) return false;
     172      return problemId2ProblemInstanceMapping.GetBySecond(run) == Problem.ProblemId;
     173    }
     174
     175    public void UpdateInstanceProjection() {
     176      if (ProblemCharacteristics.Count == 0) return;
     177
     178      var instances = new Dictionary<IRun, double[]>();
     179      foreach (var run in ProblemInstances) {
     180        var f = 0;
     181        instances[run] = new double[ProblemCharacteristics.CheckedItems.Count()];
     182        foreach (var c in ProblemCharacteristics.CheckedItems.Select(x => x.Value.Value)) {
     183          IItem item;
     184          if (run.Results.TryGetValue(c, out item)) {
     185            instances[run][f] = (double)((dynamic)item).Value;
     186          } else instances[run][f] = 0; // TODO: handle missing values
     187          f++;
     188        }
     189      }
    194190
    195191      var allValues = instances.SelectMany(x => x.Value).ToList();
     
    205201      }
    206202
    207       var key2Idx = new BidirectionalDictionary<string, int>();
     203      var key2Idx = new BidirectionalDictionary<IRun, int>();
    208204      foreach (var kvp in instances.Select((k, i) => new { Index = i, Key = k.Key }))
    209205        key2Idx.Add(kvp.Key, kvp.Index);
     
    222218      #endregion
    223219      #region PCA
    224       var ds = new double[instances.Count, commonCharacteristics.Count];
     220      var ds = new double[instances.Count, ProblemCharacteristics.CheckedItems.Count()];
    225221      foreach (var instance in instances) {
    226222        var arr = instance.Value;
     
    235231      #endregion
    236232      #region SOM
    237       var features = new DoubleMatrix(commonCharacteristics.Count, instances.Count);
     233      var features = new DoubleMatrix(ProblemCharacteristics.CheckedItems.Count(), instances.Count);
    238234      foreach (var instance in instances) {
    239235        var arr = instance.Value;
     
    241237          features[feature, key2Idx.GetByFirst(instance.Key)] = arr[feature];
    242238      }
    243       var somCoords = SOM.Map(features, new MersenneTwister(42), somSize: 20, learningRadius: 20, jittering: true);
     239      var somCoords = SOM.Map(features, new MersenneTwister(42), somSize: 20, learningRadius: 20, iterations: 200, jittering: true);
    244240      #endregion
    245241
     
    249245          double x = 0, y = 0;
    250246          for (var feature = 0; feature < ds.GetLength(1); feature++) {
    251             x += ds[key2Idx.GetByFirst(instance.Name), feature] * v[feature, 0];
    252             y += ds[key2Idx.GetByFirst(instance.Name), feature] * v[feature, 1];
     247            x += ds[key2Idx.GetByFirst(instance), feature] * v[feature, 0];
     248            y += ds[key2Idx.GetByFirst(instance), feature] * v[feature, 1];
    253249          }
    254250
     
    262258
    263259          if (instance.Results.TryGetValue("Projection.MDS.X", out item)) {
    264             ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance.Name), 0];
    265           } else instance.Results.Add("Projection.MDS.X", new DoubleValue(coords[key2Idx.GetByFirst(instance.Name), 0]));
     260            ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance), 0];
     261          } else instance.Results.Add("Projection.MDS.X", new DoubleValue(coords[key2Idx.GetByFirst(instance), 0]));
    266262          if (instance.Results.TryGetValue("Projection.MDS.Y", out item)) {
    267             ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance.Name), 1];
    268           } else instance.Results.Add("Projection.MDS.Y", new DoubleValue(coords[key2Idx.GetByFirst(instance.Name), 1]));
     263            ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance), 1];
     264          } else instance.Results.Add("Projection.MDS.Y", new DoubleValue(coords[key2Idx.GetByFirst(instance), 1]));
    269265
    270266          if (instance.Results.TryGetValue("Projection.SOM.X", out item)) {
    271             ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance.Name), 0];
    272           } else instance.Results.Add("Projection.SOM.X", new DoubleValue(somCoords[key2Idx.GetByFirst(instance.Name), 0]));
     267            ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance), 0];
     268          } else instance.Results.Add("Projection.SOM.X", new DoubleValue(somCoords[key2Idx.GetByFirst(instance), 0]));
    273269          if (instance.Results.TryGetValue("Projection.SOM.Y", out item)) {
    274             ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance.Name), 1];
    275           } else instance.Results.Add("Projection.SOM.Y", new DoubleValue(somCoords[key2Idx.GetByFirst(instance.Name), 1]));
     270            ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance), 1];
     271          } else instance.Results.Add("Projection.SOM.Y", new DoubleValue(somCoords[key2Idx.GetByFirst(instance), 1]));
    276272        }
    277273      } finally { ProblemInstances.UpdateOfRunsInProgress = false; }
    278 
    279       if (currentInstance != null) {
    280         double x = 0, y = 0;
    281         for (var feature = 0; feature < ds.GetLength(1); feature++) {
    282           x += ds[key2Idx.GetByFirst(currentInstance.Name), feature] * v[feature, 0];
    283           y += ds[key2Idx.GetByFirst(currentInstance.Name), feature] * v[feature, 1];
    284         }
    285 
    286         IItem item;
    287         if (currentInstance.Results.TryGetValue("Projection.PCA.X", out item)) {
    288           ((DoubleValue)item).Value = x;
    289         } else currentInstance.Results.Add("Projection.PCA.X", new DoubleValue(x));
    290         if (currentInstance.Results.TryGetValue("Projection.PCA.Y", out item)) {
    291           ((DoubleValue)item).Value = y;
    292         } else currentInstance.Results.Add("Projection.PCA.Y", new DoubleValue(y));
    293 
    294         if (currentInstance.Results.TryGetValue("Projection.MDS.X", out item)) {
    295           ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(currentInstance.Name), 0];
    296         } else currentInstance.Results.Add("Projection.MDS.X", new DoubleValue(coords[key2Idx.GetByFirst(currentInstance.Name), 0]));
    297         if (currentInstance.Results.TryGetValue("Projection.MDS.Y", out item)) {
    298           ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(currentInstance.Name), 1];
    299         } else currentInstance.Results.Add("Projection.MDS.Y", new DoubleValue(coords[key2Idx.GetByFirst(currentInstance.Name), 1]));
    300       }
    301     }
    302 
    303     public Tuple<double, double> ProjectCurrentInstance(string projection) {
    304       if (currentInstance == null) return null;
    305       var xKey = "Projection." + projection + ".X";
    306       var yKey = "Projection." + projection + ".Y";
    307       if (!currentInstance.Results.ContainsKey(xKey) || !currentInstance.Results.ContainsKey(yKey))
    308         return null;
    309       var x = ((DoubleValue)currentInstance.Results[xKey]).Value;
    310       var y = ((DoubleValue)currentInstance.Results[yKey]).Value;
    311       return Tuple.Create(x, y);
    312274    }
    313275
     
    455417        ProblemInstances.UpdateOfRunsInProgress = true;
    456418        ProblemInstances.Clear();
     419        var characteristics = new HashSet<string>();
    457420        var totalProblems = adminClient.Problems.Count(x => x.ProblemClassId == probClassId);
    458421        foreach (var problInst in adminClient.Problems.Where(x => x.ProblemClassId == probClassId)) {
     
    470433                foreach (var v in RunCreationClient.Instance.GetCharacteristicValues(problInst.Id)) {
    471434                  probRun.Results.Add("Characteristic." + v.Name, RunCreationClient.Instance.ConvertToItem(v));
     435                  characteristics.Add(v.Name);
    472436                }
    473437                ProblemInstances.Add(probRun);
     438                problemId2ProblemInstanceMapping.Add(problInst.Id, probRun);
    474439              } catch { }
    475440              stream.Close();
     
    561526              var result = ExpectedRuntimeHelper.CalculateErt(kvp.Value, "QualityPerEvaluations", bkQuality * target, maximization);
    562527              var resultName = kvp.Key + "@" + ((target - 1) * 100) + "%";
     528              characteristics.Add(resultName);
    563529              IItem item;
    564530              if (instance.Results.TryGetValue(resultName, out item)) {
     
    568534          }
    569535        }
     536        ProblemCharacteristics.Replace(characteristics.Select(x => new StringValue(x)));
    570537        try {
    571538          KnowledgeBase.UpdateOfRunsInProgress = true;
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/KnowledgeCenterAllinOneView.cs

    r13722 r13751  
    271271          Label = run.Name
    272272        };
    273         instancesSeries.Points.Add(dataPoint);
    274       }
    275 
    276       var curPoint = Content.ProjectCurrentInstance(projection);
    277       if (curPoint != null) {
    278         var dp = new DataPoint(curPoint.Item1, curPoint.Item2) {
    279           Label = Content.Problem.Problem.Name
    280         };
    281         currentInstanceSeries.Points.Add(dp);
     273        if (!Content.IsCurrentInstance(run)) instancesSeries.Points.Add(dataPoint);
     274        else currentInstanceSeries.Points.Add(dataPoint);
    282275      }
    283276    }
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingProblemInstanceView.Designer.cs

    r13722 r13751  
    5050      System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
    5151      System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
    52       this.projectionLabel = new System.Windows.Forms.Label();
    53       this.projectionComboBox = new System.Windows.Forms.ComboBox();
    5452      this.problemInstancesTabControl = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl();
    5553      this.mapTabPage = new System.Windows.Forms.TabPage();
    56       this.instanceMapChart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    5754      this.instancesTabPage = new System.Windows.Forms.TabPage();
    5855      this.problemInstancesView = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     56      this.mapSplitContainer = new System.Windows.Forms.SplitContainer();
     57      this.invPropCheckBox = new System.Windows.Forms.CheckBox();
     58      this.sizeLabel = new System.Windows.Forms.Label();
     59      this.projectionLabel = new System.Windows.Forms.Label();
     60      this.instanceMapChart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
     61      this.sizeComboBox = new System.Windows.Forms.ComboBox();
     62      this.projectionComboBox = new System.Windows.Forms.ComboBox();
     63      this.showCharacteristicsCheckBox = new System.Windows.Forms.CheckBox();
    5964      this.problemInstancesTabControl.SuspendLayout();
    6065      this.mapTabPage.SuspendLayout();
     66      this.instancesTabPage.SuspendLayout();
     67      ((System.ComponentModel.ISupportInitialize)(this.mapSplitContainer)).BeginInit();
     68      this.mapSplitContainer.Panel1.SuspendLayout();
     69      this.mapSplitContainer.SuspendLayout();
    6170      ((System.ComponentModel.ISupportInitialize)(this.instanceMapChart)).BeginInit();
    62       this.instancesTabPage.SuspendLayout();
    6371      this.SuspendLayout();
    64       //
    65       // projectionLabel
    66       //
    67       this.projectionLabel.AutoSize = true;
    68       this.projectionLabel.Location = new System.Drawing.Point(6, 9);
    69       this.projectionLabel.Name = "projectionLabel";
    70       this.projectionLabel.Size = new System.Drawing.Size(57, 13);
    71       this.projectionLabel.TabIndex = 10;
    72       this.projectionLabel.Text = "Projection:";
    73       //
    74       // projectionComboBox
    75       //
    76       this.projectionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    77       this.projectionComboBox.FormattingEnabled = true;
    78       this.projectionComboBox.Location = new System.Drawing.Point(69, 6);
    79       this.projectionComboBox.Name = "projectionComboBox";
    80       this.projectionComboBox.Size = new System.Drawing.Size(158, 21);
    81       this.projectionComboBox.TabIndex = 9;
    82       this.projectionComboBox.SelectedIndexChanged += new System.EventHandler(this.ProjectionComboBoxOnSelectedIndexChanged);
    8372      //
    8473      // problemInstancesTabControl
     
    9887      // mapTabPage
    9988      //
    100       this.mapTabPage.Controls.Add(this.projectionLabel);
    101       this.mapTabPage.Controls.Add(this.instanceMapChart);
    102       this.mapTabPage.Controls.Add(this.projectionComboBox);
     89      this.mapTabPage.Controls.Add(this.mapSplitContainer);
    10390      this.mapTabPage.Location = new System.Drawing.Point(4, 22);
    10491      this.mapTabPage.Name = "mapTabPage";
     
    10895      this.mapTabPage.Text = "Map";
    10996      this.mapTabPage.UseVisualStyleBackColor = true;
     97      //
     98      // instancesTabPage
     99      //
     100      this.instancesTabPage.Controls.Add(this.problemInstancesView);
     101      this.instancesTabPage.Location = new System.Drawing.Point(4, 22);
     102      this.instancesTabPage.Name = "instancesTabPage";
     103      this.instancesTabPage.Padding = new System.Windows.Forms.Padding(3);
     104      this.instancesTabPage.Size = new System.Drawing.Size(992, 734);
     105      this.instancesTabPage.TabIndex = 0;
     106      this.instancesTabPage.Text = "Instances";
     107      this.instancesTabPage.UseVisualStyleBackColor = true;
     108      //
     109      // problemInstancesView
     110      //
     111      this.problemInstancesView.Caption = "View";
     112      this.problemInstancesView.Content = null;
     113      this.problemInstancesView.Dock = System.Windows.Forms.DockStyle.Fill;
     114      this.problemInstancesView.Enabled = false;
     115      this.problemInstancesView.Location = new System.Drawing.Point(3, 3);
     116      this.problemInstancesView.Name = "problemInstancesView";
     117      this.problemInstancesView.ReadOnly = false;
     118      this.problemInstancesView.Size = new System.Drawing.Size(986, 728);
     119      this.problemInstancesView.TabIndex = 0;
     120      this.problemInstancesView.ViewsLabelVisible = true;
     121      this.problemInstancesView.ViewType = null;
     122      //
     123      // mapSplitContainer
     124      //
     125      this.mapSplitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
     126      this.mapSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
     127      this.mapSplitContainer.Location = new System.Drawing.Point(3, 3);
     128      this.mapSplitContainer.Name = "mapSplitContainer";
     129      //
     130      // mapSplitContainer.Panel1
     131      //
     132      this.mapSplitContainer.Panel1.Controls.Add(this.showCharacteristicsCheckBox);
     133      this.mapSplitContainer.Panel1.Controls.Add(this.invPropCheckBox);
     134      this.mapSplitContainer.Panel1.Controls.Add(this.sizeLabel);
     135      this.mapSplitContainer.Panel1.Controls.Add(this.projectionLabel);
     136      this.mapSplitContainer.Panel1.Controls.Add(this.instanceMapChart);
     137      this.mapSplitContainer.Panel1.Controls.Add(this.sizeComboBox);
     138      this.mapSplitContainer.Panel1.Controls.Add(this.projectionComboBox);
     139      this.mapSplitContainer.Panel1.Padding = new System.Windows.Forms.Padding(0, 3, 0, 0);
     140      this.mapSplitContainer.Size = new System.Drawing.Size(986, 728);
     141      this.mapSplitContainer.SplitterDistance = 847;
     142      this.mapSplitContainer.TabIndex = 12;
     143      //
     144      // invPropCheckBox
     145      //
     146      this.invPropCheckBox.AutoSize = true;
     147      this.invPropCheckBox.Checked = true;
     148      this.invPropCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
     149      this.invPropCheckBox.Location = new System.Drawing.Point(579, 12);
     150      this.invPropCheckBox.Name = "invPropCheckBox";
     151      this.invPropCheckBox.Size = new System.Drawing.Size(118, 17);
     152      this.invPropCheckBox.TabIndex = 17;
     153      this.invPropCheckBox.Text = "inverse proportional";
     154      this.invPropCheckBox.UseVisualStyleBackColor = true;
     155      //
     156      // sizeLabel
     157      //
     158      this.sizeLabel.AutoSize = true;
     159      this.sizeLabel.Location = new System.Drawing.Point(264, 12);
     160      this.sizeLabel.Name = "sizeLabel";
     161      this.sizeLabel.Size = new System.Drawing.Size(30, 13);
     162      this.sizeLabel.TabIndex = 15;
     163      this.sizeLabel.Text = "Size:";
     164      //
     165      // projectionLabel
     166      //
     167      this.projectionLabel.AutoSize = true;
     168      this.projectionLabel.Location = new System.Drawing.Point(2, 12);
     169      this.projectionLabel.Name = "projectionLabel";
     170      this.projectionLabel.Size = new System.Drawing.Size(57, 13);
     171      this.projectionLabel.TabIndex = 16;
     172      this.projectionLabel.Text = "Projection:";
    110173      //
    111174      // instanceMapChart
     
    140203      this.instanceMapChart.Series.Add(series1);
    141204      this.instanceMapChart.Series.Add(series2);
    142       this.instanceMapChart.Size = new System.Drawing.Size(986, 698);
    143       this.instanceMapChart.TabIndex = 0;
    144       //
    145       // instancesTabPage
    146       //
    147       this.instancesTabPage.Controls.Add(this.problemInstancesView);
    148       this.instancesTabPage.Location = new System.Drawing.Point(4, 22);
    149       this.instancesTabPage.Name = "instancesTabPage";
    150       this.instancesTabPage.Padding = new System.Windows.Forms.Padding(3);
    151       this.instancesTabPage.Size = new System.Drawing.Size(1044, 757);
    152       this.instancesTabPage.TabIndex = 0;
    153       this.instancesTabPage.Text = "Instances";
    154       this.instancesTabPage.UseVisualStyleBackColor = true;
    155       //
    156       // problemInstancesView
    157       //
    158       this.problemInstancesView.Caption = "View";
    159       this.problemInstancesView.Content = null;
    160       this.problemInstancesView.Dock = System.Windows.Forms.DockStyle.Fill;
    161       this.problemInstancesView.Enabled = false;
    162       this.problemInstancesView.Location = new System.Drawing.Point(3, 3);
    163       this.problemInstancesView.Name = "problemInstancesView";
    164       this.problemInstancesView.ReadOnly = false;
    165       this.problemInstancesView.Size = new System.Drawing.Size(1038, 751);
    166       this.problemInstancesView.TabIndex = 0;
    167       this.problemInstancesView.ViewsLabelVisible = true;
    168       this.problemInstancesView.ViewType = null;
     205      this.instanceMapChart.Size = new System.Drawing.Size(841, 692);
     206      this.instanceMapChart.TabIndex = 12;
     207      //
     208      // sizeComboBox
     209      //
     210      this.sizeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     211      this.sizeComboBox.FormattingEnabled = true;
     212      this.sizeComboBox.Location = new System.Drawing.Point(300, 6);
     213      this.sizeComboBox.Name = "sizeComboBox";
     214      this.sizeComboBox.Size = new System.Drawing.Size(273, 21);
     215      this.sizeComboBox.TabIndex = 13;
     216      //
     217      // projectionComboBox
     218      //
     219      this.projectionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     220      this.projectionComboBox.FormattingEnabled = true;
     221      this.projectionComboBox.Location = new System.Drawing.Point(65, 6);
     222      this.projectionComboBox.Name = "projectionComboBox";
     223      this.projectionComboBox.Size = new System.Drawing.Size(158, 21);
     224      this.projectionComboBox.TabIndex = 14;
     225      //
     226      // showCharacteristicsCheckBox
     227      //
     228      this.showCharacteristicsCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     229      this.showCharacteristicsCheckBox.Appearance = System.Windows.Forms.Appearance.Button;
     230      this.showCharacteristicsCheckBox.Location = new System.Drawing.Point(818, 4);
     231      this.showCharacteristicsCheckBox.Name = "showCharacteristicsCheckBox";
     232      this.showCharacteristicsCheckBox.Size = new System.Drawing.Size(26, 23);
     233      this.showCharacteristicsCheckBox.TabIndex = 18;
     234      this.showCharacteristicsCheckBox.Text = "Detail";
     235      this.showCharacteristicsCheckBox.UseVisualStyleBackColor = true;
    169236      //
    170237      // UnderstandingProblemInstanceView
     
    175242      this.Name = "UnderstandingProblemInstanceView";
    176243      this.Size = new System.Drawing.Size(1000, 760);
    177       this.Controls.SetChildIndex(this.problemInstancesTabControl, 0);
    178244      this.problemInstancesTabControl.ResumeLayout(false);
    179245      this.mapTabPage.ResumeLayout(false);
    180       this.mapTabPage.PerformLayout();
     246      this.instancesTabPage.ResumeLayout(false);
     247      this.mapSplitContainer.Panel1.ResumeLayout(false);
     248      this.mapSplitContainer.Panel1.PerformLayout();
     249      ((System.ComponentModel.ISupportInitialize)(this.mapSplitContainer)).EndInit();
     250      this.mapSplitContainer.ResumeLayout(false);
    181251      ((System.ComponentModel.ISupportInitialize)(this.instanceMapChart)).EndInit();
    182       this.instancesTabPage.ResumeLayout(false);
    183252      this.ResumeLayout(false);
    184253
     
    187256    #endregion
    188257
    189     private System.Windows.Forms.Label projectionLabel;
    190     private System.Windows.Forms.ComboBox projectionComboBox;
    191258    private MainForm.WindowsForms.DragOverTabControl problemInstancesTabControl;
    192259    private System.Windows.Forms.TabPage mapTabPage;
    193     private Visualization.ChartControlsExtensions.EnhancedChart instanceMapChart;
    194260    private System.Windows.Forms.TabPage instancesTabPage;
    195261    private MainForm.WindowsForms.ViewHost problemInstancesView;
     262    private System.Windows.Forms.SplitContainer mapSplitContainer;
     263    private System.Windows.Forms.CheckBox showCharacteristicsCheckBox;
     264    private System.Windows.Forms.CheckBox invPropCheckBox;
     265    private System.Windows.Forms.Label sizeLabel;
     266    private System.Windows.Forms.Label projectionLabel;
     267    private Visualization.ChartControlsExtensions.EnhancedChart instanceMapChart;
     268    private System.Windows.Forms.ComboBox sizeComboBox;
     269    private System.Windows.Forms.ComboBox projectionComboBox;
    196270  }
    197271}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingProblemInstanceView.cs

    r13722 r13751  
    2020#endregion
    2121
     22using HeuristicLab.Core;
    2223using HeuristicLab.MainForm;
    2324using HeuristicLab.OptimizationExpertSystem.Common;
     
    3132  [View("Understanding Problem Instance")]
    3233  [Content(typeof(KnowledgeCenter), IsDefaultView = false)]
    33   public partial class UnderstandingProblemInstanceView : KnowledgeCenterViewBase {
     34  public sealed partial class UnderstandingProblemInstanceView : KnowledgeCenterViewBase {
     35    private bool SuppressEvents { get; set; }
     36
    3437    public UnderstandingProblemInstanceView() {
    3538      InitializeComponent();
     
    4548        problemInstancesView.Content = Content.ProblemInstances;
    4649        UpdateProjectionComboBox();
     50        UpdateSizeComboBox();
    4751      }
    4852    }
     
    5862      if (Content.ProblemInstances.UpdateOfRunsInProgress) return;
    5963      UpdateProjectionComboBox();
     64      UpdateSizeComboBox();
     65      UpdateProjection();
     66    }
     67    #endregion
     68
     69    private void UpdateProjectionComboBox() {
     70      try {
     71        SuppressEvents = true;
     72        var selected = projectionComboBox.SelectedIndex >= 0 ? (string)projectionComboBox.SelectedItem : null;
     73        projectionComboBox.Items.Clear();
     74        foreach (var str in GetProjections()) {
     75          projectionComboBox.Items.Add(str);
     76          if (selected == str) projectionComboBox.SelectedItem = str;
     77        }
     78        if (selected == null && projectionComboBox.Items.Count > 0)
     79          projectionComboBox.SelectedIndex = 0;
     80      } finally { SuppressEvents = false; }
    6081    }
    6182
    62     protected override void OnDownloadEnded() {
    63       base.OnDownloadEnded();
    64       UpdateProjectionComboBox();
     83    private void UpdateSizeComboBox() {
     84      try {
     85        SuppressEvents = true;
     86        var selected = sizeComboBox.SelectedIndex >= 0 ? (string)sizeComboBox.SelectedItem : null;
     87        sizeComboBox.Items.Clear();
     88        sizeComboBox.Items.Add(string.Empty);
     89        foreach (var str in Content.ProblemInstances.ResultNames.Where(x => !(x.StartsWith("Projection.") && (x.EndsWith(".X") || x.EndsWith(".Y"))))) {
     90          sizeComboBox.Items.Add(str);
     91          if (selected == str) sizeComboBox.SelectedItem = str;
     92        }
     93        if (selected == null && sizeComboBox.Items.Count > 0)
     94          sizeComboBox.SelectedIndex = 0;
     95      } finally { SuppressEvents = false; }
    6596    }
    66     #endregion
    6797   
    68     public IEnumerable<string> GetProjections() {
     98    private IEnumerable<string> GetProjections() {
    6999      return Content.ProblemInstances
    70100        .SelectMany(x => x.Results.Where(y => Regex.IsMatch(y.Key, "^Projection[.].*[.][XY]$")))
     
    73103    }
    74104
    75     public void ProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection) {
     105    private void UpdateProjection() {
     106      if (InvokeRequired) { Invoke((Action)UpdateProjection); return; }
     107
     108      var instancesSeries = instanceMapChart.Series["InstancesSeries"];
     109      var currentInstanceSeries = instanceMapChart.Series["CurrentInstanceSeries"];
     110
     111      if (projectionComboBox.SelectedIndex < 0) {
     112        instancesSeries.Points.Clear();
     113        currentInstanceSeries.Points.Clear();
     114        return;
     115      }
     116
     117      var projection = (string)projectionComboBox.SelectedItem;
     118      var size = sizeComboBox.SelectedIndex >= 0 ? (string)sizeComboBox.SelectedItem : string.Empty;
     119
     120      DoProjectProblemInstances(instancesSeries, currentInstanceSeries, projection, size, invPropCheckBox.Checked);
     121    }
     122
     123    private void DoProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection, string size, bool invProp) {
    76124      instancesSeries.Points.Clear();
    77125      currentInstanceSeries.Points.Clear();
    78126
     127      double maxSize = 0, minSize = 0;
     128      if (!string.IsNullOrEmpty(size)) {
     129        var sizes = Content.ProblemInstances.Where(x => x.Results.ContainsKey(size)).Select(x => x.Results[size]).OfType<Data.DoubleValue>().Where(x => !double.IsNaN(x.Value)).ToList();
     130        if (sizes.Count > 0) {
     131          maxSize = sizes.Max(x => x.Value);
     132          minSize = sizes.Min(x => x.Value);
     133        }
     134      }
    79135      foreach (var run in Content.ProblemInstances) {
    80136        var xKey = "Projection." + projection + ".X";
     
    85141        var y = ((Data.DoubleValue)run.Results[yKey]).Value;
    86142        var dataPoint = new DataPoint(x, y) {
    87           Label = run.Name
     143          Label = run.Name,
    88144        };
    89         instancesSeries.Points.Add(dataPoint);
    90       }
     145        IItem item;
     146        if (maxSize > minSize && run.Results.TryGetValue(size, out item)) {
     147          var dItem = item as Data.DoubleValue;
     148          if (dItem != null) {
     149            if (double.IsNaN(dItem.Value))
     150              dataPoint.MarkerSize = 1;
     151            else {
     152              if (invProp) dataPoint.MarkerSize = (int)Math.Round(5 + 15 * (maxSize - dItem.Value) / (maxSize - minSize));
     153              else dataPoint.MarkerSize = (int)Math.Round(5 + 15 * (dItem.Value - minSize) / (maxSize - minSize));
     154            }
     155          }
     156        } else if (maxSize == minSize) {
     157          dataPoint.MarkerSize = instancesSeries.MarkerSize;
     158        } else dataPoint.MarkerSize = 1;
    91159
    92       var curPoint = Content.ProjectCurrentInstance(projection);
    93       if (curPoint != null) {
    94         var dp = new DataPoint(curPoint.Item1, curPoint.Item2) {
    95           Label = Content.Problem.Problem.Name
    96         };
    97         currentInstanceSeries.Points.Add(dp);
     160        if (Content.IsCurrentInstance(run)) currentInstanceSeries.Points.Add(dataPoint);
     161        else instancesSeries.Points.Add(dataPoint);
    98162      }
    99163    }
    100164
     165    #region Control Event Handlers
    101166    private void ProjectionComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
    102       if (InvokeRequired) { Invoke((Action<object, EventArgs>)ProjectionComboBoxOnSelectedIndexChanged, sender, e); return; }
    103       if (projectionComboBox.SelectedIndex < 0) return;
    104       var projection = (string)projectionComboBox.SelectedItem;
    105       var instancesSeries = instanceMapChart.Series["InstancesSeries"];
    106       var currentInstanceSeries = instanceMapChart.Series["CurrentInstanceSeries"];
    107 
    108       ProjectProblemInstances(instancesSeries, currentInstanceSeries, projection);
     167      UpdateProjection();
    109168    }
    110169
    111     private void UpdateProjectionComboBox() {
    112       projectionComboBox.Items.Clear();
    113       foreach (var str in GetProjections()) {
    114         projectionComboBox.Items.Add(str);
    115       }
    116       if (projectionComboBox.Items.Count > 0)
    117         projectionComboBox.SelectedIndex = 0;
     170    private void SizeComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
     171      UpdateProjection();
    118172    }
     173
     174    private void InvPropCheckBoxOnCheckedChanged(object sender, EventArgs e) {
     175      UpdateProjection();
     176    }
     177    #endregion
    119178  }
    120179}
Note: See TracChangeset for help on using the changeset viewer.