// □为待确认节点,■为障碍节点 // 当出现如下对角的□时,可选是否跨越■到达另一个□, // ■□ // □ // 该方法判断对角的两个对角节点是否被障碍所阻碍,即是否存在上述情况 public static bool IsImpededByObstruct(NodeImage[,] map, Node centerNode, Node otherNode) { // 先判断对角方向,即 // □■ ■□ // 是 ■□ 还是 □■ bool flag = (centerNode.col - otherNode.col) * (centerNode.row - otherNode.row) == 1; // 获得同时与 centerNode 和 otherNode 两个对角节点相邻的两个节点 // 假设节点的二维数组索引如下 // (1, 2)□■(2, 2) // (1, 3)■□(2, 3) // 那么(1, 3)■中的1和3,即col和row,有 // (1, 3)■.col = Mathf.FloorToInt(((1, 2)□.col + □(2, 3).col) / 2f) // (1, 3)■.row = Mathf.CeilToInt(((1, 2)□.row + □(2, 3).row) / 2f) NodeImage obstructTestNode_1 = flag ? map[Mathf.FloorToInt((centerNode.col + otherNode.col) / 2f), Mathf.CeilToInt((centerNode.row + otherNode.row) / 2f)] : map[Mathf.CeilToInt((centerNode.col + otherNode.col) / 2f), Mathf.CeilToInt((centerNode.row + otherNode.row) / 2f)]; NodeImage obstructTestNode_2 = flag ? map[Mathf.CeilToInt((centerNode.col + otherNode.col) / 2f), Mathf.FloorToInt((centerNode.row + otherNode.row) / 2f)] : map[Mathf.FloorToInt((centerNode.col + otherNode.col) / 2f), Mathf.FloorToInt((centerNode.row + otherNode.row) / 2f)]; // 先判断centerNode和otherNode是否对角 return(Mathf.Abs(centerNode.col - otherNode.col) + Mathf.Abs(centerNode.row - otherNode.row) == 2 && (obstructTestNode_1.data.state == BlockState.Obstruct || obstructTestNode_2.data.state == BlockState.Obstruct)); }
public void Reset() { F = 0; G = 0; H = 0; state = BlockState.None; parent = null; }
//刷新两个PictureBox,并用指定样式绘图 void RefreshGraph(StyleSet PaintStyle) { //普通节点视图 NodeImage.Image = DrawNode(PaintStyle, false); NodeImage.Refresh(); //高亮节点视图 HLImage.Image = DrawNode(PaintStyle, true); HLImage.Refresh(); }
public void AddObstruct(NodeImage node) { if (obstruct.Contains(node)) { return; } obstruct.Add(node); }
public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options) { LinodeNodeOptions ops = options as LinodeNodeOptions; if (ops == null && options != null) throw new Exception ("Only LinodeNodeOptions can be used as NodeOptions for creating Linode Nodes."); else if (ops == null) ops = new LinodeNodeOptions (); return API.CreateNode (name, size, image, location, auth, ops); }
public CustomNode(NodeType type, CustomNode parentNode, string text, NodeImage image, int orderBy) { Type = type; ParentNode = parentNode; Text = text; Name = text; SelectedImageIndex = Convert.ToInt32(image); ImageIndex = Convert.ToInt32(image); OrderBy = orderBy; }
public Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, LinodeNodeOptions options) { int rsize = size.Disk - options.SwapSize; string kernel = FindKernel (options); LinodeRequest request = new LinodeRequest ("linode.create", new Dictionary<string,object> { {"DatacenterID", location.Id}, {"PlanID", size.Id}, {"PaymentTerm", (int) options.PaymentTerm}}); LinodeResponse response = Execute (request); JObject node = response.Data [0]; string id = node ["LinodeID"].ToString (); string root_pass; if (auth.Type == NodeAuthType.Password) root_pass = auth.Secret; else root_pass = GenerateRandomPassword (); request = new LinodeRequest ("linode.disk.createfromdistribution", new Dictionary<string,object> { {"LinodeID", id}, {"DistributionID", image.Id}, {"Label", name}, {"Size", rsize}, {"rootPass", root_pass}}); if (auth.Type == NodeAuthType.SSHKey) request.Parameters.Add ("rootSSHKey", auth.Secret); response = Execute (request); JObject distro = response.Data [0]; string root_disk = distro ["DiskID"].ToString (); request = new LinodeRequest ("linode.disk.create", new Dictionary<string,object> { {"LinodeID", id}, {"Label", "Swap"}, {"Type", "swap"}, {"Size", options.SwapSize}}); response = Execute (request); string swap_disk = response.Data [0] ["DiskID"].ToString (); string disks = String.Format ("{0},{1},,,,,,,", root_disk, swap_disk); request = new LinodeRequest ("linode.config.create", new Dictionary<string,object> { {"LinodeID", id}, {"KernelID", kernel}, {"Label", "mcloud config"}, {"DiskList", disks}}); response = Execute (request); string config = response.Data [0]["ConfigID"].ToString (); request = new LinodeRequest ("linode.boot", new Dictionary<string,object> { {"LinodeID", id}, {"ConfigID", config}}); response = Execute (request); request = new LinodeRequest ("linode.list", new Dictionary<string,object> {{"LinodeID", id}}); response = Execute (request); return LinodeNode.FromData (response.Data [0], driver); }
void ShowPath() { foreach (NodeImage item in openList) { if (item != endNode) { item.SetDataUI(); } } foreach (NodeImage item in closeList) { if (item != startNode) { item.SetDataUI(); } } NodeImage node = endNode; path.Add(node); while (node.data.parent != null) { path.Add(node.data.parent); node = node.data.parent; } string s = ""; for (int i = path.Count - 1; i >= 0; i--) { s += "(" + path[i].data.col + "," + path[i].data.row + ")"; if (path[i] != startNode && path[i] != endNode) { path[i].SetAsPathNode(pathColor); } if (i != 0) { s += "->"; } } Debug.Log(s); }
public Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, int swap=128) { int rsize = size.Disk - swap; string kernel = FindKernel (); Console.WriteLine ("USING KERNEL: {0}", kernel); LinodeRequest request = new LinodeRequest ("linode.create", new Dictionary<string,object> { {"DatacenterID", location.Id}, {"PlanID", size.Id}, {"PaymentTerm", (int) driver.PaymentTerm}}); LinodeResponse response = Execute (request); JObject node = response.Data [0]; string id = node ["LinodeID"].ToString (); request = new LinodeRequest ("linode.disk.createfromdistribution", new Dictionary<string,object> { {"LinodeID", id}, {"DistributionID", image.Id}, {"Label", name}, {"Size", size.Disk}, {"rootPass", "F23444sd"}}); response = Execute (request); JObject distro = response.Data [0]; string root_disk = distro ["DiskID"].ToString (); request = new LinodeRequest ("linode.disk.create", new Dictionary<string,object> { {"LinodeID", id}, {"Label", "Swap"}, {"Type", "swap"}, {"Size", swap}}); response = Execute (request); string swap_disk = response.Data [0] ["DiskID"].ToString (); string disks = String.Format ("{0},{1},,,,,,,", root_disk, swap_disk); request = new LinodeRequest ("linode.config.create", new Dictionary<string,object> { {"LinodeID", id}, {"KernelID", kernel}, {"Label", "mcloud config"}, {"DiskList", disks}}); response = Execute (request); string config = response.Data [0]["ConfigID"].ToString (); request = new LinodeRequest ("linode.boot", new Dictionary<string,object> { {"LinodeID", id}, {"ConfigID", config}}); response = Execute (request); return null; }
internal GraphNodeControl(GraphNodeView view, GraphLayer manager) { View = view; // The visual element of the view is this Node = view.Node; _OwnerGraphLayer = manager; InitializeComponent(); // Initialize resources if (bResourceInitialized == false) { JumperImageStyle = NodeImage.FindResource("JumperStyleImage") as Style; TextNodeStyle = this.FindResource("TextNode") as Style; TextNodeHighLightStyle = this.FindResource("TextNodeHighlight") as Style; ImageNodeStyle = this.FindResource("ImageNode") as Style; ImageNodeHighLightStyle = this.FindResource("ImageNodeHighlight") as Style; JumperNodeStyle = this.FindResource("JumperNode") as Style; JumperNodeHighlightStyle = this.FindResource("JumperNodeHighlight") as Style; bResourceInitialized = true; } // Switch Style switch (Node.Type) { case NodeType.SimpleText: // Do nothing more setup, default assumed // Show NodeTextExpander.Visibility = Visibility.Visible; break; case NodeType.Link: SetupInterfaceForLink(); break; case NodeType.RichFlowText: SetupInterfaceForFlowText(); break; case NodeType.Jumper: SetupInterfaceForJumper(); break; } }
// 重置所有计算用辅助数据,清除所有节点UI高亮显示 public void ResetDataTotally() { startNode = null; endNode = null; ResetCalculateList(); while (obstruct.Count > 0) { obstruct[0].SetAsNormalNode(); } foreach (NodeImage node in path) { node.SetAsNormalNode(); node.data.Reset(); } path.Clear(); obstruct.Clear(); }
void InitMap(int row, int col, float nodeWidth) { map = new NodeImage[row, col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { GameObject go = Instantiate(nodePrefab, mapGenerator); NodeImage ni = go.GetComponent <NodeImage>(); map[i, j] = ni; Node data = new Node() { col = i, row = j, F = 0, G = 0, H = 0, parent = null, state = BlockState.None }; map[i, j].data = data; map[i, j].SetRect(new Vector2((i - row / 2f) * (nodeWidth + 2f) + nodeWidth / 2f, (col / 2f - j) * (nodeWidth + 2f) - nodeWidth / 2f), nodeWidth); } } StartCoroutine(ShowHintText("成功生成地图!")); }
public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options) { EC2NodeOptions ops = options as EC2NodeOptions; if (ops == null && options != null) throw new Exception ("Only EC2NodeOptions can be used as NodeOptions for creating EC2 Nodes."); else if (ops == null) ops = new EC2NodeOptions (); RunInstancesRequest request = new RunInstancesRequest () { InstanceType = size.Id, ImageId = image.Id, MinCount = 1, MaxCount = 1, KeyName = auth.UserName, }; RunInstancesResponse response = Client.RunInstances (request); foreach (var i in response.RunInstancesResult.Reservation.RunningInstance) { return EC2Node.FromRunningInstance (i, this); } return null; }
public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location) { return API.CreateNode (name, size, image, location); }
void CalculatePath() { NodeImage node = startNode; openList.Add(node); while (openList.Count > 0 && !isFind) { openList.Remove(node); closeList.Add(node); for (int i = 0; i < 3 && !isFind; i++) { for (int j = 0; j < 3; j++) { if (node.data.col - 1 + i >= 0 && node.data.col - 1 + i < map.GetLength(0) && node.data.row - 1 + j >= 0 && node.data.row - 1 + j < map.GetLength(1)) { NodeImage otherNode = map[node.data.col - 1 + i, node.data.row - 1 + j]; if (startNode.data.col == otherNode.data.col && startNode.data.row == otherNode.data.row || otherNode.data.col == node.data.col && otherNode.data.row == node.data.row || otherNode.data.state == BlockState.Obstruct || closeList.Contains(otherNode)) { continue; } // 是否可跨越障碍到达对角节点 if (!canCrossCorner) { // 与对角节点同时相邻的节点是否为障碍节点 if (Node.IsImpededByObstruct(map, node.data, otherNode.data)) { continue; } } if (endNode.data.col == otherNode.data.col && endNode.data.row == otherNode.data.row) { otherNode.data.parent = node; openList.Add(otherNode); isFind = true; break; } if (!openList.Contains(otherNode)) { otherNode.data.parent = node; openList.Add(otherNode); otherNode.data.G = Node.GetNodeG(node.data, otherNode.data); otherNode.data.H = Node.GetNodeH(otherNode.data, endNode.data); otherNode.data.F = Node.GetNodeF(otherNode.data); } else { if (node.data.G + Node.GetPrice(node.data, otherNode.data) < otherNode.data.G) { otherNode.data.parent = node; otherNode.data.G = otherNode.data.parent.data.G + Node.GetPrice(node.data, otherNode.data); otherNode.data.F = Node.GetNodeF(otherNode.data); } } } } } node = Node.GetMinFNode(openList); } lastCanCrossCorner = canCrossCorner; if (isFind) { ShowPath(); } else { ResetCalculateList(); StartCoroutine(ShowHintText("没有可达到终点的路径!")); } }
static bool IsTextEditable(TreeNode node) { NodeImage img = (NodeImage)(node.ImageIndex + 1); return(!(img == NodeImage.Element || img == NodeImage.OpenElement)); }
// creates a grid element with images to represent a grid node Grid CreateCellGrid(Row r, int level, double indent, NodeImage nodeImage) { // create grid var g = new Grid(); // add columns for images and content bool above = r.Grid.GroupRowPosition == GroupRowPosition.AboveData; // create elements for each level for (int i = 0; i < level + 1; i++) { // add images to the grid if (i <= level) { // select image to display in this part of the cell var ni = i == level ? nodeImage : NodeImage.Connector; if (ni == NodeImage.Connector) { var index = r.Index; var rows = r.Grid.Rows; // find next group row to determine the image to display int next = index; if (above) { // look for next group below this one for (next = index + 1; next < rows.Count; next++) { if (rows[next].IsVisible) { var gr = rows[next] as GroupRow; if (gr != null && gr.Level <= i) { ni = NodeImage.Terminal; } break; } } if (next == rows.Count) { ni = NodeImage.Terminal; } } else { // look for next group above this one for (next = index - 1; next > -1; next--) { if (rows[next].IsVisible) { var gr = rows[next] as GroupRow; if (gr != null && gr.Level <= i) { ni = NodeImage.Terminal; } break; } } if (next <= 0) { ni = NodeImage.Terminal; } } } // add image var img = GetNodeImage(r, ni); if (img != null) { var cd = new ColumnDefinition(); cd.Width = new GridLength(indent); g.ColumnDefinitions.Add(cd); img.SetValue(Grid.ColumnProperty, i); g.Children.Add(img); } } } // and add a cell for the content g.ColumnDefinitions.Add(new ColumnDefinition()); // done return g; }
// gets an image to represents a node Image GetNodeImage(Row r, NodeImage nodeImage) { // load bitmaps (once) if (_bmpCollapsed == null) { _bmpCollapsed = LoadBitmap("Collapsed.png"); _bmpExpandedAbove = LoadBitmap("ExpandedAbove.png"); _bmpExpandedBelow = LoadBitmap("ExpandedBelow.png"); _bmpConnector = LoadBitmap("Connector.png"); _bmpTerminalAbove = LoadBitmap("TerminalAbove.png"); _bmpTerminalBelow = LoadBitmap("TerminalBelow.png"); _bmpNoChildren = LoadBitmap("NoChildren.png"); } // get image source ImageSource src = null; var above = r.Grid.GroupRowPosition == GroupRowPosition.AboveData; switch (nodeImage) { case NodeImage.Collapsed: if (HasVisibleChildren(r)) { src = _bmpCollapsed; } break; case NodeImage.Expanded: if (HasVisibleChildren(r)) { src = above ? _bmpExpandedAbove : _bmpExpandedBelow; } break; case NodeImage.Connector: src = _bmpConnector; break; case NodeImage.Terminal: src = above ? _bmpTerminalAbove : _bmpTerminalBelow; break; } // no source? we're done if (src == null) { return null; } // create image element var img = new Image(); img.Source = src; img.Stretch = Stretch.None; img.VerticalAlignment = VerticalAlignment.Center; img.HorizontalAlignment = HorizontalAlignment.Center; img.Tag = r; // assign source switch (nodeImage) { case NodeImage.Collapsed: case NodeImage.Expanded: img.MouseLeftButtonDown += img_MouseLeftButtonDown; break; } // done return img; }
// creates a grid element with images to represent a grid node Grid CreateCellGrid(Row r, int level, double indent, NodeImage nodeImage) { // create grid var g = new Grid(); // add columns for images and content bool above = r.Grid.GroupRowPosition == GroupRowPosition.AboveData; // create elements for each level for (int i = 0; i < level + 1; i++) { // add images to the grid if (i <= level) { // select image to display in this part of the cell var ni = i == level ? nodeImage : NodeImage.Connector; if (ni == NodeImage.Connector) { var index = r.Index; var rows = r.Grid.Rows; // find next group row to determine the image to display int next = index; if (above) { // look for next group below this one for (next = index + 1; next < rows.Count; next++) { if (rows[next].IsVisible) { var gr = rows[next] as GroupRow; if (gr != null && gr.Level <= i) { ni = NodeImage.Terminal; } break; } } if (next == rows.Count) { ni = NodeImage.Terminal; } } else { // look for next group above this one for (next = index - 1; next > -1; next--) { if (rows[next].IsVisible) { var gr = rows[next] as GroupRow; if (gr != null && gr.Level <= i) { ni = NodeImage.Terminal; } break; } } if (next <= 0) { ni = NodeImage.Terminal; } } } // add image var img = GetNodeImage(r, ni); if (img != null) { var cd = new ColumnDefinition(); cd.Width = new GridLength(indent); g.ColumnDefinitions.Add(cd); img.SetValue(Grid.ColumnProperty, i); g.Children.Add(img); } } } // and add a cell for the content g.ColumnDefinitions.Add(new ColumnDefinition()); // done return(g); }
// gets an image to represents a node Image GetNodeImage(Row r, NodeImage nodeImage) { // load bitmaps (once) if (_bmpCollapsed == null) { _bmpCollapsed = LoadBitmap("Collapsed.png"); _bmpExpandedAbove = LoadBitmap("ExpandedAbove.png"); _bmpExpandedBelow = LoadBitmap("ExpandedBelow.png"); _bmpConnector = LoadBitmap("Connector.png"); _bmpTerminalAbove = LoadBitmap("TerminalAbove.png"); _bmpTerminalBelow = LoadBitmap("TerminalBelow.png"); _bmpNoChildren = LoadBitmap("NoChildren.png"); } // get image source ImageSource src = null; var above = r.Grid.GroupRowPosition == GroupRowPosition.AboveData; switch (nodeImage) { case NodeImage.Collapsed: if (HasVisibleChildren(r)) { src = _bmpCollapsed; } break; case NodeImage.Expanded: if (HasVisibleChildren(r)) { src = above ? _bmpExpandedAbove : _bmpExpandedBelow; } break; case NodeImage.Connector: src = _bmpConnector; break; case NodeImage.Terminal: src = above ? _bmpTerminalAbove : _bmpTerminalBelow; break; } // no source? we're done if (src == null) { return(null); } // create image element var img = new Image(); img.Source = src; img.Stretch = Stretch.None; img.VerticalAlignment = VerticalAlignment.Center; img.HorizontalAlignment = HorizontalAlignment.Center; img.Tag = r; // assign source switch (nodeImage) { case NodeImage.Collapsed: case NodeImage.Expanded: img.MouseLeftButtonDown += img_MouseLeftButtonDown; break; } // done return(img); }
public List<NodeImage> ListImages(NodeLocation location) { LinodeRequest request = new LinodeRequest ("avail.distributions"); LinodeResponse response = Execute (request); List<NodeImage> images = new List<NodeImage> (); foreach (JObject obj in response.Data) { string id = obj ["DISTRIBUTIONID"].ToString (); string name = (string) obj ["LABEL"]; NodeImage image = new NodeImage (id, name, driver); images.Add (image); } return images; }