コード例 #1
0
        public List <string> FDPlan(Domain d, Problem p, State curentState, Formula goal, List <Action> privateActions, int cMaxMilliseconds, out bool bUnsolvable)
        {
            RunUtils.KillPlanners();
            List <string> ffLplan = new List <string>();
            List <string> lPlan   = new List <string>();

            File.Delete("plan.txt");
            File.Delete("sas_plan");

            if (privateActions != null)
            {
                d.Actions = privateActions;
            }
            if (goal != null)
            {
                p.Goal = goal;
            }

            MemoryStream msDomain    = d.WriteSimpleDomain();
            MemoryStream problem_M_S = p.WriteSimpleProblem(curentState);

            //for now, saving files in the working directory

            StreamWriter swDomainFile = new StreamWriter("dFD.pddl");
            StreamReader srDomain     = new StreamReader(msDomain);

            swDomainFile.Write(srDomain.ReadToEnd());
            swDomainFile.Close();

            StreamWriter swProblemFile = new StreamWriter("pFD.pddl");
            StreamReader srProblem     = new StreamReader(problem_M_S);

            swProblemFile.Write(srProblem.ReadToEnd());
            swProblemFile.Close();


            problem_M_S.Position = 0;
            msDomain.Position    = 0;

            bUnsolvable = false;

            if (RunFD("./", cMaxMilliseconds))
            {
                return(ReadPlan("./"));
            }
            return(null);
        }
        public static List <string> PdbFFPlan(Domain d, Problem p, State curentState, Formula goal, List <Action> privateActions, int cMaxMilliseconds, out bool bUnsolvable)
        {
            Program.KillPlanners();
            List <string> ffLplan = new List <string>();
            List <string> lPlan   = new List <string>();


            if (privateActions != null)
            {
                d.Actions = privateActions;
            }
            if (goal != null)
            {
                p.Goal = goal;
            }

            MemoryStream msDomain    = d.WriteSimpleDomain();
            MemoryStream problem_M_S = p.WriteSimpleProblem(curentState);


            //StreamWriter swDomainFile = new StreamWriter(@"D:\Dropbox-users\shanigu\Dropbox\Dropbox\privacyPreserving\Competition\all\factored\testd.pddl");
            // StreamReader srDomain = new StreamReader(msDomain);
            // swDomainFile.Write(srDomain.ReadToEnd());
            // swDomainFile.Close();

            // StreamWriter swProblemFile = new StreamWriter(@"D:\Dropbox-users\shanigu\Dropbox\Dropbox\privacyPreserving\Competition\all\factored\testp.pddl");
            //  StreamReader srProblem = new StreamReader(problem_M_S);
            // swProblemFile.Write(srProblem.ReadToEnd());
            // swProblemFile.Close();


            problem_M_S.Position = 0;
            msDomain.Position    = 0;



            Process planer = new Process();

            //planer.StartInfo.WorkingDirectory = @"C:\project\Planning 2 new\PDDLTEST\temp";
            planer.StartInfo.FileName = "ff.exe";
            //planer.StartInfo.Arguments += "-o dT.pddl -f pT.pddl";

            FFOutput = "";

            planer.StartInfo.UseShellExecute        = false;
            planer.StartInfo.RedirectStandardInput  = true;
            planer.StartInfo.RedirectStandardOutput = true;
            planer.OutputDataReceived += new DataReceivedEventHandler(FFOutputHandler);
            planer.Start();
            planer.BeginOutputReadLine();
            StreamReader srOps = new StreamReader(msDomain);


            string domain = srOps.ReadToEnd();

            planer.StandardInput.Write(domain);
            srOps.Close();
            BinaryWriter b = new BinaryWriter(planer.StandardInput.BaseStream);

            b.Write('\0');

            StreamReader srFct   = new StreamReader(problem_M_S);
            string       problem = srFct.ReadToEnd();

            planer.StandardInput.Write(problem);
            srFct.Close();

            b.Write('\0');
            //planer.StandardInput.Flush();

            planer.StandardInput.Close();

            if (cMaxMilliseconds != -1)
            {
                if (!planer.WaitForExit(cMaxMilliseconds))//2 minutes max
                {
                    planer.Kill();
                    bUnsolvable = false;
                    return(null);
                }
            }
            else
            {
                planer.WaitForExit();
            }
            planer.Close();
            //string sOutput = planer.StandardOutput.ReadToEnd();
            Thread.Sleep(50);
            string sOutput = FFOutput;
            //throw new NotImplementedException();
            //Console.WriteLine(sOutput);
            MemoryStream planMs = new MemoryStream();

            if (sOutput.Contains("found legal plan as follows"))
            {
                string sPlan = sOutput.Substring(sOutput.IndexOf("found legal plan as follows"));
                sPlan = sPlan.Replace("found legal plan as follows", "").Trim();
                string[] asPlan     = sPlan.Split('\n');
                string   sFinalPlan = "";
                for (int i = 0; i < asPlan.Length; i++)
                {
                    if (!asPlan[i].Contains(":"))
                    {
                        break;
                    }
                    if (asPlan[i].Contains("time spent:"))
                    {
                        break;
                    }
                    sFinalPlan += asPlan[i].Substring(asPlan[i].IndexOf(':') + 2).Trim() + "\n";
                }
                StreamWriter sw = new StreamWriter(planMs);
                sw.WriteLine(sFinalPlan);
                sw.Close();
                bUnsolvable = false;
            }
            else
            {
                if (sOutput.Contains("goal can be simplified to TRUE"))
                {
                    ffLplan     = new List <string>();
                    bUnsolvable = false;
                    return(ffLplan);
                }
                else if (sOutput.Contains("goal can be simplified to FALSE"))
                {
                    ffLplan     = null;
                    bUnsolvable = true;
                    return(null);
                }
                else
                {
                    ffLplan     = null;
                    bUnsolvable = false;
                    return(null);
                }
            }


            lPlan   = ReadPlan(new MemoryStream(planMs.ToArray()));
            ffLplan = lPlan;
            return(lPlan);
        }
