[7779] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[7792] | 23 | using System.Collections.Generic;
|
---|
[7779] | 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
| 30 | using HeuristicLab.MainForm;
|
---|
| 31 | using HeuristicLab.Visualization;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.EvolutionaryTracking.Views {
|
---|
| 34 | [View("SymbolicExpressionTreeGenealogyGraph")]
|
---|
| 35 | [Content(typeof(SymbolicExpressionTreeGenealogyGraph), IsDefaultView = true)]
|
---|
| 36 | public sealed partial class GenealogyGraphView : ItemView {
|
---|
| 37 | private VisualSymbolicExpressionTreeNode _selectedVisualSymbolicExpressionTreeNode;
|
---|
| 38 |
|
---|
| 39 | public new SymbolicExpressionTreeGenealogyGraph Content {
|
---|
| 40 | get { return (SymbolicExpressionTreeGenealogyGraph)base.Content; }
|
---|
| 41 | set { base.Content = value; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public GenealogyGraphView()
|
---|
| 45 | : base() {
|
---|
| 46 | InitializeComponent();
|
---|
| 47 | similarityModeSelector.SelectedIndex = 0; // set default similarity mode to "exact"
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | protected override void DeregisterContentEvents() {
|
---|
| 51 | // TODO: Deregister your event handlers here
|
---|
| 52 | genealogyGraphChart.GenealogyGraphNodeClicked -= graphChart_GenealogyGraphNodeClicked;
|
---|
| 53 | symbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked -= treeChart_SymbolicExpressionTreeNodeClicked;
|
---|
| 54 | base.DeregisterContentEvents();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | protected override void RegisterContentEvents() {
|
---|
| 58 | base.RegisterContentEvents();
|
---|
| 59 | // TODO: Register your event handlers here
|
---|
| 60 | genealogyGraphChart.GenealogyGraphNodeClicked += graphChart_GenealogyGraphNodeClicked;
|
---|
| 61 | symbolicExpressionTreeChart.SymbolicExpressionTreeNodeClicked += treeChart_SymbolicExpressionTreeNodeClicked;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | #region Event Handlers (Content)
|
---|
| 65 | // TODO: Put event handlers of the content here
|
---|
| 66 | protected override void OnContentChanged() {
|
---|
| 67 | base.OnContentChanged();
|
---|
| 68 | if (Content == null)
|
---|
| 69 | genealogyGraphChart.Graph = null;
|
---|
| 70 | else {
|
---|
| 71 | genealogyGraphChart.Graph = Content;
|
---|
| 72 | var best = Content.Values.OrderByDescending(x => x.Quality).First();
|
---|
| 73 | symbolicExpressionTreeChart.Tree = (ISymbolicExpressionTree)best.Data;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | private void Content_GraphChanged(object sender, EventArgs e) {
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected override void SetEnabledStateOfControls() {
|
---|
| 81 | base.SetEnabledStateOfControls();
|
---|
| 82 | genealogyGraphChart.Enabled = Content != null;
|
---|
| 83 | }
|
---|
| 84 | #endregion
|
---|
| 85 |
|
---|
| 86 | #region Event Handlers (child controls)
|
---|
| 87 |
|
---|
| 88 | // TODO: Put event handlers of child controls here.
|
---|
| 89 | private void graphChart_GenealogyGraphNodeClicked(object sender, MouseEventArgs e) {
|
---|
| 90 | // the hierarchy goes like this: VisualGenealogyGraphNode --> GenealogyGraphNode --> symbolicExpressionTree
|
---|
| 91 | var visualGenealogyGraphNode = (VisualGenealogyGraphNode)sender;
|
---|
| 92 | var genealogyGraphNode = (GenealogyGraphNode)visualGenealogyGraphNode.Data;
|
---|
| 93 | symbolicExpressionTreeChart.Tree = (ISymbolicExpressionTree)genealogyGraphNode.Data;
|
---|
| 94 | if (_selectedVisualSymbolicExpressionTreeNode != null) {
|
---|
[7792] | 95 | var nodes = symbolicExpressionTreeChart.Tree.IterateNodesBreadth() as List<ISymbolicExpressionTreeNode>;
|
---|
| 96 | var fragments = _selectedVisualSymbolicExpressionTreeNode.SymbolicExpressionTreeNode.IterateNodesBreadth() as List<ISymbolicExpressionTreeNode>;
|
---|
[7785] | 97 | int index = SymbolicExpressionTreeMatching.FindMatch(nodes, fragments, similarityModeSelector.SelectedIndex);
|
---|
[7779] | 98 | if (index != -1) {
|
---|
[7792] | 99 | _selectedVisualSymbolicExpressionTreeNode = symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(nodes[index + fragments.Count - 1]);
|
---|
[7779] | 100 | var subtree = _selectedVisualSymbolicExpressionTreeNode.SymbolicExpressionTreeNode;
|
---|
| 101 | foreach (var visualNode in subtree.IterateNodesPostfix().Select(node => symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node))) {
|
---|
| 102 | visualNode.FillColor = Color.LightBlue;
|
---|
| 103 | }
|
---|
| 104 | symbolicExpressionTreeChart.Repaint();
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
[7792] | 107 | // what's left to be done here is to:
|
---|
| 108 | // - get the symbolic expression tree
|
---|
| 109 | // - get the corresponding fragment
|
---|
| 110 | // - for all symbolic expression tree nodes in the fragment, colorize the corresponding visual nodes
|
---|
| 111 | // - repaint the tree
|
---|
[7779] | 112 | }
|
---|
| 113 |
|
---|
| 114 | private void moveModeButton_CheckedChanged(object sender, EventArgs e) {
|
---|
| 115 | var btn = (RadioButton)sender;
|
---|
| 116 | if (btn.Checked) { genealogyGraphChart.Chart.Mode = ChartMode.Move; }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | private void zoomModeButton_CheckedChanged(object sender, EventArgs e) {
|
---|
| 120 | var btn = (RadioButton)sender;
|
---|
| 121 | if (btn.Checked) { genealogyGraphChart.Chart.Mode = ChartMode.Zoom; }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | private void selectModeButton_CheckedChanged(object sender, EventArgs e) {
|
---|
| 125 | var btn = (RadioButton)sender;
|
---|
| 126 | if (btn.Checked) { genealogyGraphChart.Chart.Mode = ChartMode.Select; }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | private void treeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
|
---|
| 130 | _selectedVisualSymbolicExpressionTreeNode = (VisualSymbolicExpressionTreeNode)sender;
|
---|
| 131 | // find out which individuals in the genealogy graph contain this specific subtree
|
---|
| 132 | var treeNode = _selectedVisualSymbolicExpressionTreeNode.SymbolicExpressionTreeNode;
|
---|
| 133 | Color[] colors = { Color.LightSkyBlue, Color.PaleGreen, Color.Tan };
|
---|
| 134 |
|
---|
| 135 | genealogyGraphChart.ClearAllNodes(); // clear node colors
|
---|
| 136 | // color each graph node according to the degree to which it matches the selected tree fragment
|
---|
[7785] | 137 | foreach (var i in Enum.GetValues(typeof(SymbolicExpressionTreeMatching.SimilarityLevel)).Cast<int>().Reverse()) {
|
---|
[7779] | 138 | var owners = genealogyGraphChart.Graph.TraceFragment(treeNode, i).ToList();
|
---|
| 139 | if (owners.Any()) genealogyGraphChart.HighlightNodes(owners, colors[i]); // highlight matching individuals from the genealogy
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | // highlight subtree nodes in the tree chart
|
---|
| 143 | foreach (var visualNode in symbolicExpressionTreeChart.Tree.IterateNodesPostfix().Select(node => symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node)))
|
---|
| 144 | visualNode.FillColor = Color.Transparent;
|
---|
| 145 |
|
---|
| 146 | foreach (var visualNode in treeNode.IterateNodesPostfix().Select(node => symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node)))
|
---|
| 147 | visualNode.FillColor = Color.LightBlue;
|
---|
| 148 |
|
---|
| 149 | // refresh the tree chart
|
---|
| 150 | symbolicExpressionTreeChart.Repaint();
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | private void similarityModeSelector_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 154 | if (_selectedVisualSymbolicExpressionTreeNode == null) return;
|
---|
| 155 | var treeNode = _selectedVisualSymbolicExpressionTreeNode.SymbolicExpressionTreeNode;
|
---|
| 156 | var owners = genealogyGraphChart.Graph.TraceFragment(treeNode, similarityModeSelector.SelectedIndex).ToList();
|
---|
| 157 | if (owners.Any()) {
|
---|
| 158 | genealogyGraphChart.ClearAllNodes(); // clear the fill color of all nodes
|
---|
| 159 | genealogyGraphChart.HighlightNodes(owners, Color.LightSkyBlue); // highlight matching individuals from the genealogy
|
---|
| 160 | }
|
---|
| 161 | // highlight subtree nodes in the tree chart
|
---|
| 162 | foreach (var visualNode in symbolicExpressionTreeChart.Tree.IterateNodesPostfix().Select(node => symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node)))
|
---|
| 163 | visualNode.FillColor = Color.Transparent;
|
---|
| 164 | foreach (var visualNode in treeNode.IterateNodesPostfix().Select(node => symbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(node)))
|
---|
| 165 | visualNode.FillColor = Color.LightBlue;
|
---|
| 166 | }
|
---|
| 167 | #endregion
|
---|
| 168 | }
|
---|
| 169 | }
|
---|