private IEnumerator ReverseRemoveCurrentNode(NodeRepresentation nodeRep, bool moveOther) { graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, false); if (!moveOther) { // Move element back into stack Vector3 onTopOfStack = NextElementPositionOnTopOfList() - oneListIndexUp; nodeRep.MoveNodeRepresentation(onTopOfStack); nodeRep.SetGravity(false); yield return(mediumDuration); nodeRep.SetGravity(true); } else { // Disable gravity of swapping node reps int lastNodeRep = nodeRepresentations.Count - 1; SetGravityForMultipleNodeReps(0, lastNodeRep, false); // First move all other node representations up yield return(MoveOtherNodes(0, lastNodeRep, false)); // Move element back into list nodeRep.MoveNodeRepresentation(spawnPointList.position); yield return(smallDuration); // Enable gravity of swapping node reps SetGravityForMultipleNodeReps(0, lastNodeRep, true); } graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, true); graphMain.WaitForSupportToComplete--; }
// Move other nodes up/down to make spot for <..>, changing their list index and position private IEnumerator MoveOtherNodes(int start, int end, bool increment) { // Fix gravity outside this method // Move all existing list elements up (from the point where we want to insert the new element) *** Copied - <--- Methods made for (int i = start + 1; i <= end; i++) //for (int i=listObjects.Count-1; i >= index; i--) { NodeRepresentation involvedNodeRep = nodeRepresentations[i]; // Find new position and move it Vector3 newPos = involvedNodeRep.transform.position + oneListIndexUp; // new Vector3(0f, 1f, 0f); <- oneListIndexUp involvedNodeRep.MoveNodeRepresentation(newPos); if (increment) { involvedNodeRep.ListIndex = i - 1; nodeRepresentations[i - 1] = involvedNodeRep; } else { if (i + 1 > nodeRepresentations.Count - 1) { Debug.Log("Stop!.."); continue; } involvedNodeRep.ListIndex = i + 1; nodeRepresentations[i + 1] = involvedNodeRep; } yield return(involvedNodeRep.HighlightNodeRepresentation(UtilGraph.DIST_UPDATE_COLOR, seconds)); // 1f); } }
private static void RefreshStatusAuxiliary(string workerId) { IWorker w = NetworkManager.GetRemoteWorkersObj()[workerId]; IDictionary <string, string> result = w.Status(); NodeRepresentation nodeRep = new NodeRepresentation(result); NetworkManager.UpdateNodeInformation(workerId, nodeRep); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.server.rest.repr.NodeRepresentation getNode(long nodeId) throws NodeNotFoundException public override NodeRepresentation GetNode(long nodeId) { using (Transaction transaction = _graph.beginTx()) { NodeRepresentation node = base.GetNode(nodeId); transaction.Success(); return(node); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.server.rest.repr.NodeRepresentation createNode(java.util.Map<String, Object> properties, org.neo4j.graphdb.Label... labels) throws PropertyValueException public override NodeRepresentation CreateNode(IDictionary <string, object> properties, params Label[] labels) { using (Transaction transaction = _graph.beginTx()) { NodeRepresentation nodeRepresentation = base.CreateNode(properties, labels); transaction.Success(); return(nodeRepresentation); } }
// --------------------------------------- Reset / Destroy --------------------------------------- public void DestroyAndReset() { // Destroy list objects ClearList(); // Reset variables nodeRepresentations = null; currentNode = null; seconds = 0f; }
// Adding a visual representation of the node public void AddListObject(Node node) { // Update roof to prevent list element to become buggy (jumping, shaking etc.) UpdateListRoofPosition(); // Find position and index Vector3 pos = NextElementPositionOnTopOfList(); int index = nodeRepresentations.Count; // Create object and add to list NodeRepresentation newNodeRep = CreateNodeRepresentation(node, pos, index); nodeRepresentations.Add(newNodeRep); }
// Swap 1 by 1: Not implemented/used private void SwapPositionsOf(NodeRepresentation np1, NodeRepresentation np2) { np1.SetGravity(false); np2.SetGravity(false); Debug.Log("Switching"); Vector3 np1MoveLeft = np1.transform.position + new Vector3(-0.5f, 0f, 0f); np1.MoveNodeRepresentation(np1MoveLeft); Vector3 np2MoveRight = np2.transform.position + new Vector3(0.5f, 0f, 0f); np2.MoveNodeRepresentation(np2MoveRight); Debug.Log("Done switching"); }
// Moves the removed element to the 'current node' spot private void MoveCurrentNode(NodeRepresentation currentNodeRep, bool moveOther) { UpdateListIndexes(); // Move object to current node location currentNodeRep.MoveNodeRepresentation(currentNodePoint.position); currentNodeRep.CurrentColor = UtilGraph.TRAVERSE_COLOR; currentNodeRep.name = name = "NodeRep " + currentNodeRep.Node.NodeAlphaID + " (X)"; if (moveOther) { // Move other elements in Queue/Priority list foreach (NodeRepresentation otherobj in nodeRepresentations) { otherobj.MoveNodeRepresentation(otherobj.transform.position - oneListIndexUp); //new Vector3(0f, 1f, 0f)); } } }
private void Update() { if (useDebugText) { if (nodeRepresentations != null && timeForDebugUpdate) { debuggingText.text = ""; for (int i = nodeRepresentations.Count - 1; i >= 0; i--) { NodeRepresentation noderep = nodeRepresentations[i]; debuggingText.text += "Node: " + noderep.Node.NodeAlphaID + ", index: " + noderep.ListIndex + "\n"; // + " | name = " + noderep.name + "\n\n"; } if (currentNode != null) { debuggingText.text += "Current node: " + currentNode.Node.NodeAlphaID + ", index: " + currentNode.ListIndex; // + " | name = " + currentNode.name; } timeForDebugUpdate = false; } } }
// Adding a visual representation of the node, with priority based on its distance value) public void PriorityAdd(Node node, int index) { UpdateListRoofPosition(); // Move all existing list elements up (from the point where we want to insert the new element) for (int i = 0; i < index; i++) { // Remove gravity to make it easier to move the objects nodeRepresentations[i].GetComponent <Rigidbody>().useGravity = false; // Find new position and move it Vector3 newPos = nodeRepresentations[i].transform.position + oneListIndexUp; // new Vector3(0f, 1f, 0f); nodeRepresentations[i].GetComponent <MoveObject>().SetDestination(newPos); } // Add new element into the open slot Vector3 pos = spawnPointList.position + oneListIndexUp * (nodeRepresentations.Count - index); // new Vector3(0f, 1f, 0f) <- oneListIndexUp NodeRepresentation newPrioNodeRep = CreateNodeRepresentation(node, pos, index); //newPrioNodeRep.GetComponent<TextHolder>().SetSurfaceText(node.NodeAlphaID, node.Dist); newPrioNodeRep.UpdateSurfaceText(UtilGraph.VISITED_COLOR); newPrioNodeRep.MoveNodeRepresentation(pos); nodeRepresentations.Insert(index, newPrioNodeRep); // Change color of the node representation we are looking for if (node.IsEndNode) { newPrioNodeRep.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR; } // Enable gravity again and update indexes for (int i = 0; i < nodeRepresentations.Count; i++) { NodeRepresentation nodeRep = nodeRepresentations[i]; nodeRep.SetGravity(true); nodeRep.ListIndex = i; } }
// Removes the next element from the list/queue/stack public void RemoveCurrentNode() { switch (listType) { case Util.QUEUE: currentNode = nodeRepresentations[0]; // change to queue for dequeuing instead? nodeRepresentations.RemoveAt(0); MoveCurrentNode(currentNode, true); break; case Util.STACK: currentNode = nodeRepresentations[nodeRepresentations.Count - 1]; nodeRepresentations.RemoveAt(nodeRepresentations.Count - 1); MoveCurrentNode(currentNode, false); break; case Util.PRIORITY_LIST: currentNode = nodeRepresentations[nodeRepresentations.Count - 1]; nodeRepresentations.RemoveAt(nodeRepresentations.Count - 1); MoveCurrentNode(currentNode, true); break; } }
// Instructions from the New Demo/Step-by-step public void ExecuteInstruction(ListVisualInstruction instruction, bool increment) { switch (instruction.Instruction) { case UtilGraph.ADD_NODE: if (increment) { AddListObject(instruction.Node); } else { // Reverse of adding: Find node, remove it from the list, and destroy it NodeRepresentation nodeRep = FindNodeRepresentation(instruction.Node); if (nodeRep != null) { nodeRepresentations.Remove(nodeRep); Destroy(nodeRep.gameObject); } } break; case UtilGraph.PRIORITY_ADD_NODE: if (increment) { PriorityAdd(instruction.Node, instruction.Index); } else { NodeRepresentation nodeRep = FindNodeRepresentation(instruction.Node); nodeRepresentations.Remove(nodeRep); Destroy(nodeRep.gameObject); // Fix other indexes???? } break; case UtilGraph.REMOVE_CURRENT_NODE: if (increment) { RemoveCurrentNode(); } else { // Reverse of removing current node: insert and move it back into the list currentNode.CurrentColor = Color.white; graphMain.WaitForSupportToComplete++; switch (listType) { case Util.QUEUE: nodeRepresentations.Insert(0, currentNode); currentNode.ListIndex = 0; StartCoroutine(ReverseRemoveCurrentNode(currentNode, true)); break; case Util.STACK: nodeRepresentations.Add(currentNode); currentNode.ListIndex = nodeRepresentations.Count - 1; StartCoroutine(ReverseRemoveCurrentNode(currentNode, false)); break; case Util.PRIORITY_LIST: nodeRepresentations.Insert(0, currentNode); currentNode.ListIndex = instruction.Index; StartCoroutine(ReverseRemoveCurrentNode(currentNode, true)); break; } } break; case UtilGraph.DESTROY_CURRENT_NODE: if (increment) { DestroyCurrentNode(); } else { // Reverse of destroying: Instantiate a new one and place it in the current node spot currentNode = CreateNodeRepresentation(instruction.Node, currentNodePoint.position, -1); currentNode.CurrentColor = UtilGraph.TRAVERSE_COLOR; } break; case UtilGraph.SET_START_NODE_DIST_TO_ZERO: if (!increment) { instruction.Node.Dist = UtilGraph.INF; } FindNodeRepresentation(instruction.Node).UpdateSurfaceText(UtilGraph.DIST_UPDATE_COLOR); break; case UtilGraph.HAS_NODE_REPRESENTATION: /* This case has two outcomes: * 1) If the node doesn't have any node representations in the current list, then create and add a new one * 2) There is currently a node representation, so update this one */ Node node = instruction.Node; int index = instruction.Index; if (increment) { instruction.HasNodeRepresentation = HasNodeRepresentation(node); } if (!instruction.HasNodeRepresentation) // Case 1 { if (increment) { PriorityAdd(node, index); } else { ExecuteInstruction(new ListVisualInstruction(UtilGraph.PRIORITY_ADD_NODE, instruction.InstructionNr, node), false); } } else // Case 2 { if (increment) { graphMain.WaitForSupportToComplete++; StartCoroutine(UpdateValueAndPositionOf(node, index, increment)); } } break; case UtilGraph.END_NODE_FOUND: // Start backtracking if (increment) { graphMain.GetTeachingAlgorithm().PseudoCodeViewer.DestroyContent(); } else { graphMain.GetTeachingAlgorithm().PseudoCodeViewer.PseudoCodeSetup(); } break; case UtilGraph.PREPARE_BACKTRACKING: if (increment) { CreateBackTrackList(instruction.Node); //RemoveCurrentNode(); } else { Debug.Log("Nein...."); } break; case UtilGraph.BACKTRACK_REMOVE_CURRENT_NODE: if (increment) { DestroyCurrentNode(); RemoveCurrentNode(); if (graphMain.Settings.Difficulty < Util.EXAMINATION) { instruction.Node.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR; if (instruction.BacktrackEdge != null) { instruction.BacktrackEdge.CurrentColor = UtilGraph.SHORTEST_PATH_COLOR; } } } else { instruction.Node.CurrentColor = UtilGraph.TRAVERSED_COLOR; if (instruction.BacktrackEdge != null) { instruction.BacktrackEdge.CurrentColor = UtilGraph.VISITED_COLOR; } ExecuteInstruction(new ListVisualInstruction(UtilGraph.REMOVE_CURRENT_NODE, Util.NO_INSTRUCTION_NR), false); } break; default: Debug.Log("List visual instruction '" + instruction.Instruction + "' invalid."); break; } timeForDebugUpdate = true; }
// Updates value and position of one node representation and other involved node reps. public IEnumerator UpdateValueAndPositionOf(Node node, int index, bool increment) { graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, false); Color prevColor = node.CurrentColor; node.CurrentColor = UtilGraph.DIST_UPDATE_COLOR; // Node representation we want to move NodeRepresentation mainNodeRep = FindNodeRepresentation(node); // Update surface text mainNodeRep.UpdateSurfaceText(UtilGraph.DIST_UPDATE_COLOR); // Moving from index int mainNodeRepIndex = mainNodeRep.ListIndex; //Debug.Log("Updating value of node '" + node.NodeAlphaID + "'. Current index=" + currentNodeRepIndex + " == " + nodeRepresentations.IndexOf(nodeRep) + " ???"); // Check if index changed if (mainNodeRepIndex - index != 0) { // Disable gravity of swapping node reps SetGravityForMultipleNodeReps(0, index, false); // Move node left and down Vector3 moveLeft = mainNodeRep.transform.position + new Vector3(-1f, 0f, 0f); mainNodeRep.MoveNodeRepresentation(moveLeft); yield return(smallDuration); if (increment) { int moveDownYpos = mainNodeRepIndex - index; Vector3 moveDown = mainNodeRep.transform.position + new Vector3(-1f, moveDownYpos, 0f); mainNodeRep.MoveNodeRepresentation(moveDown); yield return(mediumDuration); // Move all the other involved up yield return(MoveOtherNodes(mainNodeRepIndex, index, true)); } else { // Backward step (Move node representation up) int moveUpYpos = index - mainNodeRepIndex; Vector3 moveUp = mainNodeRep.transform.position + new Vector3(-1f, moveUpYpos, 0f); mainNodeRep.MoveNodeRepresentation(moveUp); yield return(mediumDuration); // Move all the other involved down yield return(MoveOtherNodes(mainNodeRepIndex, index, false)); } // Move back into list Vector3 backInTheList = new Vector3(spawnPointList.position.x, mainNodeRep.transform.position.y, mainNodeRep.transform.position.z); mainNodeRep.MoveNodeRepresentation(backInTheList); //nodeRep.UpdateIndexPosition(index); mainNodeRep.ListIndex = index; nodeRepresentations[index] = mainNodeRep; yield return(mainNodeRep.HighlightNodeRepresentation(UtilGraph.DIST_UPDATE_COLOR, seconds)); // 1f); // Enable gravity again SetGravityForMultipleNodeReps(0, index, true); } node.CurrentColor = prevColor; graphMain.UpdateCheckList(UtilGraph.LIST_VISUAL, true); graphMain.WaitForSupportToComplete--; }
private static void RefreshStatusAuxiliary(string workerId) { IWorker w = NetworkManager.GetRemoteWorkersObj()[workerId]; IDictionary<string, string> result = w.Status(); NodeRepresentation nodeRep = new NodeRepresentation(result); NetworkManager.UpdateNodeInformation(workerId, nodeRep); }