예제 #1
0
        public List <IPlan> Search(IPlanner IP, int k, float cutoff)
        {
            var Solutions = new List <IPlan>();

            var watch = System.Diagnostics.Stopwatch.StartNew();

            while (Frontier.Count > 0)
            {
                var plan = Frontier.Dequeue();
                IP.Expanded++;
                var flaw = plan.Flaws.Next();
                Console.WriteLine(plan.Decomps);
                if (IP.Console_log)
                {
                    Console.WriteLine(plan.ToStringOrdered());
                    Console.WriteLine(flaw);
                }

                // Termination criteria
                if (flaw == null)
                {
                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;

                    Solutions.Add(plan);
                    if (Solutions.Count >= k)
                    {
                        IP.WriteToFile(elapsedMs, plan as Plan);

                        return(Solutions);
                    }
                    continue;
                }

                if (watch.ElapsedMilliseconds > cutoff)
                {
                    watch.Stop();
                    IP.WriteToFile(watch.ElapsedMilliseconds, plan as Plan);
                    return(null);
                }

                var frontierCount = Frontier.Count;

                if (flaw.Ftype == Enums.FlawType.Link)
                {
                    IP.RepairThreat(plan, flaw as ThreatenedLinkFlaw);
                }

                else if (flaw.Ftype == Enums.FlawType.Condition)
                {
                    IP.AddStep(plan, flaw as OpenCondition);
                    IP.Reuse(plan, flaw as OpenCondition);
                }
            }

            return(null);
        }
예제 #2
0
        public List <IPlan> Search(IPlanner IP, int k, float cutoff)
        {
            var watch     = System.Diagnostics.Stopwatch.StartNew();
            var Solutions = new List <IPlan>();

            while (Frontier.Count > 0)
            {
                var plan = Frontier.Dequeue();

                IP.Expanded++;

                if (IP.Console_log)
                {
                    Console.WriteLine(plan);
                }

                if (plan.CurrentState.Satisfies(plan.Goal.Predicates))
                {
                    // Termination criteria
                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;
                    Solutions.Add(plan);
                    if (Solutions.Count >= k)
                    {
                        Console.WriteLine(IP.Open.ToString() + ", " + IP.Expanded.ToString());
                        return(Solutions);
                    }
                    continue;
                }

                if (watch.ElapsedMilliseconds > cutoff)
                {
                    watch.Stop();
                    Console.WriteLine(IP.Open.ToString() + ", " + IP.Expanded.ToString());
                    return(null);
                }

                IP.AddStep(plan);
            }

            return(null);
        }
예제 #3
0
        public List <IPlan> Search(IPlanner IP, int k, float cutoff)
        {
            var Solutions = new List <IPlan>();

            var watch = System.Diagnostics.Stopwatch.StartNew();

            while (Frontier.Count > 0)
            {
                var plan = Frontier.Dequeue();
                //if (plan.ID.Equals("135a7a13a25a51ri65ri87a189a585a1277a2965a10239d15043a44047r62295ri"))
                //if (plan.ID.Equals("1313a61a76405a") || plan.ID.Equals("1313a61a76407a")
                //    || plan.ID.Equals("1313a61a76409a")
                //    || plan.ID.Equals("1313a61a76411a")
                //    || plan.ID.Equals("1313a61a76413a")
                //    || plan.ID.Equals("1313a61a76415a"))//39709a"))
                //{
                //    Console.WriteLine("Here");
                //}
                if (plan.ID.Equals("016a"))
                {
                    Console.WriteLine("Here");
                }
                IP.Expanded++;
                var flaw = plan.Flaws.Next();
                Console.WriteLine(plan.Decomps);
                if (IP.Console_log)
                {
                    //Console.WriteLine(plan.ToStringOrdered());
                    //Console.WriteLine(plan.ToStringOrdered());
                    //Console.WriteLine(flaw);
                }

                // Termination criteria
                if (flaw == null)
                {
                    if (onlyStopOnDepth)
                    {
                        if (plan.Hdepth == 0)
                        {
                            continue;
                        }
                    }

                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;

                    Solutions.Add(plan);
                    if (Solutions.Count >= k)
                    {
                        IP.WriteToFile(elapsedMs, plan as Plan);
                        IP.WriteTimesToFile();
                        return(Solutions);
                    }
                    continue;
                }

                if (watch.ElapsedMilliseconds > cutoff)
                {
                    watch.Stop();
                    IP.WriteToFile(watch.ElapsedMilliseconds, plan as Plan);
                    IP.WriteTimesToFile();
                    return(null);
                }

                var frontierCount = Frontier.Count;

                if (flaw.Ftype == Enums.FlawType.Link)
                {
                    IP.RepairThreat(plan, flaw as ThreatenedLinkFlaw);
                }

                else if (flaw.Ftype == Enums.FlawType.Condition)
                {
                    var beforeAddStep = watch.ElapsedMilliseconds;
                    IP.AddStep(plan, flaw as OpenCondition);
                    IP.LogTime("addStep", watch.ElapsedMilliseconds - beforeAddStep);

                    var beforeReuseStep = watch.ElapsedMilliseconds;
                    IP.Reuse(plan, flaw as OpenCondition);
                    IP.LogTime("reuseStep", watch.ElapsedMilliseconds - beforeReuseStep);
                }
            }

            return(null);
        }