public void Handle(NodeUpdate message) { Draw(); //System.Threading.Thread.Sleep(10); if (message.From != null) { var actualNode = MyNodes.FirstOrDefault(x => x.Id == message.NodeId); actualNode.Height += 5; actualNode.Width += 5; var nodeFrom = MyNodes.FirstOrDefault(x => x.Name == Convert.ToString(message.From.Value)); var nodeTo = MyNodes.FirstOrDefault(x => x.Name == Convert.ToString(message.NodeId)); LineModel line = new LineModel { Stroke = Brushes.Gray, X1 = nodeFrom.X + (nodeFrom.Width / 2), Y1 = nodeFrom.Y + (nodeFrom.Height / 2), X2 = nodeTo.X + (nodeTo.Width / 2), Y2 = nodeTo.Y + (nodeTo.Height / 2), StrokeThickness = 3 }; path.Add(line); MyLines.Add(line); } }
/////////////////////////////////////////////////////////////////////// // Internal Events /////////////////////////////////////////////////////////////////////// private void AccountTLV_AfterSelect(object sender, TreeViewEventArgs e) { int accountID = -1; int envelopeID = -1; MyNodes nodeType = (this.accTLV.FocusedNode as BaseNode).NodeType; switch (nodeType) { case MyNodes.AENode: AENode aeNode = this.accTLV.FocusedNode as AENode; accountID = aeNode.AccountID; envelopeID = aeNode.EnvelopeID; break; case MyNodes.Account: accountID = (this.accTLV.FocusedNode as AccountNode).AccountID; break; case MyNodes.Envelope: envelopeID = (this.accTLV.FocusedNode as EnvelopeNode).EnvelopeID; break; case MyNodes.Root: case MyNodes.AccountType: case MyNodes.EnvelopeGroup: break; } if (accountID != selectedAccountID || envelopeID != selectedEnvelopeID) { OnSelectedAccountEnvelopeChanged(new SelectedAccountEnvelopeChangedEventArgs(accountID, envelopeID)); } }
/// <summary> /// Function to set the key value pair in HashTable /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void set(string key, int value) { //Setting index value to hash function int index = hash(key); //If hash function is empty (nothing stored) if (data[index] == null) { //Create a new key value node data[index] = new MyNodes(); } //Else, add Node to hash table at hash function index data[index].Add(new MyNode(key, value)); }
public AddForm(MyNodes select = null) { InitializeComponent(); if (select != null) { newUser = select; tb_name.Text = select.Text; tb_email.Text = select.Email; } else { newUser = new MyNodes(); } }
//O(1) public object Get(string key) { int address = _hash(key); MyNodes currentBucket = this.data[address]; if (currentBucket != null) { foreach (var node in currentBucket) { if (node.key == key) { return(node.value); } } } return(0); }
private void AccountTLV_NotifyBeforeExpand(Node node, bool isExpanding) { if (!isExpanding || node.Nodes.Count > 0) { return; } MyNodes nodeType = (node as BaseNode).NodeType; switch (nodeType) { case MyNodes.Root: this.handleThisRootNode(node as RootNode); break; case MyNodes.AccountType: this.handleThisTypeNode(node as TypeNode); break; case MyNodes.EnvelopeGroup: this.handleThisGroupNode(node as GroupNode); break; case MyNodes.Account: this.handleThisAccountNode(node as AccountNode); break; case MyNodes.Envelope: this.handleThisEnvelopeNode(node as EnvelopeNode); break; } if (node.Nodes.Count > 0) { node.HasChildren = true; } else { node.HasChildren = false; } }
private void OpenFile(object parameter) { OpenFileDialog opd = new OpenFileDialog(); opd.Filter = "XML File *.xml|*.xml"; try { if (opd.ShowDialog() == true) { XmlDocument xDoc = MLHelper.GetMLDocument(opd.FileName); MLNode retNode = MLHelper.ParserML(xDoc.DocumentElement); MyNodes.Add(retNode); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Parser Error!"); } }
/////////////////////////////////////////////////////////////////// Algorithm Implementation Function ///////////////////////////////////////////////////////////////// private void BellmanFordAlgo(Graph graph, MyNodes sourceNode) // takes in a graph reference and a source node reference as argument { Dictionary <MyNodes, NodeValue> Distance = new Dictionary <MyNodes, NodeValue>(); // creates a dictionary of nodes as keys and nodevalues as values for (int i = 0; i < graph.Nodelist.Count; i++) { NodeValue nodeValue = new NodeValue(graph.Nodelist[i], float.MaxValue); // creates node value with the cost of all nodes to max value and all prev nodes for that node as the node itself Distance.Add(graph.Nodelist[i], nodeValue); // adds the node value to the dictionary. } Distance[sourceNode].Cost = 0; // changes the cost of the source node to 0; for (int i = 0; i < graph.Nodelist.Count; i++) // for each vertice. { for (int j = 0; j < graph.Edgelist.Count; j++) // traverses each edge in the list { MyNodes startNode = graph.Edgelist[j].A; MyNodes endtNode = graph.Edgelist[j].B; float w = graph.Edgelist[j].weight; if (Distance[startNode].Cost != float.MaxValue && ((Distance[startNode].Cost + w) < Distance[endtNode].Cost)) // checks if the edge originates from a source node and if the cost of destination node is higher than the cost of movement from source node { Distance[endtNode].Cost = Distance[startNode].Cost + w; // updates the cost if its higher than the traversal cost Distance[endtNode].prevNode = startNode; // updates the previous node of the destination node as the source node of the edge. } } } //foreach (KeyValuePair<MyNodes, NodeValue> pair in Distance) //{ // Debug.Log("Coordinates: " + pair.Key.x + "," + pair.Key.y + "Cost: " + pair.Value.Cost); //} path = new Stack <MyNodes>(); // creates a stack for the path. path.Push(Destination); // pushes the destination node as the first input. while (Distance[path.Peek()].prevNode.ID != sourceNode.ID) // while the previous node is not the source node of the 1st node in stack { path.Push(Distance[path.Peek()].prevNode); // pushes in the previous node. } ShowPath = true; // gives the green light to start showing the path. }
protected BaseNode(MyNodes nodeType, String name) : base(name) { this.NodeType = nodeType; }
//////////////////////////////////////////////////////////// User Input Functions ////////////////////////////////////////////////////////////////////////// void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) // these three modes let you choose what type of setting you wish to make for the grid { Debug.Log("Add Wall"); wallMode = true; endMode = false; startMode = false; } if (Input.GetKeyDown(KeyCode.Alpha2)) { Debug.Log("Set source node"); wallMode = false; endMode = false; startMode = true; } if (Input.GetKeyDown(KeyCode.Alpha3)) { Debug.Log("Set end node"); wallMode = false; endMode = true; startMode = false; } if (Input.GetMouseButtonDown(0) && wallMode) { x = (Input.mousePosition.x - Input.mousePosition.x % 50) / 50; //deciphers the coordinates on the grid where we click y = (Input.mousePosition.y - Input.mousePosition.y % 50) / 50; //Debug.Log(x + " " + y); GameObject gO = Instantiate(buttonPrefab, GameObject.Find("Canvas").GetComponent <Transform>().Find("Buttons").GetComponent <Transform>()) as GameObject; // creates a button object on the grid to show a wall gO.transform.position = Cm.ViewportToScreenPoint(new Vector3((x / 16) + 1 / 32f, (y / 12) + 1 / 24f, 0)); // places the object at the correct grid foreach (MyNodes node in graph.Nodelist) { if (node.x == x && node.y == y) { if (!(notToUse.Contains(node.ID))) // checks which node has these coordinates and adds its ID to a list. { notToUse.Add(node.ID); } //graph.Nodelist.Remove(node); // attempts to remove that node from the list // node.setUsability(0); // attempts to set usabilty as non usable //Debug.Log("Unusable Node: " + node.x + "," + node.y + "-usability(" + node.isUsable + ")"); } } } if (Input.GetMouseButtonDown(0) && endMode && !endpointExists) // while endmode is on, alllows you to set the destination only once { x = (Input.mousePosition.x - Input.mousePosition.x % 50) / 50; // this bit works the same as the wallmode except the prefab is different y = (Input.mousePosition.y - Input.mousePosition.y % 50) / 50; GameObject gO = Instantiate(endPrefab, GameObject.Find("Canvas").GetComponent <Transform>().Find("Buttons").GetComponent <Transform>()) as GameObject; gO.transform.position = Cm.ViewportToScreenPoint(new Vector3((x / 16) + 1 / 32f, (y / 12) + 1 / 24f, 0)); endpointExists = true; foreach (MyNodes node in graph.Nodelist) { if ((x == node.x) && (y == node.y)) { Destination = node; // stores the reference to the node chosen to be the destination Debug.Log("Destination Node Coordinates : " + Destination.x + "," + Destination.y); } } } if (Input.GetMouseButtonDown(0) && startMode && !startPointExists) // allows the setting of initial point { x = (Input.mousePosition.x - Input.mousePosition.x % 50) / 50; // this also works the same as the wall mode with different prefab y = (Input.mousePosition.y - Input.mousePosition.y % 50) / 50; GameObject gO = Instantiate(objectPrefab, GameObject.Find("Canvas").GetComponent <Transform>().Find("Buttons").GetComponent <Transform>()) as GameObject; gO.transform.position = Cm.ViewportToScreenPoint(new Vector3((x / 16) + 1 / 32f, (y / 12) + 1 / 24f, 0)); startPointExists = true; foreach (MyNodes node in graph.Nodelist) { if ((x == node.x) && (y == node.y)) { Source = node; // stores the reference to the node chosen to be the source. Debug.Log("Start Node Coordinates : " + Source.x + "," + Source.y); } } } if (Input.GetKeyDown(KeyCode.Space)) // initiates the creation of edges and applies the path finding algorithm function after that { //foreach (MyNodes node in graph.Nodelist) //{ // Debug.Log("ID: " + node.ID + ", Coordinates: " +node.x + "," + node.y + " , Usability: " + node.isUsable); //} //foreach(int i in notToUse) //{ // Debug.Log(i); //} CreateEdges(); BellmanFordAlgo(graph, Source); } }
public NodeValue(MyNodes prevnode, float cost) { prevNode = prevnode; Cost = cost; }
public MyEdges(MyNodes a, MyNodes b, float w) { weight = w; A = a; B = b; }
public void Execute(int index) { ID = I * 12 + index; NodeList[index] = new MyNodes(I, index, ID); }