Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/14 00:03:36 (10 years ago)
Author:
bburlacu
Message:

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

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMaxCommonSequenceCalculator.cs

    r10650 r10833  
    1 using System;
     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;
    223using System.Collections.Generic;
    324
    425namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Matching {
    5   public class MaxCommonSequenceCalculator<T, U>
     26  public class MaxCommonSequenceCalculator<T, TComp>
    627    where T : class
    7     where U : IEqualityComparer<T> {
     28    where TComp : IEqualityComparer<T> {
    829
    9     public U Comparer { get; set; }
     30    private TComp comparer;
     31    public TComp Comparer {
     32      get { return comparer; }
     33      set { comparer = value; }
     34    }
     35
    1036    private int[,] matrix;
    1137    private List<T> sequence;
    1238
     39    public MaxCommonSequenceCalculator(TComp comparer) {
     40      this.comparer = comparer;
     41    }
     42
    1343    /// <summary>
    14     /// Calculate the maximal common subsequence between arrays a and b and return it
     44    /// Calculate the maximal common subsequence between arrays a and b and return it.
     45    /// THIS DOES NOT WORK FOR TREES
    1546    /// </summary>
    1647    /// <param name="a"></param>
     
    2758      for (int i = 0; i <= m; ++i) {
    2859        for (int j = 0; j <= n; ++j) {
    29           if (i == 0 || j == 0) {
    30             matrix[i, j] = 0;
    31           } else if (Comparer.Equals(a[i - 1], b[j - 1])) {
     60          if (comparer.Equals(a[i - 1], b[j - 1])) {
    3261            matrix[i, j] = matrix[i - 1, j - 1] + 1;
    3362          } else {
     
    3665        }
    3766      }
    38       recon(a, b, n, m);
     67      Recon(a, b, n, m); // build the common subsequence
    3968      return sequence;
    4069    }
    4170
    42     private void recon(T[] a, T[] b, int i, int j) {
    43       while (true) {
    44         if (i == 0 || j == 0) return;
    45         if (Comparer.Equals(a[i - 1], b[j - 1])) {
    46           recon(a, b, i - 1, j - 1);
     71    private void Recon(T[] a, T[] b, int i, int j) {
     72      while (i > 0 && j > 0) {
     73        if (comparer.Equals(a[i - 1], b[j - 1])) {
     74          Recon(a, b, i - 1, j - 1);
    4775          sequence.Add(a[i - 1]);
    4876        } else if (matrix[i - 1, j] > matrix[i, j - 1]) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs

    r10827 r10833  
    4646        break;
    4747      }
    48       //
    49       //      if (fragment == null) {
    50       //        throw new Exception("SymbolicDataAnalysisExpressionAfterCrossoverOperator: Could not identify fragment");
    51       //      }
    5248
    5349      arcs[0].Data = null;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs

    r10827 r10833  
    5757      }
    5858
    59       //      if (fragment == null) {
    60       //        throw new Exception("SymbolicDataAnalysisExpressionAfterManipulatorOperator: Could not identify fragment");
    61       //      }
    62 
    6359      vChild.InArcs.First().Data = fragment;
    6460      return base.Apply();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs

    r10755 r10833  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    2423using HeuristicLab.Core;
     
    3534
    3635      for (int i = 0; i < parents.Count; ++i) {
    37         var nodes = parents[i].IterateNodesPrefix().ToList();
    38         arcs[i].Data = nodes;
     36        arcs[i].Data = parents[i].IterateNodesPrefix().ToList();
    3937      }
    40       var parentVertices = childVertex.Parents.ToList();
    41       if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) {
    42         throw new Exception("Inconsistency detected in GenealogyGraph.");
    43       }
     38
     39      //      var parentVertices = childVertex.Parents.ToList();
     40      //
     41      //      if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) {
     42      //        throw new Exception("Inconsistency detected in GenealogyGraph.");
     43      //      }
    4444
    4545      return result;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs

    r10827 r10833  
    3333      vChild.InArcs.First().Data = vChild.Content.IterateNodesPrefix().ToList();
    3434
     35      var vClone = (IGenealogyGraphNode<ISymbolicExpressionTree>)vChild.InArcs.Last().Source;
     36      var fragment = (IFragment<ISymbolicExpressionTreeNode>)vClone.InArcs.Last().Data;
     37      if (fragment != null) {
     38        // this step must be performed because the fragment root actually references the original child (not the clone).
     39        // then, a mutation operation (acting on the original child), could disrupt it
     40        fragment.Root = vClone.Content.IterateNodesPrefix().ElementAt(fragment.Index1);
     41      }
     42
    3543      return result;
    3644    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r10827 r10833  
    3030          var fragmentNode = new FragmentNode {
    3131            Content = new Fragment<ISymbolicExpressionTreeNode> { Root = node.Content.NodeAt(index) },
    32             Rank = node.Rank
     32            Rank = node.Rank,
     33            Quality = node.Quality
    3334          };
    3435          if (parent != null) {
     
    9899              var fragmentNode = new FragmentNode {
    99100                Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree },
    100                 Rank = node.Rank
     101                Rank = node.Rank,
     102                Quality = node.Quality
    101103              };
    102104              if (parent != null) {
Note: See TracChangeset for help on using the changeset viewer.