public static NFA_GRAPH Create_NFAKleeneClosure(NFA_GRAPH nfaGraph) { NFA_GRAPH newGraph = null; if (nfaGraph != null) { nfaGraph.startNode.nodeType = NODE_TYPE.TRANSITIONING; nfaGraph.endNode.nodeType = NODE_TYPE.TRANSITIONING; NODE startNode = NODE.CreateNode(NODE_TYPE.START); NODE endNode = NODE.CreateNode(NODE_TYPE.END); EDGE endEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); nfaGraph.endNode.edges.Add(endEdge); EDGE endToStartEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, nfaGraph.startNode); nfaGraph.endNode.edges.Add(endToStartEdge); EDGE newStartToStartEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, nfaGraph.startNode); startNode.edges.Add(newStartToStartEdge); EDGE newStartToNewEndEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); startNode.edges.Add(newStartToNewEndEdge); newGraph = new NFA_GRAPH(startNode, endNode); } return(newGraph); }
private bool AreNodesEquivalent(NODE nodeOne, NODE nodeTwo) { bool areEquivalent = true; if (nodeOne != null && nodeTwo != null) { if (AreEdgesEquivalent(nodeOne.edges, nodeTwo.edges)) { for (int i = 0; i < nodeOne.edges.Count; i++) { if (nodeOne.edges[i].nextNode != nodeTwo.edges[i].nextNode) { areEquivalent = false; } } } else { areEquivalent = false; } } else { areEquivalent = false; } return(areEquivalent); }
/// <summary> /// This function gets geodesic distance from multiple sources to the rest of the mesh. /// The points in sources are set as 0s, and the propagation goes to the entire mesh. /// NOTES: /// Inserted points are ignored on return. /// Once can use this function to employ segmentation by propagating from /// different sources, like floodfill. /// </summary> /// <param name="sources"></param> /// <returns></returns> public double[] GetGeodesicDistance(int[] sources, double[] sourceDistances) { int n = this.nodes.Count; PriorityQueue queue = new PriorityQueue(n); for (int i = 0; i < n; i++) { this.nodes[i].parent = null; this.nodes[i].distance = double.MaxValue; } if (sourceDistances == null) { foreach (int v in sources) { this.nodes[v].distance = 0; } } else { int index = 0; foreach (int v in sources) { this.nodes[v].distance = sourceDistances[index++]; } } for (int i = 0; i < n; i++) { queue.Insert(this.nodes[i]); } while (queue.IsEmpty() == false) { NODE minRecord = queue.DeleteMin() as NODE; foreach (EDGE adjEdge in minRecord.adjEdges) { double dis = adjEdge.length + minRecord.distance; int adj = adjEdge.I == minRecord.index ? adjEdge.J : adjEdge.I; if (dis < this.nodes[adj].distance) { this.nodes[adj].distance = dis; this.nodes[adj].parent = this.nodes[minRecord.index]; if (!queue.IsEmpty()) { queue.Update(this.nodes[adj]); } } } } double[] distance = new double[n]; for (int i = 0; i < mesh.VertexCount; i++) { distance[i] = this.nodes[i].distance; } return(distance); }
public void SetTarget(NODE _target) { target = _target; Vector3 temp = target.transform.position; temp.z = -2; temp.y -= 5; transform.position = temp; ui.SetActive(true); if (_target.turret.tag == "path" | _target.turret.tag == "UpgradedTurret") { NodeUICanvas.sizeDelta = new Vector2(950, 500); UpgradeButtom.SetActive(false); SellButtom.GetComponent <RectTransform>().localPosition = new Vector2(0, 0); SellBlock.GetComponent <RectTransform>().localPosition = new Vector2(0, 0); } else { NodeUICanvas.sizeDelta = new Vector2(950, 1000); UpgradeButtom.SetActive(true); SellButtom.GetComponent <RectTransform>().localPosition = new Vector2(0, -250); SellBlock.GetComponent <RectTransform>().localPosition = new Vector2(0, -250); } GameObject drawcircle = target.GetComponent <NODE>().turret; #if UNITY_EDITOR Selection.activeGameObject = drawcircle; #endif setprice(); }
/// <summary> /// The NODE to model. /// </summary> /// <param name="node"> /// The node DataModel. /// </param> /// <returns> /// The <see cref="Node"/>. /// </returns> public static Node ToModel(this NODE node) { if (node == null) { return(null); } Node model = new Node { Created = node.Created, IsDeleted = node.IsDeleted, Modified = node.Modified, NodeId = node.NodeId, OwnerId = node.OwnerId, Text = node.Text, Title = node.Title, Tags = new List <Tag>() }; ITagManager tagManager = new TagManager(); foreach (TAGSET tagset in node.TAGSETS) { model.Tags.Add(tagManager.GetTagById(tagset.TagId)); } return(model); }
public string Search(string value) //Search { NODE temp = Head; //Temporary node to traverse bool state = false; // just to help us in the end of this funtion wehter value is there or not while (temp != null) { if (temp.data == value) { Console.WriteLine("Value Found"); state = true; return(temp.data); // if value found we print then return the value and functions end here } // will not go down further for execution else { temp = temp.next; } } if (state == false) { Console.WriteLine("Value Not Found"); } return("-999"); // if value not found return -999 }
List <NODE> GetRoomList(NODE parentsNode) { List <NODE> roomList = new List <NODE>(); //Current Node is TerminalNode if (parentsNode.roomInfo != null) { roomList.Add(parentsNode); } else { Queue <NODE> bfsQueue = new Queue <NODE>(); bfsQueue.Enqueue(parentsNode); NODE curNode; while (bfsQueue.Count > 0) { curNode = bfsQueue.Dequeue(); if (curNode.roomInfo != null) { roomList.Add(curNode); } else { bfsQueue.Enqueue(curNode.left); bfsQueue.Enqueue(curNode.right); } } } return(roomList); }
protected internal override long FetchNext() { Ktx.assertOpen(); while (Cursor.next()) { long reference = Cursor.nodeReference(); if (Ktx.dataRead().nodeExists(reference)) { return(reference); } else if (Ktx.securityContext().mode().allowsWrites()) { //remove it from index so it doesn't happen again try { NODE.remove(Ktx.indexWrite(), Name, reference); } catch (Exception e) when(e is ExplicitIndexNotFoundKernelException || e is InvalidTransactionTypeKernelException) { //ignore } } } Close(); return(NO_ID); }
public NondeterministicNode(List <double> dp, Move action, NODE type) { this.dp = dp; this.action = action; this.type = type; this.name = Constant.NONDETERMINISTIC_NODE; }
public void SelectNode(NODE node) { selectednode = node; turretToBuild = null; nodeui.gameObject.SetActive(true); nodeui.SetTarget(node); }
static void Main(string[] args) { /////////////////// //load data node NODE[] node = new NODE[DataCounter()]; DataLoad(node); /* * //data normalization * dataNormal(node); */ //////////////////// //math kMeans KMeans(node); ////////////////////// //math level in group LinKG(node); //////////////////// //math level ReMathLG(node); Level(node); ///////////////// //write to csv WriteToCsv(node); ////end System.Console.WriteLine("\nPress any key to continue....."); System.Console.ReadLine(); }
public void Delete(T remove) { if (remove.Equals(Top.Data)) { Top = Top.Next; return; } NODE temp = Top; while (temp != null) { if (temp.Next.Data.Equals(remove)) { NODE prev = temp; NODE del = temp.Next.Next; prev.Next = del; if (del != null) { del.Prev = prev; } return; } else { temp = temp.Next; } } }
private void CollectCandidates(int tileX, int tileZ, int targetX, int targetZ, NODE previousNode) { int step = (previousNode == null)? 1: (previousNode.step + 1); // MapGrid_hexagon.COORD[] tileCoords = GetSurroundHexagonTileCoord (tileX, tileZ); COORD[] tileCoords = GetSurroundSquareTileCoord(tileX, tileZ); foreach (COORD c in tileCoords) { if (_mapGrid.IsBlock(c.x, c.z)) { continue; } int index = _mapGrid.GetGridIndex(c.x, c.z); if (_gridTicket[index] == _currentTicket) { continue; } _gridTicket[index] = _currentTicket; int hot = _mapGrid.GetGridHotField(c.x, c.z); int dist = (Mathf.Abs(targetX - c.x) + Mathf.Abs(targetZ - c.z)); float weight = step + dist + hot * 0.5f; NODE node = new NODE(); node.step = step; node.x = c.x; node.z = c.z; node.weight = weight; node.previousNode = previousNode; InsertCandidate(node); } }
public void Delete(string value) //DELETE { NODE current = Head; NODE tempPrevious = null; if (IsEmpty() == true) // same as Head==null using the function !! OPtional one above { Console.WriteLine("LINKEDLIST IS EMPTY"); } else { if (Head.data == value) // if Head is the value to be deleted then we simply do this !! { Head = Head.next; } else { while (current != null) { if (current.data == value) { tempPrevious.next = current.next; current = null; } else { tempPrevious = current; current = current.next; } } } } }
public void BtnConnectionClick() { BtnIntersection.enabled = true; BtnConnection.enabled = false; BtnSpawner.enabled = true; node = NODE.CONNECTION; }
public Node CreateNode(Node newNode) { NodeValidator nodeValidator = new NodeValidator(); nodeValidator.Validate(newNode); using (IdeaStorageEntities context = new IdeaStorageEntities()) { NODE newDbNode = new NODE { Created = newNode.Created, IsDeleted = newNode.IsDeleted, Modified = newNode.Modified, OwnerId = newNode.OwnerId, Text = newNode.Text, Title = newNode.Title }; TagManager tagManager = new TagManager(); foreach (Tag tag in newNode.Tags) { tag.TagId = tagManager.CreateTag(tag).TagId; context.TAGSETS.Add(new TAGSET { NodeId = newDbNode.NodeId, TagId = tag.TagId }); } context.NODES.Add(newDbNode); context.SaveChanges(); return(newDbNode.ToModel()); } }
public NODE <Type> this[int i] { get { int k = 0; NODE <Type> temp = head; while (temp != null) { if (k == i) { return(temp); } k++; temp = temp.next; } return(null); } set { int k = 0; NODE <Type> temp = head; while (temp != null) { if (k == i) { temp = value; } k++; temp = temp.next; } } }
void OnDrawGizmos() { Gizmos.DrawWireCube(transform.position, new Vector2(gridSize.x, gridSize.y)); if (grid != null) { NODE playerNode = NODEFromWorldPoint(player.position); NODE enemyNode = NODEFromWorldPoint(enemy.position); foreach (NODE n in grid) { Gizmos.color = (n.walkable) ? Color.green : Color.red; if (playerNode == n) { Gizmos.color = Color.yellow; } if (enemyNode == n) { Gizmos.color = Color.cyan; } if (path != null) { if (path.Contains(n)) { Gizmos.color = Color.black; } } Gizmos.DrawCube(n.position, Vector2.one * (nodeDiameter - .3f)); } } }
// Use this for initialization void Start() { startnode.isStartNode = true; GameObject Path = Instantiate(PathPrefab, transform.position, Quaternion.identity); NODE node = GetComponent <NODE>(); node.turret = Path; }
public Montecarlo() { for (int idx = 0; idx < NODE_MAX; idx++) { node[idx] = new NODE(); node[idx].child = new CHILD[CHILD_MAX]; } }
private void _AppendWorkingSet(NODE node) { if (_WorkingSet.Contains(node)) { return; } _WorkingSet.Add(node); }
public DeterministicNode(BoardState state, Move action, NODE type, int piece, double probability) { this.board = new Board(state); this.action = action; this.type = type; this.piece = piece; this.probability = probability; }
protected internal Arc(NODE sourceNode, NODE targetNode, IN input, OUT output) { // makes a copy of Arc a this.sourceNode = sourceNode; this.targetNode = targetNode; this.input = input; this.output = output; }
void ReBuild(string pPreOrder, string pInOrder, int nTreeLen, NODE pRoot) { if (pPreOrder == NULL || pInOrder == NULL) { return; } NODE pTemp = new NODE; pTemp->chValue = *pPreOrder; pTemp->pLeft = NULL; pTemp->pRight = NULL; if (*pRoot == NULL) { *pRoot = pTemp; } if (nTreeLen == 1) { return; } char* pOrgInOrder = pInOrder; char* pLeftEnd = pInOrder; int nTempLen = 0; while (*pPreOrder != *pLeftEnd) { if (pPreOrder == NULL || pLeftEnd == NULL) { return; } nTempLen++; if (nTempLen > nTreeLen) { break; } pLeftEnd++; } int nLeftLen = 0; nLeftLen = (int)(pLeftEnd - pOrgInOrder); int nRightLen = 0; nRightLen = nTreeLen - nLeftLen - 1; if (nLeftLen > 0) { ReBuild(pPreOrder + 1, pInOrder, nLeftLen, &((*pRoot)->pLeft)); } if (nRightLen > 0) { ReBuild(pPreOrder + nLeftLen + 1, pInOrder + nLeftLen + 1, nRightLen, &((*pRoot)->pRight)); } }
////Level in KG static void LinKG(NODE[] n) { int maxKG = 0; for (int i = 0; i < n.Length; i++) { if (n[i].KGroup > maxKG) { maxKG = n[i].KGroup; } } //math for (int i = 0; i <= maxKG; i++) { //creat seed int NodeCounter = 0; for (int j = 0; j < n.Length; j++) { if (n[j].KGroup == i) { NodeCounter++; } } if (NodeCounter == 0) { continue; } NODE[] tempN = new NODE[NodeCounter]; int counter = 0; for (int j = 0; j < n.Length; j++) { if (n[j].KGroup == i) { tempN[counter].x = n[j].x; tempN[counter].y = n[j].y; tempN[counter].LGroup = counter; counter++; } } Level(tempN); //reWrite n counter = 0; for (int j = 0; j < n.Length; j++) { if (n[j].KGroup == i) { n[j].LGroup = tempN[counter].LGroup; n[j].Distance = tempN[counter].Distance; counter++; } } } }
/* calculates the distance between two nodes */ static int node_dist(NODE n1, NODE n2) { int SCALE = 64; int dx = itofix(n1.x - n2.x) / SCALE; int dy = itofix(n1.y - n2.y) / SCALE; return(fixsqrt(fixmul(dx, dx) + fixmul(dy, dy)) * SCALE); }
void InOrder(NODE pRoot) { if (pRoot != NULL) { InOrder(pRoot->pLeft); cout << pRoot->chValue << " "; InOrder(pRoot->pRight); } }
void PreOrder(NODE pRoot) { if (pRoot != NULL) { cout << pRoot.chValue << " "; PreOrder(pRoot->pLeft); PreOrder(pRoot->pRight); } }
public NODE <Type> GetLastNode(SingleLinkedList <Type> singlyList) { NODE <Type> temp = singlyList.head; while (temp.next != null) { temp = temp.next; } return(temp); }
public void Foreach(Action <T> action) { NODE temp = Top; while (temp != null) { action(temp.Data); temp = temp.Next; } }
public IEnumerator <NAME> GetEnumerator() { int n = graph.NameSpace.BijectFromBasetype(name); NODE node = graph.VertexSpace[n]; foreach (EDGE e in node._Successors) { yield return(e.To); } }
/* constructs nodes to go at the ends of the list, for tangent calculations */ static NODE dummy_node(NODE node, NODE prev) { NODE n; n.x = node.x - (prev.x - node.x) / 8; n.y = node.y - (prev.y - node.y) / 8; n.tangent = itofix(0); return(n); }
public GNode(NODE node, GNode predecessor, SCFGBuilder builder) { this.astNode = node; successors = new LinkedList <GNode>(); if (predecessor != null) { predecessor.successors.AddLast(this); } builder.allNodes.AddLast(this); }
// _OnInitialize : Called after all waypoints are registered public void _OnInitialize() { _WorkingSet = new List<NODE>(); _Nodes = new List<NODE>(); // Create a node for each waypoint and initialize it foreach(Component wp in _WayPoints) { NODE node = new NODE(); node._WayPoint = wp; node._IsSealed = false; node._connections = new List<NODE>(); node._PathLength = _INFINITY; node._Path = new List<NODE>(); // Add the node to the collection of nodes _Nodes.Add(node); } // Discover connections between nodes _UpdateConnections(); }
public int read_file(string filename) { string line; System.IO.StreamReader file = new System.IO.StreamReader(filename); bool newNode = false; int lastID = -1; int lastSource = -1; bool newEdge = false; float area = 25.0f; while ((line = file.ReadLine()) != null) { char[] delims = {' '}; string[] words = line.Split(delims); int i = 0; while (i < words.Length) { if (words[i].CompareTo("") == 0) { i++; continue; } else if (words[i].CompareTo("id") == 0) { newNode = true; // add new node to graph, set id as words[i+1] lastID = Convert.ToInt32(words[i + 1]); break; } else if (words[i].CompareTo("label") == 0) { if (newNode) { // get the last node created, add a label // ignore quotations NODE n = new NODE(); n.id = lastID; n.label = words[i + 1]; n.x_pos = Mathf.Floor (Random.Range(-area, area)); n.y_pos = Mathf.Floor (Random.Range(-area, area)); n.z_pos = Mathf.Floor (Random.Range(-area, area)); n.temp_x = -50.0f; n.temp_y = -50.0f; n.temp_z = -50.0f; n.edgeList = new List<EDGE> (); graph.nodes.Add(n.id, n); graph.n_nodes++; newNode = false; lastID = -1; break; } else { // unknown id read, no label accompanying break; } } else if (words[i].CompareTo("source") == 0) { newEdge = true; // add new edge from indexes lastSource = Convert.ToInt32(words[i + 1]); break; } else if (words[i].CompareTo("target") == 0) { if (newEdge) { // get last edge value created EDGE e = new EDGE(); e.source = lastSource; e.target = Convert.ToInt32(words[i + 1]); graph.edges.Insert(graph.n_edges, e); graph.n_edges++; graph.nodes [e.source].edgeList.Add (e); graph.nodes [e.target].edgeList.Add (e); newEdge = false; lastSource = -1; break; } else { // failure break; } } else // ignore any other line, namely "[" and "]" { break; } } } file.Close(); return 1; }
public string[] Get_Path(NODE FINAL) { List<string> PP = new List<string>(); while (FINAL.Parent != null) { PP.Add(ARR_MOVES.Values[ARR_MOVES.IndexOfKey(FINAL.move)]); FINAL.EQUAL(FINAL.Parent); } return PP.ToArray(); }
public string[] AStar_SOLVE_USing_HAMMing(int CASE, string FileName1="TEST.txt") { OPenList = new PaiortyQueue(); size = ARR2D.read_from_file(ARR, CASE, FileName1); NODE X = new NODE(size); X.Parent = null; X.PUZZLE = getACopy(ARR); X.HeuristicValue = Hamming(ARR, size); X.move = ""; X.PuzzleSIze = size; X.COSTSOFAR = 0; X.calac_Total_using_Hamming(); OPenList.push(X); ClosedList = new SortedDictionary<string, NODE>(); if (ChecK_Solved()) { while (OPenList.opendlistsize() != 0) { NODE CURR = new NODE(size); NODE TEMPNODE = new NODE(size); NODE T = new NODE(size); CURR = OPenList.POP(); TEMPNODE.EQUAL(CURR); T.EQUAL(CURR); if (CURR.HeuristicValue == 1) { return Get_Path(CURR); } try { ClosedList.Add(GenerateAKEy(CURR.PUZZLE, CURR.PuzzleSIze), CURR); } catch(Exception E) { MessageBox.Show("OUT OFF MEMORY" , "WRONG" , MessageBoxButtons.OK , MessageBoxIcon.Warning); } //Console.WriteLine("********************************************************"); foreach (KeyValuePair<string, string> it in ARR_MOVES) { bool change = false; ARR2D.SETMAINARRANDTEMP(getACopy(CURR.PUZZLE)); CURR.PUZZLE = ARR2D.GetTempArr(it.Key, ref change); Num_Hamming = Hamming(CURR.PUZZLE, size); if (change) { string CurentKey = GenerateAKEy(CURR.PUZZLE, size); if (ClosedList.ContainsKey(CurentKey)) { NODE NewNode = new NODE(size); ClosedList.TryGetValue(CurentKey, out NewNode); if (Num_Hamming + CURR.COSTSOFAR + 1 < NewNode.TOTAL) { ClosedList.Remove(CurentKey); NODE newnode = new NODE(size); newnode.HeuristicValue = Num_Hamming; newnode.PUZZLE = getACopy(CURR.PUZZLE); newnode.PuzzleSIze = size; newnode.move = it.Key; newnode.COSTSOFAR = TEMPNODE.COSTSOFAR + 1; newnode.calac_Total_using_Hamming(); newnode.Parent = TEMPNODE; OPenList.push(newnode); } } else { NODE newnode = new NODE(size); newnode.HeuristicValue = Num_Hamming; newnode.PUZZLE = getACopy(CURR.PUZZLE); newnode.PuzzleSIze = size; newnode.move = it.Key; newnode.COSTSOFAR = TEMPNODE.COSTSOFAR + 1; newnode.calac_Total_using_Hamming(); newnode.Parent = TEMPNODE; OPenList.push(newnode); } change = false; CURR.PUZZLE = ARR2D.GetTempArr(it.Value, ref change); } } } } return null; }
private void _AppendWorkingSet(NODE node) { if(_WorkingSet.Contains(node)) return; _WorkingSet.Add(node); }
private void _FindPath(NODE nodeStart, NODE nodeEnd) { _StartNode = nodeStart; _EndNode = nodeEnd; // Initialize Dijkstra's Algorithm foreach(NODE node in _Nodes) { node._Path.Clear(); node._PathLength = _INFINITY; node._IsSealed = false; node._IsTraveled = false; } nodeStart._PathLength = 0; nodeStart._Path.Add(nodeStart); _WorkingSet.Clear(); // Verify validity of algorithm if(nodeStart._connections.Count <= 0) return; // FAMOUS: Dijkstra's Algorithm int max_counter = 0; _AppendWorkingSet(nodeStart); while(nodeEnd._IsSealed == false) { if(max_counter++ > 1000) break; for(int nNode1 = 0; nNode1 < _WorkingSet.Count; nNode1++) { NODE node1 = _WorkingSet[nNode1]; if(node1._IsSealed) continue; for(int nNode2 = 0; nNode2 < node1._connections.Count; nNode2++) { NODE node2 = node1._connections[nNode2]; if(node2._IsSealed) continue; _AppendWorkingSet(node2); int edgeLength = 1; // Assume edge length is 1 if((node1._PathLength + edgeLength) < node2._PathLength) { node2._Path.Clear(); node2._Path.AddRange(node1._Path); node2._Path.Add(node2); node2._PathLength = node1._PathLength + edgeLength; } } // Extra stuff to give algorithm early out if(node1._connections.Count > 0) { bool bSealed = true; foreach(NODE node2 in node1._connections) { if(node2 == node1) continue; //if(node2._IsSealed == false) continue; if(node2._PathLength == _INFINITY) bSealed = false; } node1._IsSealed = bSealed; } if(nodeEnd._PathLength < _INFINITY) { if(node1._PathLength > nodeEnd._PathLength) { node1._IsSealed = true; } } } } // Set all the waypoints in the path to illuminate foreach(NODE node in _EndNode._Path) { //node._WayPoint.renderer.enabled = true; } }