public bool CyclesControl(WorldDynamic currentState, PlanAction action, StoryGraph currentGraph, KeyValuePair <AgentStateStatic, AgentStateDynamic> agent, StoryNode currentNode, bool duplicated, int globalNodeNumber, bool succsessControl) { bool result = false; // We create a test node similar to the one we are going to add to the graph as a result of the current action. StoryNode testNode = currentGraph.CreateTestNode(currentState, action, agent, currentNode, !duplicated, globalNodeNumber, succsessControl); StoryNode duplicatedNode = null; Edge testEdge = new Edge(); if (!duplicated) { duplicatedNode = currentGraph.GetNode(testNode); if (currentNode.Equals(duplicatedNode)) { return(false); } testEdge.SetUpperNode(ref currentNode); testEdge.SetLowerNode(ref duplicatedNode); currentNode.AddEdge(testEdge); duplicatedNode.AddEdge(testEdge); currentNode.AddLinkToNode(ref duplicatedNode); duplicatedNode.AddLinkToNode(ref currentNode); } string[] colors = new string[currentGraph.GetNodes().Count + 2]; for (int i = 0; i < currentGraph.GetNodes().Count + 2; i++) { colors[i] = "white"; } result = TarjanAlgStep(currentGraph.GetRoot(), ref colors, !duplicated, duplicatedNode); if (!duplicated) { currentNode.RemoveEdge(testEdge); currentNode.DeleteLink(duplicatedNode); duplicatedNode.RemoveEdge(testEdge); duplicatedNode.DeleteLink(currentNode); testEdge.ClearUpperNode(); testEdge.ClearLowerNode(); testEdge = null; } // We delete the test node and mark the loop test as passed. currentGraph.DeleteTestNode(ref testNode); return(result); }
/// <summary> /// /// </summary> /// <param name="firstNode">Current node</param> /// <param name="secondNode">New node</param> public void ConnectionTwoNodes(PlanAction action, StoryNode firstNode, StoryNode secondNode, bool duplicate) { Edge newEdge = new Edge(); newEdge.SetAction(action); newEdge.SetUpperNode(ref firstNode); newEdge.SetLowerNode(ref secondNode); firstNode.AddEdge(newEdge); secondNode.AddEdge(newEdge); firstNode.AddLinkToNode(ref secondNode); secondNode.AddLinkToNode(ref firstNode); if (firstNode.GetEdges().Count != firstNode.GetLinks().Count) { bool test = true; } }