Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/14/16 17:12:51 (8 years ago)
Author:
bburlacu
Message:

#2288: Simplify and optimize code for cluster identification in ConstrainedForceDirectedLayout.cs. Introduce a TrackBar for adjusting network threshold in the RunCollectionVariableInteractionNetworkView. Minor improvements to the DirectedGraphChart (work in progress).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/Layout/ConstrainedForceDirectedLayout.cs

    r13821 r13893  
    2525using System.Linq;
    2626using Cola;
    27 using HeuristicLab.Common;
    2827using HeuristicLab.Core;
    2928using HeuristicLab.Random;
     
    180179
    181180    private static IEnumerable<Cluster> IdentifyClusters(RectanglePtrs rectangles, ColaEdges edges) {
    182       var vertices = rectangles.Select(x => new Vertex()).ToList();
     181      // build a graph using the rectangles and the edges
     182      var vertices = new List<IVertex>(rectangles.Select(x => new Vertex()));
    183183      foreach (var e in edges) {
    184184        var i = (int)e.first;
     
    188188        vertices[j].AddArc(arc);
    189189      }
    190       while (vertices.Min(x => x.Weight).IsAlmost(0)) {
    191         foreach (var v in vertices) {
    192           if (v.Weight > 0) continue;
    193           v.Weight = vertices.Max(x => x.Weight) + 1;
     190      // group vertices into clusters
     191      var clusters = new List<RectangularCluster>();
     192      for (int i = 0; i < vertices.Count; ++i) {
     193        var v = vertices[i];
     194        if (v.Weight > 0) {
     195          clusters[(int)Math.Round(v.Weight) - 1].addChildNode((uint)i);
     196        } else {
     197          var cluster = new RectangularCluster();
     198          cluster.addChildNode((uint)i);
     199          clusters.Add(cluster);
     200          v.Weight = clusters.Count;
    194201          ColourNeighbours(v);
    195202        }
    196203      }
    197       var colors = vertices.Select(x => (int)Math.Round(x.Weight)).ToList();
    198       foreach (var i in colors.Distinct()) {
    199         var cluster = new RectangularCluster();
    200         for (int j = 0; j < colors.Count; ++j) {
    201           if (colors[j] == i) cluster.addChildNode((uint)j);
    202         }
    203         yield return cluster;
    204       }
     204      return clusters;
    205205    }
    206206
Note: See TracChangeset for help on using the changeset viewer.