コード例 #1
0
        public void LightLampTest()
        {
            var domain    = new Domain();
            var tom       = new Actor("Tom");
            var lighted   = new Fluent("lighted");
            var broken    = new Fluent("broken");
            var turnOn    = new Action("TurnOn");
            var turnOff   = new Action("TurnOff");
            var throwDown = new Action("ThrowDown");
            var world     = World.Instance;

            world.SetActions(new List <Action> {
                turnOn, turnOff, throwDown
            });
            world.SetFluents(new List <Fluent> {
                lighted, broken
            });
            world.SetActors(new List <Actor> {
                tom
            });
            domain.AddInitiallyClause(new Initially(new Conjunction(new Negation(broken), lighted)));
            domain.AddTypicallyCausesClause(new TypicallyCauses(throwDown, false, new List <Actor> {
                tom
            }, broken));
            domain.AddCausesClause(new Causes(turnOn, false, new List <Actor> {
                tom
            }, lighted));
            domain.AddCausesClause(new Causes(turnOff, false, new List <Actor> {
                tom
            }, new Negation(lighted)));
            domain.AddAlwaysClause(new Always(new Implication(lighted, new Negation(broken))));
            domain.AddPreservesClause(new Preserves(turnOn, false, new List <Actor> {
                tom
            }, broken, null));
            world.SetDomain(domain);
            world.Build();
            var scenario = new Scenario();

            scenario.AddScenarioStep(new ScenarioStep(throwDown, tom));
            scenario.AddScenarioStep(new ScenarioStep(turnOn, tom));

            var ever       = new AccessibleEverScenarioQuery(new Conjunction(new Negation(broken), lighted), lighted, scenario);
            var resultEver = ever.Evaluate(world);

            var typically       = new AccessibleTypicallyScenarioQuery(new Conjunction(new Negation(broken), lighted), lighted, scenario);
            var resultTypically = typically.Evaluate(world);

            var always       = new AccessibleAlwaysScenarioQuery(new Conjunction(new Negation(broken), lighted), lighted, scenario);
            var resultAlways = always.Evaluate(world);

            Assert.AreEqual(resultEver, true);
            Assert.AreEqual(resultTypically, false);
            Assert.AreEqual(resultAlways, true);
        }
コード例 #2
0
        public NeroTests()
        {
            var burnedFluent      = new Fluent("burned");
            var entertainedFluent = new Fluent("entertained");
            var neroActor         = new Actor("Nero");
            var drinkAction       = new Action("Drink");
            var torchAction       = new Action("Torch");
            var restAction        = new Action("Rest");

            var domain = new Domain();

            domain.AddInitiallyClause(new Initially(new Conjunction(new Negation(burnedFluent), new Negation(entertainedFluent))));
            domain.AddReleasesClause(new Releases(drinkAction, false, new List <Actor> {
                neroActor
            }, entertainedFluent, new Negation(entertainedFluent)));
            domain.AddTypicallyCausesClause(new TypicallyCauses(torchAction, false, new List <Actor> {
                neroActor
            }, entertainedFluent));
            domain.AddCausesClause(new Causes(torchAction, false, new List <Actor> {
                neroActor
            }, burnedFluent));
            domain.AddCausesClause(new Causes(restAction, false, new List <Actor> {
                neroActor
            }, new Negation(entertainedFluent)));
            domain.AddImpossibleClause(new Impossible(torchAction, false, new List <Actor> {
                neroActor
            }, burnedFluent));

            _world.SetActors(new List <Actor> {
                neroActor
            });
            _world.SetActions(new List <Action> {
                drinkAction, torchAction, restAction
            });
            _world.SetFluents(new List <Fluent> {
                burnedFluent, entertainedFluent
            });
            _world.SetDomain(domain);

            _world.Build();



            _drinkRestTorchScenario = new Scenario();
            _drinkRestTorchScenario.AddScenarioStep(new ScenarioStep(drinkAction, neroActor));
            _drinkRestTorchScenario.AddScenarioStep(new ScenarioStep(restAction, neroActor));
            _drinkRestTorchScenario.AddScenarioStep(new ScenarioStep(torchAction, neroActor));

            _accessibleQueryGamma = new Negation(burnedFluent);
            _accessibleQueryPi    = null;
        }
