public void MediationTreeUpdateTest() { tree = new MediationTree(testDomain, testProblem, pathEvent); MediationTreeNode child = tree.GetNode(tree.Root.Domain, tree.Root.Problem, tree.Root.Outgoing.Find(x => x.ActionType == ActionType.Constituent)); Assert.AreEqual(child.Outgoing.Count, 2); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("move-location")).ActionType, ActionType.Constituent); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("toggle-green")).ActionType, ActionType.Consistent); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("move-location"))); Assert.AreEqual(child.Outgoing.FindAll(x => x.ActionType == ActionType.Constituent).Count, 1); }
public void SuperpositionManipulationTest() { tree = new MediationTree(testDomain, testProblem, pathSuper, false, false, true); List <VirtualMediationTreeEdge> supers = new List <VirtualMediationTreeEdge>(); foreach (MediationTreeEdge edge in tree.Root.Outgoing) { if (edge is VirtualMediationTreeEdge) { supers.Add(edge as VirtualMediationTreeEdge); } } Assert.AreEqual(supers.Count, 1); VirtualMediationTreeNode node = tree.GetNode(tree.Root.Domain, tree.Root.Problem, supers[0]) as VirtualMediationTreeNode; node = tree.GetNode(node.Domain, node.Problem, node.Outgoing.Find(x => x.Action.Name.Equals("toggle-green"))) as VirtualMediationTreeNode; node = tree.GetNode(node.Domain, node.Problem, node.Outgoing[0]) as VirtualMediationTreeNode; Assert.IsTrue(node.Outgoing.Count > 1); node = tree.GetNode(node.Domain, node.Problem, node.Outgoing.Find(x => x.Action.Name.Equals("toggle-red"))) as VirtualMediationTreeNode; node = tree.GetNode(node.Domain, node.Problem, node.Outgoing[0]) as VirtualMediationTreeNode; node = tree.GetNode(node.Domain, node.Problem, node.Outgoing.Find(x => x.Action.Name.Equals("toggle-green"))) as VirtualMediationTreeNode; node = tree.GetNode(node.Domain, node.Problem, node.Outgoing[0]) as VirtualMediationTreeNode; Predicate term = new Predicate("used", new List <ITerm> { new Term("terminal1", true), new Term("boss", true) }, true); Predicate term2 = new Predicate("used", new List <ITerm> { new Term("terminal2", true), new Term("boss", true) }, true); Predicate term3 = new Predicate("has", new List <ITerm> { new Term("snake", true), new Term("c4", true) }, true); Predicate bossGear = new Predicate("at", new List <ITerm> { new Term("boss", true), new Term("gear", true) }, true); Superposition super = node.State as Superposition; Assert.IsTrue(super.IsUndetermined(term)); Assert.IsTrue(super.IsUndetermined(term2)); Assert.IsFalse(super.IsUndetermined(term3)); node = tree.GetNode(node.Domain, node.Problem, node.Outgoing.Find(x => x.Action.Name.Equals("move-location"))) as VirtualMediationTreeNode; super = node.State as Superposition; Assert.IsFalse(super.IsUndetermined(term)); if (super.IsFalse(bossGear)) { Assert.IsTrue(super.IsUndetermined(term2)); } else { Assert.IsFalse(super.IsUndetermined(term2)); } }
/// <summary> /// Moves along the outgoing wait edge from the current node in mediation space. /// </summary> public static void Wait() { // Provide feedback to the player. Console.Out.WriteLine(); Console.Out.WriteLine("Time passes..."); // Loop through the outgoing edges... foreach (MediationTreeEdge edge in current.Outgoing) { // Identify if (edge.Action.Name.Equals("do-nothing")) { if (frontier.ContainsKey(edge)) { current = frontier[edge] as MediationTreeNode; } else { current = tree.GetNode(current.Domain, current.Problem, edge); } } } Look(); }
private MediationTreeNode BuildTree() { tree = new MediationTree(testDomain, testProblem, path, false, true); MediationTreeNode child = tree.GetNode(tree.Root.Domain, tree.Root.Problem, tree.Root.Outgoing.Find(x => x.Action.Name.Equals("move-location") && x.Action.TermAt(1).Equals("right"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("move-location"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("make-trap-wire"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("place-explosive-thing") && x.Action.TermAt(2).Equals("gears"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("set-trap"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("move-location") && x.Action.TermAt(1).Equals("left"))); return(child); }
public void EventRevisionTest() { tree = new MediationTree(testDomain, testProblem, pathEvent, false, true); MediationTreeNode child = tree.GetNode(tree.Root.Domain, tree.Root.Problem, tree.Root.Outgoing.Find(x => x.Action.Name.Equals("move-location") && x.Action.TermAt(1).Equals("right"))); Assert.AreEqual(child.Outgoing.Count, 2); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("move-location")).ActionType, ActionType.Constituent); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("toggle-green")).ActionType, ActionType.Consistent); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("move-location"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("make-trap-wire"))); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("place-explosive-thing") && x.Action.TermAt(2).Equals("gears")).ActionType, ActionType.Constituent); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("place-explosive-thing") && x.Action.TermAt(2).Equals("gears"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("set-trap"))); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("move-location") && x.Action.TermAt(1).Equals("right")).ActionType, ActionType.Constituent); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("move-location") && x.Action.TermAt(1).Equals("left"))); Assert.IsFalse(child.DeadEnd); Assert.AreEqual(child.Plan.Steps.Count, 7); }
public void BatmanTestEventRevision() { path = Parser.GetTopDirectory() + @"MediationTrees\Data\Unit-Tests\Batman\event\"; Assert.IsTrue(testPlan.Steps.Count > 0); tree = new MediationTree(testDomain, testProblem, path, false, true, false); Assert.IsTrue(tree.Root.Plan.Steps.Count > 0); Assert.IsTrue(tree.Root.Outgoing.Count == 1); MediationTreeNode current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, tree.Root.Outgoing[0]); Assert.IsTrue(current.Outgoing.Count == 1); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); Assert.IsTrue(current.Outgoing.Count == 1); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); Assert.IsTrue(current.Outgoing.Count == 2); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); Assert.IsTrue(current.Outgoing.Count == 2); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[0]); current = tree.GetNode(tree.Root.Domain, tree.Root.Problem, current.Outgoing[1]); Assert.IsFalse(current.DeadEnd); }
public void DomainRevisionTest() { tree = new MediationTree(testDomain, testProblem, pathDomain, true, false); MediationTreeNode child = tree.GetNode(tree.Root.Domain, tree.Root.Problem, tree.Root.Outgoing.Find(x => x.Action.Name.Equals("move-location") && x.Action.TermAt(1).Equals("right"))); Assert.AreEqual(child.Outgoing.Count, 2); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("move-location")).ActionType, ActionType.Constituent); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("toggle-green")).ActionType, ActionType.Consistent); Assert.AreEqual(child.Domain.Operators.Find(x => x.Name.Equals("detonate-explosive")).Conditionals.Count, 2); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("move-location"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("make-trap-wire"))); Assert.AreEqual(child.Outgoing.Find(x => x.Action.Name.Equals("place-explosive-thing") && x.Action.TermAt(2).Equals("gears")).ActionType, ActionType.Constituent); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("place-explosive-thing") && x.Action.TermAt(2).Equals("terminal1"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("set-trap"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("detonate-explosive"))); Assert.IsFalse(child.DeadEnd); Assert.AreEqual(child.Domain.Operators.Find(x => x.Name.Equals("detonate-explosive")).Conditionals.Count, 1); Assert.AreEqual(child.Domain.Operators.Find(x => x.Name.Equals("detonate-explosive")).Conditionals[0].Preconditions[0].Name, "green"); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("move-location"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("take-explosive"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("use-computer"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("toggle-green"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("link-phone"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("place-explosive-thing") && x.Action.TermAt(2).Equals("terminal1"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("do-nothing"))); child = tree.GetNode(child.Domain, child.Problem, child.Outgoing.Find(x => x.Action.Name.Equals("detonate-explosive"))); Assert.IsTrue(child.DeadEnd); }
// Creates a single tree of specified depth without specifying a folder name. public static void BreadthFirst(string domainName, int endDepth, bool domainRevision, bool eventRevision, bool superposition) { string modifier = "vanilla"; if (domainRevision && eventRevision) { modifier = "domain-event"; } else if (domainRevision) { modifier = "domain"; } else if (eventRevision) { modifier = "event"; } else if (superposition) { modifier = "superposition"; } // Parse the domain file. Domain domain = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl", PlanType.StateSpace); // Parse the problem file. Problem problem = Parser.GetProblemWithTypes(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\prob01.pddl", domain); // Create the initial node of mediation space. MediationTree tree = new MediationTree(domain, problem, Parser.GetTopDirectory() + @"MediationTrees\Data\" + domain.Name + @"\" + modifier + @"\", domainRevision, eventRevision, superposition); // Remember the game tree path. string dataPath = Parser.GetTopDirectory() + @"TestLogs\Level\" + domainName + @"\" + modifier + @"\"; // Check each path to see if it exists. If not, create the folder. if (!File.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } TestData data = new TestData(); Stopwatch watch = new Stopwatch(); Console.WriteLine("Creating a " + modifier + " tree to level " + endDepth); // If data already exists, load it from memory. if (File.Exists(dataPath + "mediationtreedata")) { data = BinarySerializer.DeSerializeObject <TestData>(dataPath + "mediationtreedata"); } else { data.elapsedMilliseconds = 0; data.frontier = new List <int>() { 0 }; data.depth = 0; data.nodeCounter = 1; data.goalStateCount = 0; data.deadEndCount = 0; data.summarySkip = 1000; data.summaries = new List <List <Tuple <string, string> > >(); } Console.WriteLine("Beginning at level " + data.depth); Console.WriteLine("Beginning at node number " + data.nodeCounter); watch.Start(); while (endDepth - data.depth > 0 && data.frontier.Count > 0) { MediationTreeNode current = tree.GetNode(data.frontier[0]); foreach (MediationTreeEdge edge in current.Outgoing) { bool newDepth = false; MediationTreeNode child = tree.GetNode(current.Domain, current.Problem, edge); if (child.Depth > data.depth) { data.depth = child.Depth; newDepth = true; Console.WriteLine("Reached level " + data.depth); } data.nodeCounter++; if (child.IsGoal) { data.goalStateCount++; } if (child.DeadEnd) { data.deadEndCount++; } data.frontier.Add(child.ID); watch.Stop(); if (newDepth) { data.summaries.Add(CreateSummary(data)); } watch.Start(); } data.frontier.RemoveAt(0); data.elapsedMilliseconds += watch.ElapsedMilliseconds; watch.Reset(); BinarySerializer.SerializeObject <TestData>(dataPath + "mediationtreedata", data); if (data.nodeCounter % 1000 == 0) { Console.WriteLine("Reached node number " + data.nodeCounter); } watch.Start(); } watch.Stop(); int size = data.summaries.Count + 1; BinarySerializer.SerializeObject <TestData>(dataPath + "mediationtreedata", data); WriteSummary(@"\Level\" + domainName + @"\" + modifier, data.nodeCounter.ToString(), data.summaries); if (data.summaries.Count > 0) { Grapher.CreateGraphs(domainName, data.nodeCounter.ToString(), size, dataPath, data.summaries); } }