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).

Location:
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/DirectedGraphChart.Designer.cs

    r13874 r13893  
    3030      this.SuspendLayout();
    3131      //
    32       // pictureBox
    33       //
    34       this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image")));
    35       //
    3632      // toolTip
    3733      //
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/DirectedGraphChart.cs

    r13874 r13893  
    159159        Pen pen;
    160160        var penWidth = weight / max * 3;
    161         //var penColor = colors[(int)Math.Min(255, weight / max * 255)];
    162         var penColor = Color.Black;
     161        var colorIndex = (int)Math.Min(255, weight / max * 255);
     162        if (colorIndex < 0) colorIndex = 0;
     163        if (colorIndex > 255) colorIndex = 255;
     164        var penColor = colors[colorIndex];
    163165        if (len == 2) {
    164           if (double.IsInfinity(penWidth) || double.IsNaN(penWidth)) penWidth = 1;
     166          if (double.IsInfinity(penWidth) || double.IsNaN(penWidth))
     167            penWidth = 1;
     168
    165169          pen = new Pen(penColor, (float)penWidth) { CustomEndCap = new AdjustableArrowCap(5, 3) };
    166170          var start = points[0];
     
    169173          var rect = target.Primitive as Rectangle;
    170174          var ell = target.Primitive as Ellipse;
     175
     176          // calculate intersection point
    171177          PointD intersectionPoint;
    172178          if (rect != null)
     
    176182          else
    177183            throw new InvalidOperationException("Unknown vertex shape.");
     184
    178185          if (intersectionPoint == default(PointD))
    179186            intersectionPoint = end;
     187
    180188          line = new Line(Chart, new PointD(start.X, start.Y), intersectionPoint, pen) { ToolTipText = arc.Label };
    181189          Chart.Group.Add(line);
     
    184192        } else {
    185193          for (int i = 0; i < points.Length - 1; ++i) {
    186             Line line;
    187194            var start = points[i];
    188195            var end = points[i + 1];
     
    208215              pen = new Pen(penColor, (float)penWidth);
    209216            }
    210             line = new Line(Chart, new PointD(start.X, start.Y), endPoint, pen) { ToolTipText = arc.Label };
     217            var startPoint = new PointD(start.X, start.Y);
     218            var line = new Line(Chart, startPoint, endPoint, pen) { ToolTipText = arc.Label };
    211219            Chart.Group.Add(line);
    212220            if (intersectionPoints.Any()) {
     
    248256      var rectangle = p as Rectangle;
    249257      var ellipse = p as Ellipse;
    250       var brush = (SolidBrush)shape.Brush;
     258      var pen = new Pen(shape.Pen.Color);
     259      var brush = new SolidBrush(((SolidBrush)shape.Brush).Color);
    251260
    252261      if (rectangle != null) {
    253         var r = new Rectangle(this.Chart, shape.LowerLeft, shape.UpperRight, new Pen(shape.Pen.Color), new SolidBrush(brush.Color));
     262        var r = new Rectangle(this.Chart, shape.LowerLeft, shape.UpperRight, pen, brush);
    254263        return new LabeledPrimitive(r, v.Label, shape.Font);
    255264      }
    256265      if (ellipse != null) {
    257         var e = new Ellipse(this.Chart, shape.LowerLeft, shape.UpperRight, new Pen(shape.Pen.Color), new SolidBrush(brush.Color));
     266        var e = new Ellipse(this.Chart, shape.LowerLeft, shape.UpperRight, pen, brush);
    258267        return new LabeledPrimitive(e, v.Label, shape.Font);
    259268      }
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/HeuristicLab.VariableInteractionNetworks.Views-3.3.csproj

    r13727 r13893  
    171171    <None Include="Plugin.cs.frame" />
    172172  </ItemGroup>
     173  <ItemGroup>
     174    <EmbeddedResource Include="RunCollectionVariableInteractionNetworkView.resx">
     175      <DependentUpon>RunCollectionVariableInteractionNetworkView.cs</DependentUpon>
     176    </EmbeddedResource>
     177  </ItemGroup>
    173178  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    174179  <PropertyGroup>
  • 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
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.Designer.cs

    r13874 r13893  
    2626      this.components = new System.ComponentModel.Container();
    2727      this.settingsGroupBox = new System.Windows.Forms.GroupBox();
     28      this.impactThresholdTrackBar = new System.Windows.Forms.TrackBar();
     29      this.exportImpactsMatrixButton = new System.Windows.Forms.Button();
    2830      this.onlineImpactCalculationButton = new System.Windows.Forms.Button();
    2931      this.maximizationCheckBox = new System.Windows.Forms.CheckBox();
    3032      this.qualityResultNameComboBox = new System.Windows.Forms.ComboBox();
    3133      this.qualityResultNameLabel = new System.Windows.Forms.Label();
    32       this.impactThresholdTextBox = new System.Windows.Forms.TextBox();
    3334      this.impactAggregationComboBox = new System.Windows.Forms.ComboBox();
    3435      this.impactResultNameComboBox = new System.Windows.Forms.ComboBox();
     
    4243      this.label3 = new System.Windows.Forms.Label();
    4344      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
     45      this.impactThresholdLabel = new System.Windows.Forms.Label();
     46      this.relayoutGraphButton = new System.Windows.Forms.Button();
    4447      this.graphChart = new HeuristicLab.VariableInteractionNetworks.Views.DirectedGraphChart();
    4548      this.settingsGroupBox.SuspendLayout();
     49      ((System.ComponentModel.ISupportInitialize)(this.impactThresholdTrackBar)).BeginInit();
    4650      this.layoutOptionsGroupBox.SuspendLayout();
    4751      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     
    5256      this.settingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    5357            | System.Windows.Forms.AnchorStyles.Left)));
     58      this.settingsGroupBox.Controls.Add(this.impactThresholdLabel);
     59      this.settingsGroupBox.Controls.Add(this.impactThresholdTrackBar);
     60      this.settingsGroupBox.Controls.Add(this.exportImpactsMatrixButton);
    5461      this.settingsGroupBox.Controls.Add(this.onlineImpactCalculationButton);
    5562      this.settingsGroupBox.Controls.Add(this.maximizationCheckBox);
    5663      this.settingsGroupBox.Controls.Add(this.qualityResultNameComboBox);
    5764      this.settingsGroupBox.Controls.Add(this.qualityResultNameLabel);
    58       this.settingsGroupBox.Controls.Add(this.impactThresholdTextBox);
    5965      this.settingsGroupBox.Controls.Add(this.impactAggregationComboBox);
    6066      this.settingsGroupBox.Controls.Add(this.impactResultNameComboBox);
     
    6470      this.settingsGroupBox.Location = new System.Drawing.Point(4, 4);
    6571      this.settingsGroupBox.Name = "settingsGroupBox";
    66       this.settingsGroupBox.Size = new System.Drawing.Size(331, 230);
     72      this.settingsGroupBox.Size = new System.Drawing.Size(331, 235);
    6773      this.settingsGroupBox.TabIndex = 1;
    6874      this.settingsGroupBox.TabStop = false;
    6975      this.settingsGroupBox.Text = "Network Configuration";
    7076      //
     77      // impactThresholdTrackBar
     78      //
     79      this.impactThresholdTrackBar.AutoSize = false;
     80      this.impactThresholdTrackBar.LargeChange = 1;
     81      this.impactThresholdTrackBar.Location = new System.Drawing.Point(10, 118);
     82      this.impactThresholdTrackBar.Maximum = 1000;
     83      this.impactThresholdTrackBar.Name = "impactThresholdTrackBar";
     84      this.impactThresholdTrackBar.Size = new System.Drawing.Size(312, 23);
     85      this.impactThresholdTrackBar.TabIndex = 7;
     86      this.impactThresholdTrackBar.ValueChanged += new System.EventHandler(this.impactThresholdTrackBar_ValueChanged);
     87      //
     88      // exportImpactsMatrixButton
     89      //
     90      this.exportImpactsMatrixButton.Location = new System.Drawing.Point(10, 203);
     91      this.exportImpactsMatrixButton.Name = "exportImpactsMatrixButton";
     92      this.exportImpactsMatrixButton.Size = new System.Drawing.Size(149, 23);
     93      this.exportImpactsMatrixButton.TabIndex = 6;
     94      this.exportImpactsMatrixButton.Text = "Export Impacts Matrix";
     95      this.exportImpactsMatrixButton.UseVisualStyleBackColor = true;
     96      this.exportImpactsMatrixButton.Click += new System.EventHandler(this.exportImpactsMatrixButton_Click);
     97      //
    7198      // onlineImpactCalculationButton
    7299      //
    73       this.onlineImpactCalculationButton.Location = new System.Drawing.Point(10, 201);
     100      this.onlineImpactCalculationButton.Location = new System.Drawing.Point(10, 174);
    74101      this.onlineImpactCalculationButton.Name = "onlineImpactCalculationButton";
    75102      this.onlineImpactCalculationButton.Size = new System.Drawing.Size(149, 23);
     
    108135      this.qualityResultNameLabel.Text = "Quality result name";
    109136      //
    110       // impactThresholdTextBox
    111       //
    112       this.impactThresholdTextBox.Location = new System.Drawing.Point(121, 94);
    113       this.impactThresholdTextBox.Name = "impactThresholdTextBox";
    114       this.impactThresholdTextBox.Size = new System.Drawing.Size(201, 20);
    115       this.impactThresholdTextBox.TabIndex = 2;
    116       this.impactThresholdTextBox.Text = "0.2";
    117       this.impactThresholdTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.TextBoxValidating);
    118       this.impactThresholdTextBox.Validated += new System.EventHandler(this.ImpactThresholdTextBoxValidated);
    119       //
    120137      // impactAggregationComboBox
    121138      //
     
    124141            "Best run",
    125142            "Runs average"});
    126       this.impactAggregationComboBox.Location = new System.Drawing.Point(121, 120);
     143      this.impactAggregationComboBox.Location = new System.Drawing.Point(121, 147);
    127144      this.impactAggregationComboBox.Name = "impactAggregationComboBox";
    128145      this.impactAggregationComboBox.Size = new System.Drawing.Size(201, 21);
     
    143160      //
    144161      this.weightAggregationLabel.AutoSize = true;
    145       this.weightAggregationLabel.Location = new System.Drawing.Point(7, 123);
     162      this.weightAggregationLabel.Location = new System.Drawing.Point(7, 150);
    146163      this.weightAggregationLabel.Name = "weightAggregationLabel";
    147164      this.weightAggregationLabel.Size = new System.Drawing.Size(98, 13);
     
    171188      this.layoutOptionsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    172189            | System.Windows.Forms.AnchorStyles.Left)));
     190      this.layoutOptionsGroupBox.Controls.Add(this.relayoutGraphButton);
    173191      this.layoutOptionsGroupBox.Controls.Add(this.idealEdgeLengthTextBox);
    174192      this.layoutOptionsGroupBox.Controls.Add(this.edgeRoutingComboBox);
    175193      this.layoutOptionsGroupBox.Controls.Add(this.label4);
    176194      this.layoutOptionsGroupBox.Controls.Add(this.label3);
    177       this.layoutOptionsGroupBox.Location = new System.Drawing.Point(4, 240);
     195      this.layoutOptionsGroupBox.Location = new System.Drawing.Point(4, 245);
    178196      this.layoutOptionsGroupBox.Name = "layoutOptionsGroupBox";
    179       this.layoutOptionsGroupBox.Size = new System.Drawing.Size(331, 222);
     197      this.layoutOptionsGroupBox.Size = new System.Drawing.Size(331, 217);
    180198      this.layoutOptionsGroupBox.TabIndex = 2;
    181199      this.layoutOptionsGroupBox.TabStop = false;
     
    227245      //
    228246      this.errorProvider.ContainerControl = this;
     247      //
     248      // impactThresholdLabel
     249      //
     250      this.impactThresholdLabel.Location = new System.Drawing.Point(118, 92);
     251      this.impactThresholdLabel.Name = "impactThresholdLabel";
     252      this.impactThresholdLabel.Size = new System.Drawing.Size(204, 23);
     253      this.impactThresholdLabel.TabIndex = 8;
     254      this.impactThresholdLabel.Text = "0";
     255      this.impactThresholdLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
     256      //
     257      // relayoutGraphButton
     258      //
     259      this.relayoutGraphButton.Location = new System.Drawing.Point(10, 69);
     260      this.relayoutGraphButton.Name = "relayoutGraphButton";
     261      this.relayoutGraphButton.Size = new System.Drawing.Size(149, 23);
     262      this.relayoutGraphButton.TabIndex = 4;
     263      this.relayoutGraphButton.Text = "Recalculate Layout";
     264      this.relayoutGraphButton.UseVisualStyleBackColor = true;
     265      this.relayoutGraphButton.Click += new System.EventHandler(this.relayoutGraphButton_Click);
    229266      //
    230267      // graphChart
     
    256293      this.settingsGroupBox.ResumeLayout(false);
    257294      this.settingsGroupBox.PerformLayout();
     295      ((System.ComponentModel.ISupportInitialize)(this.impactThresholdTrackBar)).EndInit();
    258296      this.layoutOptionsGroupBox.ResumeLayout(false);
    259297      this.layoutOptionsGroupBox.PerformLayout();
     
    270308    private System.Windows.Forms.Label label2;
    271309    private System.Windows.Forms.ComboBox impactResultNameComboBox;
    272     private System.Windows.Forms.TextBox impactThresholdTextBox;
    273310    private System.Windows.Forms.GroupBox layoutOptionsGroupBox;
    274311    private System.Windows.Forms.Label label3;
     
    283320    private System.Windows.Forms.CheckBox maximizationCheckBox;
    284321    private System.Windows.Forms.Button onlineImpactCalculationButton;
     322    private System.Windows.Forms.Button exportImpactsMatrixButton;
     323    private System.Windows.Forms.TrackBar impactThresholdTrackBar;
     324    private System.Windows.Forms.Label impactThresholdLabel;
     325    private System.Windows.Forms.Button relayoutGraphButton;
    285326  }
    286327}
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.cs

    r13874 r13893  
    322322      foreach (var run in runs) {
    323323        var impactsMatrix = (DoubleMatrix)run.Results[resultName];
    324 
    325324        int i = 0;
    326325        foreach (var v in impactsMatrix.RowNames) {
     
    412411    private void NetworkConfigurationChanged(object sender, EventArgs e) {
    413412      var useBest = impactAggregationComboBox.SelectedIndex <= 0;
    414       var threshold = double.Parse(impactThresholdTextBox.Text);
     413      var threshold = impactThresholdTrackBar.Value / 100.0;
    415414      var qualityResultName = qualityResultNameComboBox.Text;
    416415      var impactsResultName = impactResultNameComboBox.Text;
     
    451450        = impactResultNameComboBox.Enabled
    452451        = impactAggregationComboBox.Enabled
    453         = impactThresholdTextBox.Enabled
     452        = impactThresholdTrackBar.Enabled
    454453        = onlineImpactCalculationButton.Enabled
    455454        = edgeRoutingComboBox.Enabled
    456         = idealEdgeLengthTextBox.Enabled = enabled;
     455        = idealEdgeLengthTextBox.Enabled
     456        = maximizationCheckBox.Enabled = enabled;
    457457    }
    458458
     
    463463        var impacts = CalculateVariableImpactsOnline(Content, false);
    464464        variableInteractionNetwork = CreateNetwork(impacts);
    465         var threshold = double.Parse(impactThresholdTextBox.Text);
     465        var threshold = impactThresholdTrackBar.Minimum + (double)impactThresholdTrackBar.Value / impactThresholdTrackBar.Maximum;
    466466        graphChart.Graph = ApplyThreshold(variableInteractionNetwork, threshold);
    467467      };
     
    469469      worker.RunWorkerAsync();
    470470    }
     471
     472    private void relayoutGraphButton_Click(object sender, EventArgs e) {
     473      graphChart.Draw();
     474    }
    471475    #endregion
     476
     477    private void exportImpactsMatrixButton_Click(object sender, EventArgs e) {
     478      var graph = graphChart.Graph;
     479      var labels = graph.Vertices.OfType<VariableNetworkNode>().Select(x => x.Label).ToList();
     480      labels.Sort(); // sort variables alphabetically
     481      var matrix = new DoubleMatrix(labels.Count, labels.Count) { RowNames = labels, ColumnNames = labels };
     482      var indexes = labels.Select((x, i) => new { Label = x, Index = i }).ToDictionary(x => x.Label, x => x.Index);
     483      var junctions = graph.Vertices.OfType<JunctionNetworkNode>().ToList();
     484      foreach (var jn in junctions) {
     485        var target = jn.OutArcs.First().Target.Label;
     486        var targetIndex = indexes[target];
     487        foreach (var input in jn.InArcs) {
     488          var inputIndex = indexes[input.Source.Label];
     489          var inputImpact = input.Weight;
     490          matrix[targetIndex, inputIndex] = inputImpact;
     491        }
     492      }
     493      for (int i = 0; i < labels.Count; ++i) matrix[i, i] = 1;
     494      MainFormManager.MainForm.ShowContent(matrix);
     495    }
     496
     497    private void impactThresholdTrackBar_ValueChanged(object sender, EventArgs e) {
     498      var impact = impactThresholdTrackBar.Minimum + (double)impactThresholdTrackBar.Value / impactThresholdTrackBar.Maximum;
     499      impactThresholdLabel.Text = impact.ToString("N3", CultureInfo.CurrentCulture);
     500      var network = ApplyThreshold(variableInteractionNetwork, impact);
     501      graphChart.Graph = network;
     502    }
     503
     504
    472505  }
    473506}
Note: See TracChangeset for help on using the changeset viewer.