コード例 #3
0
        private Domain createDomain()
        {
            Domain domain    = new Domain();
            var    emptyList = new List <Actor>();

            domain.AddInitiallyClause(new Initially(new Conjunction(new Negation(loaded), alive)));
            domain.AddCausesClause(new Causes(load, true, emptyList, loaded));
            domain.AddCausesClause(new Causes(shoot, true, emptyList, new Negation(loaded)));
            domain.AddCausesClause(new Causes(entice, true, emptyList, walking));
            domain.AddTypicallyCausesClause(new TypicallyCauses(shoot, true, emptyList, new Negation(alive), loaded));
            domain.AddAlwaysClause(new Always(new Implication(walking, alive)));
            domain.AddPreservesClause(new Preserves(entice, true, emptyList, alive, null));

            return(domain);
        }
コード例 #4
0
        protected World CreateITWorld()
        {
            var world = World.Instance;

            painted = new Fluent("painted");
            paint   = new Action("PAINT");
            clear   = new Action("CLEAR");
            Fred    = new Actor("Fred");
            Bill    = new Actor("Bill");

            world.SetActions(new List <Action>()
            {
                paint, clear
            });
            world.SetActors(new List <Actor>()
            {
                Fred, Bill
            });
            world.SetFluents(new List <Fluent> {
                painted
            });

            var domain = new Domain();

            domain.AddInitiallyClause(new Initially(new Negation(painted)));
            domain.AddCausesClause(new Causes(clear, true, new List <Actor>(), new Negation(painted)));
            domain.AddTypicallyCausesClause(new TypicallyCauses(paint, false, new List <Actor>()
            {
                Fred
            }, painted));
            world.SetDomain(domain);
            world.Build();
            return(world);
        }
コード例 #5
0
        public void LightLampTest2()
        {
            var domain    = new Domain();
            var tom       = new Actor("Tom");
            var lighted   = new Fluent("lighted");
            var broken    = new Fluent("broken");
            var turnOn    = new Action("TurnOn");
            var turnOff   = new Action("TurnOff");
            var throwDown = new Action("ThrowDown");
            var world     = World.Instance;

            world.SetActions(new List <Action> {
                turnOn, turnOff, throwDown
            });
            world.SetFluents(new List <Fluent> {
                lighted, broken
            });
            world.SetActors(new List <Actor> {
                tom
            });
            domain.AddInitiallyClause(new Initially(new Conjunction(new Negation(broken), lighted)));
            domain.AddTypicallyCausesClause(new TypicallyCauses(throwDown, false, new List <Actor> {
                tom
            }, broken));
            domain.AddCausesClause(new Causes(turnOn, false, new List <Actor> {
                tom
            }, lighted));
            domain.AddCausesClause(new Causes(turnOff, false, new List <Actor> {
                tom
            }, new Negation(lighted)));
            domain.AddAlwaysClause(new Always(new Implication(lighted, new Negation(broken))));
            domain.AddPreservesClause(new Preserves(turnOn, false, new List <Actor> {
                tom
            }, broken, null));
            world.SetDomain(domain);
            world.Build();
            var scenario = new Scenario();

            scenario.AddScenarioStep(new ScenarioStep(throwDown, tom));
            scenario.AddScenarioStep(new ScenarioStep(turnOn, tom));

            var q = new ScenarioAlwaysExecutableQuery(scenario);
            var r = q.Evaluate(world);

            Assert.AreEqual(r, false);
        }
