public void AddChild(DominatorTreeNode child) { if (!ChildrenNodes.Contains(child)) { ChildrenNodes.Add(child); } }
public void Initialize(int depth, bool isFull) { if (depth <= 1) { ChildrenNodes = ChildrenNodes.Select(c => c = CreateIndex()).ToArray(); return; } if (isFull) { ChildrenNodes = ChildrenNodes.Select(c => { c = CreateLogic(); c.Initialize(depth - 1, isFull); return(c); }).ToArray(); } else { ChildrenNodes = ChildrenNodes.Select(c => { //終端1/3,非終端2/3ずつの割合 if (rand.Next(3) == 0) { c = CreateIndex(); } else { c = CreateLogic(); c.Initialize(depth - 1, isFull); } return(c); }).ToArray(); } }
/// <summary> /// /// </summary> /// <param name="tableName"></param> /// <param name="avTables">перечень таблиц, которые нам нужно для дерева</param> /// <param name="parentNode"></param> /// <param name="infoRows"></param> /// <param name="alterTables"></param> public Ais7IssoDefectsTreeNode2(string tableName, IList <string> avTables, Ais7IssoDefectsTreeNode parentNode, List <InfoRow> infoRows, List <CustomDefectAlterTable> alterTables) : base(false) { TableName = tableName; ParentNode = parentNode; ItemType = Ais7IssoDefectsTreeNodeType.Type1; // по умолчанию верхний уровень NGrConstr = infoRows.Find(x => x.SysName == tableName).Description; CGrConstr = infoRows.Find(x => x.SysName == tableName).CGrConstr; var subAlterTables = alterTables.Where(x => x.c_gr_constr == CGrConstr).ToList(); if (subAlterTables.Count > 0) { isForConstr = subAlterTables[0].is_constr; Life = subAlterTables[0].life; ItemType = (Ais7IssoDefectsTreeNodeType)subAlterTables[0].ITEM_TYPE; OrderInTree = subAlterTables[0].ord; } else { isForConstr = false; } foreach (var subtable in infoRows.Where(x => x.CGrConstr != 10 && x.ParentId == infoRows.Find(y => y.SysName == tableName).CGrConstr).ToList()) { if (avTables.IndexOf(subtable.SysName) != -1) { ChildrenNodes.Add(new Ais7IssoDefectsTreeNode2(subtable.SysName, avTables, this, infoRows, alterTables)); } } IsNotLeaf = ChildrenNodes.Count > 0; LoadDefectList(CGrConstr, alterTables); }
/// <inheritdoc /> /// <summary> /// Перечень конструкций для данной ноды /// </summary> /// <param name="cIsso"></param> /// <param name="cGrConstr"></param> /// <param name="mode"></param> /// <returns></returns> public override bool Visible(int cIsso, int cGrConstr, VisibleMode mode) { var retV = ChildrenNodes.Any(x => x.Visible(cIsso, cGrConstr, mode)) || DefectList.Count > 0; var connectionClass = ConnectionClass.CreateDatabase(); switch (mode) { case VisibleMode.ExistConstructions: if (CGrConstr < 1000) // если эта нода связана с реальным сооружением и есть такая таблица { var cnt = connectionClass.ExecuteScalar <int>($"select count(*) from {TableName} where c_isso={cIsso}"); retV = cnt > 0; } break; case VisibleMode.AllContructions: // Текущий тип ИССО var issoType = connectionClass.ExecuteScalar <int>( $"select C_GR_CONSTR from S_TYPISSO where C_TYPISSO=(select CTYPEISSO from I_ISSO where C_ISSO={cIsso})"); retV = connectionClass.ExecuteScalar <int>($"select count(*) from s_cnct where c_nmd1={issoType} and c_nmd2={CGrConstr}") > 0; break; case VisibleMode.All: break; default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } connectionClass.Close(); return(retV); }
public void AddRoute(string[] route, T service) { if (route.Length == 0) { Services.AddService(service); return; } var children = System.Threading.Volatile.Read(ref _childrenNodes); for (int i = Math.Min(children.KeyLength, route.Length); i > 0; i--) { //We need to first see if the first part of the route matches any of the current nodes var matche = children.FindFirstNodeThatMatches(route, i); if (matche != null) { //we found something that matched our prefix, if the key length is a match then just pass down the service to the next node if (children.KeyLength == i) { matche.AddRoute(route.Skip(i).ToArray(), service); return; } else { var newChildren = children.SplitContainer(i, Path); newChildren[route].AddRoute(route.Skip(i).ToArray(), service); System.Threading.Volatile.Write(ref _childrenNodes, newChildren); return; } } } //Nothing matched, if we have a key >= current prefix length we can just add it, otherwise we need a split if (route.Length >= children.KeyLength) { //Create a new node and add it Node <T> n = new Node <T>(route.Take(children.KeyLength).ToArray(), Path); n.AddRoute(route.Skip(children.KeyLength).ToArray(), service); var newChildren = children.Clone(); newChildren.Add(n.Prefix, n); System.Threading.Volatile.Write(ref _childrenNodes, newChildren); return; } else { //The key is smaller than the current key length so we are going to have to split before we add var newChildren = ChildrenNodes.SplitContainer(route.Length, Path); Node <T> n = new Node <T>(route, Path); n.AddRoute(new string[0], service); newChildren.Add(n.Prefix, n); System.Threading.Volatile.Write(ref _childrenNodes, newChildren); return; } }
public bool ApplyAlphaRule() { foreach (var prop in CurrentNode) { var set = new HashSet <Proposition>(CurrentNode); set.Remove(prop); if (prop is Negation n && n.Operand is Negation n1) { set.Add(n1.Operand); var tableau = new SemanticTableau(set, ActiveVariables, PropositionsProcessedByGamma); ChildrenNodes.Add(tableau); stack.Push(tableau); return(true); }
/// <summary> /// Stringify the node /// </summary> /// <returns></returns> public override string ToString() { StringBuilder result = new StringBuilder(); result.AppendLine(StringContent); if (Program.displayCompleteMessage) { ChildrenNodes.ForEach(c => { result.AppendLine(c.ToString()); }); } return(result.ToString()); }
/// <summary> /// Проверка видимости этой ноды /// </summary> /// <param name="cIsso"></param> /// <param name="cGrConstr"></param> /// <param name="mode">режим видимости</param> /// <returns></returns> public virtual bool Visible(int cIsso, int cGrConstr, VisibleMode mode) { switch (mode) { case VisibleMode.All: return(true); case VisibleMode.AllContructions: case VisibleMode.ExistConstructions: return(DefectList.Count > 0 || ChildrenNodes.Any(x => x.Visible(cIsso, cGrConstr, mode))); default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } }
public void SetIsChecked(bool?value, bool updateChildren, bool updateParent) { if (value == isChecked) { return; } isChecked = value; if (updateChildren && isChecked.HasValue) { ChildrenNodes.ForEach(c => c.SetIsChecked(isChecked, true, false)); } if (updateParent && ParentNode != null) { ParentNode.VerifyCheckedState(); } NotifyPropertyChanged("IsChecked"); }
/// <summary> /// Gets a random child assuring the new random is not the previous random picked. /// </summary> /// <returns></returns> private BehaviorNode GetRandomChild() { while (true) { int randomChildIndex = Random.Range(0, ChildrenNodes.Count); if (Agent.Memory.Contains(Agent.TargetProfessor)) { return(ChildrenNodes.First(node => node.Professor == Agent.TargetProfessor)); } if (ChildrenNodes[randomChildIndex] == _previousRandom || _memory.Contains(ChildrenNodes[randomChildIndex].Professor)) { continue; } return(ChildrenNodes[randomChildIndex]); } }
/// <summary> /// 设置子节点 /// </summary> /// <param name="childNode"></param> public virtual void SetChildNode(INeuralNode childNode) { //childNode.SetParentNode(this); ChildrenNodes.Add(childNode); }
public bool Insert(uint id, T name, Stack <Node> nodes = null, uint pid = 0) { var done = false; if (NodesLeft == -1) { throw new IndexOutOfRangeException("红黑树叶节点无法生成分支"); } else { if (ChildrenNodes.Count < ChildrenNodeNumber) { ChildrenNodes.Push(new Node(id, name, RootId)); done = true; NodesLeft -= 1; if (ChildrenNodes.Count == ChildrenNodeNumber) { InLeaf += 1; Weight += 1; } } else { if (nodes == null) { InLeaf = 1; WeightBuffer = Weight; Weight = 2; Insert(id, name, ChildrenNodes, RootId); } if (nodes != null) { var buffer = new Stack <Node>(nodes); var length = nodes.Count; for (var i = 0; i < length; i++) { var item = buffer.Peek(); if (item.Children == null) { item.Children = new Stack <Node>(); } if (item.Children.Count >= ChildrenNodeNumber && InLeaf < MaximumHeight - 1 && InLeaf < WeightBuffer) { InLeaf += 1; done = Insert(id, name, item.Children, item.Id); if (done) { Weight += 1; } } else if (!done) { if (item.Children.Count < ChildrenNodeNumber) { item.Children.Push(new Node(id, name, item.Id)); if (Weight == MaximumHeight) { if (item.Children.Count == ChildrenNodeNumber) { Weight = 1; } } if (InLeaf == MaximumHeight - 1) { InLeaf += 1; } NodesLeft -= 1; done = true; } } buffer.Pop(); } InLeaf -= 1; } } } return(done); }
protected Expression(Option <ExpressionReadMode> readMode) { this.readMode = readMode; this.flow = Later.Create(() => ExecutionFlow.CreatePath(ChildrenNodes.WhereType <IExpression>())); }
private bool ReturnDefectsCount() { return(ChildrenNodes.Count(item => item.ItemType == Ais7IssoDefectsTreeNodeType.Type0) == 0 && DefectList.Count == 0); }