当前位置: 首页>>代码示例>>C#>>正文


C# ISymbolicExpressionTreeNode.ToString方法代码示例

本文整理汇总了C#中ISymbolicExpressionTreeNode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbolicExpressionTreeNode.ToString方法的具体用法?C# ISymbolicExpressionTreeNode.ToString怎么用?C# ISymbolicExpressionTreeNode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISymbolicExpressionTreeNode的用法示例。


在下文中一共展示了ISymbolicExpressionTreeNode.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompareNodes

    public static int CompareNodes(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
      var ta = a as SymbolicExpressionTreeTerminalNode;
      var tb = b as SymbolicExpressionTreeTerminalNode;

      if (ta == null)
        return tb == null ? String.CompareOrdinal(a.Symbol.Name, b.Symbol.Name) : -1;

      if (tb == null)
        return 1;

      // at this point we know a and b are both terminals
      var va = a as VariableTreeNode;
      var vb = b as VariableTreeNode;

      if (va != null)
        return vb == null ? -1 : CompareVariables(va, vb);

      if (vb != null)
        return 1;

      // at this point we know a and b are not variables
      var ca = a as ConstantTreeNode;
      var cb = b as ConstantTreeNode;

      if (ca != null && cb != null)
        return ca.Value.CompareTo(cb.Value);

      // for other unknown terminal types, compare strings
      return string.CompareOrdinal(a.ToString(), b.ToString());
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:30,代码来源:SymbolicExpressionTreeNodeComparer.cs

示例2: FormatRecursively

    private string FormatRecursively(ISymbolicExpressionTreeNode node, int indentLength, ref int nodeId) {
      // save id of current node
      int currentNodeId = nodeId;
      // increment id for next node
      nodeId++;

      StringBuilder strBuilder = new StringBuilder();
      if (Indent) strBuilder.Append(' ', indentLength);

      // get label for node and map if necessary
      string nodeLabel = node.ToString();
      if (symbolNameMap.ContainsKey(nodeLabel)) {
        nodeLabel = symbolNameMap[nodeLabel];
      }

      strBuilder.Append("node" + currentNodeId + "[label=\"" + nodeLabel + "\"");
      // leaf nodes should have box shape
      if (node.SubtreeCount == 0) {
        strBuilder.AppendLine(", shape=\"box\"];");
      } else {
        strBuilder.AppendLine("];");
      }

      // internal nodes or leaf nodes?
      foreach (ISymbolicExpressionTreeNode subTree in node.Subtrees) {
        // add an edge 
        if (Indent) strBuilder.Append(' ', indentLength);
        strBuilder.AppendLine("node" + currentNodeId + " -- node" + nodeId + ";");
        // format the whole subtree
        strBuilder.Append(FormatRecursively(subTree, indentLength + 2, ref nodeId));
      }

      return strBuilder.ToString();
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:34,代码来源:SymbolicExpressionTreeGraphvizFormatter.cs

示例3: RenderNode

 public static void RenderNode(TextWriter writer, ISymbolicExpressionTreeNode node, string prefix) {
   string label = node.ToString();
   writer.Write(label);
   if (node.SubtreeCount > 0) {
     var padding = prefix + new string(' ', label.Length);
     for (int i = 0; i != node.SubtreeCount; ++i) {
       char connector, extender = ' ';
       if (i == 0) {
         if (node.SubtreeCount > 1) {
           connector = RenderChars.JunctionDown;
           extender = RenderChars.VerticalLine;
         } else {
           connector = RenderChars.HorizontalLine;
           extender = ' ';
         }
       } else {
         writer.Write(padding);
         if (i == node.SubtreeCount - 1) {
           connector = RenderChars.CornerRight;
           extender = ' ';
         } else {
           connector = RenderChars.JunctionRight;
           extender = RenderChars.VerticalLine;
         }
       }
       writer.Write(string.Concat(connector, RenderChars.HorizontalLine));
       var newPrefix = string.Concat(padding, extender, ' ');
       RenderNode(writer, node.GetSubtree(i), newPrefix);
     }
   } else
     writer.WriteLine();
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:32,代码来源:SymbolicExpressionTreeHierarchicalFormatter.cs

示例4: FormatRecursively

 private static string FormatRecursively(ISymbolicExpressionTreeNode node) {
   StringBuilder strBuilder = new StringBuilder();
   if (node.Subtrees.Count() > 0) {
     // node
     foreach (var subtree in node.Subtrees) {
       strBuilder.Append(FormatRecursively(subtree));
     }
   } else {
     // leaf
     strBuilder.Append(node.ToString());
   }
   return strBuilder.ToString();
 }
开发者ID:t-h-e,项目名称:HeuristicLab.CFGGP,代码行数:13,代码来源:SymbolicExpressionTreeTerminalNodeStringFormatter.cs

示例5: FormatRecursively

 private string FormatRecursively(ISymbolicExpressionTreeNode node, int indentLength) {
   StringBuilder strBuilder = new StringBuilder();
   if (Indent) strBuilder.Append(' ', indentLength);
   strBuilder.Append("(");
   // internal nodes or leaf nodes?
   if (node.Subtrees.Count() > 0) {
     // symbol on same line as '('
     strBuilder.AppendLine(node.ToString());
     // each subtree expression on a new line
     // and closing ')' also on new line
     foreach (var subtree in node.Subtrees) {
       strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2));
     }
     if (Indent) strBuilder.Append(' ', indentLength);
     strBuilder.Append(")");
   } else {
     // symbol in the same line with as '(' and ')'
     strBuilder.Append(node.ToString());
     strBuilder.Append(")");
   }
   return strBuilder.ToString();
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:22,代码来源:SymbolicExpressionTreeStringFormatter.cs

示例6: GetHashCode

 public int GetHashCode(ISymbolicExpressionTreeNode n) {
   return n.ToString().ToLower().GetHashCode();
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:3,代码来源:SymbolicExpressionTreeNodeEqualityComparer.cs

示例7: GetLabel

    private static string GetLabel(ISymbolicExpressionTreeNode node) {
      if (node.SubtreeCount > 0)
        return node.Symbol.Name;

      var constant = node as ConstantTreeNode;
      if (constant != null)
        return constant.Value.ToString(CultureInfo.InvariantCulture);

      var variable = node as VariableTreeNode;
      if (variable != null)
        return variable.Weight + variable.VariableName;

      return node.ToString();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:14,代码来源:SymbolicExpressionTreeBottomUpSimilarityCalculator.cs


注:本文中的ISymbolicExpressionTreeNode.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。