Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/16 16:38:20 (7 years ago)
Author:
bburlacu
Message:

#2704: Added the possibility to sample possible arguments without repetition when instantiating expression templates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/Expression.cs

    r14409 r14410  
    8989        case ExpressionType.Function:
    9090          sb.Append(string.Format("{0} (", Label));
    91           if (arguments != null) {
     91          if (Arguments.Any()) {
    9292            for (int i = 0; i < arguments.Count - 1; ++i)
    9393              sb.Append(string.Format("{0}, ", arguments[i]));
     
    9797      }
    9898
     99      return sb.ToString();
     100    }
     101
     102    public string PrintDot() {
     103      var stack = new Stack<Expression>();
     104      stack.Push(this);
     105
     106      var sb = new StringBuilder();
     107      sb.AppendLine("digraph g {");
     108
     109      while (stack.Count > 0) {
     110        var top = stack.Pop();
     111
     112        if (!top.Arguments.Any())
     113          continue;
     114
     115        foreach (var arg in top.Arguments) {
     116          var from = top.Arguments.Any() ? top.Label : top.ToString();
     117          var to = arg.Arguments.Any() ? arg.Label : arg.ToString();
     118          sb.AppendLine(string.Format("\"{0}\" -> \"{1}\";", from, to));
     119          stack.Push(arg);
     120        }
     121      }
     122
     123      sb.AppendLine("}");
    99124      return sb.ToString();
    100125    }
Note: See TracChangeset for help on using the changeset viewer.