Exemplo n.º 1
0
 public ActionType Run(TGameState initialState, OpertorsMethodType OpertorsFunc1, OpertorsMethodType OpertorsFunc2,
                       GoalMethodType cuttFunc, HuristicMethodType evalFunc)
 {
     _cuffOFFunc = cuttFunc;
     _Operators1 = OpertorsFunc1;
     _Operators2 = OpertorsFunc2;
     _Eval       = evalFunc;
     return(Run(initialState));
 }
Exemplo n.º 2
0
        public override SearchPath Run(TSearchState initialState, OpertorsMethodType releventOpertorsFunc,
                                       GoalMethodType goalFunc, HuristicMethodType huristicFunc)
        {
            init(initialState);
            while (!openSet.IsEmpty && !toStop())
            {
                var current = openSet.DequeueItem();
                if (goalFunc(current))
                {
                    return(reconstruct_path(current));
                }

                closedSet.Add(current);
                ++Expansations;
                var operators = releventOpertorsFunc(current);
                if (operators == null)
                {
                    operators = new ActionsCollection();
                }
                foreach (var opertor in operators)
                {
                    var neighboorStateAndCost = opertor(current);
                    var neighboor             = neighboorStateAndCost.State;

                    //if the state exists at the closedSet it means  that is have a better f already
                    // so no need to calculate the huristic
                    if (closedSet.Contains(neighboor))
                    {
                        continue;
                    }

                    double gValue = neighboorStateAndCost.Cost + g[current];
                    double fValue = gValue + huristicFunc(neighboor);
                    SearchStateAndAction stateAndAction = new SearchStateAndAction()
                    {
                        state = current, action = opertor
                    };
                    HandleDuplicatesInOpenSet(neighboor, gValue, fValue, stateAndAction);
                }
            }
            return(null);
        }
        public override SearchPath Run(TSeachState initialState, OpertorsMethodType releventOpertorsFunc, GoalMethodType goalFunc, HuristicMethodType huristicFunc)
        {
            var path = base.Run(initialState, releventOpertorsFunc, goalFunc, huristicFunc);

            if (path == null)
            {
                var res = openSet.DequeueItem();
                return(reconstruct_path(res));
            }
            else
            {
                return(path);
            }
        }
Exemplo n.º 4
0
 public abstract SearchPath Run(TSearchState initialState, OpertorsMethodType releventOpertorsFunc,
                                GoalMethodType goalFunc, HuristicMethodType huristicFunc);