Exemplo n.º 1
0
        public virtual void search(State s)
        {
            branchingCount = 1;
            branchingSum   = 1;
            maxGVal        = 0;

            printMessage("--- search started ---", quiet);
            State currentState = null;

            predecessor = new Dictionary <State, State>();
            gValues.Clear();
            openNodes.clear();
            start = DateTime.Now;
            openNodes.insert(0, s);
            gValues.Add(s, new StateInformation());
            predecessor.Add(s, null);
            int steps = -1;

            while (openNodes.size() > 0)
            {
                steps++;

                if (steps % 10000 == 0)
                {
                    printSearchStats(quiet);
                }

                currentState = openNodes.removeMin();
                if (gValues[currentState].isClosed)
                {
                    continue;
                }
                addToClosedList(currentState);
                if (currentState.isFinal())
                {
                    DateTime end = DateTime.Now;
                    searchTime = (end - start);
                    int GVAL = gValues[currentState].gValue;
                    printMessage("search ended in " + searchTime.TotalSeconds + " seconds, plan length: " + GVAL, quiet);
                    printSearchStats(quiet);
                    this.result       = extractSolution(currentState);
                    this.solutionCost = GVAL;
                    printMessage("--- search ended ---", quiet);
                    return;
                }
                int currentGValue = gValues[currentState].gValue;

                currentState.getSuccessors(successors);
                branchingSum += successors.Count;
                branchingCount++;
                foreach (var item in successors)
                {
                    State state = item.state;
                    int   gVal  = currentGValue + item.cost;
                    addToOpenList(state, gVal, currentState);
                }
            }
            printMessage("No solution exists.", quiet);
        }