Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs @ 10833

Last change on this file since 10833 was 10833, checked in by bburlacu, 10 years ago

#1772: Fixed another minor display bug concerning elite individuals. Fixed bug when saving fragments from mutation. Displayed quality as well in the SymbolicExpressionTreeTile.

File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.EvolutionTracking;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
30  public class SymbolicDataAnalysisExpressionAfterManipulatorOperator : AfterManipulatorOperator<ISymbolicExpressionTree> {
31    private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer;
32
33    public SymbolicDataAnalysisExpressionAfterManipulatorOperator() {
34      comparer = new SymbolicExpressionTreeNodeSimilarityComparer {
35        MatchVariableNames = true,
36        MatchVariableWeights = true,
37        MatchConstantValues = true
38      };
39    }
40
41    public override IOperation Apply() {
42      var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue];
43      var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs.First().Data;
44      var nodesAfter = ChildParameter.ActualValue.IterateNodesPrefix().ToList();
45      IFragment<ISymbolicExpressionTreeNode> fragment = null;
46
47      for (int i = 0; i < Math.Min(nodesAfter.Count, nodesBefore.Count); ++i) {
48        var a = nodesAfter[i];
49        var b = nodesBefore[i];
50        if (ReferenceEquals(a, b) && comparer.Equals(a, b)) continue;
51        fragment = new Fragment<ISymbolicExpressionTreeNode> {
52          Root = a,
53          Index1 = i,
54          Index2 = i
55        };
56        break;
57      }
58
59      vChild.InArcs.First().Data = fragment;
60      return base.Apply();
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.