Exemple #1
0
        public virtual JObject CreateJson(IList <InputProgram> pddlInputProgram)
        {
            string problem = "";
            string domain  = "";

            foreach (InputProgram ip in pddlInputProgram)
            {
                if (!(ip is PDDLInputProgram))
                {
                    continue;
                }

                PDDLInputProgram pip = (PDDLInputProgram)ip;
                switch (pip.ProgramsType)
                {
                case PDDLProgramType.DOMAIN:
                    domain += pip.Programs + pip.Separator;
                    domain += GetFromFile(pip.FilesPaths, pip.Separator);
                    break;

                case PDDLProgramType.PROBLEM:
                    problem += pip.Programs + pip.Separator;
                    problem += GetFromFile(pip.FilesPaths, pip.Separator);
                    break;

                default:
                    throw new PDDLException("Program type : " + pip.ProgramsType + " not valid.");
                }
            }

            if (problem.Equals(""))
            {
                throw new PDDLException("Problem file not specified");
            }
            if (domain.Equals(""))
            {
                throw new PDDLException("Domain file not specified");
            }

            JObject obj = new JObject();

            obj.Add("problem", problem);
            obj.Add("domain", domain);

            return(obj);
        }
Exemple #2
0
        public virtual string CreateJson(IList <InputProgram> pddlInputProgram)
        {
            string problem = "";
            string domain  = "";

            foreach (InputProgram ip in pddlInputProgram)
            {
                if (!(ip is PDDLInputProgram))
                {
                    continue;
                }

                PDDLInputProgram pip = (PDDLInputProgram)ip;
                switch (pip.ProgramsType)
                {
                case PDDLProgramType.DOMAIN:
                    domain += pip.Programs + pip.Separator;
                    domain += GetFromFile(pip.FilesPaths, pip.Separator);
                    break;

                case PDDLProgramType.PROBLEM:
                    problem += pip.Programs + pip.Separator;
                    problem += GetFromFile(pip.FilesPaths, pip.Separator);
                    break;

                default:
                    throw new PDDLException("Program type : " + pip.ProgramsType + " not valid.");
                }
            }

            if (problem.Equals(""))
            {
                throw new PDDLException("Problem file not specified");
            }
            if (domain.Equals(""))
            {
                throw new PDDLException("Domain file not specified");
            }

            return("{\"problem\":\"" + Escape(problem) + "\", \"domain\":\"" + Escape(domain) + "\"}");;
        }
        private void Test(int[] results_sizes, string instance_name)
        {
            string instance_path = base_path + instance_name + Path.DirectorySeparatorChar;

            Console.WriteLine("Testing " + results_sizes.Length + " files for " + instance_path);

            for (int i = 1; i <= results_sizes.Length; i++)
            {
                try
                {
                    plan  = null;
                    @lock = new CountdownEvent(1);
                    Handler handler = new DesktopHandler(new SPDDesktopService());

                    Console.WriteLine();

                    InputProgram inputProgramDomain = new PDDLInputProgram(PDDLProgramType.DOMAIN);

                    inputProgramDomain.AddFilesPath(instance_path + "domain.pddl");

                    InputProgram inputProgramProblem = new PDDLInputProgram(PDDLProgramType.PROBLEM);
                    string       problem             = instance_path + "p" + (i < 10 ? "0" : "") + i + ".pddl";

                    Console.WriteLine(problem);
                    Assert.IsTrue(File.Exists(problem), "File not found: " + problem);
                    inputProgramProblem.AddFilesPath(problem);
                    handler.AddProgram(inputProgramDomain);
                    handler.AddProgram(inputProgramProblem);
                    PDDLMapper.Instance.RegisterClass(typeof(PickUp));
                    Assert.IsNull(plan);
                    handler.StartAsync(new CallbackAction(o =>
                    {
                        if (!(o is Plan))
                        {
                            return;
                        }

                        plan = (Plan)o;

                        foreach (embasp.languages.pddl.Action action in plan.Actions)
                        {
                            Console.Write(action.Name + ",");
                        }

                        @lock.Signal();
                    }));
                    @lock.Wait(new TimeSpan(0, 0, 0, 0, 15000));
                    Assert.IsNotNull(plan);

                    if (results_sizes[i - 1] != 0)
                    {
                        Assert.IsTrue(String.IsNullOrEmpty(plan.ErrorsString) || plan.ErrorsString.ToLower().Contains("server busy"), "Found error in the Plan " + problem + "\n" + plan.ErrorsString);
                    }

                    if (plan.ErrorsString.ToLower().Contains("server busy."))
                    {
                        Console.WriteLine("[WARNING] Server busy occurred!");
                    }

                    Assert.AreEqual(results_sizes[i - 1], plan.Actions.Count);

                    foreach (object obj in plan.ActionsObjects)
                    {
                        if (obj is PickUp)
                        {
                            PickUp pickUp = (PickUp)obj;
                            Console.WriteLine(pickUp.getBlock());
                        }
                    }

                    Thread.Sleep(500);
                }
                catch (Exception e)
                {
                    Assert.Fail(e.Message);
                }
            }

            Console.WriteLine();
        }