public void connect(Node <T> target) { if (m_neighbors.Contains(target) == false) { m_neighbors.Add(target); } }
public void addToReactionManager(Node <string> node) { if (!rManList.Contains(node)) { rManList.Add(node); } }
public void ContainsTest() { var list = new NodeList(); var node = new Node(); Assert.That(list.Contains(node), Is.False); list.Add(node); Assert.That(list.Contains(node), Is.True); }
/// <summary> /// 递归删除子节点 /// </summary> /// <param name="NodeList"></param> /// <param name="Node"></param> private void RecursionDeleteNode(ContractBoiNode Node) { List <ContractBoiNode> lstChildren = Node.Children.ToList(); if (lstChildren.Count > 0) { lstChildren.ForEach(m => { RecursionDeleteNode(m); if (NodeList.Contains(m)) { NodeList.Remove(m); } if (updateList.Contains(m)) { updateList.Remove(m); } }); } if (NodeList.Contains(Node)) { NodeList.Remove(Node); } if (updateList.Contains(Node)) { updateList.Remove(Node); } if (Node.ParentBoiNode != null && Node.ParentBoiNode.Children.Contains(Node)) { Node.ParentBoiNode.Children.Remove(Node); } }
public static List<Node> PossibleNode = new List<Node>(); // Les noeuds possibles (cases adjacentes de tout le chemin) #endregion Fields #region Methods public static MyLinkedList<Tile> CalculatePathWithAStar(Map map, Tile startTile, Tile endTile) { PossibleNode.Clear(); NodeList<Node> openList = new NodeList<Node>(); // Contiens tout les noeuds candidat (qui vont être examinés) NodeList<Node> closedList = new NodeList<Node>(); // Contiens la liste des meilleurs noeuds (le resultat du plus cours chemin) List<Node> possibleNodes; // cases adjacentes du noeud courant // Le noeud de départ Node startNode = new Node(startTile, null, endTile); // FIXME : on recupère le noeud de départ /**********************************/ /* Traitement des noeuds candidat */ /**********************************/ openList.Add(startNode); while (openList.Count > 0) // Tant que la liste ouverte contient des éléments { Node current = openList[0]; openList.RemoveAt(0); closedList.Add(current); if (current.Tile == endTile) // si l'élément courant est la case destination { MyLinkedList<Tile> solution = new MyLinkedList<Tile>(); // on reverse la liste fermée et on la retourne pour l'avoir dans le bonne ordre while (current.Parent != null) { solution.AddFirst(current.Tile); current = current.Parent; } return solution; } possibleNodes = current.GetPossibleNode(map, endTile); // FIXME : recupère la listes des cases adjacentes // on ajoute cette liste a notre variable static qui contient l'ensemble des listes adjacentes (gestion de l'affichage) PossibleNode.AddRange(possibleNodes) ; /***************************************/ /* Ajout des noeuds adjacents candidat */ /***************************************/ for (int i = 0; i < possibleNodes.Count; i++) // on vérifie que chaque noeuds adjacent (possibleNodes) { if (!closedList.Contains(possibleNodes[i])) // n'existe pas dans la liste fermée (eviter la redondance) { if (openList.Contains(possibleNodes[i])) // FIXME : Si il existe dans la liste ouverte on vérifie { if (possibleNodes[i].EstimatedMovement < openList[possibleNodes[i]].EstimatedMovement) // si le cout de deplacement du // noeud est inferieur a un coût calculer précedement, dance cas la on remonte le chemin dans la liste ouverte openList[possibleNodes[i]].Parent = current; } else openList.DichotomicInsertion(possibleNodes[i]); } } } return null; }
/// <summary> /// Adds a node to the route /// </summary> /// <param name="node"></param> public void AddNode(Node node) { if (node == null || NodeList.Contains(node)) { return; } NodeList.Add(node); }
public void RemoveAtNotEmptyTest() { var owner = new Node(); var node1 = new Node(); var node2 = new Node(); var node3 = new Node(); var list = new NodeList(owner) { node1, node2, node3 }; list.RemoveAt(1); Assert.That(list.Contains(node1)); Assert.That(list, Is.Not.Contains(node2)); Assert.That(list.Contains(node3)); Assert.That(node1.NextSibling, Is.SameAs(node3)); Assert.That(node2.Parent, Is.Null); Assert.That(node2.NextSibling, Is.Null); }
public virtual Node RemoveChild(Node child) { if (_children.Contains(child)) { child._parent = null; _children.Remove(child); } return(child); }
public bool checkIfPath(Transform startObj, Transform endObj) { bool done = false; bool isPath = false; NodeList <string> neighborList = geomanager.neighborsOfNode(startObj.GetComponent <AbstractGeoObj>().figName); NodeList <string> rmNeighborList = new NodeList <string>(); Node <string> target = geomanager.findGraphNode(endObj.GetComponent <AbstractGeoObj>().figName); while (!done) { if (neighborList.Contains(target)) { isPath = true; done = true; } else { int idx = 0; foreach (Node <string> node in neighborList) { foreach (Node <string> node2 in geomanager.neighborsOfNode(node.Value)) { if (!neighborList.Contains(node2) && !rmNeighborList.Contains(node)) { neighborList.Add(node2); neighborList.Remove(node); rmNeighborList.Add(node); idx++; } } } if (idx == 0) { done = true; isPath = neighborList.Contains(target); } } } return(isPath); }
// diferenta dintre doua NodeList. public static NodeList <string> GetDiff(NodeList <string> first, NodeList <string> second) { NodeList <string> diferenta = new NodeList <string>(); foreach (GraphNode <string> nod in first) { if (!second.Contains(nod)) { diferenta.Add(nod); } } return(diferenta); }
private void AddNode(ref PathNode origin) { if (!nodes.Contains(origin)) { origin = nodes.AddAndGet(origin); foreach (var area in areas) { if (area.isInside(origin)) { area.AddNode(origin); } } } }
/// <summary> /// Core logic of syntax analyzer. /// </summary> /// <param name="node">The node.</param> /// <param name="token">The token.</param> /// <param name="onlySubNodes">if set to <c>true</c> [only sub nodes].</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private Task AnalyzeCore(SyntaxNode node, CancellationToken token, bool onlySubNodes = false) { RootNode.AnalyzeId = _analyzeId; // visit all members if (!onlySubNodes) { Visit(node); } else { foreach (var subNode in node.ChildNodes()) { if (token.IsCancellationRequested) { return(Task.FromResult(0)); } Visit(subNode); } } // remove all sub-walkers which where not touched in analysis _subWalkers.RemoveAll(x => x._analyzeId != _analyzeId); if (onlySubNodes) { return(Task.FromResult(0)); } _dispatcherService.Dispatch(() => { var tree = RootNode.AllTreeItems.ToList(); foreach (var unused in NodeList.Where(x => !tree.Contains(x)).ToList()) { _nodeList.Remove(unused); } foreach (var added in tree.Where(x => !NodeList.Contains(x)).ToList()) { _nodeList.Add(added); } }); return(Task.FromResult(0)); }
public static List<Case> CalculChemin(Carte carte, Case depart, Case arrivee) { List<Case> resultat = new List<Case>(); NodeList<Noeud> listeOuverte = new NodeList<Noeud>(); NodeList<Noeud> listeFermee = new NodeList<Noeud>(); List<Noeud> noeudsPossibles; int nombreNoeudsPossibles; listeOuverte.Add(new Noeud(depart, null, arrivee)); while (listeOuverte.Count > 0) { Noeud current = listeOuverte[0]; listeOuverte.RemoveAt(0); listeFermee.Add(current); if (current.Case == arrivee) { List<Case> solution = new List<Case>(); while (current.Parent != null) { solution.Add(current.Case); current = current.Parent; } return solution; } noeudsPossibles = current.NoeudsPossibles(carte, arrivee); nombreNoeudsPossibles = noeudsPossibles.Count; foreach (Noeud voisin in current.NoeudsPossibles(carte, arrivee)) if (!listeFermee.Contains(voisin)) { if (listeOuverte.Contains(voisin)) { if (voisin.Manhattan < listeOuverte[voisin].Manhattan) listeOuverte[voisin].Parent = current; } else listeOuverte.DichotomicInsertion(voisin); } } return null; }
private void next_Click(object sender, RoutedEventArgs e) { if (CurrentBlockIndex < BlockCount - 2) { // CurrentBlock is current from previous iteration HighlightBlock(CurrentBlock, ClearHighlightBrush); CurrentBlock = CurrentBlock.NextBlock; CurrentBlockIndex++; // time slot List <Tuple <int, int> > tuples = new List <Tuple <int, int> >(); String blockText = GetBlockText(CurrentBlock); String regex = "^([0-9]+):( [0-9]+ -> [0-9]+,)* [0-9]+ -> [0-9]+$"; String tupleRegexString = " ?([0-9]+) -> ([0-9]+),?"; bool success = true; String errorMessage = ""; Match match = Regex.Match(blockText, regex); if (match.Success && match.Groups.Count > 1) { bool timeMatched = false; int time; Int32.TryParse(match.Groups[1].Value, out time); if (time == CurrentBlockIndex) { timeMatched = true; } if (timeMatched == true) { Regex tupleRegex = new Regex(tupleRegexString, RegexOptions.Compiled); foreach (Match tupleMatch in tupleRegex.Matches(blockText)) { if (tupleMatch.Success && tupleMatch.Groups.Count >= 2) { int value1, value2; Int32.TryParse(tupleMatch.Groups[1].Value, out value1); Int32.TryParse(tupleMatch.Groups[2].Value, out value2); int missingValue = -1; if (!NodeList.Contains(value1)) { missingValue = value1; } else if (!NodeList.Contains(value2)) { missingValue = value2; } if (missingValue == -1) { tuples.Add(new Tuple <int, int>(value1, value2)); } else { success = false; errorMessage = String.Format("Node with id \"{0}\" does not exist", missingValue); break; } } } } else { success = false; errorMessage = String.Format("Failed to parse time id \"{0}\".\nTime slots should be numbered sequentialy starting from 0.", time); } } else { success = false; } if (!success) { SetupErrorState(); ShowErrorMessage(errorMessage); return; } HighlightBlock(CurrentBlock, GreenHighlightBrush); ExecuteEventArgs args = new ExecuteEventArgs(tuples); Execute(this, args); } if (CurrentBlockIndex == BlockCount - 2) { nextBtn.IsEnabled = false; } }
/// <summary> /// checks if any of the items in the second list need to react to items in the first list /// recursively adds items from second list to first list if they need to react /// </summary> /// <param name="nodesmovinglist"></param> /// <param name="potentiallyaffectednodes"></param> private static void CheckIfNeighborsAreAffected(NodeList <string> nodesmovinglist, NodeList <string> potentiallyaffectednodes, NodeList <string> newItems, NodeList <string> falseItems, NodeList <string> updateNodeList) { if (potentiallyaffectednodes != null) { foreach (Node <string> neighbor in potentiallyaffectednodes.Where(p => !(newItems.Contains(p) || falseItems.Contains(p)))) { UpdatableFigure neighborUF = (UpdatableFigure)neighbor.mytransform.GetComponent <AbstractGeoObj>(); if (neighborUF.reactMotion(nodesmovinglist)) { updateNodeList.Add(neighbor); nodesmovinglist.Add(neighbor); newItems.Add(neighbor); } else { falseItems.Add(neighbor); } } } }
/// <summary> /// 删除节点 /// </summary> /// <param name="Node"></param> public void DeleteNode(ContractBoiNode Node) { //已删除过,则返回 if (!NodeList.Contains(Node)) { return; } // RecursionDeleteNode(Node); List <ContractBoiNode> lstChildren = Node.Children.ToList(); for (int i = lstChildren.Count - 1; i >= 0; i--) { DeleteNode(lstChildren[i]); } if (NodeList.Contains(Node)) { NodeList.Remove(Node); } if (updateList.Contains(Node)) { updateList.Remove(Node); } String strCode = null; int iCode = 0; if (Node.ParentBoiNode != null) { //删除节点的序号 int iIndex = Node.ParentBoiNode.Children.IndexOf(Node); //删除节点不是最后一个 if (iIndex < Node.ParentBoiNode.Children.Count - 1) { //移除节点 Node.ParentBoiNode.Children.Remove(Node); for (int i = iIndex; i < Node.ParentBoiNode.Children.Count; i++) { //对后面的节点的序号 统一减1 strCode = Node.ParentBoiNode.Children[i].ItemCode; iCode = System.Convert.ToInt32(strCode.Substring(strCode.Length - 3, 3)); iCode = iCode - 1; strCode = Node.ParentBoiNode.ItemCode + iCode.ToString().PadLeft(3, '0'); ChangeCode(Node.ParentBoiNode.Children[i], strCode); } } else { Node.ParentBoiNode.Children.Remove(Node); } CalcParentNode(Node.ParentBoiNode); } else { int iIndex = RootList.IndexOf(Node); //删除节点不是最后一个 if (iIndex < RootList.Count - 1) { //移除节点 RootList.Remove(Node); for (int i = iIndex; i < RootList.Count; i++) { //对后面的节点的序号 统一减1 strCode = RootList[i].ItemCode; iCode = System.Convert.ToInt32(strCode); iCode = iCode - 1; strCode = iCode.ToString().PadLeft(2, '0'); ChangeCode(RootList[i], strCode); } } else { RootList.Remove(Node); } } if (ListChanged != null) { ListChanged(); } }
public bool Contains(ComNode node) { return(NodeList.Contains(node)); }
private void start_Click(object sender, RoutedEventArgs e) { richTextBox.IsEnabled = false; startBtn.IsEnabled = false; nextBtn.IsEnabled = true; stopBtn.IsEnabled = true; BlockCount = richTextBox.Document.Blocks.Count(); if (BlockCount <= 1) { nextBtn.IsEnabled = false; return; } else if (BlockCount == 2) { nextBtn.IsEnabled = false; } CurrentBlockIndex = 0; { var enumerator = richTextBox.Document.Blocks.AsEnumerable().GetEnumerator(); enumerator.MoveNext(); CurrentBlock = enumerator.Current; } String blockText = GetBlockText(CurrentBlock); String regex = "^0: server <- ([0-9]+)$"; int serverId = -1; bool error = false; String errorMessage = ""; Match match = Regex.Match(blockText, regex); if (match.Success && match.Groups.Count > 1) { Int32.TryParse(match.Groups[1].Value, out serverId); if (!NodeList.Contains(serverId)) { errorMessage = String.Format("Node with id \"{0}\" does not exist", serverId); error = true; } } else { error = true; } if (error) { SetupErrorState(); ShowErrorMessage(errorMessage); return; } HighlightBlock(CurrentBlock, GreenHighlightBrush); MarkServerEventArgs args = new MarkServerEventArgs(serverId); MarkServer(this, args); }