コード例 #6
0
        protected World CreateITWorld()
        {
            var world = World.Instance;

            cm       = new Fluent("cm");
            code     = new Action("Code");
            refactor = new Action("Refactor");
            debug    = new Action("Debug");
            cc       = new Fluent("cc");
            Fred     = new Actor("Fred");
            Bill     = new Actor("Bill");
            world.SetActions(new List <Action>()
            {
                entice, shoot, load
            });
            world.SetActors(new List <Actor>()
            {
                Bill
            });
            world.SetFluents(new List <Fluent> {
                alive, walking, loaded
            });
            var domain = new Domain();

            var emptyList = new List <Actor>();

            domain.AddInitiallyClause(new Initially(new Conjunction(new Negation(loaded), alive)));
            domain.AddCausesClause(new Causes(load, true, emptyList, loaded));
            domain.AddCausesClause(new Causes(shoot, true, emptyList, new Negation(loaded)));
            domain.AddCausesClause(new Causes(entice, true, emptyList, walking));
            domain.AddTypicallyCausesClause(new TypicallyCauses(shoot, true, emptyList, new Negation(alive), loaded));
            domain.AddAlwaysClause(new Always(new Implication(walking, alive)));
            domain.AddPreservesClause(new Preserves(entice, true, emptyList, alive, null));

            world.SetDomain(domain);
            world.Build();
            return(world);
        }
コード例 #7
0
        protected World CreateITWorld()
        {
            var world = World.Instance;

            aliceSmall   = new Fluent("aliceSmall");
            hatterMad    = new Fluent("hatterMad");
            catVisible   = new Fluent("catVisible");
            cakeExists   = new Fluent("cakeExists");
            elixirExists = new Fluent("elixirExists");

            alice  = new Actor("alice");
            cat    = new Actor("cat");
            hatter = new Actor("hatter");
            rabbit = new Actor("rabbit");

            drink = new Action("drink");
            eat   = new Action("eat");

            world.SetActions(new List <Action>()
            {
                drink, eat
            });
            world.SetActors(new List <Actor>()
            {
                alice, cat, hatter, rabbit
            });
            world.SetFluents(new List <Fluent> {
                aliceSmall, hatterMad, catVisible, cakeExists, elixirExists
            });

            var domain = new Domain();

            domain.AddInitiallyClause(new Initially(new Conjunction(new Negation(aliceSmall), new Negation(hatterMad), new Negation(catVisible))));
            domain.AddInitiallyClause(new Initially(new Conjunction(cakeExists, elixirExists)));
            domain.AddCausesClause(new Causes(drink, false, new List <Actor>()
            {
                alice
            }, aliceSmall, elixirExists));
            domain.AddCausesClause(new Causes(eat, false, new List <Actor>()
            {
                alice
            }, new Negation(aliceSmall)));
            domain.AddImpossibleClause(new Impossible(eat, false, new List <Actor>()
            {
                cat
            }, new True()));
            domain.AddTypicallyCausesClause(new TypicallyCauses(drink, false, new List <Actor>()
            {
                cat
            }, catVisible, elixirExists));
            domain.AddReleasesClause(new Releases(drink, false, new List <Actor>()
            {
                hatter
            }, hatterMad, new Conjunction(new Negation(hatterMad), elixirExists)));
            domain.AddTypicallyCausesClause(new TypicallyCauses(eat, false, new List <Actor>()
            {
                hatter
            }, new Negation(hatterMad), hatterMad));
            domain.AddCausesClause(new Causes(eat, true, new List <Actor>(), new Negation(cakeExists)));
            domain.AddImpossibleClause(new Impossible(eat, true, new List <Actor>(), new Negation(cakeExists)));
            domain.AddReleasesClause(new Releases(drink, true, new List <Actor>(), elixirExists, elixirExists));
            domain.AddImpossibleClause(new Impossible(eat, false, new List <Actor>()
            {
                rabbit
            }, new True()));
            domain.AddCausesClause(new Causes(drink, false, new List <Actor>()
            {
                rabbit
            }, cakeExists, elixirExists));


            world.SetDomain(domain);
            world.Build();
            return(world);
        }
