示例#1
0
        public override List <int> runSimulation(Plan p, int maxSimulationLength)
        {
            this.d.initialState = p.currentState;
            engine.search(true);
            var sol = engine.getSolution();

            foreach (var item in sol)
            {
                p.addAction(d.operators[item]);
            }
            return(sol);
        }
示例#2
0
        /// <summary>
        /// Vyuziva turnajovou selekci
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public override List <int> runSimulation(Plan p, int maxSimulationLength)
        {
            this.maxLenght = maxSimulationLength;
            simulation.Clear();
            State state = p.currentState;

            for (int i = 0; i < maxLenght; i++)
            {
                if (dom.isGoalState(state))
                {
                    break;
                }
                var successors = dom.getSuccessors(state);
                if (successors.Count <= 0)
                {
                    return(simulation);
                }
                int    opIndex       = -1;
                double opPerformance = double.MaxValue;
                while (opIndex == -1)
                {
                    foreach (var item in successors.Keys)
                    {
                        if (Program.r.NextDouble() <= tournamentSizeProportional)
                        {
                            if (opPerformance > getOperatorPerformance(item.orderIndex))
                            {
                                opPerformance = getOperatorPerformance(item.orderIndex);
                                opIndex       = item.orderIndex;
                            }
                        }
                    }
                }

                simulation.Add(opIndex);
                p.addAction(dom.operators[opIndex]);
                state = Operator.apply(dom.operators[opIndex], state);
            }
            return(simulation);
        }
示例#3
0
文件: MCTSSolver.cs 项目: vvancak/ai
        public TreeNode selectSuccesor(Plan simulPlan)
        {
            if (this.isLeaf)
            {
                return(this);
            }
            if (this.succesors.Count == 0)
            {
                removeNode();
                simulPlan.removeLastAction();
                return(parrent.selectSuccesor(simulPlan));
            }
            double   max          = -10;
            TreeNode bestSuccesor = null;

            foreach (var item in succesors)
            {
                if (item.isFinished)
                {
                    continue;
                }
                double val = item.eval();
                if (val > max)
                {
                    max          = val;
                    bestSuccesor = item;
                }
            }
            if (bestSuccesor == null)
            {
                this.isFinished = true;
                bestSuccesor    = succesors[0];
            }
            simulPlan.addAction(dom.operators[bestSuccesor.action]);
            return(bestSuccesor.selectSuccesor(simulPlan));
        }
示例#4
0
        public override List <int> runSimulation(Plan p, int maxSimulationLength)
        {
            simulation.Clear();
            State state = p.currentState;

            for (int i = 0; i < maxLength; i++)
            {
                if (dom.isGoalState(state))
                {
                    break;
                }
                var successors = dom.getSuccessors(state);
                if (successors.Count == 0)
                {
                    break;
                }
                Operator op = successors.Keys.ElementAt(Program.r.Next(successors.Keys.Count));
                simulation.Add(op.orderIndex);
                p.addAction(op);
                state = Operator.apply(op, state);
            }
            this.finalState = state;
            return(simulation);
        }