protected int Generate(double maxUncert, NNBaseHeuristic nn, int maxSteps = 1000)
        {
            IState state = Goal();

            Operation?pop = null;

            int count = 0;

            double uncert = 0;

            while (uncert < maxUncert)
            {
                count++;

                if (count >= maxSteps)
                {
                    break;
                }

                List <Edge> children = Expand(state);

                if (pop != null)
                {
                    children = children.Where(x => !x.OP.Equals(pop)).ToList();
                }

                SummaryStatistics[] summaryStatistics = nn.GetSummaryStatistics(children.Select(x => x.Child).ToArray());

                double[] stateUncerts = new double[summaryStatistics.Length];

                for (int i = 0; i < summaryStatistics.Length; i++)
                {
                    stateUncerts[i] = summaryStatistics[i].SDModel;
                }

                double norm = stateUncerts.Sum(x => Math.Exp(x));

                double[] weights = stateUncerts.Select(x => Math.Exp(x) / norm).ToArray();

                int index = Global.Sample(weights);

                Edge e = children[index];

                state = e.Child;

                uncert = Math.Max(uncert, stateUncerts[index]);

                pop = e.POP;
            }

            Console.WriteLine("steps: " + count);

            this.init = state.Arr;

            return(count);
        }
Example #2
0
 public DomainContainer(NNBaseHeuristic heuristic, double maxUncert, int maxSteps = 1000)
 {
     if (Global.DOMAINTYPE == typeof(SlidingPuzzle.SlidingPuzzle))
     {
         domain = new SlidingPuzzle.SlidingPuzzle(heuristic, maxUncert, maxSteps);
     }
     else if (Global.DOMAINTYPE == typeof(PancakePuzzle.PancakePuzzle))
     {
         domain = new PancakePuzzle.PancakePuzzle(heuristic, maxUncert, maxSteps);
     }
     else if (Global.DOMAINTYPE == typeof(BlocksWorld.BlocksWorld))
     {
         domain = new BlocksWorld.BlocksWorld(heuristic, maxUncert, maxSteps);
     }
     else
     {
         throw new ArgumentOutOfRangeException();
     }
 }
 public BlocksWorld(NNBaseHeuristic heuristic, double maxUncert, int maxSteps = 1000) : base(heuristic, null)
 {
     this.numSteps = Generate(maxUncert, heuristic, maxSteps);
 }
 public PancakePuzzle(NNBaseHeuristic heuristic, double maxUncert, int maxSteps = 1000) : base(heuristic, null)
 {
     this.numSteps = Generate(maxUncert, heuristic, maxSteps);
 }