Пример #1
0
        private State ApplyAxiom(State s, List <Action> lActions, Domain d)
        {
            State     sCurrent = s;
            Predicate pNew     = new GroundedPredicate("new");
            Predicate pDone    = new GroundedPredicate("done");

            while (!sCurrent.Contains(pNew.Negate()) || !sCurrent.Contains(pDone))
            {
                Action a1 = d.GroundActionByName(new string[] { "pre-axiom", "" }, sCurrent.Predicates, false);
                Action a2 = d.GroundActionByName(new string[] { "axiom", "" }, sCurrent.Predicates, false);
                if (a1 != null && a2 != null)
                {
                    sCurrent = sCurrent.Apply(a1);
                    sCurrent = sCurrent.Apply(a2);
                    lActions.Add(a1);
                    lActions.Add(a2);
                }
            }

            Action a = d.GroundActionByName(new string[] { "observe-new-F", "" }, sCurrent.Predicates, false);

            sCurrent = sCurrent.Apply(a);
            lActions.Add(a);

            a        = d.GroundActionByName(new string[] { "fixpoint", "" }, sCurrent.Predicates, false);
            sCurrent = sCurrent.Apply(a);
            lActions.Add(a);

            return(sCurrent);
        }
Пример #2
0
        private State ApplyCompute(State s, string sName, List <Action> lActions, Domain d)
        {
            State     sCurrent = s;
            Predicate pNew     = new GroundedPredicate("new-" + sName);
            Predicate pDone    = new GroundedPredicate("done-" + sName);
            int       i        = 0;

            while (!sCurrent.Contains(pNew.Negate()) || !sCurrent.Contains(pDone) || i < 10)
            {
                Action a1 = d.GroundActionByName(new string[] { "pre-" + sName, "" }, sCurrent.Predicates, false);
                Action a2 = d.GroundActionByName(new string[] { "compute-" + sName, "" }, sCurrent.Predicates, false);
                if (a1 != null && a2 != null)
                {
                    sCurrent = sCurrent.Apply(a1);
                    sCurrent = sCurrent.Apply(a2);
                    lActions.Add(a1);
                    lActions.Add(a2);
                }
                i++;
            }

            Action a = d.GroundActionByName(new string[] { "observe-new-" + sName + "-F", "" }, sCurrent.Predicates, false);

            sCurrent = sCurrent.Apply(a);
            lActions.Add(a);

            a        = d.GroundActionByName(new string[] { "post-" + sName, "" }, sCurrent.Predicates, false);
            sCurrent = sCurrent.Apply(a);
            lActions.Add(a);

            return(sCurrent);
        }
Пример #3
0
        public static void Add(string sName, List <Argument> lParameters, Dictionary <string, Constant> dBindings, GroundedPredicate gp, bool bNegation)
        {
            string sFullName    = GetString(sName, lParameters, dBindings, bNegation);
            string sNotFullName = GetString(sName, lParameters, dBindings, !bNegation);

            gp.Cached = true;
            AllGrounded[sFullName] = gp;
            GroundedPredicate gpNot = (GroundedPredicate)gp.Negate();

            gpNot.Cached = true;
            AllGrounded[sNotFullName] = gpNot;
        }
Пример #4
0
        public override Predicate GenerateGiven(string sTag)
        {
            GroundedPredicate pGiven = new GroundedPredicate("Given" + Name);

            foreach (Constant c in Constants)
            {
                pGiven.AddConstant(c);
            }
            pGiven.AddConstant(new Constant(Domain.TAG, sTag));
            if (Negation)
            {
                return(pGiven.Negate());
            }
            return(pGiven);
        }
