Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/30/10 19:40:13 (14 years ago)
Author:
gkronber
Message:

Implemented a solution visualizer for the artificial ant problem. #952 (Artificial Ant Problem for 3.3)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs

    r3223 r3238  
    2424using System.Collections.Generic;
    2525using System;
     26using System.Linq;
    2627using HeuristicLab.Core;
    2728namespace HeuristicLab.Problems.ArtificialAnt {
     
    142143
    143144    #endregion
     145
     146    #region ISymbolicExpressionGrammar Members
     147
     148
     149    public bool IsValidExpression(SymbolicExpressionTree expression) {
     150      if (expression.Root.Symbol != StartSymbol) return false;
     151      return IsValidExpression(expression.Root);
     152    }
     153
     154    #endregion
     155
     156    private bool IsValidExpression(SymbolicExpressionTreeNode root) {
     157      if (root.SubTrees.Count < MinSubTrees(root.Symbol)) return false;
     158      if (root.SubTrees.Count > MaxSubTrees(root.Symbol)) return false;
     159      for (int i = 0; i < root.SubTrees.Count; i++) {
     160        if (!AllowedSymbols(root.Symbol, i).Contains(root.SubTrees[i].Symbol)) return false;
     161        if (!IsValidExpression(root.SubTrees[i])) return false;
     162      }
     163      return true;
     164    }
    144165  }
    145166}
Note: See TracChangeset for help on using the changeset viewer.