Exemplo n.º 1
0
        public static void ReadAgentFiles(DirectoryInfo dir, string sOutputFile)
        {
            Console.WriteLine("Reading files " + dir.Name);
            List <string> lDomainFiles  = new List <string>();
            List <string> lProblemFiles = new List <string>();

            foreach (FileInfo fi in dir.GetFiles())
            {
                if (fi.Name.Contains("domain"))
                {
                    lDomainFiles.Add(fi.FullName);
                }
                if (fi.Name.Contains("problem"))
                {
                    lProblemFiles.Add(fi.FullName);
                }
            }
            //try
            {
                Domain.ResetStaticVar();
                List <Domain>  lDomains  = new List <Domain>();
                List <Problem> lProblems = new List <Problem>();
                Domain         dJoint    = null;
                Problem        pJoint    = null;
                Runner.ReadAgentFiles(lDomainFiles, lProblemFiles, lDomains, lProblems);
                GetJointDomain(lDomains, lProblems, out dJoint, out pJoint);
                pdbPath = @"PdbFiles/" + dir.Parent.Name;
                if (!Directory.Exists(pdbPath))
                {
                    Directory.CreateDirectory(pdbPath);
                }
                pdbPath += "/" + dir.Name + ".pdb";
                List <Agent>  agents = null;
                List <string> lPlan  = SolveFactored(lDomains, lProblems, ref agents, dJoint);
                //Program.projResults.WriteLine(
                if (lPlan != null)
                {
                    if (Program.VerifyPlan(dJoint, pJoint, lPlan))
                    {
                        Program.PlanMakeSpan = Program.MaxMakespanCalculation(agents, lPlan, dJoint);
                        Program.WritePlanToFile(lPlan, sOutputFile);
                        Program.WriteResults(dir.Name, " success");
                    }
                    else
                    {
                        Program.WriteResults(dir.Name, " plan verification failed - could not solve the problem :(");
                    }
                    Console.WriteLine();
                }
                else
                {
                    Program.WritePlanToFile(new List <string>(), sOutputFile);
                    Program.WriteResults(dir.Name, " fail, plan is null");
                }
            }
            //catch (Exception e)
            {
                //WriteResults(dir.Name , " fail, " + e.Message + ", " + e.StackTrace);
            }
        }
Exemplo n.º 2
0
        /**
         * The starting point of the program.
         **/
        static void Main(string[] args)
        {
            Console.WriteLine("Running configuration " + highLevelPlanerType);

            // CASE 0: Run on default problem and default output path
            if (args.Length == 0)
            {
                swResults = new StreamWriter(@"Results.txt", false);
                swResults.Close();
                string sPath =
                    Directory.GetCurrentDirectory() + @"\..\..\benchmarks\" + defaultProblem;

                // RunUsingProcesses(new DirectoryInfo(sPath), "Plan.txt");
                Runner.ParseAll(new DirectoryInfo(sPath), "Plan.txt");
            }
            // CASE 1: Run on a given problem and default output path
            else if (args.Length == 1)
            {
                Runner.ParseAll(new DirectoryInfo(args[0]), outputPath);
            }
            // CASE 2: Run on a given problem and output results into a given path
            else if (args.Length == 2)
            {
                if (args[1][args[1].Length - 1] == '\'')
                {
                    args[1] = args[1].Remove(args[1].Length - 1);
                }
                outputPath = args[1];
                Runner.ParseAll(new DirectoryInfo(args[0]), args[1]);
            }
            // CASE 3: Run on a specific given set of problems
            else
            {
                List <string> lDomainFiles  = new List <string>();
                List <string> lProblemFiles = new List <string>();
                for (int i = 0; i < args.Length - 1; i += 2)
                {
                    lDomainFiles.Add(args[i]);
                    lProblemFiles.Add(args[1]);
                }
                try
                {
                    List <Domain>  lDomains  = new List <Domain>();
                    List <Problem> lProblems = new List <Problem>();
                    Runner.ReadAgentFiles(lDomainFiles, lProblemFiles, lDomains, lProblems);
                    List <Agent>  agents = null;
                    List <string> lPlan  = Runner.SolveFactored(lDomains, lProblems, ref agents, null);
                    if (lPlan != null)
                    {
                        WritePlanToFile(lPlan, args[args.Length - 1] + "/Plan.txt");

                        Console.WriteLine();
                    }
                    WriteResults("?", " success");
                }
                catch (Exception e)
                {
                    WriteResults("?", " fail " + e.Message + ", " + e.StackTrace);
                }
            }
        }