コード例 #8
0
        private void addClauseButton_Click(object sender, EventArgs e)
        {
            Actor epsilonActor = new Actor("ϵ");

            switch (currentClause)
            {
            case 0:
            {
                Initially stmt = ((InitiallyClauseControl)clauseControls[currentClause]).getClause();
                if (stmt != null)
                {
                    clausesListBox.Items.Add(stmt);
                    _domain.AddInitiallyClause(stmt);
                }
                break;
            }

            case 1:
            {
                Causes stmt = ((CausesClauseControl)clauseControls[currentClause]).getClause();
                if (stmt != null)
                {
                    if (stmt.Actors.Contains(epsilonActor))
                    {
                        stmt = new Causes(stmt.Action, stmt.Exclusion, availableActors, stmt.Effect, stmt.Condition);
                    }
                    clausesListBox.Items.Add(stmt);
                    _domain.AddCausesClause(stmt);
                }
                break;
            }

            case 2:
            {
                TypicallyCauses stmt = ((TypicallyCausesClauseControl)clauseControls[currentClause]).getClause();
                if (stmt != null)
                {
                    if (stmt.Actors.Contains(epsilonActor))
                    {
                        stmt = new TypicallyCauses(stmt.Action, stmt.Exclusion, availableActors, stmt.Effect, stmt.Condition);
                    }
                    clausesListBox.Items.Add(stmt);
                    _domain.AddTypicallyCausesClause(stmt);
                }
                break;
            }

            case 3:
            {
                Releases stmt = ((ReleasesClauseControl)clauseControls[currentClause]).getClause();
                if (stmt != null)
                {
                    if (stmt.Actors.Contains(epsilonActor))
                    {
                        stmt = new Releases(stmt.Action, stmt.Exclusion, availableActors, stmt.Fluent, stmt.Condition);
                    }
                    clausesListBox.Items.Add(stmt);
                    _domain.AddReleasesClause(stmt);
                }
                break;
            }

            case 4:
            {
                Preserves stmt = ((PreservesClauseControl)clauseControls[currentClause]).getClause();
                if (stmt != null)
                {
                    if (stmt.Actors.Contains(epsilonActor))
                    {
                        stmt = new Preserves(stmt.Action, stmt.Exclusion, availableActors, stmt.Fluent, stmt.Condition);
                    }
                    clausesListBox.Items.Add(stmt);
                    _domain.AddPreservesClause(stmt);
                }
                break;
            }

            case 5:
            {
                Always stmt = ((AlwaysClauseControl)clauseControls[currentClause]).getClause();
                if (stmt != null)
                {
                    clausesListBox.Items.Add(stmt);
                    _domain.AddAlwaysClause(stmt);
                }
                break;
            }

            case 6:
            {
                Impossible stmt = ((ImpossibleClauseControl)clauseControls[currentClause]).getClause();
                if (stmt != null)
                {
                    if (stmt.Actors.Contains(epsilonActor))
                    {
                        stmt = new Impossible(stmt.Action, stmt.Exclusion, availableActors, stmt.Condition);
                    }
                    clausesListBox.Items.Add(stmt);
                    _domain.AddImpossibleClause(stmt);
                }
                break;
            }
            }
        }
