public void CleanUnUsePredicate(Domain d)
        {
            HashSet <GroundedPredicate> allPredicate = new HashSet <GroundedPredicate>();

            foreach (Action act in Domain.GroundAllActions(this))
            {
                foreach (GroundedPredicate gp in act.HashEffects)
                {
                    if (!allPredicate.Contains(gp))
                    {
                        allPredicate.Add(gp);
                    }
                }
                foreach (GroundedPredicate gp in act.HashPrecondition)
                {
                    if (!allPredicate.Contains(gp))
                    {
                        allPredicate.Add(gp);
                    }
                }
            }
            HashSet <Predicate> startState = new HashSet <Predicate>();

            foreach (Predicate p in m_lKnown)
            {
                if (p is GroundedPredicate)
                {
                    if (allPredicate.Contains((GroundedPredicate)p))
                    {
                        startState.Add(p);
                    }
                }
            }
            m_lKnown = startState;
        }
        public static List <string> ManualSolve(Problem p, Domain d)
        {
            List <string> lPlan  = new List <string>();
            State         sStart = new State(p);

            foreach (GroundedPredicate gp in p.Known)
            {
                sStart.AddPredicate(gp);
            }
            State sCurrent = null, sNext = null;
            Dictionary <State, Action> dMapStateToGeneratingAction = new Dictionary <State, Action>();

            dMapStateToGeneratingAction[sStart] = null;
            Dictionary <State, State> dParents = new Dictionary <State, State>();

            dParents[sStart] = null;
            int           cProcessed           = 0;
            List <string> lActionNames         = new List <string>();

            sCurrent = sStart;
            while (!p.IsGoalState(sCurrent))
            {
                List <Action> lActions = new List <Action>(d.GroundAllActions(sCurrent.Predicates, false));
                Console.WriteLine("Available actions:");
                for (int i = 0; i < lActions.Count; i++)
                {
                    Console.WriteLine(i + ") " + lActions[i].Name);
                }
                Console.Write("Choose action number: ");
                int    iAction = int.Parse(Console.ReadLine());
                Action a       = lActions[iAction];
                sNext = sCurrent.Apply(a);

                lPlan.Add(a.Name);

                foreach (Predicate pNew in sNext.Predicates)
                {
                    if (!sCurrent.Predicates.Contains(pNew))
                    {
                        Console.WriteLine(pNew);
                    }
                }

                if (!dParents.Keys.Contains(sNext))
                {
                    dParents[sNext] = sCurrent;
                    dMapStateToGeneratingAction[sNext] = a;
                }

                sCurrent = sNext;

                cProcessed++;
            }
            return(lPlan);
            //return GeneratePlan(sCurrent, null, dParents, dMapStateToGeneratingAction);
        }
        public BuildAgents(Problem p, Domain d, string par)
        {
            problem        = p;
            domain         = d;
            groundedAction = domain.GroundAllActions(p);
            DivideActions(groundedAction, par);
            FindPublicAndPrivateAction(out publicAction, out privateAction);

            DivideStartState();
            DivideGoal();
            //HarderProblemsAlg hpal = new HarderProblemsAlg(p, d);
            foreach (var agentName in agentPredicate.Keys)
            {
                if (!agentsGoal.ContainsKey(agentName))
                {
                    agentsGoal.Add(agentName, new List <GroundedPredicate>());
                }
                Agent agent = new Agent(p, d, agentActions[agentName], publicAgentActions[agentName], privateAgentActions[agentName], agentPredicate[agentName], publicAgentPredicate[agentName], agentsStartState[agentName], agentsGoal[agentName], agentName, getProjectionPublicActionForAgent(agentName), null);
                agents.Add(agent);
            }
        }
Beispiel #4
0
        public BuildAgents_II(Problem p, Domain d, string folderName, string domainName, string problemName)
        {
            problem        = p;
            domain         = d;
            groundedAction = domain.GroundAllActions(p);
            DivideActions(groundedAction, folderName);
            FindPublicAndPrivateAction(out publicAction, out privateAction);
            FindPublicPredicate();
            DivideStartState();
            DivideGoal();
            Dictionary <Predicate, HashSet <Predicate> > lInvariants = null;

            if (folderName.Contains("MABlocksWorld") || folderName.Contains("cMABlocks"))
            {
                lInvariants = d.IdentifyInvariants(d.groundedAction);
            }
            else
            {
                try
                {
                    //lInvariants = d.IdentifyMutexSAS(folderName, domainName, problemName);
                }
                catch (Exception ex)
                {
                    // lInvariants = new Dictionary<Predicate, HashSet<Predicate>>();
                }
            }

            foreach (var agentName in agentPredicate.Keys)
            {
                if (!agentsGoal.ContainsKey(agentName))
                {
                    agentsGoal.Add(agentName, new List <GroundedPredicate>());
                }
                Agent agent = new Agent(p, d, agentActions[agentName], publicAgentActions[agentName], privateAgentActions[agentName], agentPredicate[agentName], publicAgentPredicate[agentName], agentsStartState[agentName], agentsGoal[agentName], agentName, getProjectionPublicActionForAgent(agentName), lInvariants);
                agents.Add(agent);
            }
        }