private NodeTree RotateLR(NodeTree parent) { NodeTree pivot = parent.left; parent.left = RotateRR(pivot); return(RotateLL(parent)); }
protected Dictionary <TermNode, HashSet <TermNode> > FormGeneralTermGraphOverlapped(NodeTree _completeGraph, out Dictionary <TermNode, HashSet <TermNode> > termGraphChildParentsMap) { NodeTree generalGraph = _completeGraph; Dictionary <TermNode, HashSet <TermNode> > TermCPMap = _completeGraph.TermChildParentsMap; Dictionary <TermNode, HashSet <TermNode> > TermPCMap = _completeGraph.TermParentChildrenMap; //TermNodes relationship after Transitive Reduction Dictionary <TermNode, HashSet <TermNode> > ReducedTermCPMap = new Dictionary <TermNode, HashSet <TermNode> >(); Dictionary <TermNode, HashSet <TermNode> > ReducedTermPCMap = new Dictionary <TermNode, HashSet <TermNode> >(); //direct child of pNode should be those whose parents are not children of pNode foreach (TermNode pNode in TermPCMap.Keys) { ReducedTermPCMap.Add(pNode, new HashSet <TermNode>()); HashSet <TermNode> allChildren = new HashSet <TermNode>(TermPCMap[pNode]); foreach (TermNode cNode in allChildren) { HashSet <TermNode> childSParents = new HashSet <TermNode>(TermCPMap[cNode]); if (!childSParents.Overlaps(TermPCMap[pNode])) { ReducedTermPCMap[pNode].Add(cNode); } } } termGraphChildParentsMap = ReducedTermCPMap; return(ReducedTermPCMap); }
private NodeTree RotateRL(NodeTree parent) { NodeTree pivot = parent.right; parent.right = RotateLL(pivot); return(RotateRR(parent)); }
public void SaveTree(String TreeXml, string treeType) { if (String.IsNullOrEmpty(TreeXml)) { //创建一棵空树 XElement root = new XElement("root"); TreeXml = root.ToString(); } using (MyDBEntities context = new MyDBEntities(EFConnectionString)) { NodeTree treeObj = context.NodeTrees.FirstOrDefault(p => p.TreeType == treeType); if (treeObj != null) { //更新树 treeObj.WholeTree = Encoding.UTF8.GetBytes(TreeXml); treeObj.TreeType = treeType; context.SaveChanges(); } else { //正常情况下应该不会走到这个分支,但仍然写在这里,逻辑就完整了。 treeObj = new NodeTree(); treeObj.WholeTree = Encoding.UTF8.GetBytes(TreeXml); context.NodeTrees.Add(treeObj); treeObj.TreeType = treeType; context.SaveChanges(); } } }
public static void SetPNSbyScore(NodeTree current) { if (current.endOfGame()) { if (current.isMaximizing) { current.pns = PNS.PROVEN; return; } else { current.pns = PNS.DISPROVEN; return; } } else { int parentScore = current.parent == null ? 0 : current.parent.nodeScore; if (current.nodeScore - parentScore > 0) { //current.pns = PNS.PROVEN; } else { current.pns = PNS.DISPROVEN; } } //current.pns = PNS.UNKNOWN; }
private XmpNode NewNode(string ns, string name) { Dictionary <string, XmpNode> ns_nodes = null; if (!nodes.ContainsKey(ns)) { ns_nodes = new Dictionary <string, XmpNode>(); nodes.Add(ns, ns_nodes); } else { ns_nodes = nodes[ns]; } if (ns_nodes.ContainsKey(name)) { foreach (XmpNode child_node in NodeTree.Children) { if (child_node.Namespace == ns && child_node.Name == name) { NodeTree.RemoveChild(child_node); break; } } ns_nodes.Remove(name); } XmpNode node = new XmpNode(ns, name); ns_nodes.Add(name, node); NodeTree.AddChild(node); return(node); }
private bool TryGenKnownType(NodeTree node, bool requireBoxing, out object prototype) { // Try Primitive Type Type type; if (PrimitiveTypeDic.TryGetValue(node.Type, out type)) { // reader.Read<T>() il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Call, PrimitiveReaderDic[type]); if (requireBoxing) { il.Emit(OpCodes.Box, type); } prototype = Activator.CreateInstance(type); return(true); } // Try String else if (node.Type == "string") { GenReadString(); prototype = ""; return(true); } else { prototype = null; return(false); } }
public List <NodeTree> FirstSearch(NodeTree root, int[,] goal) { List <NodeTree> pathSolution = new List <NodeTree>(); List <NodeTree> openList = new List <NodeTree>(); List <NodeTree> closeList = new List <NodeTree>(); bool goalFound = false; openList.Add(root); while (openList.Count > 0 && !goalFound) { NodeTree currentNode = openList[0]; closeList.Add(currentNode); openList.RemoveAt(0); currentNode.SideMove(); for (int i = 0; i < currentNode.children.Count; i++) { NodeTree currentChild = currentNode.children[i]; if (currentChild.IsTheGoal(goal)) { goalFound = true; TracePath(pathSolution, currentChild); } if (!Contains(openList, currentChild) && !Contains(closeList, currentChild)) { openList.Add(currentChild); } } } return(pathSolution); }
internal override void Clear() { _tree = null; _treeUpToDate = false; base.Clear(); }
public void Bind(INode root) { List <INode> nodes = new List <INode>(); NodeTree.Flatten(root, nodes); // Build dictionary. Dictionary <string, INode> nodeDictionary = new Dictionary <string, INode>(); for (int i = 0; i < nodes.Count; i++) { INode node = nodes[i]; if (string.IsNullOrEmpty(node.Name)) { continue; } if (nodeDictionary.ContainsKey(node.Name)) { continue; } //if (nodeDictionary.ContainsKey(node.Name)) throw new InvalidOperationException("The node tree can not contain two nodes with the same name."); nodeDictionary.Add(node.Name, node); } Bind(Timeline, nodeDictionary); }
private static bool IsLeaf(NodeTree <int> tree) { if (tree.ChildNodes != null && tree.ChildNodes.Count > 0) { return(false); } return(true); }
/// <summary> /// Create a new tree view item /// </summary> /// <param name="parent">link to the parent</param> /// <param name="lazyLoadChildren">true to lazy load the children or false otherwise</param> public UIAutomatorNodeVM(INode node, SelectionChangedEventHandler eh) { _Model = node; _EH = eh; SelectionChanged += _EH; _Children = new NodeTree<UIAutomatorNodeVM>(); _LoadChildren(); }
public NodeTree(int newValue = 0, int newbal = 1, NodeTree par = null, NodeTree l = null, NodeTree r = null) { value = newValue; bal = newbal; parent = par; left = l; right = r; }
/// <summary> /// Create a new tree view item /// </summary> /// <param name="parent">link to the parent</param> /// <param name="lazyLoadChildren">true to lazy load the children or false otherwise</param> public UIAutomatorNodeVM(INode node, SelectionChangedEventHandler eh) { _Model = node; _EH = eh; SelectionChanged += _EH; _Children = new NodeTree <UIAutomatorNodeVM>(); _LoadChildren(); }
public int Height(NodeTree N) { if (N == null) { return(0); } return(N.bal); }
public void Draw(NodeTree top) // рисование дерева { g.Clear(Color.White); if (top != null) { DrawNode(top); } }
public int GetBalance(NodeTree N) { if (N == null) { return(0); } return(Height(N.left) - Height(N.right)); }
public NodeTree FormCompleteGraph() { //Do the Node Tree NodeTree CompleteGraph = new NodeTree(TermNodeList, CoverNodeList); CompleteGraph.Run(); return(CompleteGraph); }
public void DeSelect(NodeTree node) { if (node != null) { node.Visit = false; DeSelect(node.Left); DeSelect(node.Right); } }
public void PostOrder(NodeTree node) { if (node == null) { return; } PreOrder(node.Left); PreOrder(node.Right); Console.Write(node.Data + " "); }
private void setNodeAllNodes(NodeTree nodeInsert) { List <NodeTree> nodesChilds = nodeInsert.getChilds(); foreach (var nodeC in nodesChilds) { setLabelNode(nodeC); setNodeAllNodes(nodeC); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { TNode tnode = new TNode(); NodeBLL nodebll = new NodeBLL(); DataTable dt = nodebll.GetAllNode(); L_CateTree.Text = NodeTree.GetJqueryNodeTree(dt, 0); } }
private static void updateNode_DeleteNode(Node nodeToDelete, NodeTree nodeTree) { updateNode_ClearPrevLinks(nodeToDelete, nodeTree); for (int i = 0; i < nodeToDelete.NextNodeLinks.Count; i++) { updateNode_RemoveLink(nodeToDelete, i, nodeTree); } nodeTree.Nodes.Remove(nodeToDelete); }
public static List <Node> GetChainAsNodes(Node node, NodeTree tree) { var list = new List <Node>() { node }; GetAllLinkedNodes(node, tree, ref list); return(list); }
/// <summary> /// Create root Node /// </summary> /// <param name="player"></param> /// <param name="opponentPlayer"></param> public NodeTree(Player player, Player opponentPlayer) : base(player, opponentPlayer) { isInitialPlayer = true; parent = null; children = new List <NodeTree> (); setPNS(); isMaximizing = true; isExpanded = false; move = null; }
public static void Save(this NodeTree tree, EndianReader stream) { stream.Write((byte)1); // version stream.Write((ushort)tree.Nodes.Count); stream.Write((uint)1); // Initial ID / Line Number foreach (Node node in tree.Nodes) { node.Write(stream); } }
public override void Update(GameTime gameTime) { ScoreClientMock scoreClientMock = ScoreClient as ScoreClientMock; if (scoreClientMock != null) { scoreClientMock.Update(gameTime); } NodeTree.Update(Root, gameTime); }
static void PrintTree(NodeTree root, string prefix) { if (root == null) { Console.WriteLine(prefix + "+- <null>"); return; } Console.WriteLine(prefix + "+- " + root.OrderId); PrintTree(root.Left, prefix + "| "); PrintTree(root.Right, prefix + "| "); }
public void Add(MultiLabelMarkQueue node) { if (root == null) { root = new NodeTree(node); } else { AddPrivate(root, node); } }
public void Add(NodeGraphDTO node) { if (root == null) { root = new NodeTree(node); } else { AddPrivate(root, node); } }
private void TreeView_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Released) { return; } if (IsRenamingInProgress) { return; } try { var currentPosition = e.GetPosition(this.TreeViewMenu); if (Math.Abs(currentPosition.X - this._lastLeftMouseButtonDownPoint.X) <= 10.0 && Math.Abs(currentPosition.Y - this._lastLeftMouseButtonDownPoint.Y) <= 10.0) { return; } _draggingItem = this.TreeViewMenu.SelectedItem as NodeTree; if (_draggingItem is NodeFeed) { if (!(((_draggingItem as NodeFeed).Status == NodeFeed.DownloadStatus.normal) || ((_draggingItem as NodeFeed).Status == NodeFeed.DownloadStatus.error))) { return; } } if (_draggingItem != null) { if ((_draggingItem is NodeService) || (_draggingItem is NodeFolder) || (_draggingItem is NodeFeed)) { DragDropEffects finalDropEffect = DragDrop.DoDragDrop(this.TreeViewMenu, this.TreeViewMenu.SelectedValue, DragDropEffects.Move); //Checking target is not null and item is dragging(moving) if ((finalDropEffect == DragDropEffects.Move) && (_targetItem != null)) { // A Move drop was accepted if (!_draggingItem.Name.Equals(_targetItem.Name)) { MoveItem(_draggingItem, _targetItem); _targetItem = null; _draggingItem = null; } } } } } catch (Exception) { } }
public void ApplyUpgrade(Upgrade.UpgradeType type) { foreach (NodeTree<Upgrade.UpgradeType> t in upgradeTreePos.Children) { if (t.Data == type) { upgradeTreePos = t; return; } } }
public UIMenu() { controls = new NodeTree<UIControl>(); controls.Root = new Node<UIControl>(new UIControlWindow()); }
private void _RefreshItems(object state) { bool firstTime = false; // start the driver if (!_Driver.IsStarted) { firstTime = true; string errorMessage; if (_Settings.UseRemoteServer) { Message = "Attempting to connect to remote server at " + _Settings.IPAddress; } else Message = "Starting Selenium Driver"; if (!_Driver.Start(out errorMessage)) { Console.WriteLine("error: {0}", errorMessage); if (_Settings.UseRemoteServer) { Message = "Failed to connect (please check the configuration and that the remote server is online)."; } else { Message = "Error Starting Selenium Driver"; } return; } } Message = "Updating"; string pageSource = null; // grab the page source and parse it if (!string.IsNullOrWhiteSpace(pageSource = _Driver.GetPageSource())) { _CleanUpRoot(); var root = _ConvertToUIAutomatorNode(pageSource); _RootNode = new NodeTree<UIAutomatorNodeVM>(); UIAutomatorNodeVM vm = new UIAutomatorNodeVM(root, vm_SelectionChanged); _RootNode.Add(vm); FirePropertyChanged(() => RootNode); } else { Message = "Error getting page source"; } if (firstTime) { // added sleep timer here since the setup I had was pulling in the "previous" picture System.Threading.Thread.Sleep(300); } // grab the image ImageByteArray = _Driver.GetScreenshot(); if (ImageByteArray == null) { Message = "Error getting screenshot"; } // Show success message if the "Updating" message was not changed if (Message.Equals("Updating")) { Message = string.Format("Last successfully updated on {0}", DateTime.Now); } }
private void _RefreshItems(object state) { bool firstTime = false; // start the driver if (_Driver == null) { firstTime = true; Message = "Attempting to connect to Appium"; try { Dictionary<string, object> capsDef = new Dictionary<string, object>(); // Only set automation name if it isn't equal to the default if (_Settings.AutomationName != "Appium") { capsDef.Add("automationName", _Settings.AutomationName); } if (_Settings.UseDeviceName && _Settings.DeviceName != "") { capsDef.Add("deviceName", _Settings.DeviceName); } if (!_Settings.UseAndroidBrowser) { if (_Settings.UseApplicationPath && _Settings.ApplicationPath != "") { capsDef.Add("app", _Settings.ApplicationPath); } if (_Settings.UseAndroidActivity && _Settings.AndroidActivity != "") { capsDef.Add("appActivity", _Settings.AndroidActivity); } if (_Settings.UseAndroidPackage && _Settings.AndroidPackage != "") { capsDef.Add("appPackage", _Settings.AndroidPackage); } if (_Settings.UseAndroidWaitForActivity && _Settings.AndroidWaitForActivity != "") { capsDef.Add("appWaitActivity", _Settings.AndroidWaitForActivity); } if (_Settings.UseAndroidWaitForPackage && _Settings.AndroidWaitForPackage != "") { capsDef.Add("appWaitPackage", _Settings.AndroidWaitForPackage); } } else { capsDef.Add("browserName", _Settings.AndroidBrowser); } if (_Settings.UseAndroidDeviceReadyTimeout && _Settings.AndroidDeviceReadyTimeout.ToString() != "") { capsDef.Add("deviceReadyTimeout", _Settings.AndroidDeviceReadyTimeout.ToString()); } if (_Settings.UseCoverageClass && _Settings.CoverageClass != "") { capsDef.Add("androidCoverage", _Settings.CoverageClass); } if (_Settings.UseAndroidIntentAction && _Settings.AndroidIntentAction != "") { capsDef.Add("intentAction", _Settings.AndroidIntentAction); } if (_Settings.UseAndroidIntentCategory && _Settings.AndroidIntentCategory != "") { capsDef.Add("intentCategory", _Settings.AndroidIntentCategory); } if (_Settings.UseAndroidIntentFlags && _Settings.AndroidIntentFlags != "") { capsDef.Add("intentFlags", _Settings.AndroidIntentFlags); } if (_Settings.UseAndroidIntentArguments && _Settings.AndroidIntentArguments != "") { capsDef.Add("optionalIntentArguments", _Settings.AndroidIntentArguments); } // Include the platform if any of the capabilities were set if (capsDef.Count != 0 && _Settings.PlatformName != "") { capsDef.Add("platformName", _Settings.PlatformName); } _Driver = new AppiumDriver(new Uri(String.Format("http://{0}:{1}/wd/hub", _Settings.IPAddress, _Settings.Port)), new DesiredCapabilities(capsDef)); } catch { MessageBox.Show("Failed to connect to the server. Please check that it is running.", "Inspector Connection Error", MessageBoxButton.OK, MessageBoxImage.Error); Message = "Failed to connect to Appium"; } if (_Driver == null) { if (_Settings.UseRemoteServer) { Message = "Failed to connect to remote Appium server"; } else { Message = "Failed to connect to Appium"; } return; } } Message = "Updating"; string pageSource = null; // grab the page source and parse it try { if (!string.IsNullOrWhiteSpace(pageSource = _Driver.PageSource)) { _CleanUpRoot(); var root = _ConvertToUIAutomatorNode(pageSource); _RootNode = new NodeTree<UIAutomatorNodeVM>(); UIAutomatorNodeVM vm = new UIAutomatorNodeVM(root, vm_SelectionChanged); _RootNode.Add(vm); FirePropertyChanged(() => RootNode); } else { Message = "Error getting page source"; } } catch (Exception e) { Message = String.Format("Error getting source page: {0}", e.Message); } if (firstTime) { // added sleep timer here since the setup I had was pulling in the "previous" picture System.Threading.Thread.Sleep(300); } // grab the image Screenshot screenshot = null; try { screenshot = _Driver.GetScreenshot(); } catch (Exception e) { Message = String.Format("Error getting screenshot: {0}", e.Message); } finally { if (screenshot != null) { ImageByteArray = screenshot.AsByteArray; if (ImageByteArray == null) { Message = "Error getting screenshot"; } } else { Message = "Error getting screenshot"; } } // Show success message if the "Updating" message was not changed if (Message.Equals("Updating")) { Message = string.Format("Last successfully updated on {0}", DateTime.Now); } }
private static List<NodeTree<int>> ReadAndParseInput() { List<NodeTree<int>> nodes = new List<NodeTree<int>>(); int edges = int.Parse(Console.ReadLine()); for (int i = 0; i < edges - 1; i++) { int[] values = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(value => int.Parse(value)) .ToArray(); var parent = nodes.FirstOrDefault(node => values[0] == node.Value); if (parent == null) { parent = new NodeTree<int>(values[0]); nodes.Add(parent); } var child = nodes.FirstOrDefault(node => values[1] == node.Value); if (child == null) { child = new NodeTree<int>(values[1]); nodes.Add(child); } parent.AddChild(child); } return nodes; }
private static int GetSubtreeSum(int sum, NodeTree<int> node, List<NodeTree<int>> roots) { if (!node.HasChildren) { if (node.Value == sum) roots.Add(node); return node.Value; } else { int subtreeSum = node.Value; foreach (var child in node.Children) { subtreeSum += GetSubtreeSum(sum, child, roots); } if (subtreeSum == sum) roots.Add(node); return subtreeSum; } }
private static void GetPathsFromNode(NodeTree<int> node, Stack<NodeTree<int>> stack, List<NodeTree<int>[]> paths) { stack.Push(node); paths.Add(stack.ToArray()); foreach (var child in node.Children) { GetPathsFromNode(child, stack, paths); } stack.Pop(); }
private static void GetPath(NodeTree<int> node, Stack<NodeTree<int>> path, List<NodeTree<int>[]> paths) { path.Push(node); foreach (var child in node.Children) { GetPath(child, path, paths); } if (!node.HasChildren) paths.Add(path.ToArray()); path.Pop(); }