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);
        }
        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);
        }
Esempio n. 3
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);
        }
        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;
            }
            }
        }
Esempio n. 5
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);
        }