コード例 #9
0
        public void OnlyAtypical()
        {
            World world = World.Instance;

            var aAction     = new Action("A");
            var nonameActor = new Actor("Noname");
            var pFluent     = new Fluent("p");
            var qFluent     = new Fluent("q");
            var fluentList  = new List <Fluent> {
                pFluent, qFluent
            };

            var domain = new Domain();

            domain.AddInitiallyClause(new Initially(new Conjunction(pFluent, qFluent)));
            domain.AddAlwaysClause(new Always(new Alternative(pFluent, qFluent)));
            domain.AddCausesClause(new Causes(aAction, false, new List <Actor> {
                nonameActor
            }, new Negation(pFluent)));
            domain.AddTypicallyCausesClause(new TypicallyCauses(aAction, false, new List <Actor> {
                nonameActor
            }, new Negation(qFluent), pFluent));

            world.SetActions(new List <Action> {
                aAction
            });
            world.SetActors(new List <Actor> {
                nonameActor
            });
            world.SetFluents(fluentList);
            world.SetDomain(domain);

            Assert.IsTrue(world.Build());

            State state0 = new State(fluentList, new List <bool> {
                true, true
            });
            State state1 = new State(fluentList, new List <bool> {
                true, false
            });
            State state2 = new State(fluentList, new List <bool> {
                false, true
            });

            ISet <State> expectedResN, expectedResAb, actualResN, actualResAb;

            // A; Noname; p & q
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
                state2
            };
            actualResN  = world.GetStates(aAction, nonameActor, state0, false);
            actualResAb = world.GetStates(aAction, nonameActor, state0, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // A; Noname; p & -q
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
                state2
            };
            actualResN  = world.GetStates(aAction, nonameActor, state1, false);
            actualResAb = world.GetStates(aAction, nonameActor, state1, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // A; Noname; -p & q
            expectedResN = new HashSet <State> {
                state2
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(aAction, nonameActor, state2, false);
            actualResAb   = world.GetStates(aAction, nonameActor, state2, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);
        }
コード例 #10
0
        public void CookingJohn()
        {
            World world = World.Instance;

            var cookAction    = new Action("Cook");
            var eatAction     = new Action("Eat");
            var johnActor     = new Actor("John");
            var hungryFluent  = new Fluent("hungry");
            var hasMealFluent = new Fluent("hasMeal");
            var fluentList    = new List <Fluent> {
                hungryFluent, hasMealFluent
            };

            var domain = new Domain();

            domain.AddInitiallyClause(new Initially(new Conjunction(hungryFluent, new Negation(hasMealFluent))));
            domain.AddImpossibleClause(new Impossible(eatAction, false, new List <Actor> {
                johnActor
            }, new Negation(hasMealFluent)));
            domain.AddTypicallyCausesClause(new TypicallyCauses(cookAction, false, new List <Actor> {
                johnActor
            }, hasMealFluent));
            domain.AddCausesClause(new Causes(eatAction, false, new List <Actor> {
                johnActor
            }, new Negation(hasMealFluent)));
            domain.AddReleasesClause(new Releases(eatAction, false, new List <Actor> {
                johnActor
            }, hungryFluent, hungryFluent));

            world.SetActors(new List <Actor> {
                johnActor
            });
            world.SetActions(new List <Action> {
                cookAction, eatAction
            });
            world.SetFluents(fluentList);
            world.SetDomain(domain);

            Assert.IsTrue(world.Build());

            State state0 = new State(fluentList, new List <bool> {
                true, false
            });
            State state1 = new State(fluentList, new List <bool> {
                true, true
            });
            State state2 = new State(fluentList, new List <bool> {
                false, true
            });
            State state3 = new State(fluentList, new List <bool> {
                false, false
            });

            ISet <State> expectedResN, expectedResAb, actualResN, actualResAb;

            // cook; john; hungry & -hasMeal
            expectedResN = new HashSet <State> {
                state1
            };
            expectedResAb = new HashSet <State> {
                state0
            };
            actualResN  = world.GetStates(cookAction, johnActor, state0, false);
            actualResAb = world.GetStates(cookAction, johnActor, state0, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // cook; john; hungry & hasMeal
            expectedResN = new HashSet <State> {
                state1
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(cookAction, johnActor, state1, false);
            actualResAb   = world.GetStates(cookAction, johnActor, state1, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // cook; john; -hungry & hasMeal
            expectedResN = new HashSet <State> {
                state2
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(cookAction, johnActor, state2, false);
            actualResAb   = world.GetStates(cookAction, johnActor, state2, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // cook; john; -hungry & -hasMeal
            expectedResN = new HashSet <State> {
                state2
            };
            expectedResAb = new HashSet <State> {
                state3
            };
            actualResN  = world.GetStates(cookAction, johnActor, state3, false);
            actualResAb = world.GetStates(cookAction, johnActor, state3, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; john; hungry & -hasMeal
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, johnActor, state0, false);
            actualResAb   = world.GetStates(eatAction, johnActor, state0, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; john; hungry & hasMeal
            expectedResN = new HashSet <State> {
                state0, state3
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, johnActor, state1, false);
            actualResAb   = world.GetStates(eatAction, johnActor, state1, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; john; -hungry & hasMeal
            expectedResN = new HashSet <State> {
                state3
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, johnActor, state2, false);
            actualResAb   = world.GetStates(eatAction, johnActor, state2, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; john; -hungry & -hasMeal
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, johnActor, state3, false);
            actualResAb   = world.GetStates(eatAction, johnActor, state3, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);
        }
コード例 #11
0
        public void Blowfish()
        {
            World world = World.Instance;

            var inflateAction  = new Action("Inflate");
            var deflateAction  = new Action("Deflate");
            var blowfishActor  = new Actor("Blowfish");
            var puffedUpFluent = new Fluent("puffedUp");
            var fluentList     = new List <Fluent> {
                puffedUpFluent
            };

            var domain = new Domain();

            domain.AddInitiallyClause(new Initially(puffedUpFluent));
            domain.AddCausesClause(new Causes(inflateAction, false, new List <Actor> {
                blowfishActor
            }, puffedUpFluent));
            domain.AddCausesClause(new Causes(deflateAction, false, new List <Actor> {
                blowfishActor
            }, new Negation(puffedUpFluent)));

            world.SetActions(new List <Action> {
                inflateAction, deflateAction
            });
            world.SetActors(new List <Actor> {
                blowfishActor
            });
            world.SetFluents(fluentList);
            world.SetDomain(domain);

            Assert.IsTrue(world.Build());

            State state0 = new State(fluentList, new List <bool> {
                true
            });
            State state1 = new State(fluentList, new List <bool> {
                false
            });

            ISet <State> expectedResN, expectedResAb, actualResN, actualResAb;

            // inflate; blowfish; puffedUp
            expectedResN = new HashSet <State> {
                state0
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(inflateAction, blowfishActor, state0, false);
            actualResAb   = world.GetStates(inflateAction, blowfishActor, state0, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // inflate; blowfish; -puffedUp
            expectedResN = new HashSet <State> {
                state0
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(inflateAction, blowfishActor, state1, false);
            actualResAb   = world.GetStates(inflateAction, blowfishActor, state1, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // deflate; blowfish; puffedUp
            expectedResN = new HashSet <State> {
                state1
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(deflateAction, blowfishActor, state0, false);
            actualResAb   = world.GetStates(deflateAction, blowfishActor, state0, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // deflate; blowfish; -puffedUp
            expectedResN = new HashSet <State> {
                state1
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(deflateAction, blowfishActor, state1, false);
            actualResAb   = world.GetStates(deflateAction, blowfishActor, state1, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);
        }
コード例 #12
0
        public void Alice()
        {
            World world = World.Instance;

            var hatterActor        = new Actor("Hatter");
            var drinkAction        = new Action("Drink");
            var eatAction          = new Action("Eat");
            var hatterMadFluent    = new Fluent("hatterMad");
            var cakeExistsFluent   = new Fluent("cakeExists");
            var elixirExistsFluent = new Fluent("elixirExists");
            var fluentList         = new List <Fluent> {
                hatterMadFluent, cakeExistsFluent, elixirExistsFluent
            };

            var domain     = new Domain();
            var initially1 = new Initially(new Conjunction(new Negation(hatterMadFluent), cakeExistsFluent, elixirExistsFluent));
            var causes1    = new Causes(drinkAction, false, new List <Actor> {
                hatterActor
            }, hatterMadFluent, elixirExistsFluent);
            var causes2 = new Causes(eatAction, false, new List <Actor> {
                hatterActor
            }, new Negation(cakeExistsFluent));
            var tCauses1 = new TypicallyCauses(eatAction, false, new List <Actor> {
                hatterActor
            }, new Negation(hatterMadFluent), hatterMadFluent);
            var impossible1 = new Impossible(eatAction, false, new List <Actor> {
                hatterActor
            }, new Negation(cakeExistsFluent));
            var releases1 = new Releases(drinkAction, false, new List <Actor> {
                hatterActor
            }, elixirExistsFluent, elixirExistsFluent);

            domain.AddInitiallyClause(initially1);
            domain.AddCausesClause(causes1);
            domain.AddTypicallyCausesClause(tCauses1);
            domain.AddImpossibleClause(impossible1);
            domain.AddReleasesClause(releases1);
            domain.AddCausesClause(causes2);

            world.SetActions(new List <Action> {
                drinkAction, eatAction
            });
            world.SetActors(new List <Actor> {
                hatterActor
            });
            world.SetFluents(fluentList);
            world.SetDomain(domain);

            Assert.IsTrue(world.Build());

            State state0 = new State(fluentList, new List <bool> {
                false, true, true
            });
            State state1 = new State(fluentList, new List <bool> {
                true, true, true
            });
            State state2 = new State(fluentList, new List <bool> {
                true, false, true
            });
            State state3 = new State(fluentList, new List <bool> {
                false, false, true
            });
            State state4 = new State(fluentList, new List <bool> {
                true, false, false
            });
            State state5 = new State(fluentList, new List <bool> {
                true, true, false
            });
            State state6 = new State(fluentList, new List <bool> {
                false, true, false
            });
            State state7 = new State(fluentList, new List <bool> {
                false, false, false
            });

            ISet <State> expectedResN, expectedResAb, actualResN, actualResAb;

            // drink; hatter; -hatterMad & cakeExists & elixirExists
            expectedResN = new HashSet <State> {
                state1, state5
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state0, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state0, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // drink; hatter; hatterMad & cakeExists & elixirExists
            expectedResN = new HashSet <State> {
                state1, state5
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state1, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state1, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // drink; hatter; hatterMad & -cakeExists & elixirExists
            expectedResN = new HashSet <State> {
                state2, state4
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state2, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state2, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // drink; hatter; -hatterMad & -cakeExists & elixirExists
            expectedResN = new HashSet <State> {
                state2, state4
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state3, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state3, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // drink; hatter; hatterMad & -cakeExists & -elixirExists
            expectedResN = new HashSet <State> {
                state4
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state4, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state4, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // drink; hatter; hatterMad & cakeExists & -elixirExists
            expectedResN = new HashSet <State> {
                state5
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state5, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state5, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // drink; hatter; -hatterMad & cakeExists & -elixirExists
            expectedResN = new HashSet <State> {
                state6
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state6, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state6, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // drink; hatter; -hatterMad & -cakeExists & -elixirExists
            expectedResN = new HashSet <State> {
                state7
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(drinkAction, hatterActor, state7, false);
            actualResAb   = world.GetStates(drinkAction, hatterActor, state7, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; -hatterMad & cakeExists & elixirExists
            expectedResN = new HashSet <State> {
                state3
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, hatterActor, state0, false);
            actualResAb   = world.GetStates(eatAction, hatterActor, state0, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; hatterMad & cakeExists & elixirExists
            expectedResN = new HashSet <State> {
                state3
            };
            expectedResAb = new HashSet <State> {
                state2
            };
            actualResN  = world.GetStates(eatAction, hatterActor, state1, false);
            actualResAb = world.GetStates(eatAction, hatterActor, state1, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; hatterMad & -cakeExists & elixirExists
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, hatterActor, state2, false);
            actualResAb   = world.GetStates(eatAction, hatterActor, state2, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; -hatterMad & -cakeExists & elixirExists
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, hatterActor, state3, false);
            actualResAb   = world.GetStates(eatAction, hatterActor, state3, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; hatterMad & -cakeExists & -elixirExists
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, hatterActor, state4, false);
            actualResAb   = world.GetStates(eatAction, hatterActor, state4, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; hatterMad & cakeExists & -elixirExists
            expectedResN = new HashSet <State> {
                state7
            };
            expectedResAb = new HashSet <State> {
                state4
            };
            actualResN  = world.GetStates(eatAction, hatterActor, state5, false);
            actualResAb = world.GetStates(eatAction, hatterActor, state5, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; -hatterMad & cakeExists & -elixirExists
            expectedResN = new HashSet <State> {
                state7
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, hatterActor, state6, false);
            actualResAb   = world.GetStates(eatAction, hatterActor, state6, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);

            // eat; hatter; -hatterMad & -cakeExists & -elixirExists
            expectedResN  = new HashSet <State> {
            };
            expectedResAb = new HashSet <State> {
            };
            actualResN    = world.GetStates(eatAction, hatterActor, state7, false);
            actualResAb   = world.GetStates(eatAction, hatterActor, state7, true);
            AssertResSetsEqual(expectedResN, actualResN);
            AssertResSetsEqual(expectedResAb, actualResAb);
        }