Esempio n. 1
0
        private void btnRunSingleAgentPlan_Click(object sender, EventArgs e)
        {
            // Active agent
            Constant activeAgent = (Constant)cbActiveAgents.SelectedItem;

            // Active goals
            List <Predicate> activeGoals = new List <Predicate>();

            for (int i = 0; i < clbActiveGoals.Items.Count; i++)
            {
                if (clbActiveGoals.GetItemChecked(i))
                {
                    activeGoals.Add((Predicate)clbActiveGoals.Items[i]);
                }
            }

            // Required Actions to be preformed
            List <Action> reqCollabActions = new List <Action>();

            for (int i = 0; i < clbActiveJointActions.Items.Count; i++)
            {
                if (clbActiveJointActions.GetItemChecked(i))
                {
                    reqCollabActions.Add((Action)clbActiveJointActions.Items[i]);
                }
            }

            // Active Prev achieved goals
            List <KeyValuePair <Predicate, int> > prevAchievedGoals = new List <KeyValuePair <Predicate, int> >();

            for (int i = 0; i < clbPrevGoalTime.Items.Count; i++)
            {
                if (clbPrevGoalTime.GetItemChecked(i))
                {
                    prevAchievedGoals.Add((KeyValuePair <Predicate, int>)clbPrevGoalTime.Items[i]);
                }
            }

            Domain  reducedDomain  = Parser.ParseDomain(m_DomainPath, m_AgentCallsign);
            Problem reducedProblem = Parser.ParseProblem(m_ProblemPath, reducedDomain);

            string sPath = Directory.GetParent(reducedDomain.Path).FullName + "\\";

            SingleAgentSDRPlanner m_saSDRPlanner = new SingleAgentSDRPlanner(reducedDomain,
                                                                             reducedProblem,
                                                                             (SDRPlanner.Planners)cbPlanner.SelectedItem);

            PlanResult planResult = m_saSDRPlanner.Plan(activeAgent, activeGoals, prevAchievedGoals, reqCollabActions);

            ConditionalPlanTreeNode root = planResult.Plan;
            PlanDetails             pd   = root.ScanDetails(reducedDomain, reducedProblem);

            pd.PlanningTime = planResult.PlanningTime;
            pd.Valid        = planResult.Valid;
            pd.ActiveAgent  = activeAgent;
            AddResult(pd);
        }
Esempio n. 2
0
        public PlanResult Plan(Constant activeAgent, List <Predicate> activeGoals,
                               List <KeyValuePair <Predicate, int> > goalsCompletionTime,
                               List <Action> reqActions)
        {
            m_AgentDomain  = Parser.ParseDomain(m_GeneralDomain.FilePath, m_GeneralDomain.AgentCallsign);
            m_AgentProblem = Parser.ParseProblem(m_GeneralProblem.FilePath, m_AgentDomain);

            m_ActiveAgent = activeAgent;
            m_ActiveGoals = m_AgentProblem.GetGoals();

            m_GoalsCompletionTime = goalsCompletionTime;
            m_ReqCollabActions    = reqActions;

            DateTime start = DateTime.Now;

            AddNoopAction();
            AddTimeConstraints();
            List <Action> extractedActions;

            AddCollabActionReq(out extractedActions);
            ConvertToSingleAgentProblem();
            AddPrevCompletionOfGoals();
            SetGoals();
            //Reasoning not working for button pushing domain
            AddReasoningActions();
            //AddCosts();

            SDRPlanner sdrPlanner        = new SDRPlanner(m_AgentDomain, m_AgentProblem, m_planner);
            string     s1                = m_AgentDomain.ToString();
            string     s2                = m_AgentProblem.ToString();
            ConditionalPlanTreeNode Plan = sdrPlanner.OfflinePlanning();
            string s     = m_AgentDomain.ToString();
            bool   Valid = sdrPlanner.Valid;

            // Return extracted actions to domain
            foreach (var action in extractedActions)
            {
                m_AgentDomain.Actions.Add(action);
            }

            TimeSpan PlanningTime = DateTime.Now - start;

            PlanResult result = new PlanResult(activeAgent, Plan, PlanningTime, Valid,
                                               goalsCompletionTime, reqActions,
                                               m_AgentDomain, m_AgentProblem,
                                               m_GeneralDomain, m_GeneralProblem);
            // Write plan to file
            string path = Path.GetDirectoryName(m_AgentDomain.FilePath) + "\\plan_" + m_ActiveAgent.Name + ".txt";

            File.WriteAllText(path, PlanTreePrinter.Print(result.Plan));
            return(result);
        }
        private void AddResult(Constant agent, ConditionalPlanTreeNode plan, PlanDetails pd, TimeSpan planningTime, Boolean valid)
        {
            string           planAsText = PlanTreePrinter.Print(plan);
            ucExecuteResults er         = new ucExecuteResults(agent, planAsText, pd, planningTime, valid);

            er.SelectedGoalAchievementTime += Er_SelectedGoalAchievementTime;
            er.CloseTab   += Er_CloseTab;
            er.AddtoFinal += Er_AddtoFinal;
            TabPage tp = new TabPage();

            tp.Text = "agent " + agent.ToString();
            tp.Controls.Add(er);
            tcResults.TabPages.Add(tp);
        }
Esempio n. 4
0
 public PlanResult(Constant agent, ConditionalPlanTreeNode plan, TimeSpan planningTime, bool valid,
                   List <KeyValuePair <Predicate, int> > goalsCompletionTime, List <Action> reqActions, Domain d, Problem p,
                   Domain general_d, Problem general_p)
 {
     m_planningAgent  = agent;
     Plan             = plan;
     PlanningTime     = planningTime;
     Valid            = valid;
     m_agentDomain    = d;
     m_agentProblem   = p;
     m_generalDomain  = general_d;
     m_generalProblem = general_p;
     // The plan generated under the following variables..
     this.goalsCompletionTime = goalsCompletionTime;
     this.reqActions          = reqActions;
 }
Esempio n. 5
0
        public void TestPrint2()
        {
            ConditionalPlanTreeNode cptn1 = new ConditionalPlanTreeNode();

            Assert.AreEqual(PlanTreePrinter.Print(cptn1), "");
        }