Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12880


Ignore:
Timestamp:
08/18/15 16:32:04 (9 years ago)
Author:
pfleck
Message:

#2379
Adapted dimension matching for NSGA-II Sample.
Changed default views.

Location:
branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/BubbleChartView.cs

    r12647 r12880  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.Linq;
     
    3334namespace HeuristicLab.Optimization.BubbleChart {
    3435  [View("Bubble Chart (Recursive)")]
    35   [Content(typeof(RecursiveDataItem), false)]
     36  [Content(typeof(RecursiveDataItem), true)]
    3637  public partial class BubbleChartView : ItemView {
    3738    private const string Separator = ":";
     
    8687    }
    8788    private IEnumerable<string> GetAvailableKeys() {
    88       var collector = new HashSet<string>();
     89      var collector = new List<string>();
    8990      GetAvailableKeys(Content, collector);
    90       return collector;
    91     }
    92     private void GetAvailableKeys(RecursiveDataItem node, ISet<string> collector) {
    93       foreach (var child in node.Children) {
    94         foreach (var key in child.Data.Keys) {
    95           collector.Add(node.Name + Separator + key);
    96         }
    97       }
     91      return collector.Distinct();
     92    }
     93    private void GetAvailableKeys(RecursiveDataItem node, List<string> collector) {
     94      collector.AddRange(node.Data.Keys);
    9895
    9996      foreach (var child in node.Children)
     
    153150        var additionalSizeDimension = Enum.GetNames(typeof(SizeDimension));
    154151
    155         xAxisComboBox.Items.AddRange(additionalAxisDimension);
     152        //xAxisComboBox.Items.AddRange(additionalAxisDimension);
    156153        xAxisComboBox.Items.AddRange(axisNames);
    157         yAxisComboBox.Items.AddRange(additionalAxisDimension);
     154        //yAxisComboBox.Items.AddRange(additionalAxisDimension);
    158155        yAxisComboBox.Items.AddRange(axisNames);
    159156        sizeComboBox.Items.AddRange(additionalSizeDimension);
     
    190187      chart.ChartAreas[0].AxisY.IsMarginVisible = !(YAxisValue != null && YAxisValue.Contains(AxisDimension.Index.ToString()));
    191188
    192       if (Content != null) {
    193         var items = GetAvailableItems().ToList();
    194         var xss = GetValues(items, XAxisValue).Select(x => x.ToList()).ToList();
    195         var yss = GetValues(items, YAxisValue).Select(x => x.ToList()).ToList();
    196         var sss = GetValues(items, SizeAxisValue).Select(x => x.ToList()).ToList();
    197 
    198         if (xss.Any(xs => xs.Any()) && yss.Any(ys => ys.Any()) && sss.Any(ss => ss.Any())) {
    199           var xDim = Tuple.Create(xss.Count, xss.Max(xs => xs.Count));
    200           var yDim = Tuple.Create(yss.Count, yss.Max(ys => ys.Count));
    201           var sDim = Tuple.Create(sss.Count, sss.Max(ss => ss.Count));
    202 
    203           var isSimple = new Func<Tuple<int, int>, bool>(dim => dim.Item1 == 1 && dim.Item2 > 1 || dim.Item1 > 1 && dim.Item2 == 1);
    204           var flatten = new Func<List<List<double>>, List<double>>(ss => ss.SelectMany(s => s).ToList());
    205 
    206           if (isSimple(xDim) && isSimple(yDim)) {
    207             var xs = flatten(xss);
    208             var ys = flatten(yss);
    209             if (xs.Count == ys.Count) {
    210               var xsEnum = xs.GetEnumerator();
    211               var ysEnum = ys.GetEnumerator();
    212               while (xsEnum.MoveNext() & ysEnum.MoveNext())
    213                 series.Points.Add(new DataPoint(xsEnum.Current, new[] { ysEnum.Current, sss[0][0] }));
    214             } /*else {
    215               foreach (var x in xs)
    216                 foreach (var y in ys)
    217                   series.Points.Add(new DataPoint(x, new[] { y, sss[0][0] }));
    218             }*/
    219           } else if (isSimple(xDim)) {
    220             var xs = flatten(xss);
    221             if (xs.Count == yss.Count) {
    222               var xsEnum = xs.GetEnumerator();
    223               var yssEnum = yss.GetEnumerator();
    224               while (xsEnum.MoveNext() & yssEnum.MoveNext()) {
    225                 var x = xsEnum.Current;
    226                 var ys = yssEnum.Current;
    227                 foreach (var y in ys)
    228                   series.Points.Add(new DataPoint(x, new[] { y, sss[0][0] }));
    229               }
    230             }
    231           } else if (isSimple(yDim)) {
    232             var ys = flatten(yss);
    233             if (xss.Count == ys.Count) {
    234               var xssEnum = xss.GetEnumerator();
    235               var ysEnum = ys.GetEnumerator();
    236               while (xssEnum.MoveNext() & ysEnum.MoveNext()) {
    237                 var xs = xssEnum.Current;
    238                 var y = ysEnum.Current;
    239                 foreach (var x in xs)
    240                   series.Points.Add(new DataPoint(x, new[] { y, sss[0][0] }));
    241               }
    242             }
    243           } else {
    244             if (xss.Count == yss.Count) {
    245               var xssEnum = xss.GetEnumerator();
    246               var yssEnum = yss.GetEnumerator();
    247               while (xssEnum.MoveNext() & yssEnum.MoveNext()) {
    248                 var xs = xssEnum.Current;
    249                 var ys = yssEnum.Current;
    250                 if (xs.Count == ys.Count) {
    251                   var xsEnum = xs.GetEnumerator();
    252                   var ysEnum = ys.GetEnumerator();
    253                   while (xsEnum.MoveNext() & ysEnum.MoveNext())
    254                     series.Points.Add(new DataPoint(xsEnum.Current, new[] { ysEnum.Current, sss[0][0] }));
    255                 }
    256               }
    257             } else if (xDim.Item2 == yDim.Item2) {
    258               foreach (var xs in xss) {
    259                 foreach (var ys in yss) {
    260                   var xsEnum = xs.GetEnumerator();
    261                   var ysEnum = ys.GetEnumerator();
    262                   while (xsEnum.MoveNext() & ysEnum.MoveNext()) {
    263                     series.Points.Add(new DataPoint(xsEnum.Current, new[] { ysEnum.Current, sss[0][0] }));
    264                   }
    265                 }
    266               }
    267             }
    268           }
    269         }
    270         UpdateMarkerSizes();
    271       }
    272     }
    273 
    274     /*var items = GetAvailableItems();
    275           foreach (var item in items) {
    276             var xs = GetValues(item, XAxisValue).ToList();
    277             var ys = GetValues(item, YAxisValue).ToList();
    278             var ss = GetValues(item, SizeAxisValue).ToList();
    279             if (xs.Count > 0 && ys.Count > 0 && (ss.Count == 1 || ss.Count == xs.Count || ss.Count == ys.Count)) {
    280               var sEnum = ss.Count > 1 ? ss.GetEnumerator() : Enumerable.Repeat(ss[0], xs.Count * ys.Count).GetEnumerator();
    281               sEnum.MoveNext();
    282               if (xs.Count > 1 && ys.Count > 1) { // index matching
    283                 for (int i = 0; i < Math.Min(xs.Count, ys.Count); i++)
    284                   series.Points.Add(new DataPoint(xs[i], new[] { ys[i], sEnum.Current }));
    285               } else {
    286                 foreach (var x in xs) {
    287                   foreach (var y in ys) {
    288                     series.Points.Add(new DataPoint(x, new[] { y, sEnum.Current }));
    289                     sEnum.MoveNext();
    290                   }
    291                 }
    292               }
    293             }
    294           }*/
     189      if (Content == null || string.IsNullOrEmpty(XAxisValue) || string.IsNullOrEmpty(YAxisValue)) return;
     190
     191      var xss = GetValues(XAxisValue);
     192      var yss = GetValues(YAxisValue);
     193
     194      if (xss.Count == yss.Count) {
     195        for (int i = 0; i < xss.Count; i++)
     196          AddPoints(xss[i], yss[i], series);
     197      } else if (xss.Count == 1 || yss.Count == 1) {
     198        for (int i = 0; i < xss.Count; i++)
     199          for (int j = 0; j < yss.Count; j++)
     200            AddPoints(xss[i], yss[j], series);
     201      }
     202    }
     203    void AddPoints(double[] xs, double[] ys, Series series) {
     204      if (xs.Length != ys.Length) return;
     205      for (int k = 0; k < xs.Length; k++) {
     206        series.Points.Add(new DataPoint(xs[k], new[] { ys[k], 1.0 }));
     207      }
     208    }
     209
     210    private List<double[]> GetValues(string key) {
     211      var collector = new List<double[]>();
     212      GetValues(Content, key, collector);
     213      return collector;
     214    }
     215    private void GetValues(RecursiveDataItem node, string key, List<double[]> collector) {
     216      IItem item;
     217      if (node.Data.TryGetValue(key, out item)) {
     218        var value = ConvertToDoubles(node, key);
     219        collector.Add(value);
     220      }
     221
     222      foreach (var child in node.Children)
     223        GetValues(child, key, collector);
     224    }
     225
     226    private double[] ConvertToDoubles(RecursiveDataItem item, string key) {
     227      IItem value = item.Data[key];
     228      var doubleValue = value as DoubleValue;
     229      var doubleArray = value as DoubleArray;
     230      var intValue = value as IntValue;
     231      var intArray = value as IntArray;
     232      var timeSpanValue = value as TimeSpanValue;
     233      if (doubleValue != null) return new double[1] { doubleValue.Value };
     234      if (intValue != null) return new double[1] { intValue.Value };
     235      if (timeSpanValue != null) return new double[1] { timeSpanValue.Value.TotalSeconds };
     236      if (doubleArray != null) return doubleArray.ToArray();
     237      if (intArray != null) return intArray.Select(v => (double)v).ToArray();
     238      return new double[1] { GetCategoricalValue(key, value.ToString()).Value };
     239    }
    295240
    296241    private IEnumerable<IEnumerable<double>> GetValues(IEnumerable<RecursiveDataItem> items, string key) {
  • branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/RecursiveDataItemView.cs

    r12388 r12880  
    2828namespace HeuristicLab.Optimization.BubbleChart {
    2929  [View("RecursiveDataItem View")]
    30   [Content(typeof(RecursiveDataItem), true)]
     30  [Content(typeof(RecursiveDataItem), false)]
    3131  public partial class RecursiveDataItemView : NamedItemView {
    3232
Note: See TracChangeset for help on using the changeset viewer.