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


C# ISymbolicExpressionTreeNode.InsertSubtree方法代码示例

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


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

示例1: Modify

 /// <summary>
 /// Remove, Replace or Insert subtrees
 /// </summary>
 /// <param name="tree">The symbolic expression tree</param>
 /// <param name="parent">The insertion point (ie, the parent node who will receive a new child)</param>
 /// <param name="oldChild">The subtree to be replaced</param>
 /// <param name="newChild">The replacement subtree</param>
 /// <param name="removeSubtree">Flag used to indicate if whole subtrees should be removed (default behavior), or just the subtree root</param>
 private void Modify(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode parent,
   ISymbolicExpressionTreeNode oldChild, ISymbolicExpressionTreeNode newChild, bool removeSubtree = true) {
   if (oldChild == null && newChild == null)
     throw new ArgumentNullException("Cannot deduce operation type from the arguments. Please provide non null operands.");
   if (oldChild == null) {
     // insertion operation
     parent.AddSubtree(newChild);
     newChild.Parent = parent;
   } else if (newChild == null) {
     // removal operation
     parent.RemoveSubtree(parent.IndexOfSubtree(oldChild));
     if (!removeSubtree) {
       for (int i = oldChild.SubtreeCount - 1; i >= 0; --i) {
         var subtree = oldChild.GetSubtree(i);
         oldChild.RemoveSubtree(i);
         parent.AddSubtree(subtree);
       }
     }
   } else {
     // replacement operation
     var replacementIndex = parent.IndexOfSubtree(oldChild);
     parent.RemoveSubtree(replacementIndex);
     parent.InsertSubtree(replacementIndex, newChild);
     newChild.Parent = parent;
     if (changedNodes.ContainsKey(oldChild)) {
       changedNodes.Add(newChild, changedNodes[oldChild]); // so that on double click the original node is restored
       changedNodes.Remove(oldChild);
     } else {
       changedNodes.Add(newChild, oldChild);
     }
   }
   treeState = IsValid(tree) ? TreeState.Valid : TreeState.Invalid;
   switch (treeState) {
     case TreeState.Valid:
       this.grpViewHost.Enabled = true;
       UpdateModel(Content.Model.SymbolicExpressionTree);
       break;
     case TreeState.Invalid:
       this.grpViewHost.Enabled = false;
       break;
   }
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:50,代码来源:InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

示例2: ReplaceWithMinimalTree

    private static void ReplaceWithMinimalTree(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode parent, int childIndex) {
      // determine possible symbols that will lead to the smallest possible tree
      var possibleSymbols = (from s in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, childIndex)
                             where s.InitialFrequency > 0.0
                             group s by parent.Grammar.GetMinimumExpressionLength(s) into g
                             orderby g.Key
                             select g).First().ToList();
      var weights = possibleSymbols.Select(x => x.InitialFrequency).ToList();

#pragma warning disable 612, 618
      var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
#pragma warning restore 612, 618

      var newTreeNode = selectedSymbol.CreateTreeNode();
      if (newTreeNode.HasLocalParameters) newTreeNode.ResetLocalParameters(random);
      parent.RemoveSubtree(childIndex);
      parent.InsertSubtree(childIndex, newTreeNode);

      var topLevelNode = newTreeNode as SymbolicExpressionTreeTopLevelNode;
      if (topLevelNode != null)
        topLevelNode.SetGrammar((ISymbolicExpressionTreeGrammar)root.Grammar.Clone());

      for (int i = 0; i < newTreeNode.Grammar.GetMinimumSubtreeCount(newTreeNode.Symbol); i++) {
        // insert a dummy sub-tree and add the pending extension to the list
        var dummy = new SymbolicExpressionTreeNode();
        newTreeNode.AddSubtree(dummy);
        // replace the just inserted dummy by recursive application
        ReplaceWithMinimalTree(random, root, newTreeNode, i);
      }
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:30,代码来源:RemoveBranchManipulation.cs

示例3: SwitchNodeWithReplacementNode

 private void SwitchNodeWithReplacementNode(ISymbolicExpressionTreeNode parent, int subTreeIndex) {
   ISymbolicExpressionTreeNode subTree = parent.GetSubtree(subTreeIndex);
   if (foldedNodes.ContainsKey(subTree)) {
     parent.RemoveSubtree(subTreeIndex);
     var replacementNode = foldedNodes[subTree];
     parent.InsertSubtree(subTreeIndex, replacementNode);
     // exchange key and value 
     foldedNodes.Remove(subTree);
     foldedNodes.Add(replacementNode, subTree);
   }
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:11,代码来源:InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

示例4: SwitchNode

 private void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) {
   for (int i = 0; i < root.SubtreeCount; i++) {
     if (root.GetSubtree(i) == oldBranch) {
       root.RemoveSubtree(i);
       root.InsertSubtree(i, newBranch);
       return;
     }
   }
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:9,代码来源:InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs


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