本文整理汇总了C#中INode.HasChildren方法的典型用法代码示例。如果您正苦于以下问题:C# INode.HasChildren方法的具体用法?C# INode.HasChildren怎么用?C# INode.HasChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INode
的用法示例。
在下文中一共展示了INode.HasChildren方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateNoisyConstantsForNodeLeafes
private static void GenerateNoisyConstantsForNodeLeafes(INode node)
{
if (node.HasChildren())
{
node.Children.ToList().ForEach(GenerateNoisyConstantsForNodeLeafes);
return;
}
if (!(node is Constant))
return;
var childIndex = node.Parent.IndexOfChild(node);
node.Parent.Children[childIndex] = CalculateNewConstant((Constant<double>)node);
}
示例2: NoisyConstants
private static void NoisyConstants(INode node)
{
if (node.HasChildren())
{
foreach (var child in node.Children)
{
NoisyConstants(child);
}
}
else
{
if (node is Constant)
{
var oldValue = ((Constant<double>)node).Value;
var childIndex = node.Parent.IndexOfChild(node);
INode newConst = new Constant<double>(oldValue + Math.Pow((-1), Rnd.Next(3)) * Rnd.Next((int)(oldValue / 2), (int)(oldValue * 2)) * NoiseLevel);
node.Parent.Children[childIndex] = newConst;
}
}
}
示例3: RebuildTree
/// <summary>
/// Rebuilds the tree nodes
/// </summary>
/// <param name="node">Tree (root node)</param>
/// <param name="replaceConstant">
/// Replaces all of the constants by new variables when true.
/// Replaces all of the new variables by calculated contants from _inContants list when false.
/// </param>
private void RebuildTree(INode node, bool replaceConstant)
{
if (node.HasChildren())
{
foreach (var child in node.Children)
{
RebuildTree(child, replaceConstant);
}
return;
}
int childIndex;
INode newVar;
if (node is Constant && replaceConstant)
{
InConstant.Add(Double.Parse(node.ToString()));
childIndex = node.Parent.IndexOfChild(node);
newVar = VariableNode.Make<double>(_index, VarName + (InConstant.Count-1));
node.Parent.Children[childIndex] = newVar;
_index++;
}
if (!(node is VariableNode) || replaceConstant)
return;
if (((VariableNode) node).Index < _index - InConstant.Count)
return;
childIndex = node.Parent.IndexOfChild(node);
newVar = new Constant<double>(InConstant[((VariableNode)node).Index-(_index - InConstant.Count)]);
node.Parent.Children[childIndex] = newVar;
}