Пример #5
0
        public static List <string> MasterMindHeuristic(PartiallySpecifiedState pssCurrent, Domain domain)
        {
            List <Constant> lColors = new List <Constant>();
            List <Constant> lPegs   = new List <Constant>();
            List <Constant> lValues = new List <Constant>();

            foreach (Constant c in domain.Constants)
            {
                if (c.Type.ToLower() == "color")
                {
                    lColors.Add(c);
                }
                if (c.Type.ToLower() == "peg")
                {
                    lPegs.Add(c);
                }
                if (c.Type.ToLower() == "value")
                {
                    lValues.Add(c);
                }
            }

            //DateTime dtStart = DateTime.Now;

            //BeliefState bs = pssCurrent.m_bsInitialBelief;

            //State s = bs.ChooseState(true);
            //List<Predicate> l = bs.RunSatSolver();


            //Console.WriteLine((DateTime.Now - dtStart).TotalSeconds);


            Permute(lColors);
            List <Constant> lGuessColors = new List <Constant>();

            for (int iPeg = 0; iPeg < lPegs.Count; iPeg++)
            {
                /*
                 * //foreach (GroundedPredicate gp in s.Predicates)
                 * foreach (GroundedPredicate gp in l)
                 * {
                 *  if (gp.ToString().StartsWith("(on p" + iPeg) && gp.Negation == false)
                 *  {
                 *      lGuessColors.Add(gp.Constants[1]);
                 *  }
                 *
                 *
                 * }
                 */
                foreach (Constant cColor in lColors)
                {
                    GroundedPredicate gp = new GroundedPredicate("on");
                    gp.AddConstant(lPegs[iPeg]);
                    gp.AddConstant(cColor);
                    if (!pssCurrent.Observed.Contains(gp.Negate()))
                    {
                        lGuessColors.Add(cColor);
                        break;
                    }
                }
                lColors.Remove(lGuessColors.Last());
            }
            if (lGuessColors.Count == lPegs.Count)
            {
                List <string> lActions = new List <string>();
                string        sGuess   = "guess-all";
                foreach (Constant c in lGuessColors)
                {
                    sGuess += " " + c.Name;
                }
                lActions.Add(sGuess);
                lActions.Add("evaluate-guess");
                foreach (Constant cValue in lValues)
                {
                    lActions.Add("observe-LocationHits " + cValue.Name);
                    lActions.Add("observe-ColorHits " + cValue.Name);
                }
                return(lActions);
            }
            return(null);
        }
Пример #6
0
        public static List <string> MineSweeperHeuristic(PartiallySpecifiedState pssCurrent, Domain d, Formula fObserve)
        {
            int[,] aBoard;
            aBoard = new int[Size, Size];
            List <string> lActions = new List <string>();
            List <int>    lUnknown = new List <int>();

            for (int iX = 0; iX < Size; iX++)
            {
                for (int iY = 0; iY < Size; iY++)
                {
                    GroundedPredicate gp = GetPredicate("opened", iX, iY);
                    if (pssCurrent.Observed.Contains(gp))
                    {
                        aBoard[iX, iY] = 1;//opened
                    }
                    else
                    {
                        gp = GetPredicate("mine-at", iX, iY);
                        if (pssCurrent.Observed.Contains(gp))
                        {
                            gp = GetPredicate("flagged", iX, iY);
                            if (pssCurrent.Observed.Contains(gp))
                            {
                                aBoard[iX, iY] = 4;//flagged mine
                            }
                            else
                            {
                                aBoard[iX, iY] = 2;//unflagged mine
                            }
                        }
                        else if (pssCurrent.Observed.Contains(gp.Negate()))
                        {
                            aBoard[iX, iY] = 3;//no mine
                        }
                    }
                }
            }



            List <int> lCandidates = new List <int>();

            for (int iX = 0; iX < Size; iX++)
            {
                for (int iY = 0; iY < Size; iY++)
                {
                    if (aBoard[iX, iY] == 0 || aBoard[iX, iY] == 3)
                    {
                        lCandidates.Add((iX) * 1000 + iY);
                    }
                    else if (aBoard[iX, iY] == 2)
                    {
                        lActions.Add("flag p" + iX + "-" + iY);
                    }
                }
            }

            if (lCandidates.Count > 0)
            {
                int iChosen  = lCandidates[RandomGenerator.Next(lCandidates.Count)];
                int iChosenX = iChosen / 1000;
                int iChosenY = iChosen % 1000;
                lActions.Add("open-cell-" + iChosenX + "-" + iChosenY);
                //lActions.Add("open-cell p" + iChosenX + "-" + iChosenY);
                lActions.Add("observe-dead");
                for (int i = 0; i < 9; i++)
                {
                    lActions.Add("observe-mine-count p" + iChosenX + "-" + iChosenY + " v" + i);
                }
                Shootings++;
            }

            /*
             * else if (lUnknown.Count > 0)
             * {
             * int iChosen = lUnknown[RandomGenerator.Next(lUnknown.Count)];
             * int iChosenX = iChosen / 1000;
             * int iChosenY = iChosen % 1000;
             * lActions.Add("shoot p-" + iChosenX + " p-" + iChosenY);
             * Shootings++;
             * }
             */



            return(lActions);
        }