コード例 #3
0
        public List <string> Plan(string agent, bool bUseFF, bool bUseFD, Domain d, Problem p, State curentState, Formula goal, List <Action> privateActions, int cMaxMilliseconds, out bool bUnsolvable)
        {
            //Program.KillPlanners();
            List <string> lPlan = null;


            if (privateActions != null)
            {
                d.Actions = privateActions;
            }
            if (goal != null)
            {
                p.Goal = goal;
            }

            string  sFDPath = @"C:\cygwin\home\shlomi\FastDownward\src\";
            Process pFF = null, pFD = null;

            if (bUseFF)
            {
                pFF = RunFF(d.WriteSimpleDomain(), p.WriteSimpleProblem(curentState));
            }
            if (bUseFD)
            {
                pFD = RunFD(agent, sFDPath, d.WriteSimpleDomain(), p.WriteSimpleProblem(curentState));
            }
            bUnsolvable = false;
            bool bFFDone = false, bFDDone = false;

            Process[] process;
            if (bUseFF && !bUseFD)
            {
                process = new Process[] { pFF }
            }
            ;
            else
            if (!bUseFF && bUseFD)
            {
                process = new Process[] { pFD }
            }
            ;
            else
            {
                process = new Process[] { pFF, pFD }
            };

            if (WaitForProcesses(process, cMaxMilliseconds, out bFFDone, out bFDDone))
            {
                if (bFFDone)
                {
                    //  Console.WriteLine("Plan found by FF");
                    Thread.Sleep(200);
                    lPlan = ReadFFPlan(process[0].Id, out bUnsolvable);
                    KillAll(process.ToList());
                }
                else if (bFDDone)
                {
                    Console.WriteLine("Plan found by FD");
                    Thread.Sleep(100);
                    lPlan = ReadPlan(@"C:\cygwin\home\shlomi\");
                    KillAll(process.ToList());
                }
                return(lPlan);
            }
            return(null);
        }